diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2023-12-21 22:46:53 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2023-12-21 22:46:53 +0800 |
| commit | f06956efd2dc4bf77244a9fcce2b883a00b925af (patch) | |
| tree | 0123cb73ce67f1f4b17e1d6cbabff076ee44e31b /node_modules/@babel/helper-create-class-features-plugin/lib/misc.js | |
| parent | 8d980c13970c15b6d2312b6fc4ac51698dd0d220 (diff) | |
updated node modules
Diffstat (limited to 'node_modules/@babel/helper-create-class-features-plugin/lib/misc.js')
| -rw-r--r-- | node_modules/@babel/helper-create-class-features-plugin/lib/misc.js | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/node_modules/@babel/helper-create-class-features-plugin/lib/misc.js b/node_modules/@babel/helper-create-class-features-plugin/lib/misc.js index 8a4f662f..27b5a844 100644 --- a/node_modules/@babel/helper-create-class-features-plugin/lib/misc.js +++ b/node_modules/@babel/helper-create-class-features-plugin/lib/misc.js @@ -44,7 +44,7 @@ function handleClassTDZ(path, state) { const classFieldDefinitionEvaluationTDZVisitor = { ReferencedIdentifier: handleClassTDZ }; -function injectInitialization(path, constructor, nodes, renamer) { +function injectInitialization(path, constructor, nodes, renamer, lastReturnsThis) { if (!nodes.length) return; const isDerived = !!path.node.superClass; if (!constructor) { @@ -66,10 +66,16 @@ function injectInitialization(path, constructor, nodes, renamer) { let isFirst = true; for (const bareSuper of bareSupers) { if (isFirst) { - bareSuper.insertAfter(nodes); isFirst = false; } else { - bareSuper.insertAfter(nodes.map(n => _core.types.cloneNode(n))); + nodes = nodes.map(n => _core.types.cloneNode(n)); + } + if (!bareSuper.parentPath.isExpressionStatement()) { + const allNodes = [bareSuper.node, ...nodes.map(n => _core.types.toExpression(n))]; + if (!lastReturnsThis) allNodes.push(_core.types.thisExpression()); + bareSuper.replaceWith(_core.types.sequenceExpression(allNodes)); + } else { + bareSuper.insertAfter(nodes); } } } else { @@ -91,13 +97,25 @@ function extractComputedKeys(path, computedPaths, file) { } const computedNode = computedPath.node; if (!computedKey.isConstantExpression()) { - const ident = path.scope.generateUidIdentifierBasedOnNode(computedNode.key); - path.scope.push({ - id: ident, - kind: "let" - }); - declarations.push(_core.types.expressionStatement(_core.types.assignmentExpression("=", _core.types.cloneNode(ident), computedNode.key))); - computedNode.key = _core.types.cloneNode(ident); + const scope = path.scope; + const isUidReference = _core.types.isIdentifier(computedKey.node) && scope.hasUid(computedKey.node.name); + const isMemoiseAssignment = computedKey.isAssignmentExpression({ + operator: "=" + }) && _core.types.isIdentifier(computedKey.node.left) && scope.hasUid(computedKey.node.left.name); + if (isUidReference) { + continue; + } else if (isMemoiseAssignment) { + declarations.push(_core.types.expressionStatement(_core.types.cloneNode(computedNode.key))); + computedNode.key = _core.types.cloneNode(computedNode.key.left); + } else { + const ident = path.scope.generateUidIdentifierBasedOnNode(computedNode.key); + scope.push({ + id: ident, + kind: "let" + }); + declarations.push(_core.types.expressionStatement(_core.types.assignmentExpression("=", _core.types.cloneNode(ident), computedNode.key))); + computedNode.key = _core.types.cloneNode(ident); + } } } return declarations; |
