You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
5.6 KiB
1 line
5.6 KiB
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { declare } from \"@babel/helper-plugin-utils\";\nimport { types as t } from \"@babel/core\";\nimport type { NodePath } from \"@babel/core\";\n\nfunction needsWrapping(node: t.Node): boolean {\n if (t.isLiteral(node) && !t.isTemplateLiteral(node)) {\n return false;\n }\n\n if (\n t.isCallExpression(node) ||\n t.isOptionalCallExpression(node) ||\n t.isNewExpression(node)\n ) {\n return needsWrapping(node.callee) || node.arguments.some(needsWrapping);\n }\n\n if (t.isTemplateLiteral(node)) {\n return node.expressions.some(needsWrapping);\n }\n\n if (t.isTaggedTemplateExpression(node)) {\n return needsWrapping(node.tag) || needsWrapping(node.quasi);\n }\n\n if (t.isArrayExpression(node)) {\n return node.elements.some(needsWrapping);\n }\n\n if (t.isObjectExpression(node)) {\n return node.properties.some(prop => {\n if (t.isObjectProperty(prop)) {\n return (\n needsWrapping(prop.value) ||\n (prop.computed && needsWrapping(prop.key))\n );\n }\n if (t.isObjectMethod(prop)) {\n return false;\n }\n return false;\n });\n }\n\n if (t.isMemberExpression(node) || t.isOptionalMemberExpression(node)) {\n return (\n needsWrapping(node.object) ||\n (node.computed && needsWrapping(node.property))\n );\n }\n\n if (\n t.isFunctionExpression(node) ||\n t.isArrowFunctionExpression(node) ||\n t.isClassExpression(node)\n ) {\n return false;\n }\n\n if (t.isThisExpression(node)) {\n return false;\n }\n\n if (t.isSequenceExpression(node)) {\n return node.expressions.some(needsWrapping);\n }\n\n // Is an identifier, or anything else not covered above\n return true;\n}\n\nfunction wrapInitializer(\n path: NodePath<t.ClassProperty | t.ClassPrivateProperty>,\n) {\n const { value } = path.node;\n\n if (value && needsWrapping(value)) {\n path.node.value = t.callExpression(\n t.arrowFunctionExpression([], value),\n [],\n );\n }\n}\n\nexport default declare(api => {\n api.assertVersion(REQUIRED_VERSION(\"^7.16.0\"));\n\n return {\n name: \"plugin-bugfix-safari-class-field-initializer-scope\",\n\n visitor: {\n ClassProperty(path) {\n wrapInitializer(path);\n },\n ClassPrivateProperty(path) {\n wrapInitializer(path);\n },\n },\n };\n});\n"],"names":["needsWrapping","node","t","isLiteral","isTemplateLiteral","isCallExpression","isOptionalCallExpression","isNewExpression","callee","arguments","some","expressions","isTaggedTemplateExpression","tag","quasi","isArrayExpression","elements","isObjectExpression","properties","prop","isObjectProperty","value","computed","key","isObjectMethod","isMemberExpression","isOptionalMemberExpression","object","property","isFunctionExpression","isArrowFunctionExpression","isClassExpression","isThisExpression","isSequenceExpression","wrapInitializer","path","callExpression","arrowFunctionExpression","declare","api","assertVersion","name","visitor","ClassProperty","ClassPrivateProperty"],"mappings":";;;;;;;AAIA,SAASA,aAAaA,CAACC,IAAY,EAAW;AAC5C,EAAA,IAAIC,UAAC,CAACC,SAAS,CAACF,IAAI,CAAC,IAAI,CAACC,UAAC,CAACE,iBAAiB,CAACH,IAAI,CAAC,EAAE;AACnD,IAAA,OAAO,KAAK,CAAA;AACd,GAAA;EAEA,IACEC,UAAC,CAACG,gBAAgB,CAACJ,IAAI,CAAC,IACxBC,UAAC,CAACI,wBAAwB,CAACL,IAAI,CAAC,IAChCC,UAAC,CAACK,eAAe,CAACN,IAAI,CAAC,EACvB;AACA,IAAA,OAAOD,aAAa,CAACC,IAAI,CAACO,MAAM,CAAC,IAAIP,IAAI,CAACQ,SAAS,CAACC,IAAI,CAACV,aAAa,CAAC,CAAA;AACzE,GAAA;AAEA,EAAA,IAAIE,UAAC,CAACE,iBAAiB,CAACH,IAAI,CAAC,EAAE;AAC7B,IAAA,OAAOA,IAAI,CAACU,WAAW,CAACD,IAAI,CAACV,aAAa,CAAC,CAAA;AAC7C,GAAA;AAEA,EAAA,IAAIE,UAAC,CAACU,0BAA0B,CAACX,IAAI,CAAC,EAAE;AACtC,IAAA,OAAOD,aAAa,CAACC,IAAI,CAACY,GAAG,CAAC,IAAIb,aAAa,CAACC,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