mirror of https://github.com/jkjoy/sunpeiwen.git
1 line
3.8 KiB
Plaintext
1 line
3.8 KiB
Plaintext
{"version":3,"names":["declare","api","assertVersion","name","inherits","syntaxLogicalAssignmentOperators","default","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 syntaxLogicalAssignmentOperators from \"@babel/plugin-syntax-logical-assignment-operators\";\nimport { types as t } from \"@babel/core\";\n\nexport default declare(api => {\n api.assertVersion(7);\n\n return {\n name: \"proposal-logical-assignment-operators\",\n inherits: syntaxLogicalAssignmentOperators.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 );\n },\n },\n };\n});\n"],"mappings":";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