1 line
4.1 KiB
Plaintext
1 line
4.1 KiB
Plaintext
{"version":3,"names":["_helperPluginUtils","require","_core","_default","exports","default","declare","api","assertVersion","name","inherits","version","undefined","visitor","AssignmentExpression","path","node","scope","operator","left","right","operatorTrunc","slice","t","LOGICAL_OPERATORS","includes","lhs","cloneNode","isMemberExpression","object","property","computed","memo","maybeGenerateMemoised","assignmentExpression","replaceWith","logicalExpression"],"sources":["../src/index.ts"],"sourcesContent":["import { declare } from \"@babel/helper-plugin-utils\";\nimport { types as t } from \"@babel/core\";\n\nexport default declare(api => {\n api.assertVersion(REQUIRED_VERSION(7));\n\n return {\n name: \"transform-logical-assignment-operators\",\n inherits:\n USE_ESM || IS_STANDALONE || api.version[0] === \"8\"\n ? undefined\n : // eslint-disable-next-line no-restricted-globals\n require(\"@babel/plugin-syntax-logical-assignment-operators\").default,\n\n visitor: {\n AssignmentExpression(path) {\n const { node, scope } = path;\n const { operator, left, right } = node;\n const operatorTrunc = operator.slice(0, -1);\n if (!t.LOGICAL_OPERATORS.includes(operatorTrunc)) {\n return;\n }\n\n const lhs = t.cloneNode(left) as t.Identifier | t.MemberExpression;\n if (t.isMemberExpression(left)) {\n const { object, property, computed } = left;\n const memo = scope.maybeGenerateMemoised(object);\n if (memo) {\n left.object = memo;\n (lhs as t.MemberExpression).object = t.assignmentExpression(\n \"=\",\n t.cloneNode(memo),\n // object must not be Super when `memo` is an identifier\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n object as t.Expression,\n );\n }\n\n if (computed) {\n const memo = scope.maybeGenerateMemoised(property);\n if (memo) {\n left.property = memo;\n (lhs as t.MemberExpression).property = t.assignmentExpression(\n \"=\",\n t.cloneNode(memo),\n // @ts-expect-error todo(flow->ts): property can be t.PrivateName\n property,\n );\n }\n }\n }\n\n path.replaceWith(\n t.logicalExpression(\n // @ts-expect-error operatorTrunc has been tested by t.LOGICAL_OPERATORS\n operatorTrunc,\n lhs,\n t.assignmentExpression(\"=\", left, right),\n ),\n );\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