Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@babel/plugin-transform-duplicate-keys

Package Overview
Dependencies
Maintainers
4
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@babel/plugin-transform-duplicate-keys - npm Package Compare versions

Comparing version
8.0.0-beta.3
to
8.0.0-beta.4
+1
-1
lib/index.js

@@ -11,3 +11,3 @@ import { declare } from '@babel/helper-plugin-utils';

var index = declare(api => {
api.assertVersion("8.0.0-beta.3");
api.assertVersion("^7.0.0-0 || ^8.0.0 || 8.0.0-beta.4");
return {

@@ -14,0 +14,0 @@ name: "transform-duplicate-keys",

@@ -1,1 +0,1 @@

{"version":3,"file":"index.js","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(REQUIRED_VERSION(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"],"names":["getName","key","t","isIdentifier","name","value","toString","declare","api","assertVersion","visitor","ObjectExpression","path","node","plainProps","properties","filter","prop","isSpreadElement","computed","alreadySeenData","Object","create","alreadySeenGetters","alreadySeenSetters","isDuplicate","kind","stringLiteral"],"mappings":";;;AAGA,SAASA,OAAOA,CACdC,GAAwE,EACxE;AACA,EAAA,IAAIC,KAAC,CAACC,YAAY,CAACF,GAAG,CAAC,EAAE;IACvB,OAAOA,GAAG,CAACG,IAAI,CAAA;AACjB,GAAA;AACA,EAAA,OAAOH,GAAG,CAACI,KAAK,CAACC,QAAQ,EAAE,CAAA;AAC7B,CAAA;AAEA,YAAeC,OAAO,CAACC,GAAG,IAAI;EAC5BA,GAAG,CAACC,aAAa,CAAA,cAAoB,CAAC,CAAA;EAEtC,OAAO;AACLL,IAAAA,IAAI,EAAE,0BAA0B;AAEhCM,IAAAA,OAAO,EAAE;MACPC,gBAAgBA,CAACC,IAAI,EAAE;QACrB,MAAM;AAAEC,UAAAA,IAAAA;AAAK,SAAC,GAAGD,IAAI,CAAA;QACrB,MAAME,UAAU,GAAGD,IAAI,CAACE,UAAU,CAACC,MAAM,CACvCC,IAAI,IAAI,CAACf,KAAC,CAACgB,eAAe,CAACD,IAAI,CAAC,IAAI,CAACA,IAAI,CAACE,QAC5C,CAA0C,CAAA;AAU1C,QAAA,MAAMC,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G,GAAGC,KAAC,CAACyB,aAAa,CAACvB,IAAI,CAAC,CAAA;AAClC,WAAA;AACF,SAAA;AACF,OAAA;AACF,KAAA;GACD,CAAA;AACH,CAAC,CAAC;;;;"}
{"version":3,"file":"index.js","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(REQUIRED_VERSION(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"],"names":["getName","key","t","isIdentifier","name","value","toString","declare","api","assertVersion","visitor","ObjectExpression","path","node","plainProps","properties","filter","prop","isSpreadElement","computed","alreadySeenData","Object","create","alreadySeenGetters","alreadySeenSetters","isDuplicate","kind","stringLiteral"],"mappings":";;;AAGA,SAASA,OAAOA,CACdC,GAAwE,EACxE;AACA,EAAA,IAAIC,KAAC,CAACC,YAAY,CAACF,GAAG,CAAC,EAAE;IACvB,OAAOA,GAAG,CAACG,IAAI,CAAA;AACjB,GAAA;AACA,EAAA,OAAOH,GAAG,CAACI,KAAK,CAACC,QAAQ,EAAE,CAAA;AAC7B,CAAA;AAEA,YAAeC,OAAO,CAACC,GAAG,IAAI;EAC5BA,GAAG,CAACC,aAAa,CAAA,oCAAoB,CAAC,CAAA;EAEtC,OAAO;AACLL,IAAAA,IAAI,EAAE,0BAA0B;AAEhCM,IAAAA,OAAO,EAAE;MACPC,gBAAgBA,CAACC,IAAI,EAAE;QACrB,MAAM;AAAEC,UAAAA,IAAAA;AAAK,SAAC,GAAGD,IAAI,CAAA;QACrB,MAAME,UAAU,GAAGD,IAAI,CAACE,UAAU,CAACC,MAAM,CACvCC,IAAI,IAAI,CAACf,KAAC,CAACgB,eAAe,CAACD,IAAI,CAAC,IAAI,CAACA,IAAI,CAACE,QAC5C,CAA0C,CAAA;AAU1C,QAAA,MAAMC,eAAe,GAAGC,MAAM,CAACC,MAAM,CAAC,IAAI,CAAC,CAAA;AAC3C,QAAA,MAAMC,kBAAkB,GAAGF,MAAM,CAACC,MAAM,CAAC,IAAI,CAAC,CAAA;AAC9C,QAAA,MAAME,kBAAkB,GAAGH,MAAM,CAACC,MAAM,CAAC,IAAI,CAAC,CAAA;AAE9C,QAAA,KAAK,MAAML,IAAI,IAAIH,UAAU,EAAE;AAC7B,UAAA,MAAMV,IAAI,GAAGJ,OAAO,CAElBiB,IAAI,CAAChB,GAKP,CAAC,CAAA;UACD,IAAIwB,WAAW,GAAG,KAAK,CAAA;UAEvB,QAAQR,IAAI,CAACS,IAAI;AACf,YAAA,KAAK,KAAK;cACR,IAAIN,eAAe,CAAChB,IAAI,CAAC,IAAImB,kBAAkB,CAACnB,IAAI,CAAC,EAAE;AACrDqB,gBAAAA,WAAW,GAAG,IAAI,CAAA;AACpB,eAAA;AACAF,cAAAA,kBAAkB,CAACnB,IAAI,CAAC,GAAG,IAAI,CAAA;AAC/B,cAAA,MAAA;AACF,YAAA,KAAK,KAAK;cACR,IAAIgB,eAAe,CAAChB,IAAI,CAAC,IAAIoB,kBAAkB,CAACpB,IAAI,CAAC,EAAE;AACrDqB,gBAAAA,WAAW,GAAG,IAAI,CAAA;AACpB,eAAA;AACAD,cAAAA,kBAAkB,CAACpB,IAAI,CAAC,GAAG,IAAI,CAAA;AAC/B,cAAA,MAAA;AACF,YAAA;AACE,cAAA,IACEgB,eAAe,CAAChB,IAAI,CAAC,IACrBmB,kBAAkB,CAACnB,IAAI,CAAC,IACxBoB,kBAAkB,CAACpB,IAAI,CAAC,EACxB;AACAqB,gBAAAA,WAAW,GAAG,IAAI,CAAA;AACpB,eAAA;AACAL,cAAAA,eAAe,CAAChB,IAAI,CAAC,GAAG,IAAI,CAAA;AAChC,WAAA;AAEA,UAAA,IAAIqB,WAAW,EAAE;YAGfR,IAAI,CAACE,QAAQ,GAAG,IAAI,CAAA;YACpBF,IAAI,CAAChB,GAAG,GAAGC,KAAC,CAACyB,aAAa,CAACvB,IAAI,CAAC,CAAA;AAClC,WAAA;AACF,SAAA;AACF,OAAA;AACF,KAAA;GACD,CAAA;AACH,CAAC,CAAC;;;;"}
{
"name": "@babel/plugin-transform-duplicate-keys",
"version": "8.0.0-beta.3",
"version": "8.0.0-beta.4",
"description": "Compile objects with duplicate keys to valid strict ES5",

@@ -20,10 +20,10 @@ "repository": {

"dependencies": {
"@babel/helper-plugin-utils": "^8.0.0-beta.3"
"@babel/helper-plugin-utils": "^8.0.0-beta.4"
},
"peerDependencies": {
"@babel/core": "^8.0.0-beta.3"
"@babel/core": "^7.0.0-0"
},
"devDependencies": {
"@babel/core": "^8.0.0-beta.3",
"@babel/helper-plugin-test-runner": "^8.0.0-beta.3"
"@babel/core": "^8.0.0-beta.4",
"@babel/helper-plugin-test-runner": "^8.0.0-beta.4"
},

@@ -30,0 +30,0 @@ "engines": {