summaryrefslogtreecommitdiff
path: root/node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js.map
blob: 86ce6dbbb4c53d0c8b4fe7091d3cdd9bccf59b3c (plain)
1
{"version":3,"names":["_helperPluginUtils","require","_core","getName","key","t","isIdentifier","name","value","toString","_default","declare","api","assertVersion","visitor","ObjectExpression","path","node","plainProps","properties","filter","prop","isSpreadElement","computed","alreadySeenData","Object","create","alreadySeenGetters","alreadySeenSetters","isDuplicate","kind","stringLiteral","exports","default"],"sources":["../src/index.ts"],"sourcesContent":["import { declare } from \"@babel/helper-plugin-utils\";\nimport { types as t } from \"@babel/core\";\n\nfunction getName(\n  key: t.Identifier | t.StringLiteral | t.NumericLiteral | t.BigIntLiteral,\n) {\n  if (t.isIdentifier(key)) {\n    return key.name;\n  }\n  return key.value.toString();\n}\n\nexport default declare(api => {\n  api.assertVersion(7);\n\n  return {\n    name: \"transform-duplicate-keys\",\n\n    visitor: {\n      ObjectExpression(path) {\n        const { node } = path;\n        const plainProps = node.properties.filter(\n          prop => !t.isSpreadElement(prop) && !prop.computed,\n        ) as (t.ObjectMethod | t.ObjectProperty)[];\n\n        // A property is a duplicate key if:\n        // * the property is a data property, and is preceded by a data,\n        //   getter, or setter property of the same name.\n        // * the property is a getter property, and is preceded by a data or\n        //   getter property of the same name.\n        // * the property is a setter property, and is preceded by a data or\n        //   setter property of the same name.\n\n        const alreadySeenData = Object.create(null);\n        const alreadySeenGetters = Object.create(null);\n        const alreadySeenSetters = Object.create(null);\n\n        for (const prop of plainProps) {\n          const name = getName(\n            // prop must be non-computed\n            prop.key as\n              | t.Identifier\n              | t.StringLiteral\n              | t.NumericLiteral\n              | t.BigIntLiteral,\n          );\n          let isDuplicate = false;\n          // @ts-expect-error prop.kind is not defined in ObjectProperty\n          switch (prop.kind) {\n            case \"get\":\n              if (alreadySeenData[name] || alreadySeenGetters[name]) {\n                isDuplicate = true;\n              }\n              alreadySeenGetters[name] = true;\n              break;\n            case \"set\":\n              if (alreadySeenData[name] || alreadySeenSetters[name]) {\n                isDuplicate = true;\n              }\n              alreadySeenSetters[name] = true;\n              break;\n            default:\n              if (\n                alreadySeenData[name] ||\n                alreadySeenGetters[name] ||\n                alreadySeenSetters[name]\n              ) {\n                isDuplicate = true;\n              }\n              alreadySeenData[name] = true;\n          }\n\n          if (isDuplicate) {\n            // Rely on the computed properties transform to split the property\n            // assignment out of the object literal.\n            prop.computed = true;\n            prop.key = t.stringLiteral(name);\n          }\n        }\n      },\n    },\n  };\n});\n"],"mappings":";;;;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAEA,SAASE,OAAOA,CACdC,GAAwE,EACxE;EACA,IAAIC,WAAC,CAACC,YAAY,CAACF,GAAG,CAAC,EAAE;IACvB,OAAOA,GAAG,CAACG,IAAI;EACjB;EACA,OAAOH,GAAG,CAACI,KAAK,CAACC,QAAQ,CAAC,CAAC;AAC7B;AAAC,IAAAC,QAAA,GAEc,IAAAC,0BAAO,EAACC,GAAG,IAAI;EAC5BA,GAAG,CAACC,aAAa,CAAC,CAAC,CAAC;EAEpB,OAAO;IACLN,IAAI,EAAE,0BAA0B;IAEhCO,OAAO,EAAE;MACPC,gBAAgBA,CAACC,IAAI,EAAE;QACrB,MAAM;UAAEC;QAAK,CAAC,GAAGD,IAAI;QACrB,MAAME,UAAU,GAAGD,IAAI,CAACE,UAAU,CAACC,MAAM,CACvCC,IAAI,IAAI,CAAChB,WAAC,CAACiB,eAAe,CAACD,IAAI,CAAC,IAAI,CAACA,IAAI,CAACE,QAC5C,CAA0C;QAU1C,MAAMC,eAAe,GAAGC,MAAM,CAACC,MAAM,CAAC,IAAI,CAAC;QAC3C,MAAMC,kBAAkB,GAAGF,MAAM,CAACC,MAAM,CAAC,IAAI,CAAC;QAC9C,MAAME,kBAAkB,GAAGH,MAAM,CAACC,MAAM,CAAC,IAAI,CAAC;QAE9C,KAAK,MAAML,IAAI,IAAIH,UAAU,EAAE;UAC7B,MAAM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