challenge-algorithms-v2.0-u.../node_modules/@babel/helper-simple-access/lib/index.js.map

1 line
8.2 KiB
Plaintext

{"version":3,"names":["LOGICAL_OPERATORS","assignmentExpression","binaryExpression","cloneNode","identifier","logicalExpression","numericLiteral","sequenceExpression","unaryExpression","simplifyAccess","path","bindingNames","includeUpdateExpression","traverse","simpleAssignmentVisitor","scope","seen","WeakSet","UpdateExpression","exit","arg","get","isIdentifier","localName","node","name","has","getBinding","parentPath","isExpressionStatement","isCompletionRecord","operator","replaceWith","prefix","old","generateUidIdentifierBasedOnNode","varName","push","id","binary","AssignmentExpression","add","left","slice","includes","right"],"sources":["../src/index.ts"],"sourcesContent":["import {\n LOGICAL_OPERATORS,\n assignmentExpression,\n binaryExpression,\n cloneNode,\n identifier,\n logicalExpression,\n numericLiteral,\n sequenceExpression,\n unaryExpression,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\nimport type { NodePath, Scope, Visitor } from \"@babel/traverse\";\n\ntype State = {\n scope: Scope;\n bindingNames: Set<string>;\n seen: WeakSet<t.Node>;\n includeUpdateExpression: boolean;\n};\nexport default function simplifyAccess(\n path: NodePath,\n bindingNames: Set<string>,\n // TODO(Babel 8): Remove this\n includeUpdateExpression: boolean = true,\n) {\n path.traverse(simpleAssignmentVisitor, {\n scope: path.scope,\n bindingNames,\n seen: new WeakSet(),\n includeUpdateExpression,\n });\n}\n\nconst simpleAssignmentVisitor: Visitor<State> = {\n // TODO(Babel 8): Remove UpdateExpression\n UpdateExpression: {\n exit(path) {\n const { scope, bindingNames, includeUpdateExpression } = this;\n if (!includeUpdateExpression) {\n return;\n }\n\n const arg = path.get(\"argument\");\n if (!arg.isIdentifier()) return;\n const localName = arg.node.name;\n\n if (!bindingNames.has(localName)) return;\n\n // redeclared in this scope\n if (scope.getBinding(localName) !== path.scope.getBinding(localName)) {\n return;\n }\n\n if (\n path.parentPath.isExpressionStatement() &&\n !path.isCompletionRecord()\n ) {\n // ++i => (i += 1);\n const operator = path.node.operator == \"++\" ? \"+=\" : \"-=\";\n path.replaceWith(\n assignmentExpression(operator, arg.node, numericLiteral(1)),\n );\n } else if (path.node.prefix) {\n // ++i => (i = (+i) + 1);\n path.replaceWith(\n assignmentExpression(\n \"=\",\n identifier(localName),\n binaryExpression(\n path.node.operator[0] as \"+\" | \"-\",\n unaryExpression(\"+\", arg.node),\n numericLiteral(1),\n ),\n ),\n );\n } else {\n const old = path.scope.generateUidIdentifierBasedOnNode(\n arg.node,\n \"old\",\n );\n const varName = old.name;\n path.scope.push({ id: old });\n\n const binary = binaryExpression(\n path.node.operator[0] as \"+\" | \"-\",\n identifier(varName),\n // todo: support bigint\n numericLiteral(1),\n );\n\n // i++ => (_old = (+i), i = _old + 1, _old)\n path.replaceWith(\n sequenceExpression([\n assignmentExpression(\n \"=\",\n identifier(varName),\n unaryExpression(\"+\", arg.node),\n ),\n assignmentExpression(\"=\", cloneNode(arg.node), binary),\n identifier(varName),\n ]),\n );\n }\n },\n },\n\n AssignmentExpression: {\n exit(path) {\n const { scope, seen, bindingNames } = this;\n\n if (path.node.operator === \"=\") return;\n\n if (seen.has(path.node)) return;\n seen.add(path.node);\n\n const left = path.get(\"left\");\n if (!left.isIdentifier()) return;\n\n // Simple update-assign foo += 1;\n // => exports.foo = (foo += 1);\n const localName = left.node.name;\n\n if (!bindingNames.has(localName)) return;\n\n // redeclared in this scope\n if (scope.getBinding(localName) !== path.scope.getBinding(localName)) {\n return;\n }\n\n const operator = path.node.operator.slice(0, -1);\n if (LOGICAL_OPERATORS.includes(operator)) {\n // &&, ||, ??\n // (foo &&= bar) => (foo && foo = bar)\n path.replaceWith(\n logicalExpression(\n // @ts-expect-error Guarded by LOGICAL_OPERATORS.includes\n operator,\n path.node.left,\n assignmentExpression(\n \"=\",\n cloneNode(path.node.left),\n path.node.right,\n ),\n ),\n );\n } else {\n // (foo += bar) => (foo = foo + bar)\n path.node.right = binaryExpression(\n // @ts-expect-error An assignment expression operator removing \"=\" must\n // be a valid binary operator\n operator,\n cloneN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