| 1 | // This file contains methods that convert the path node into another node or some other type of data. |
| 2 | |
| 3 | import { |
| 4 | arrowFunctionExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/arrowFunctionExpression()., |
| 5 | assignmentExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/assignmentExpression()., |
| 6 | binaryExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/binaryExpression()., |
| 7 | blockStatementscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/blockStatement()., |
| 8 | callExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/callExpression()., |
| 9 | conditionalExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/conditionalExpression()., |
| 10 | expressionStatementscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/expressionStatement()., |
| 11 | identifierscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/identifier()., |
| 12 | isIdentifierscip-typescript npm @babel/types 7.20.7 src/validators/generated/`index.ts`/isIdentifier()., |
| 13 | jsxIdentifierscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/jsxIdentifier()., |
| 14 | logicalExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/logicalExpression()., |
| 15 | LOGICAL_OPERATORSscip-typescript npm @babel/types 7.20.7 src/constants/`index.ts`/LOGICAL_OPERATORS., |
| 16 | memberExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/memberExpression()., |
| 17 | metaPropertyscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/metaProperty()., |
| 18 | numericLiteralscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/numericLiteral()., |
| 19 | objectExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/objectExpression()., |
| 20 | restElementscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/restElement()., |
| 21 | returnStatementscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/returnStatement()., |
| 22 | sequenceExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/sequenceExpression()., |
| 23 | spreadElementscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/spreadElement()., |
| 24 | stringLiteralscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/stringLiteral()., |
| 25 | super as _superscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/_super()., |
| 26 | thisExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/thisExpression()., |
| 27 | toExpression, |
| 28 | unaryExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/unaryExpression()., |
| 29 | } from "@babel/types"scip-typescript npm @babel/types 7.20.7 src/`index.ts`/; |
| 30 | import type * as tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/ from "@babel/types"scip-typescript npm @babel/types 7.20.7 src/`index.ts`/; |
| 31 | import environmentVisitorscip-typescript npm @babel/helper-environment-visitor 7.18.9 src/`index.ts`/visitor. from "@babel/helper-environment-visitor"scip-typescript npm @babel/helper-environment-visitor 7.18.9 src/`index.ts`/; |
| 32 | import nameFunction from "@babel/helper-function-name"scip-typescript npm @babel/helper-function-name 7.19.0 src/`index.ts`/; |
| 33 | import { mergescip-typescript npm @babel/traverse 7.20.13 src/`visitors.ts`/merge(). as mergeVisitorsscip-typescript npm @babel/traverse 7.20.13 src/`visitors.ts`/merge(). } from "../visitors"scip-typescript npm @babel/traverse 7.20.13 src/`visitors.ts`/; |
| 34 | import type NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath# from "./index"scip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/; |
| 35 | |
| 36 | export function toComputedKeyscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/toComputedKey().(thisscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/toComputedKey().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#) { |
| 37 | let key; |
| 38 | if (this.isMemberExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isMemberExpression().()) { |
| 39 | key = this.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..propertyscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/MemberExpression#property.; |
| 40 | } else if (this.isPropertyscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isProperty().() || this.isMethodscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isMethod().()) { |
| 41 | key = this.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..keyscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/ClassAccessorProperty#key.; |
| 42 | } else { |
| 43 | throw new ReferenceErrorscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/ReferenceError#("todo"); |
| 44 | } |
| 45 | |
| 46 | // @ts-expect-error todo(flow->ts) computed does not exist in ClassPrivateProperty |
| 47 | if (!this.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..computed) { |
| 48 | if (isIdentifierscip-typescript npm @babel/types 7.20.7 src/validators/generated/`index.ts`/isIdentifier().(key)) key = stringLiteralscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/stringLiteral().(key.namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#name.); |
| 49 | } |
| 50 | |
| 51 | return key; |
| 52 | } |
| 53 | |
| 54 | export function ensureBlockscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/ensureBlock().( |
| 55 | thisscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/ensureBlock().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#< |
| 56 | tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Loopscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Loop# | tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.WithStatementscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/WithStatement# | tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Functionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Function# | tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.LabeledStatementscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/LabeledStatement# | tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.CatchClausescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/CatchClause# |
| 57 | >, |
| 58 | ) { |
| 59 | const body = this.get("body"); |
| 60 | const bodyNode = body.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node.; |
| 61 | |
| 62 | if (Arrayscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#.isArrayscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/ArrayConstructor#isArray().(body)) { |
| 63 | throw new Errorscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Error#("Can't convert array path to a block statement"); |
| 64 | } |
| 65 | if (!bodyNode) { |
| 66 | throw new Errorscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Error#("Can't convert node without a body"); |
| 67 | } |
| 68 | |
| 69 | if (body.isBlockStatementscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isBlockStatement().()) { |
| 70 | return bodyNode; |
| 71 | } |
| 72 | |
| 73 | const statements: Arrayscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Statementscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Statement#> = []; |
| 74 | |
| 75 | let stringPath = "body"; |
| 76 | let key; |
| 77 | let listKey; |
| 78 | if (body.isStatementscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isStatement().()) { |
| 79 | listKey = "body"; |
| 80 | key = 0; |
| 81 | statements.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(body.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node.); |
| 82 | } else { |
| 83 | stringPath += ".body.0"; |
| 84 | if (this.isFunctionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isFunction().()) { |
| 85 | key = "argument"; |
| 86 | statements.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(returnStatementscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/returnStatement().(body.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node. as tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Expressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Expression#)); |
| 87 | } else { |
| 88 | key = "expression"; |
| 89 | statements.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(expressionStatementscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/expressionStatement().(body.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node. as tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Expressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Expression#)); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | this.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..bodyscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/ArrowFunctionExpression#body. = blockStatementscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/blockStatement().(statements); |
| 94 | const parentPath = this.get(stringPath) as NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#; |
| 95 | body.setupscip-typescript npm @babel/traverse 7.20.13 src/path/`context.ts`/setup().( |
| 96 | parentPath, |
| 97 | listKey |
| 98 | ? // @ts-expect-error listKey must present in parent path |
| 99 | parentPath.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node.[listKey] |
| 100 | : parentPath.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node., |
| 101 | listKey, |
| 102 | key, |
| 103 | ); |
| 104 | |
| 105 | return this.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node.; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Keeping this for backward-compatibility. You should use arrowFunctionToExpression() for >=7.x. |
| 110 | */ |
| 111 | // TODO(Babel 8): Remove this |
| 112 | export function arrowFunctionToShadowedscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/arrowFunctionToShadowed().(thisscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/arrowFunctionToShadowed().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#) { |
| 113 | if (!this.isArrowFunctionExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isArrowFunctionExpression().()) return; |
| 114 | |
| 115 | this.arrowFunctionToExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/arrowFunctionToExpression().(); |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Given an arbitrary function, process its content as if it were an arrow function, moving references |
| 120 | * to "this", "arguments", "super", and such into the function's parent scope. This method is useful if |
| 121 | * you have wrapped some set of items in an IIFE or other function, but want "this", "arguments", and super" |
| 122 | * to continue behaving as expected. |
| 123 | */ |
| 124 | export function unwrapFunctionEnvironmentscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/unwrapFunctionEnvironment().(thisscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/unwrapFunctionEnvironment().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#) { |
| 125 | if ( |
| 126 | !this.isArrowFunctionExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isArrowFunctionExpression().() && |
| 127 | !this.isFunctionExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isFunctionExpression().() && |
| 128 | !this.isFunctionDeclarationscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isFunctionDeclaration().() |
| 129 | ) { |
| 130 | throw this.buildCodeFrameErrorscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#buildCodeFrameError().( |
| 131 | "Can only unwrap the environment of a function.", |
| 132 | ); |
| 133 | } |
| 134 | |
| 135 | hoistFunctionEnvironmentscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/hoistFunctionEnvironment().(this); |
| 136 | } |
| 137 | |
| 138 | function setTypescip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/setType().<Nscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/setType().[N] extends tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Nodescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Node#, Tscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/setType().[T] extends Nscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/setType().[N]["type"scip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/ArrayExpression#type.]>( |
| 139 | pathscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/setType().(path): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<Nscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/setType().[N]>, |
| 140 | typescip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/setType().(type): Tscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/setType().[T], |
| 141 | ): asserts pathscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/setType().(path) is NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<Extractscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Extract#<Nscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/setType().[N], { type: Tscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/setType().[T] }>> { |
| 142 | pathscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/setType().(path).nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..typescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/ArrayExpression#type. = typescip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/setType().(type); |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Convert a given arrow function into a normal ES5 function expression. |
| 147 | */ |
| 148 | export function arrowFunctionToExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/arrowFunctionToExpression().( |
| 149 | thisscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/arrowFunctionToExpression().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.ArrowFunctionExpressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/ArrowFunctionExpression#>, |
| 150 | { |
| 151 | allowInsertArrowscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/arrowFunctionToExpression().(`{ allowInsertArrow = true, allowInsertArrowWithRest = allowInsertArrow, /** @deprecated Use ``noNewArrows`` instead */ specCompliant = false, // TODO(Babel 8): Consider defaulting to ``false`` for spec compliancy noNewArrows = !specCompliant, }`)typeLiteral39:allowInsertArrow. = true, |
| 152 | allowInsertArrowWithRestscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/arrowFunctionToExpression().(`{ allowInsertArrow = true, allowInsertArrowWithRest = allowInsertArrow, /** @deprecated Use ``noNewArrows`` instead */ specCompliant = false, // TODO(Babel 8): Consider defaulting to ``false`` for spec compliancy noNewArrows = !specCompliant, }`)typeLiteral39:allowInsertArrowWithRest. = allowInsertArrow, |
| 153 | /** @deprecated Use `noNewArrows` instead */ |
| 154 | specCompliantscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/arrowFunctionToExpression().(`{ allowInsertArrow = true, allowInsertArrowWithRest = allowInsertArrow, /** @deprecated Use ``noNewArrows`` instead */ specCompliant = false, // TODO(Babel 8): Consider defaulting to ``false`` for spec compliancy noNewArrows = !specCompliant, }`)typeLiteral39:specCompliant. = false, |
| 155 | // TODO(Babel 8): Consider defaulting to `false` for spec compliancy |
| 156 | noNewArrowsscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/arrowFunctionToExpression().(`{ allowInsertArrow = true, allowInsertArrowWithRest = allowInsertArrow, /** @deprecated Use ``noNewArrows`` instead */ specCompliant = false, // TODO(Babel 8): Consider defaulting to ``false`` for spec compliancy noNewArrows = !specCompliant, }`)typeLiteral39:noNewArrows. = !specCompliant, |
| 157 | }: { |
| 158 | allowInsertArrowscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/arrowFunctionToExpression().(`{ allowInsertArrow = true, allowInsertArrowWithRest = allowInsertArrow, /** @deprecated Use ``noNewArrows`` instead */ specCompliant = false, // TODO(Babel 8): Consider defaulting to ``false`` for spec compliancy noNewArrows = !specCompliant, }`)typeLiteral39:allowInsertArrow.?: boolean | void; |
| 159 | allowInsertArrowWithRestscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/arrowFunctionToExpression().(`{ allowInsertArrow = true, allowInsertArrowWithRest = allowInsertArrow, /** @deprecated Use ``noNewArrows`` instead */ specCompliant = false, // TODO(Babel 8): Consider defaulting to ``false`` for spec compliancy noNewArrows = !specCompliant, }`)typeLiteral39:allowInsertArrowWithRest.?: boolean | void; |
| 160 | specCompliantscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/arrowFunctionToExpression().(`{ allowInsertArrow = true, allowInsertArrowWithRest = allowInsertArrow, /** @deprecated Use ``noNewArrows`` instead */ specCompliant = false, // TODO(Babel 8): Consider defaulting to ``false`` for spec compliancy noNewArrows = !specCompliant, }`)typeLiteral39:specCompliant.?: boolean | void; |
| 161 | noNewArrowsscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/arrowFunctionToExpression().(`{ allowInsertArrow = true, allowInsertArrowWithRest = allowInsertArrow, /** @deprecated Use ``noNewArrows`` instead */ specCompliant = false, // TODO(Babel 8): Consider defaulting to ``false`` for spec compliancy noNewArrows = !specCompliant, }`)typeLiteral39:noNewArrows.?: boolean; |
| 162 | } = {}, |
| 163 | ): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#< |
| 164 | Excludescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Exclude#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Functionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Function#, tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Methodscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Method# | tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.ArrowFunctionExpressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/ArrowFunctionExpression#> | tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.CallExpressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/CallExpression# |
| 165 | > { |
| 166 | if (!this.isArrowFunctionExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isArrowFunctionExpression().()) { |
| 167 | throw (this as NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#).buildCodeFrameErrorscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#buildCodeFrameError().( |
| 168 | "Cannot convert non-arrow function to a function expression.", |
| 169 | ); |
| 170 | } |
| 171 | |
| 172 | const { thisBindingscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/hoistFunctionEnvironment().typeLiteral48:thisBinding., fnPathscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/hoistFunctionEnvironment().typeLiteral48:fnPath.: fn } = hoistFunctionEnvironmentscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/hoistFunctionEnvironment().( |
| 173 | this, |
| 174 | noNewArrows, |
| 175 | allowInsertArrow, |
| 176 | allowInsertArrowWithRest, |
| 177 | ); |
| 178 | |
| 179 | // @ts-expect-error TS requires explicit fn type annotation |
| 180 | fn.ensureBlockscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#ensureBlock().(); |
| 181 | setTypescip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/setType().(fn, "FunctionExpression"); |
| 182 | |
| 183 | if (!noNewArrows) { |
| 184 | const checkBinding = thisBinding |
| 185 | ? null |
| 186 | : fn.scopescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#scope..generateUidIdentifierscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#generateUidIdentifier().("arrowCheckId"); |
| 187 | if (checkBinding) { |
| 188 | fn.parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath..scopescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#scope..pushscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#push().({ |
| 189 | idscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#push().(opts)typeLiteral191:id.: checkBinding, |
| 190 | initscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#push().(opts)typeLiteral191:init.: objectExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/objectExpression().([]), |
| 191 | }); |
| 192 | } |
| 193 | |
| 194 | fn.get("body").unshiftContainerscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/unshiftContainer().( |
| 195 | "body", |
| 196 | expressionStatementscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/expressionStatement().( |
| 197 | callExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/callExpression().(this.hubscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#hub..addHelperscip-typescript npm @babel/traverse 7.20.13 src/`hub.ts`/HubInterface#addHelper().("newArrowCheck"), [ |
| 198 | thisExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/thisExpression().(), |
| 199 | checkBinding |
| 200 | ? identifierscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/identifier().(checkBinding.namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#name.) |
| 201 | : identifierscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/identifier().(thisBinding), |
| 202 | ]), |
| 203 | ), |
| 204 | ); |
| 205 | |
| 206 | fn.replaceWithscip-typescript npm @babel/traverse 7.20.13 src/path/`replacement.ts`/replaceWith().( |
| 207 | callExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/callExpression().( |
| 208 | memberExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/memberExpression().( |
| 209 | // @ts-expect-error TS can't infer nameFunction returns CallExpression | ArrowFunctionExpression here |
| 210 | nameFunction(this, true) || fn.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node., |
| 211 | identifierscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/identifier().("bind"), |
| 212 | ), |
| 213 | [checkBinding ? identifierscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/identifier().(checkBinding.namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#name.) : thisExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/thisExpression().()], |
| 214 | ), |
| 215 | ); |
| 216 | |
| 217 | return fn.get("callee.object"); |
| 218 | } |
| 219 | |
| 220 | return fn; |
| 221 | } |
| 222 | |
| 223 | const getSuperCallsVisitorscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getSuperCallsVisitor. = mergeVisitorsscip-typescript npm @babel/traverse 7.20.13 src/`visitors.ts`/merge().<{ |
| 224 | allSuperCalls: NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.CallExpressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/CallExpression#>[]; |
| 225 | }>([ |
| 226 | { |
| 227 | CallExpression(child, { allSuperCalls }) { |
| 228 | if (!child.get("callee").isSuperscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isSuper().()) return; |
| 229 | allSuperCalls.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(child); |
| 230 | }, |
| 231 | }, |
| 232 | environmentVisitorscip-typescript npm @babel/helper-environment-visitor 7.18.9 src/`index.ts`/visitor., |
| 233 | ]); |
| 234 | |
| 235 | /** |
| 236 | * Given a function, traverse its contents, and if there are references to "this", "arguments", "super", |
| 237 | * or "new.target", ensure that these references reference the parent environment around this function. |
| 238 | * |
| 239 | * @returns `thisBinding`: the name of the injected reference to `this`; for example "_this" |
| 240 | * @returns `fnPath`: the new path to the function node. This is different from the fnPath |
| 241 | * parameter when the function node is wrapped in another node. |
| 242 | */ |
| 243 | function hoistFunctionEnvironmentscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/hoistFunctionEnvironment().( |
| 244 | fnPathscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/hoistFunctionEnvironment().(fnPath): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Functionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Function#>, |
| 245 | // TODO(Babel 8): Consider defaulting to `false` for spec compliancy |
| 246 | noNewArrowsscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/hoistFunctionEnvironment().(noNewArrows): boolean | void = true, |
| 247 | allowInsertArrowscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/hoistFunctionEnvironment().(allowInsertArrow): boolean | void = true, |
| 248 | allowInsertArrowWithRestscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/hoistFunctionEnvironment().(allowInsertArrowWithRest): boolean | void = true, |
| 249 | ): { thisBindingscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/hoistFunctionEnvironment().typeLiteral48:thisBinding.: string; fnPathscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/hoistFunctionEnvironment().typeLiteral48:fnPath.: NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Functionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Function#> } { |
| 250 | let arrowParent; |
| 251 | let thisEnvFn: NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Functionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Function#> = fnPathscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/hoistFunctionEnvironment().(fnPath).findParentscip-typescript npm @babel/traverse 7.20.13 src/path/`ancestry.ts`/findParent().(p => { |
| 252 | if (p.isArrowFunctionExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isArrowFunctionExpression().()) { |
| 253 | arrowParent ??= p; |
| 254 | return false; |
| 255 | } |
| 256 | return ( |
| 257 | p.isFunctionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isFunction().() || |
| 258 | p.isProgramscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isProgram().() || |
| 259 | p.isClassPropertyscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isClassProperty().({ staticscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/static0:: false }) || |
| 260 | p.isClassPrivatePropertyscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isClassPrivateProperty().({ staticscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/static1:: false }) |
| 261 | ); |
| 262 | }) as NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Functionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Function#>; |
| 263 | const inConstructor = thisEnvFn.isClassMethodscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isClassMethod().({ kindscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/kind0:: "constructor" }); |
| 264 | |
| 265 | if (thisEnvFn.isClassPropertyscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isClassProperty().() || thisEnvFn.isClassPrivatePropertyscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isClassPrivateProperty().()) { |
| 266 | if (arrowParent) { |
| 267 | thisEnvFn = arrowParent; |
| 268 | } else if (allowInsertArrowscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/hoistFunctionEnvironment().(allowInsertArrow)) { |
| 269 | // It's safe to wrap this function in another and not hoist to the |
| 270 | // top level because the 'this' binding is constant in class |
| 271 | // properties (since 'super()' has already been called), so we don't |
| 272 | // need to capture/reassign it at the top level. |
| 273 | fnPathscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/hoistFunctionEnvironment().(fnPath).replaceWithscip-typescript npm @babel/traverse 7.20.13 src/path/`replacement.ts`/replaceWith().( |
| 274 | callExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/callExpression().( |
| 275 | arrowFunctionExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/arrowFunctionExpression().([], toExpression(fnPathscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/hoistFunctionEnvironment().(fnPath).nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node.)), |
| 276 | [], |
| 277 | ), |
| 278 | ); |
| 279 | thisEnvFn = fnPathscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/hoistFunctionEnvironment().(fnPath).get("callee") as NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.ArrowFunctionExpressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/ArrowFunctionExpression#>; |
| 280 | fnPathscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/hoistFunctionEnvironment().(fnPath) = thisEnvFn.get("body") as NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.FunctionExpressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/FunctionExpression#>; |
| 281 | } else { |
| 282 | throw fnPathscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/hoistFunctionEnvironment().(fnPath).buildCodeFrameErrorscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#buildCodeFrameError().( |
| 283 | "Unable to transform arrow inside class property", |
| 284 | ); |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | const { thisPathsscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/thisPaths0:, argumentsPathsscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/argumentsPaths0:, newTargetPathsscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/newTargetPaths0:, superPropsscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/superProps0:, superCallsscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/superCalls0: } = |
| 289 | getScopeInformationscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getScopeInformation().(fnPathscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/hoistFunctionEnvironment().(fnPath)); |
| 290 | |
| 291 | // Convert all super() calls in the constructor, if super is used in an arrow. |
| 292 | if (inConstructor && superCalls.lengthscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#length. > 0) { |
| 293 | if (!allowInsertArrowscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/hoistFunctionEnvironment().(allowInsertArrow)) { |
| 294 | throw superCalls[0].buildCodeFrameErrorscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#buildCodeFrameError().( |
| 295 | "When using '@babel/plugin-transform-arrow-functions', " + |
| 296 | "it's not possible to compile `super()` in an arrow function without compiling classes.\n" + |
| 297 | "Please add '@babel/plugin-transform-classes' to your Babel configuration.", |
| 298 | ); |
| 299 | } |
| 300 | if (!allowInsertArrowWithRestscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/hoistFunctionEnvironment().(allowInsertArrowWithRest)) { |
| 301 | // preset-env with target `since 2017` enables `transform-parameters` without `transform-classes`. |
| 302 | throw superCalls[0].buildCodeFrameErrorscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#buildCodeFrameError().( |
| 303 | "When using '@babel/plugin-transform-parameters', " + |
| 304 | "it's not possible to compile `super()` in an arrow function with default or rest parameters without compiling classes.\n" + |
| 305 | "Please add '@babel/plugin-transform-classes' to your Babel configuration.", |
| 306 | ); |
| 307 | } |
| 308 | const allSuperCalls: NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.CallExpressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/CallExpression#>[] = []; |
| 309 | thisEnvFn.traversescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#traverse().(getSuperCallsVisitorscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getSuperCallsVisitor., { allSuperCallsscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/allSuperCalls0: }); |
| 310 | const superBinding = getSuperBindingscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getSuperBinding().(thisEnvFn); |
| 311 | allSuperCalls.forEachscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#forEach().(superCall => { |
| 312 | const callee = identifierscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/identifier().(superBinding); |
| 313 | callee.locscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/BaseNode#loc. = superCall.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..calleescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/CallExpression#callee..locscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/BaseNode#loc.; |
| 314 | |
| 315 | superCall.get("callee").replaceWithscip-typescript npm @babel/traverse 7.20.13 src/path/`replacement.ts`/replaceWith().(callee); |
| 316 | }); |
| 317 | } |
| 318 | |
| 319 | // Convert all "arguments" references in the arrow to point at the alias. |
| 320 | if (argumentsPaths.lengthscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#length. > 0) { |
| 321 | const argumentsBinding = getBindingscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getBinding().(thisEnvFn, "arguments", () => { |
| 322 | const args = () => identifierscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/identifier().("arguments"); |
| 323 | if (thisEnvFn.scopescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#scope..pathscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#path..isProgramscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isProgram().()) { |
| 324 | return conditionalExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/conditionalExpression().( |
| 325 | binaryExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/binaryExpression().( |
| 326 | "===", |
| 327 | unaryExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/unaryExpression().("typeof", args()), |
| 328 | stringLiteralscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/stringLiteral().("undefined"), |
| 329 | ), |
| 330 | thisEnvFn.scopescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#scope..buildUndefinedNodescip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#buildUndefinedNode().(), |
| 331 | args(), |
| 332 | ); |
| 333 | } else { |
| 334 | return args(); |
| 335 | } |
| 336 | }); |
| 337 | |
| 338 | argumentsPaths.forEachscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#forEach().(argumentsChild => { |
| 339 | const argsRef = identifierscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/identifier().(argumentsBinding); |
| 340 | argsRef.locscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/BaseNode#loc. = argumentsChild.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..locscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/BaseNode#loc.; |
| 341 | |
| 342 | argumentsChild.replaceWithscip-typescript npm @babel/traverse 7.20.13 src/path/`replacement.ts`/replaceWith().(argsRef); |
| 343 | }); |
| 344 | } |
| 345 | |
| 346 | // Convert all "new.target" references in the arrow to point at the alias. |
| 347 | if (newTargetPaths.lengthscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#length. > 0) { |
| 348 | const newTargetBinding = getBindingscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getBinding().(thisEnvFn, "newtarget", () => |
| 349 | metaPropertyscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/metaProperty().(identifierscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/identifier().("new"), identifierscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/identifier().("target")), |
| 350 | ); |
| 351 | |
| 352 | newTargetPaths.forEachscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#forEach().(targetChild => { |
| 353 | const targetRef = identifierscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/identifier().(newTargetBinding); |
| 354 | targetRef.locscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/BaseNode#loc. = targetChild.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..locscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/BaseNode#loc.; |
| 355 | |
| 356 | targetChild.replaceWithscip-typescript npm @babel/traverse 7.20.13 src/path/`replacement.ts`/replaceWith().(targetRef); |
| 357 | }); |
| 358 | } |
| 359 | |
| 360 | // Convert all "super.prop" references to point at aliases. |
| 361 | if (superProps.lengthscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#length. > 0) { |
| 362 | if (!allowInsertArrowscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/hoistFunctionEnvironment().(allowInsertArrow)) { |
| 363 | throw superProps[0].buildCodeFrameErrorscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#buildCodeFrameError().( |
| 364 | "When using '@babel/plugin-transform-arrow-functions', " + |
| 365 | "it's not possible to compile `super.prop` in an arrow function without compiling classes.\n" + |
| 366 | "Please add '@babel/plugin-transform-classes' to your Babel configuration.", |
| 367 | ); |
| 368 | } |
| 369 | |
| 370 | const flatSuperProps: NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.MemberExpressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/MemberExpression#>[] = superProps.reducescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#reduce().( |
| 371 | (acc, superProp) => acc.concatscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#concat().(standardizeSuperPropertyscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/standardizeSuperProperty().(superProp)), |
| 372 | [], |
| 373 | ); |
| 374 | |
| 375 | flatSuperProps.forEachscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#forEach().(superProp => { |
| 376 | const key = superProp.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..computedscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/MemberExpression#computed. |
| 377 | ? "" |
| 378 | : // @ts-expect-error super property must not contain private name |
| 379 | superProp.get("property").nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..name; |
| 380 | |
| 381 | const superParentPath = superProp.parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath.; |
| 382 | |
| 383 | const isAssignment = superParentPath.isAssignmentExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isAssignmentExpression().({ |
| 384 | leftscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/left0:: superProp.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node., |
| 385 | }); |
| 386 | const isCall = superParentPath.isCallExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isCallExpression().({ |
| 387 | calleescip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/callee0:: superProp.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node., |
| 388 | }); |
| 389 | const isTaggedTemplate = superParentPath.isTaggedTemplateExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isTaggedTemplateExpression().({ |
| 390 | tagscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/tag0:: superProp.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node., |
| 391 | }); |
| 392 | const superBinding = getSuperPropBindingscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getSuperPropBinding().(thisEnvFn, isAssignment, key); |
| 393 | |
| 394 | const args: tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Expressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Expression#[] = []; |
| 395 | if (superProp.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..computedscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/MemberExpression#computed.) { |
| 396 | // SuperProperty must not be a private name |
| 397 | args.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(superProp.get("property").nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node. as tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Expressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Expression#); |
| 398 | } |
| 399 | |
| 400 | if (isAssignment) { |
| 401 | const value = superParentPath.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..rightscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/AssignmentExpression#right.; |
| 402 | args.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(value); |
| 403 | } |
| 404 | |
| 405 | const call = callExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/callExpression().(identifierscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/identifier().(superBinding), args); |
| 406 | |
| 407 | if (isCall) { |
| 408 | superParentPath.unshiftContainerscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/unshiftContainer().("arguments", thisExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/thisExpression().()); |
| 409 | superProp.replaceWithscip-typescript npm @babel/traverse 7.20.13 src/path/`replacement.ts`/replaceWith().(memberExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/memberExpression().(call, identifierscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/identifier().("call"))); |
| 410 | |
| 411 | thisPaths.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().( |
| 412 | superParentPath.get("arguments.0") as NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.ThisExpressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/ThisExpression#>, |
| 413 | ); |
| 414 | } else if (isAssignment) { |
| 415 | // Replace not only the super.prop, but the whole assignment |
| 416 | superParentPath.replaceWithscip-typescript npm @babel/traverse 7.20.13 src/path/`replacement.ts`/replaceWith().(call); |
| 417 | } else if (isTaggedTemplate) { |
| 418 | superProp.replaceWithscip-typescript npm @babel/traverse 7.20.13 src/path/`replacement.ts`/replaceWith().( |
| 419 | callExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/callExpression().(memberExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/memberExpression().(call, identifierscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/identifier().("bind"), false), [ |
| 420 | thisExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/thisExpression().(), |
| 421 | ]), |
| 422 | ); |
| 423 | |
| 424 | thisPaths.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().( |
| 425 | superProp.get("arguments.0") as NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.ThisExpressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/ThisExpression#>, |
| 426 | ); |
| 427 | } else { |
| 428 | superProp.replaceWithscip-typescript npm @babel/traverse 7.20.13 src/path/`replacement.ts`/replaceWith().(call); |
| 429 | } |
| 430 | }); |
| 431 | } |
| 432 | |
| 433 | // Convert all "this" references in the arrow to point at the alias. |
| 434 | let thisBinding: string | null; |
| 435 | if (thisPaths.lengthscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#length. > 0 || !noNewArrowsscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/hoistFunctionEnvironment().(noNewArrows)) { |
| 436 | thisBinding = getThisBindingscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getThisBinding().(thisEnvFn, inConstructor); |
| 437 | |
| 438 | if ( |
| 439 | noNewArrowsscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/hoistFunctionEnvironment().(noNewArrows) || |
| 440 | // In subclass constructors, still need to rewrite because "this" can't be bound in spec mode |
| 441 | // because it might not have been initialized yet. |
| 442 | (inConstructor && hasSuperClassscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/hasSuperClass().(thisEnvFn)) |
| 443 | ) { |
| 444 | thisPaths.forEachscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#forEach().(thisChild => { |
| 445 | const thisRef = thisChild.isJSXscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isJSX().() |
| 446 | ? jsxIdentifierscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/jsxIdentifier().(thisBinding) |
| 447 | : identifierscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/identifier().(thisBinding); |
| 448 | |
| 449 | thisRef.locscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/BaseNode#loc. = thisChild.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..locscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/BaseNode#loc.; |
| 450 | thisChild.replaceWithscip-typescript npm @babel/traverse 7.20.13 src/path/`replacement.ts`/replaceWith().(thisRef); |
| 451 | }); |
| 452 | |
| 453 | if (!noNewArrowsscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/hoistFunctionEnvironment().(noNewArrows)) thisBinding = null; |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | return { thisBindingscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/hoistFunctionEnvironment().typeLiteral48:thisBinding., fnPathscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/hoistFunctionEnvironment().typeLiteral48:fnPath. }; |
| 458 | } |
| 459 | |
| 460 | type LogicalOpscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/LogicalOp# = Parametersscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Parameters#<typeof logicalExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/logicalExpression().>[0]; |
| 461 | type BinaryOpscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/BinaryOp# = Parametersscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Parameters#<typeof binaryExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/binaryExpression().>[0]; |
| 462 | |
| 463 | function isLogicalOpscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/isLogicalOp().(opscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/isLogicalOp().(op): string): opscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/isLogicalOp().(op) is LogicalOpscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/LogicalOp# { |
| 464 | return LOGICAL_OPERATORSscip-typescript npm @babel/types 7.20.7 src/constants/`index.ts`/LOGICAL_OPERATORS..includesscip-typescript npm typescript 5.9.3 lib/`lib.es2016.array.include.d.ts`/Array#includes().(opscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/isLogicalOp().(op)); |
| 465 | } |
| 466 | |
| 467 | function standardizeSuperPropertyscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/standardizeSuperProperty().( |
| 468 | superPropscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/standardizeSuperProperty().(superProp): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.MemberExpressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/MemberExpression#>, |
| 469 | ): |
| 470 | | [NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.MemberExpressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/MemberExpression#>] |
| 471 | | [NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.MemberExpressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/MemberExpression#>, NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.MemberExpressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/MemberExpression#>] { |
| 472 | if ( |
| 473 | superPropscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/standardizeSuperProperty().(superProp).parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath..isAssignmentExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isAssignmentExpression().() && |
| 474 | superPropscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/standardizeSuperProperty().(superProp).parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath..nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..operatorscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/AssignmentExpression#operator. !== "=" |
| 475 | ) { |
| 476 | const assignmentPath = superPropscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/standardizeSuperProperty().(superProp).parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath.; |
| 477 | |
| 478 | const op = assignmentPath.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..operatorscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/AssignmentExpression#operator..slicescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/String#slice().(0, -1) as |
| 479 | | LogicalOpscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/LogicalOp# |
| 480 | | BinaryOpscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/BinaryOp#; |
| 481 | |
| 482 | const value = assignmentPath.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..rightscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/AssignmentExpression#right.; |
| 483 | |
| 484 | const isLogicalAssignment = isLogicalOpscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/isLogicalOp().(op); |
| 485 | |
| 486 | if (superPropscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/standardizeSuperProperty().(superProp).nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..computedscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/MemberExpression#computed.) { |
| 487 | // from: super[foo] **= 4; |
| 488 | // to: super[tmp = foo] = super[tmp] ** 4; |
| 489 | |
| 490 | // from: super[foo] ??= 4; |
| 491 | // to: super[tmp = foo] ?? super[tmp] = 4; |
| 492 | |
| 493 | const tmp = superPropscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/standardizeSuperProperty().(superProp).scopescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#scope..generateDeclaredUidIdentifierscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#generateDeclaredUidIdentifier().("tmp"); |
| 494 | |
| 495 | const object = superPropscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/standardizeSuperProperty().(superProp).nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..objectscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/MemberExpression#object.; |
| 496 | const property = superPropscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/standardizeSuperProperty().(superProp).nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..propertyscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/MemberExpression#property. as tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Expressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Expression#; |
| 497 | |
| 498 | assignmentPath |
| 499 | .get("left") |
| 500 | .replaceWithscip-typescript npm @babel/traverse 7.20.13 src/path/`replacement.ts`/replaceWith().( |
| 501 | memberExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/memberExpression().( |
| 502 | object, |
| 503 | assignmentExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/assignmentExpression().("=", tmp, property), |
| 504 | true /* computed */, |
| 505 | ), |
| 506 | ); |
| 507 | |
| 508 | assignmentPath |
| 509 | .get("right") |
| 510 | .replaceWithscip-typescript npm @babel/traverse 7.20.13 src/path/`replacement.ts`/replaceWith().( |
| 511 | rightExpression( |
| 512 | isLogicalAssignment ? "=" : op, |
| 513 | memberExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/memberExpression().(object, identifierscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/identifier().(tmp.namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#name.), true /* computed */), |
| 514 | value, |
| 515 | ), |
| 516 | ); |
| 517 | } else { |
| 518 | // from: super.foo **= 4; |
| 519 | // to: super.foo = super.foo ** 4; |
| 520 | |
| 521 | // from: super.foo ??= 4; |
| 522 | // to: super.foo ?? super.foo = 4; |
| 523 | |
| 524 | const object = superPropscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/standardizeSuperProperty().(superProp).nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..objectscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/MemberExpression#object.; |
| 525 | const property = superPropscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/standardizeSuperProperty().(superProp).nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..propertyscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/MemberExpression#property. as tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Identifierscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#; |
| 526 | |
| 527 | assignmentPath |
| 528 | .get("left") |
| 529 | .replaceWithscip-typescript npm @babel/traverse 7.20.13 src/path/`replacement.ts`/replaceWith().(memberExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/memberExpression().(object, property)); |
| 530 | |
| 531 | assignmentPath |
| 532 | .get("right") |
| 533 | .replaceWithscip-typescript npm @babel/traverse 7.20.13 src/path/`replacement.ts`/replaceWith().( |
| 534 | rightExpression( |
| 535 | isLogicalAssignment ? "=" : op, |
| 536 | memberExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/memberExpression().(object, identifierscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/identifier().(property.namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#name.)), |
| 537 | value, |
| 538 | ), |
| 539 | ); |
| 540 | } |
| 541 | |
| 542 | if (isLogicalAssignment) { |
| 543 | assignmentPath.replaceWithscip-typescript npm @babel/traverse 7.20.13 src/path/`replacement.ts`/replaceWith().( |
| 544 | logicalExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/logicalExpression().( |
| 545 | op, |
| 546 | assignmentPath.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..leftscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/AssignmentExpression#left. as tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.MemberExpressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/MemberExpression#, |
| 547 | assignmentPath.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..rightscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/AssignmentExpression#right., |
| 548 | ), |
| 549 | ); |
| 550 | } else { |
| 551 | assignmentPath.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..operatorscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/AssignmentExpression#operator. = "="; |
| 552 | } |
| 553 | |
| 554 | return [ |
| 555 | assignmentPath.get("left") as NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.MemberExpressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/MemberExpression#>, |
| 556 | assignmentPath.get("right").get("left"), |
| 557 | ]; |
| 558 | } else if (superPropscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/standardizeSuperProperty().(superProp).parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath..isUpdateExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isUpdateExpression().()) { |
| 559 | const updateExpr = superPropscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/standardizeSuperProperty().(superProp).parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath.; |
| 560 | |
| 561 | const tmp = superPropscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/standardizeSuperProperty().(superProp).scopescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#scope..generateDeclaredUidIdentifierscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#generateDeclaredUidIdentifier().("tmp"); |
| 562 | const computedKey = superPropscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/standardizeSuperProperty().(superProp).nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..computedscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/MemberExpression#computed. |
| 563 | ? superPropscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/standardizeSuperProperty().(superProp).scopescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#scope..generateDeclaredUidIdentifierscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#generateDeclaredUidIdentifier().("prop") |
| 564 | : null; |
| 565 | |
| 566 | const parts: tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Expressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Expression#[] = [ |
| 567 | assignmentExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/assignmentExpression().( |
| 568 | "=", |
| 569 | tmp, |
| 570 | memberExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/memberExpression().( |
| 571 | superPropscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/standardizeSuperProperty().(superProp).nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..objectscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/MemberExpression#object., |
| 572 | computedKey |
| 573 | ? assignmentExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/assignmentExpression().( |
| 574 | "=", |
| 575 | computedKey, |
| 576 | superPropscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/standardizeSuperProperty().(superProp).nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..propertyscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/MemberExpression#property. as tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Expressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Expression#, |
| 577 | ) |
| 578 | : superPropscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/standardizeSuperProperty().(superProp).nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..propertyscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/MemberExpression#property., |
| 579 | superPropscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/standardizeSuperProperty().(superProp).nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..computedscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/MemberExpression#computed., |
| 580 | ), |
| 581 | ), |
| 582 | assignmentExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/assignmentExpression().( |
| 583 | "=", |
| 584 | memberExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/memberExpression().( |
| 585 | superPropscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/standardizeSuperProperty().(superProp).nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..objectscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/MemberExpression#object., |
| 586 | computedKey ? identifierscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/identifier().(computedKey.namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#name.) : superPropscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/standardizeSuperProperty().(superProp).nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..propertyscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/MemberExpression#property., |
| 587 | superPropscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/standardizeSuperProperty().(superProp).nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..computedscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/MemberExpression#computed., |
| 588 | ), |
| 589 | binaryExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/binaryExpression().( |
| 590 | // map `++` to `+`, and `--` to `-` |
| 591 | superPropscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/standardizeSuperProperty().(superProp).parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath..nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..operatorscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/UpdateExpression#operator.[0] as "+" | "-", |
| 592 | identifierscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/identifier().(tmp.namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#name.), |
| 593 | numericLiteralscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/numericLiteral().(1), |
| 594 | ), |
| 595 | ), |
| 596 | ]; |
| 597 | |
| 598 | if (!superPropscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/standardizeSuperProperty().(superProp).parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath..nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..prefixscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/UpdateExpression#prefix.) { |
| 599 | parts.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(identifierscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/identifier().(tmp.namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#name.)); |
| 600 | } |
| 601 | |
| 602 | updateExpr.replaceWithscip-typescript npm @babel/traverse 7.20.13 src/path/`replacement.ts`/replaceWith().(sequenceExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/sequenceExpression().(parts)); |
| 603 | |
| 604 | const left = updateExpr.get( |
| 605 | "expressions.0.right", |
| 606 | ) as NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.MemberExpressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/MemberExpression#>; |
| 607 | const right = updateExpr.get( |
| 608 | "expressions.1.left", |
| 609 | ) as NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.MemberExpressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/MemberExpression#>; |
| 610 | return [left, right]; |
| 611 | } |
| 612 | |
| 613 | return [superPropscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/standardizeSuperProperty().(superProp)]; |
| 614 | |
| 615 | function rightExpression( |
| 616 | op: BinaryOpscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/BinaryOp# | "=", |
| 617 | left: tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.MemberExpressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/MemberExpression#, |
| 618 | right: tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Expressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Expression#, |
| 619 | ) { |
| 620 | if (op === "=") { |
| 621 | return assignmentExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/assignmentExpression().("=", left, right); |
| 622 | } else { |
| 623 | return binaryExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/binaryExpression().(op, left, right); |
| 624 | } |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | function hasSuperClassscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/hasSuperClass().(thisEnvFnscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/hasSuperClass().(thisEnvFn): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Functionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Function#>) { |
| 629 | return ( |
| 630 | thisEnvFnscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/hasSuperClass().(thisEnvFn).isClassMethodscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isClassMethod().() && |
| 631 | !!(thisEnvFnscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/hasSuperClass().(thisEnvFn).parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath..parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath..nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node. as tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Classscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Class#).superClassscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/ClassDeclaration#superClass. |
| 632 | ); |
| 633 | } |
| 634 | |
| 635 | const assignSuperThisVisitorscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/assignSuperThisVisitor. = mergeVisitorsscip-typescript npm @babel/traverse 7.20.13 src/`visitors.ts`/merge().<{ |
| 636 | supers: WeakSetscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/WeakSet#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.CallExpressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/CallExpression#>; |
| 637 | thisBinding: string; |
| 638 | }>([ |
| 639 | { |
| 640 | CallExpression(child, { supers, thisBinding }) { |
| 641 | if (!child.get("callee").isSuperscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isSuper().()) return; |
| 642 | if (supers.hasscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/WeakSet#has().(child.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node.)) return; |
| 643 | supers.addscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/WeakSet#add().(child.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node.); |
| 644 | |
| 645 | child.replaceWithMultiplescip-typescript npm @babel/traverse 7.20.13 src/path/`replacement.ts`/replaceWithMultiple().([ |
| 646 | child.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node., |
| 647 | assignmentExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/assignmentExpression().("=", identifierscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/identifier().(thisBinding), identifierscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/identifier().("this")), |
| 648 | ]); |
| 649 | }, |
| 650 | }, |
| 651 | environmentVisitorscip-typescript npm @babel/helper-environment-visitor 7.18.9 src/`index.ts`/visitor., |
| 652 | ]); |
| 653 | |
| 654 | // Create a binding that evaluates to the "this" of the given function. |
| 655 | function getThisBindingscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getThisBinding().( |
| 656 | thisEnvFnscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getThisBinding().(thisEnvFn): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Functionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Function#>, |
| 657 | inConstructorscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getThisBinding().(inConstructor): boolean, |
| 658 | ) { |
| 659 | return getBindingscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getBinding().(thisEnvFnscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getThisBinding().(thisEnvFn), "this", thisBinding => { |
| 660 | if (!inConstructorscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getThisBinding().(inConstructor) || !hasSuperClassscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/hasSuperClass().(thisEnvFnscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getThisBinding().(thisEnvFn))) return thisExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/thisExpression().(); |
| 661 | |
| 662 | thisEnvFnscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getThisBinding().(thisEnvFn).traversescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#traverse().(assignSuperThisVisitorscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/assignSuperThisVisitor., { |
| 663 | supersscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/supers0:: new WeakSetscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/WeakSet#(), |
| 664 | thisBindingscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/thisBinding0:, |
| 665 | }); |
| 666 | }); |
| 667 | } |
| 668 | |
| 669 | // Create a binding for a function that will call "super()" with arguments passed through. |
| 670 | function getSuperBindingscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getSuperBinding().(thisEnvFnscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getSuperBinding().(thisEnvFn): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Functionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Function#>) { |
| 671 | return getBindingscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getBinding().(thisEnvFnscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getSuperBinding().(thisEnvFn), "supercall", () => { |
| 672 | const argsBinding = thisEnvFnscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getSuperBinding().(thisEnvFn).scopescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#scope..generateUidIdentifierscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#generateUidIdentifier().("args"); |
| 673 | return arrowFunctionExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/arrowFunctionExpression().( |
| 674 | [restElementscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/restElement().(argsBinding)], |
| 675 | callExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/callExpression().(_superscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/_super().(), [spreadElementscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/spreadElement().(identifierscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/identifier().(argsBinding.namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#name.))]), |
| 676 | ); |
| 677 | }); |
| 678 | } |
| 679 | |
| 680 | // Create a binding for a function that will call "super.foo" or "super[foo]". |
| 681 | function getSuperPropBindingscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getSuperPropBinding().( |
| 682 | thisEnvFnscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getSuperPropBinding().(thisEnvFn): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Functionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Function#>, |
| 683 | isAssignmentscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getSuperPropBinding().(isAssignment): boolean, |
| 684 | propNamescip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getSuperPropBinding().(propName): string, |
| 685 | ) { |
| 686 | const op = isAssignmentscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getSuperPropBinding().(isAssignment) ? "set" : "get"; |
| 687 | |
| 688 | return getBindingscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getBinding().(thisEnvFnscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getSuperPropBinding().(thisEnvFn), `superprop_${op}:${propNamescip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getSuperPropBinding().(propName) || ""}`, () => { |
| 689 | const argsList = []; |
| 690 | |
| 691 | let fnBody; |
| 692 | if (propNamescip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getSuperPropBinding().(propName)) { |
| 693 | // () => super.foo |
| 694 | fnBody = memberExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/memberExpression().(_superscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/_super().(), identifierscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/identifier().(propNamescip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getSuperPropBinding().(propName))); |
| 695 | } else { |
| 696 | const method = thisEnvFnscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getSuperPropBinding().(thisEnvFn).scopescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#scope..generateUidIdentifierscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#generateUidIdentifier().("prop"); |
| 697 | // (method) => super[method] |
| 698 | argsList.unshiftscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#unshift().(method); |
| 699 | fnBody = memberExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/memberExpression().( |
| 700 | _superscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/_super().(), |
| 701 | identifierscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/identifier().(method.namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#name.), |
| 702 | true /* computed */, |
| 703 | ); |
| 704 | } |
| 705 | |
| 706 | if (isAssignmentscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getSuperPropBinding().(isAssignment)) { |
| 707 | const valueIdent = thisEnvFnscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getSuperPropBinding().(thisEnvFn).scopescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#scope..generateUidIdentifierscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#generateUidIdentifier().("value"); |
| 708 | argsList.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(valueIdent); |
| 709 | |
| 710 | fnBody = assignmentExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/assignmentExpression().("=", fnBody, identifierscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/identifier().(valueIdent.namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#name.)); |
| 711 | } |
| 712 | |
| 713 | return arrowFunctionExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/arrowFunctionExpression().(argsList, fnBody); |
| 714 | }); |
| 715 | } |
| 716 | |
| 717 | function getBindingscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getBinding().( |
| 718 | thisEnvFnscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getBinding().(thisEnvFn): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#, |
| 719 | keyscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getBinding().(key): string, |
| 720 | initscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getBinding().(init): (name: string) => tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Expressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Expression#, |
| 721 | ) { |
| 722 | const cacheKey = "binding:" + keyscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getBinding().(key); |
| 723 | let data: string | undefined = thisEnvFnscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getBinding().(thisEnvFn).getDatascip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#getData().(cacheKey); |
| 724 | if (!data) { |
| 725 | const id = thisEnvFnscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getBinding().(thisEnvFn).scopescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#scope..generateUidIdentifierscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#generateUidIdentifier().(keyscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getBinding().(key)); |
| 726 | data = id.namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#name.; |
| 727 | thisEnvFnscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getBinding().(thisEnvFn).setDatascip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#setData().(cacheKey, data); |
| 728 | |
| 729 | thisEnvFnscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getBinding().(thisEnvFn).scopescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#scope..pushscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#push().({ |
| 730 | idscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#push().(opts)typeLiteral191:id.: id, |
| 731 | initscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#push().(opts)typeLiteral191:init.: initscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getBinding().(init)(data), |
| 732 | }); |
| 733 | } |
| 734 | |
| 735 | return data; |
| 736 | } |
| 737 | |
| 738 | type ScopeInfoscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/ScopeInfo# = { |
| 739 | thisPathsscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/ScopeInfo#typeLiteral263:thisPaths.: NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.ThisExpressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/ThisExpression# | tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.JSXIdentifierscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/JSXIdentifier#>[]; |
| 740 | superCallsscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/ScopeInfo#typeLiteral263:superCalls.: NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.CallExpressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/CallExpression#>[]; |
| 741 | superPropsscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/ScopeInfo#typeLiteral263:superProps.: NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.MemberExpressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/MemberExpression#>[]; |
| 742 | argumentsPathsscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/ScopeInfo#typeLiteral263:argumentsPaths.: NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Identifierscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier# | tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.JSXIdentifierscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/JSXIdentifier#>[]; |
| 743 | newTargetPathsscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/ScopeInfo#typeLiteral263:newTargetPaths.: NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.MetaPropertyscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/MetaProperty#>[]; |
| 744 | }; |
| 745 | |
| 746 | const getScopeInformationVisitorscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getScopeInformationVisitor. = mergeVisitorsscip-typescript npm @babel/traverse 7.20.13 src/`visitors.ts`/merge().<ScopeInfoscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/ScopeInfo#>([ |
| 747 | { |
| 748 | ThisExpression(child, { thisPathsscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/ScopeInfo#typeLiteral263:thisPaths. }) { |
| 749 | thisPaths.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(child); |
| 750 | }, |
| 751 | JSXIdentifier(child, { thisPathsscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/ScopeInfo#typeLiteral263:thisPaths. }) { |
| 752 | if (child.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/JSXIdentifier#name. !== "this") return; |
| 753 | if ( |
| 754 | !child.parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath..isJSXMemberExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isJSXMemberExpression().({ objectscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/object0:: child.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node. }) && |
| 755 | !child.parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath..isJSXOpeningElementscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isJSXOpeningElement().({ namescip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/name0:: child.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node. }) |
| 756 | ) { |
| 757 | return; |
| 758 | } |
| 759 | |
| 760 | thisPaths.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(child); |
| 761 | }, |
| 762 | CallExpression(child, { superCallsscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/ScopeInfo#typeLiteral263:superCalls. }) { |
| 763 | if (child.get("callee").isSuperscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isSuper().()) superCalls.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(child); |
| 764 | }, |
| 765 | MemberExpression(child, { superPropsscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/ScopeInfo#typeLiteral263:superProps. }) { |
| 766 | if (child.get("object").isSuperscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isSuper().()) superProps.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(child); |
| 767 | }, |
| 768 | Identifier(child, { argumentsPathsscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/ScopeInfo#typeLiteral263:argumentsPaths. }) { |
| 769 | if (!child.isReferencedIdentifierscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`virtual-types-validator.ts`/VirtualTypeNodePathValidators#isReferencedIdentifier().({ namescip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/name1:: "arguments" })) return; |
| 770 | |
| 771 | let curr = child.scopescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#scope.; |
| 772 | do { |
| 773 | if (curr.hasOwnBindingscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#hasOwnBinding().("arguments")) { |
| 774 | curr.renamescip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#rename().("arguments"); |
| 775 | return; |
| 776 | } |
| 777 | if (curr.pathscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#path..isFunctionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isFunction().() && !curr.pathscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#path..isArrowFunctionExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isArrowFunctionExpression().()) { |
| 778 | break; |
| 779 | } |
| 780 | } while ((curr = curr.parentscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#`<get>parent`().)); |
| 781 | |
| 782 | argumentsPaths.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(child); |
| 783 | }, |
| 784 | MetaProperty(child, { newTargetPathsscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/ScopeInfo#typeLiteral263:newTargetPaths. }) { |
| 785 | if (!child.get("meta").isIdentifierscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isIdentifier().({ namescip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/name2:: "new" })) return; |
| 786 | if (!child.get("property").isIdentifierscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isIdentifier().({ namescip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/name3:: "target" })) return; |
| 787 | |
| 788 | newTargetPaths.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(child); |
| 789 | }, |
| 790 | }, |
| 791 | environmentVisitorscip-typescript npm @babel/helper-environment-visitor 7.18.9 src/`index.ts`/visitor., |
| 792 | ]); |
| 793 | |
| 794 | function getScopeInformationscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getScopeInformation().(fnPathscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getScopeInformation().(fnPath): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#) { |
| 795 | const thisPaths: ScopeInfoscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/ScopeInfo#["thisPaths"scip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/ScopeInfo#typeLiteral263:thisPaths.] = []; |
| 796 | const argumentsPaths: ScopeInfoscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/ScopeInfo#["argumentsPaths"scip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/ScopeInfo#typeLiteral263:argumentsPaths.] = []; |
| 797 | const newTargetPaths: ScopeInfoscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/ScopeInfo#["newTargetPaths"scip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/ScopeInfo#typeLiteral263:newTargetPaths.] = []; |
| 798 | const superProps: ScopeInfoscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/ScopeInfo#["superProps"scip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/ScopeInfo#typeLiteral263:superProps.] = []; |
| 799 | const superCalls: ScopeInfoscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/ScopeInfo#["superCalls"scip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/ScopeInfo#typeLiteral263:superCalls.] = []; |
| 800 | |
| 801 | fnPathscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getScopeInformation().(fnPath).traversescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#traverse().(getScopeInformationVisitorscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/getScopeInformationVisitor., { |
| 802 | thisPathsscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/thisPaths1:, |
| 803 | argumentsPathsscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/argumentsPaths1:, |
| 804 | newTargetPathsscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/newTargetPaths1:, |
| 805 | superPropsscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/superProps1:, |
| 806 | superCallsscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/superCalls1:, |
| 807 | }); |
| 808 | |
| 809 | return { |
| 810 | thisPathsscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/thisPaths0:, |
| 811 | argumentsPathsscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/argumentsPaths0:, |
| 812 | newTargetPathsscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/newTargetPaths0:, |
| 813 | superPropsscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/superProps0:, |
| 814 | superCallsscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/superCalls0:, |
| 815 | }; |
| 816 | } |