| 1 |
// This file contains methods responsible for introspecting the current path for certain values. |
| 2 |
|
| 3 |
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`/; |
| 4 |
import { |
| 5 |
STATEMENT_OR_BLOCK_KEYSscip-typescript npm @babel/types 7.20.7 src/constants/`index.ts`/STATEMENT_OR_BLOCK_KEYS., |
| 6 |
VISITOR_KEYSscip-typescript npm @babel/types 7.20.7 src/definitions/`utils.ts`/VISITOR_KEYS., |
| 7 |
isBlockStatementscip-typescript npm @babel/types 7.20.7 src/validators/generated/`index.ts`/isBlockStatement()., |
| 8 |
isExpressionscip-typescript npm @babel/types 7.20.7 src/validators/generated/`index.ts`/isExpression()., |
| 9 |
isIdentifierscip-typescript npm @babel/types 7.20.7 src/validators/generated/`index.ts`/isIdentifier()., |
| 10 |
isLiteralscip-typescript npm @babel/types 7.20.7 src/validators/generated/`index.ts`/isLiteral()., |
| 11 |
isStringLiteralscip-typescript npm @babel/types 7.20.7 src/validators/generated/`index.ts`/isStringLiteral()., |
| 12 |
isTypescip-typescript npm @babel/types 7.20.7 src/validators/`isType.ts`/isType()., |
| 13 |
matchesPattern as _matchesPatternscip-typescript npm @babel/types 7.20.7 src/validators/`matchesPattern.ts`/matchesPattern()., |
| 14 |
} from "@babel/types"scip-typescript npm @babel/types 7.20.7 src/`index.ts`/; |
| 15 |
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`/; |
| 16 |
|
| 17 |
/** |
| 18 |
* Match the current node if it matches the provided `pattern`. |
| 19 |
* |
| 20 |
* For example, given the match `React.createClass` it would match the |
| 21 |
* parsed nodes of `React.createClass` and `React["createClass"]`. |
| 22 |
*/ |
| 23 |
|
| 24 |
export function matchesPatternscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/matchesPattern().( |
| 25 |
thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/matchesPattern().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#, |
| 26 |
patternscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/matchesPattern().(pattern): string, |
| 27 |
allowPartialscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/matchesPattern().(allowPartial)?: boolean, |
| 28 |
): boolean { |
| 29 |
return _matchesPatternscip-typescript npm @babel/types 7.20.7 src/validators/`matchesPattern.ts`/matchesPattern().(this.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node., patternscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/matchesPattern().(pattern), allowPartialscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/matchesPattern().(allowPartial)); |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Check whether we have the input `key`. If the `key` references an array then we check |
| 34 |
* if the array has any items, otherwise we just check if it's falsy. |
| 35 |
*/ |
| 36 |
|
| 37 |
export function hasscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/has().<Nscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/has().[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#>( |
| 38 |
thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/has().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<Nscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/has().[N]>, |
| 39 |
keyscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/has().(key): keyof Nscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/has().[N], |
| 40 |
): boolean { |
| 41 |
const val = this.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node. && this.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node.[keyscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/has().(key)]; |
| 42 |
if (val && 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().(val)) { |
| 43 |
return !!val.lengthscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#length.; |
| 44 |
} else { |
| 45 |
return !!val; |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Description |
| 51 |
*/ |
| 52 |
|
| 53 |
export function isStaticscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isStatic().(thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isStatic().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#): boolean { |
| 54 |
return this.scopescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#scope..isStaticscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#isStatic().(this.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node.); |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Alias of `has`. |
| 59 |
*/ |
| 60 |
|
| 61 |
export const isscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/is. = hasscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/has().; |
| 62 |
|
| 63 |
/** |
| 64 |
* Opposite of `has`. |
| 65 |
*/ |
| 66 |
|
| 67 |
export function isntscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isnt().<Nscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isnt().[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#>( |
| 68 |
thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isnt().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<Nscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isnt().[N]>, |
| 69 |
keyscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isnt().(key): keyof Nscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isnt().[N], |
| 70 |
): boolean { |
| 71 |
return !this.hasscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/has().(keyscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isnt().(key)); |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Check whether the path node `key` strict equals `value`. |
| 76 |
*/ |
| 77 |
|
| 78 |
export function equalsscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/equals().<Nscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/equals().[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#>( |
| 79 |
thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/equals().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<Nscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/equals().[N]>, |
| 80 |
keyscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/equals().(key): keyof Nscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/equals().[N], |
| 81 |
valuescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/equals().(value): any, |
| 82 |
): boolean { |
| 83 |
return this.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node.[keyscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/equals().(key)] === valuescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/equals().(value); |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* Check the type against our stored internal type of the node. This is handy when a node has |
| 88 |
* been removed yet we still internally know the type and need it to calculate node replacement. |
| 89 |
*/ |
| 90 |
|
| 91 |
export function isNodeTypescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isNodeType().(thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isNodeType().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#, typescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isNodeType().(type): string): boolean { |
| 92 |
return isTypescip-typescript npm @babel/types 7.20.7 src/validators/`isType.ts`/isType().(this.typescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#type., typescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isNodeType().(type)); |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* This checks whether or not we're in one of the following positions: |
| 97 |
* |
| 98 |
* for (KEY in right); |
| 99 |
* for (KEY;;); |
| 100 |
* |
| 101 |
* This is because these spots allow VariableDeclarations AND normal expressions so we need |
| 102 |
* to tell the path replacement that it's ok to replace this with an expression. |
| 103 |
*/ |
| 104 |
|
| 105 |
export function canHaveVariableDeclarationOrExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/canHaveVariableDeclarationOrExpression().(thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/canHaveVariableDeclarationOrExpression().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#) { |
| 106 |
return ( |
| 107 |
(this.keyscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#key. === "init" || this.keyscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#key. === "left") && this.parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath..isForscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isFor().() |
| 108 |
); |
| 109 |
} |
| 110 |
|
| 111 |
/** |
| 112 |
* This checks whether we are swapping an arrow function's body between an |
| 113 |
* expression and a block statement (or vice versa). |
| 114 |
* |
| 115 |
* This is because arrow functions may implicitly return an expression, which |
| 116 |
* is the same as containing a block statement. |
| 117 |
*/ |
| 118 |
|
| 119 |
export function canSwapBetweenExpressionAndStatementscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/canSwapBetweenExpressionAndStatement().( |
| 120 |
thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/canSwapBetweenExpressionAndStatement().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#, |
| 121 |
replacementscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/canSwapBetweenExpressionAndStatement().(replacement): 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#, |
| 122 |
): boolean { |
| 123 |
if (this.keyscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#key. !== "body" || !this.parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath..isArrowFunctionExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isArrowFunctionExpression().()) { |
| 124 |
return false; |
| 125 |
} |
| 126 |
|
| 127 |
if (this.isExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isExpression().()) { |
| 128 |
return isBlockStatementscip-typescript npm @babel/types 7.20.7 src/validators/generated/`index.ts`/isBlockStatement().(replacementscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/canSwapBetweenExpressionAndStatement().(replacement)); |
| 129 |
} else if (this.isBlockStatementscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isBlockStatement().()) { |
| 130 |
return isExpressionscip-typescript npm @babel/types 7.20.7 src/validators/generated/`index.ts`/isExpression().(replacementscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/canSwapBetweenExpressionAndStatement().(replacement)); |
| 131 |
} |
| 132 |
|
| 133 |
return false; |
| 134 |
} |
| 135 |
|
| 136 |
/** |
| 137 |
* Check whether the current path references a completion record |
| 138 |
*/ |
| 139 |
|
| 140 |
export function isCompletionRecordscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isCompletionRecord().( |
| 141 |
thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isCompletionRecord().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#, |
| 142 |
allowInsideFunctionscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isCompletionRecord().(allowInsideFunction)?: boolean, |
| 143 |
): boolean { |
| 144 |
let path = this; |
| 145 |
let first = true; |
| 146 |
|
| 147 |
do { |
| 148 |
const { typescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#type., containerscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#container. } = path; |
| 149 |
|
| 150 |
// we're in a function so can't be a completion record |
| 151 |
if (!first && (path.isFunctionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isFunction().() || type === "StaticBlock")) { |
| 152 |
return !!allowInsideFunctionscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isCompletionRecord().(allowInsideFunction); |
| 153 |
} |
| 154 |
|
| 155 |
first = false; |
| 156 |
|
| 157 |
// check to see if we're the last item in the container and if we are |
| 158 |
// we're a completion record! |
| 159 |
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().(container) && path.keyscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#key. !== container.lengthscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#length. - 1) { |
| 160 |
return false; |
| 161 |
} |
| 162 |
} while ( |
| 163 |
(path = path.parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath.) && |
| 164 |
!path.isProgramscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isProgram().() && |
| 165 |
!path.isDoExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isDoExpression().() |
| 166 |
); |
| 167 |
|
| 168 |
return true; |
| 169 |
} |
| 170 |
|
| 171 |
/** |
| 172 |
* Check whether or not the current `key` allows either a single statement or block statement |
| 173 |
* so we can explode it if necessary. |
| 174 |
*/ |
| 175 |
|
| 176 |
export function isStatementOrBlockscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isStatementOrBlock().(thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isStatementOrBlock().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#): boolean { |
| 177 |
if ( |
| 178 |
this.parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath..isLabeledStatementscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isLabeledStatement().() || |
| 179 |
isBlockStatementscip-typescript npm @babel/types 7.20.7 src/validators/generated/`index.ts`/isBlockStatement().(this.containerscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#container.) |
| 180 |
) { |
| 181 |
return false; |
| 182 |
} else { |
| 183 |
return STATEMENT_OR_BLOCK_KEYSscip-typescript npm @babel/types 7.20.7 src/constants/`index.ts`/STATEMENT_OR_BLOCK_KEYS..includesscip-typescript npm typescript 5.9.3 lib/`lib.es2016.array.include.d.ts`/Array#includes().(this.keyscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#key. as string); |
| 184 |
} |
| 185 |
} |
| 186 |
|
| 187 |
/** |
| 188 |
* Check if the currently assigned path references the `importName` of `moduleSource`. |
| 189 |
*/ |
| 190 |
|
| 191 |
export function referencesImportscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/referencesImport().( |
| 192 |
thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/referencesImport().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#, |
| 193 |
moduleSourcescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/referencesImport().(moduleSource): string, |
| 194 |
importNamescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/referencesImport().(importName): string, |
| 195 |
): boolean { |
| 196 |
if (!this.isReferencedIdentifierscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`virtual-types-validator.ts`/VirtualTypeNodePathValidators#isReferencedIdentifier().()) { |
| 197 |
if ( |
| •198 |
// @ts-ignore |
| 199 |
(this.isJSXMemberExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isJSXMemberExpression().() && |
| •200 |
// @ts-ignore |
| 201 |
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`/JSXMemberExpression#property..namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/JSXIdentifier#name. === importNamescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/referencesImport().(importName)) || |
| •202 |
// @ts-ignore |
| 203 |
((this.isMemberExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isMemberExpression().() || this.isOptionalMemberExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isOptionalMemberExpression().()) && |
| •204 |
// @ts-ignore |
| 205 |
(this.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. |
| •206 |
// @ts-ignore |
| 207 |
? isStringLiteralscip-typescript npm @babel/types 7.20.7 src/validators/generated/`index.ts`/isStringLiteral().(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., { valuescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/value0:: importNamescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/referencesImport().(importName) }) |
| •208 |
// @ts-ignore |
| 209 |
: (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. 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#).namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#name. === importNamescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/referencesImport().(importName))) |
| 210 |
) { |
| 211 |
const object = ( |
| 212 |
this 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# | tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.OptionalMemberExpressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/OptionalMemberExpression#> |
| 213 |
).get("object"); |
| 214 |
return ( |
| 215 |
object.isReferencedIdentifierscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`virtual-types-validator.ts`/VirtualTypeNodePathValidators#isReferencedIdentifier().() && |
| 216 |
object.referencesImportscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/referencesImport().(moduleSourcescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/referencesImport().(moduleSource), "*") |
| 217 |
); |
| 218 |
} |
| 219 |
|
| 220 |
return false; |
| 221 |
} |
| 222 |
|
| 223 |
const binding = this.scopescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#scope..getBindingscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#getBinding().((this.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`/.Identifierscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#).namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#name.); |
| 224 |
if (!binding || binding.kindscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#kind. !== "module") return false; |
| 225 |
|
| 226 |
const path = binding.pathscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#path.; |
| 227 |
const parent = path.parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath.; |
| 228 |
if (!parent.isImportDeclarationscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isImportDeclaration().()) return false; |
| 229 |
|
| 230 |
// check moduleSource |
| 231 |
if (parent.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..sourcescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/ImportDeclaration#source..valuescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/StringLiteral#value. === moduleSourcescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/referencesImport().(moduleSource)) { |
| 232 |
if (!importNamescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/referencesImport().(importName)) return true; |
| 233 |
} else { |
| 234 |
return false; |
| 235 |
} |
| 236 |
|
| 237 |
if (path.isImportDefaultSpecifierscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isImportDefaultSpecifier().() && importNamescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/referencesImport().(importName) === "default") { |
| 238 |
return true; |
| 239 |
} |
| 240 |
|
| 241 |
if (path.isImportNamespaceSpecifierscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isImportNamespaceSpecifier().() && importNamescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/referencesImport().(importName) === "*") { |
| 242 |
return true; |
| 243 |
} |
| 244 |
|
| 245 |
if ( |
| 246 |
path.isImportSpecifierscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isImportSpecifier().() && |
| 247 |
isIdentifierscip-typescript npm @babel/types 7.20.7 src/validators/generated/`index.ts`/isIdentifier().(path.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..importedscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/ImportSpecifier#imported., { namescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/name0:: importNamescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/referencesImport().(importName) }) |
| 248 |
) { |
| 249 |
return true; |
| 250 |
} |
| 251 |
|
| 252 |
return false; |
| 253 |
} |
| 254 |
|
| 255 |
/** |
| 256 |
* Get the source code associated with this node. |
| 257 |
*/ |
| 258 |
|
| 259 |
export function getSourcescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/getSource().(thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/getSource().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#): string { |
| 260 |
const node = this.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node.; |
| 261 |
if (node.endscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/BaseNode#end.) { |
| 262 |
const code = this.hubscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#hub..getCodescip-typescript npm @babel/traverse 7.20.13 src/`hub.ts`/HubInterface#getCode().(); |
| 263 |
if (code) return code.slicescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/String#slice().(node.startscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/BaseNode#start., node.endscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/BaseNode#end.); |
| 264 |
} |
| 265 |
return ""; |
| 266 |
} |
| 267 |
|
| 268 |
export function willIMaybeExecuteBeforescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/willIMaybeExecuteBefore().( |
| 269 |
thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/willIMaybeExecuteBefore().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#, |
| 270 |
targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/willIMaybeExecuteBefore().(target): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#, |
| 271 |
): boolean { |
| 272 |
return this._guessExecutionStatusRelativeToscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeTo().(targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/willIMaybeExecuteBefore().(target)) !== "after"; |
| 273 |
} |
| 274 |
|
| 275 |
function getOuterFunctionscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/getOuterFunction().(pathscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/getOuterFunction().(path): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#) { |
| 276 |
return pathscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/getOuterFunction().(path).isProgramscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isProgram().() |
| 277 |
? pathscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/getOuterFunction().(path) |
| 278 |
: ( |
| 279 |
pathscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/getOuterFunction().(path).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..getFunctionParentscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#getFunctionParent().() || |
| 280 |
pathscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/getOuterFunction().(path).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..getProgramParentscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#getProgramParent().() |
| 281 |
).pathscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#path.; |
| 282 |
} |
| 283 |
|
| 284 |
function isExecutionUncertainscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isExecutionUncertain().(typescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isExecutionUncertain().(type): 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#["type"scip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/ArrayExpression#type.], keyscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isExecutionUncertain().(key): string) { |
| 285 |
switch (typescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isExecutionUncertain().(type)) { |
| 286 |
// a && FOO |
| 287 |
// a || FOO |
| 288 |
case "LogicalExpression": |
| 289 |
return keyscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isExecutionUncertain().(key) === "right"; |
| 290 |
|
| 291 |
// a ? FOO : FOO |
| 292 |
// if (a) FOO; else FOO; |
| 293 |
case "ConditionalExpression": |
| 294 |
case "IfStatement": |
| 295 |
return keyscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isExecutionUncertain().(key) === "consequent" || keyscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isExecutionUncertain().(key) === "alternate"; |
| 296 |
|
| 297 |
// while (a) FOO; |
| 298 |
case "WhileStatement": |
| 299 |
case "DoWhileStatement": |
| 300 |
case "ForInStatement": |
| 301 |
case "ForOfStatement": |
| 302 |
return keyscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isExecutionUncertain().(key) === "body"; |
| 303 |
|
| 304 |
// for (a; b; FOO) FOO; |
| 305 |
case "ForStatement": |
| 306 |
return keyscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isExecutionUncertain().(key) === "body" || keyscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isExecutionUncertain().(key) === "update"; |
| 307 |
|
| 308 |
// switch (a) { FOO } |
| 309 |
case "SwitchStatement": |
| 310 |
return keyscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isExecutionUncertain().(key) === "cases"; |
| 311 |
|
| 312 |
// try { a } catch FOO finally { b } |
| 313 |
case "TryStatement": |
| 314 |
return keyscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isExecutionUncertain().(key) === "handler"; |
| 315 |
|
| 316 |
// var [ x = FOO ] |
| 317 |
case "AssignmentPattern": |
| 318 |
return keyscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isExecutionUncertain().(key) === "right"; |
| 319 |
|
| 320 |
// a?.[FOO] |
| 321 |
case "OptionalMemberExpression": |
| 322 |
return keyscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isExecutionUncertain().(key) === "property"; |
| 323 |
|
| 324 |
// a?.(FOO) |
| 325 |
case "OptionalCallExpression": |
| 326 |
return keyscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isExecutionUncertain().(key) === "arguments"; |
| 327 |
|
| 328 |
default: |
| 329 |
return false; |
| 330 |
} |
| 331 |
} |
| 332 |
|
| 333 |
function isExecutionUncertainInListscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isExecutionUncertainInList().(pathsscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isExecutionUncertainInList().(paths): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#[], maxIndexscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isExecutionUncertainInList().(maxIndex): number) { |
| 334 |
for (let i = 0; i < maxIndexscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isExecutionUncertainInList().(maxIndex); i++) { |
| 335 |
const path = pathsscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isExecutionUncertainInList().(paths)[i]; |
| 336 |
if (isExecutionUncertainscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isExecutionUncertain().(path.parentscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parent..typescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/ArrayExpression#type., path.parentKeyscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#`<get>parentKey`().)) { |
| 337 |
return true; |
| 338 |
} |
| 339 |
} |
| 340 |
return false; |
| 341 |
} |
| 342 |
|
| 343 |
// TODO (Babel 8) |
| 344 |
// This can be { before: boolean, after: boolean, unknown: boolean }. |
| 345 |
// This allows transforms like the tdz one to treat cases when the status |
| 346 |
// is both before and unknown/after like if it were before. |
| 347 |
type RelativeExecutionStatusscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/RelativeExecutionStatus# = "before" | "after" | "unknown"; |
| 348 |
|
| 349 |
// Used to avoid infinite recursion in cases like |
| 350 |
// function f() { if (false) f(); } |
| 351 |
// f(); |
| 352 |
// It also works with indirect recursion. |
| 353 |
const SYMBOL_CHECKINGscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/SYMBOL_CHECKING. = Symbolscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Symbol#(); |
| 354 |
|
| 355 |
type ExecutionStatusCachescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/ExecutionStatusCache# = Mapscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/Map#< |
| 356 |
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#, |
| 357 |
Mapscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/Map#<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#, RelativeExecutionStatusscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/RelativeExecutionStatus# | typeof SYMBOL_CHECKINGscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/SYMBOL_CHECKING.> |
| 358 |
>; |
| 359 |
|
| 360 |
/** |
| 361 |
* Given a `target` check the execution status of it relative to the current path. |
| 362 |
* |
| 363 |
* "Execution status" simply refers to where or not we **think** this will execute |
| 364 |
* before or after the input `target` element. |
| 365 |
*/ |
| 366 |
|
| 367 |
export function _guessExecutionStatusRelativeToscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeTo().( |
| 368 |
thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeTo().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#, |
| 369 |
targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeTo().(target): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#, |
| 370 |
): RelativeExecutionStatusscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/RelativeExecutionStatus# { |
| 371 |
return _guessExecutionStatusRelativeToCachedscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToCached().(this, targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeTo().(target), new Mapscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/Map#()); |
| 372 |
} |
| 373 |
|
| 374 |
function _guessExecutionStatusRelativeToCachedscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToCached().( |
| 375 |
basescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToCached().(base): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#, |
| 376 |
targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToCached().(target): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#, |
| 377 |
cachescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToCached().(cache): ExecutionStatusCachescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/ExecutionStatusCache#, |
| 378 |
): RelativeExecutionStatusscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/RelativeExecutionStatus# { |
| 379 |
// check if the two paths are in different functions, we can't track execution of these |
| 380 |
const funcParent = { |
| 381 |
thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/this0:: getOuterFunctionscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/getOuterFunction().(basescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToCached().(base)), |
| 382 |
targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/target0:: getOuterFunctionscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/getOuterFunction().(targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToCached().(target)), |
| 383 |
}; |
| 384 |
|
| 385 |
// here we check the `node` equality as sometimes we may have different paths for the |
| 386 |
// same node due to path thrashing |
| 387 |
if (funcParent.targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/target0:.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node. !== funcParent.thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/this0:.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node.) { |
| 388 |
return _guessExecutionStatusRelativeToDifferentFunctionsCachedscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToDifferentFunctionsCached().( |
| 389 |
basescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToCached().(base), |
| 390 |
funcParent.targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/target0:, |
| 391 |
cachescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToCached().(cache), |
| 392 |
); |
| 393 |
} |
| 394 |
|
| 395 |
const paths = { |
| 396 |
targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/target1:: targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToCached().(target).getAncestryscip-typescript npm @babel/traverse 7.20.13 src/path/`ancestry.ts`/getAncestry().(), |
| 397 |
thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/this1:: basescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToCached().(base).getAncestryscip-typescript npm @babel/traverse 7.20.13 src/path/`ancestry.ts`/getAncestry().(), |
| 398 |
}; |
| 399 |
|
| 400 |
// If this is an ancestor of the target path, |
| 401 |
// e.g. f(g); where this is f and target is g. |
| 402 |
if (paths.targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/target1:.indexOfscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#indexOf().(basescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToCached().(base)) >= 0) return "after"; |
| 403 |
if (paths.thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/this1:.indexOfscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#indexOf().(targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToCached().(target)) >= 0) return "before"; |
| 404 |
|
| 405 |
// get ancestor where the branches intersect |
| 406 |
let commonPath; |
| 407 |
const commonIndex = { targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/target2:: 0, thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/this2:: 0 }; |
| 408 |
|
| 409 |
while (!commonPath && commonIndex.thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/this2: < paths.thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/this1:.lengthscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#length.) { |
| 410 |
const path = paths.thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/this1:[commonIndex.thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/this2:]; |
| 411 |
commonIndex.targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/target2: = paths.targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/target1:.indexOfscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#indexOf().(path); |
| 412 |
if (commonIndex.targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/target2: >= 0) { |
| 413 |
commonPath = path; |
| 414 |
} else { |
| 415 |
commonIndex.thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/this2:++; |
| 416 |
} |
| 417 |
} |
| 418 |
|
| 419 |
if (!commonPath) { |
| 420 |
throw new Errorscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Error#( |
| 421 |
"Internal Babel error - The two compared nodes" + |
| 422 |
" don't appear to belong to the same program.", |
| 423 |
); |
| 424 |
} |
| 425 |
|
| 426 |
if ( |
| 427 |
isExecutionUncertainInListscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isExecutionUncertainInList().(paths.thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/this1:, commonIndex.thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/this2: - 1) || |
| 428 |
isExecutionUncertainInListscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isExecutionUncertainInList().(paths.targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/target1:, commonIndex.targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/target2: - 1) |
| 429 |
) { |
| 430 |
return "unknown"; |
| 431 |
} |
| 432 |
|
| 433 |
const divergence = { |
| 434 |
thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/this3:: paths.thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/this1:[commonIndex.thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/this2: - 1], |
| 435 |
targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/target3:: paths.targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/target1:[commonIndex.targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/target2: - 1], |
| 436 |
}; |
| 437 |
|
| 438 |
// container list so let's see which one is after the other |
| 439 |
// e.g. [ THIS, TARGET ] |
| 440 |
if ( |
| 441 |
divergence.targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/target3:.listKeyscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#listKey. && |
| 442 |
divergence.thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/this3:.listKeyscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#listKey. && |
| 443 |
divergence.targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/target3:.containerscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#container. === divergence.thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/this3:.containerscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#container. |
| 444 |
) { |
| 445 |
return divergence.targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/target3:.keyscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#key. > divergence.thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/this3:.keyscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#key. ? "before" : "after"; |
| 446 |
} |
| 447 |
|
| 448 |
// otherwise we're associated by a parent node, check which key comes before the other |
| 449 |
const keys = VISITOR_KEYSscip-typescript npm @babel/types 7.20.7 src/definitions/`utils.ts`/VISITOR_KEYS.[commonPath.typescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#type.]; |
| 450 |
const keyPosition = { |
| 451 |
thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/this4:: keys.indexOfscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#indexOf().(divergence.thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/this3:.parentKeyscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#`<get>parentKey`().), |
| 452 |
targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/target4:: keys.indexOfscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#indexOf().(divergence.targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/target3:.parentKeyscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#`<get>parentKey`().), |
| 453 |
}; |
| 454 |
return keyPosition.targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/target4: > keyPosition.thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/this4: ? "before" : "after"; |
| 455 |
} |
| 456 |
|
| 457 |
function _guessExecutionStatusRelativeToDifferentFunctionsInternalscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToDifferentFunctionsInternal().( |
| 458 |
basescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToDifferentFunctionsInternal().(base): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#, |
| 459 |
targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToDifferentFunctionsInternal().(target): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#, |
| 460 |
cachescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToDifferentFunctionsInternal().(cache): ExecutionStatusCachescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/ExecutionStatusCache#, |
| 461 |
): RelativeExecutionStatusscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/RelativeExecutionStatus# { |
| 462 |
if (!targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToDifferentFunctionsInternal().(target).isFunctionDeclarationscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isFunctionDeclaration().()) { |
| 463 |
if ( |
| 464 |
_guessExecutionStatusRelativeToCachedscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToCached().(basescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToDifferentFunctionsInternal().(base), targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToDifferentFunctionsInternal().(target), cachescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToDifferentFunctionsInternal().(cache)) === "before" |
| 465 |
) { |
| 466 |
return "before"; |
| 467 |
} |
| 468 |
return "unknown"; |
| 469 |
} else if (targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToDifferentFunctionsInternal().(target).parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath..isExportDeclarationscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isExportDeclaration().()) { |
| 470 |
return "unknown"; |
| 471 |
} |
| 472 |
|
| 473 |
// so we're in a completely different function, if this is a function declaration |
| 474 |
// then we can be a bit smarter and handle cases where the function is either |
| 475 |
// a. not called at all (part of an export) |
| 476 |
// b. called directly |
| 477 |
const binding = targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToDifferentFunctionsInternal().(target).scopescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#scope..getBindingscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#getBinding().(targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToDifferentFunctionsInternal().(target).nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..idscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/FunctionDeclaration#id..namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#name.); |
| 478 |
|
| 479 |
// no references! |
| 480 |
if (!binding.referencesscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#references.) return "before"; |
| 481 |
|
| 482 |
const referencePaths: Arrayscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#<NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#> = binding.referencePathsscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#referencePaths.; |
| 483 |
|
| 484 |
let allStatus; |
| 485 |
|
| 486 |
// verify that all the calls have the same execution status |
| 487 |
for (const path of referencePaths) { |
| 488 |
// if a reference is a child of the function we're checking against then we can |
| 489 |
// safely ignore it |
| 490 |
const childOfFunction = !!path.findscip-typescript npm @babel/traverse 7.20.13 src/path/`ancestry.ts`/find().(path => path.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node. === targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToDifferentFunctionsInternal().(target).nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node.); |
| 491 |
if (childOfFunction) continue; |
| 492 |
|
| 493 |
if (path.keyscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#key. !== "callee" || !path.parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath..isCallExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isCallExpression().()) { |
| 494 |
// This function is passed as a reference, so we don't |
| 495 |
// know when it will be called. |
| 496 |
return "unknown"; |
| 497 |
} |
| 498 |
|
| 499 |
const status = _guessExecutionStatusRelativeToCachedscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToCached().(basescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToDifferentFunctionsInternal().(base), path, cachescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToDifferentFunctionsInternal().(cache)); |
| 500 |
|
| 501 |
if (allStatus && allStatus !== status) { |
| 502 |
return "unknown"; |
| 503 |
} else { |
| 504 |
allStatus = status; |
| 505 |
} |
| 506 |
} |
| 507 |
|
| 508 |
return allStatus; |
| 509 |
} |
| 510 |
|
| 511 |
function _guessExecutionStatusRelativeToDifferentFunctionsCachedscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToDifferentFunctionsCached().( |
| 512 |
basescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToDifferentFunctionsCached().(base): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#, |
| 513 |
targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToDifferentFunctionsCached().(target): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#, |
| 514 |
cachescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToDifferentFunctionsCached().(cache): ExecutionStatusCachescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/ExecutionStatusCache#, |
| 515 |
): RelativeExecutionStatusscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/RelativeExecutionStatus# { |
| 516 |
let nodeMap = cachescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToDifferentFunctionsCached().(cache).getscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/Map#get().(basescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToDifferentFunctionsCached().(base).nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node.); |
| 517 |
let cached; |
| 518 |
|
| 519 |
if (!nodeMap) { |
| 520 |
cachescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToDifferentFunctionsCached().(cache).setscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/Map#set().(basescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToDifferentFunctionsCached().(base).nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node., (nodeMap = new Mapscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/Map#())); |
| 521 |
} else if ((cached = nodeMap.getscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/Map#get().(targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToDifferentFunctionsCached().(target).nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node.))) { |
| 522 |
if (cached === SYMBOL_CHECKINGscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/SYMBOL_CHECKING.) { |
| 523 |
return "unknown"; |
| 524 |
} |
| 525 |
return cached; |
| 526 |
} |
| 527 |
|
| 528 |
nodeMap.setscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/Map#set().(targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToDifferentFunctionsCached().(target).nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node., SYMBOL_CHECKINGscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/SYMBOL_CHECKING.); |
| 529 |
|
| 530 |
const result = _guessExecutionStatusRelativeToDifferentFunctionsInternalscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToDifferentFunctionsInternal().( |
| 531 |
basescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToDifferentFunctionsCached().(base), |
| 532 |
targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToDifferentFunctionsCached().(target), |
| 533 |
cachescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToDifferentFunctionsCached().(cache), |
| 534 |
); |
| 535 |
|
| 536 |
nodeMap.setscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/Map#set().(targetscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_guessExecutionStatusRelativeToDifferentFunctionsCached().(target).nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node., result); |
| 537 |
return result; |
| 538 |
} |
| 539 |
|
| 540 |
/** |
| 541 |
* Resolve a "pointer" `NodePath` to it's absolute path. |
| 542 |
*/ |
| 543 |
export function resolvescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/resolve().( |
| 544 |
thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/resolve().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#, |
| 545 |
dangerousscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/resolve().(dangerous)?: boolean, |
| 546 |
resolvedscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/resolve().(resolved)?: NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#[], |
| 547 |
) { |
| 548 |
return this._resolvescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_resolve().(dangerousscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/resolve().(dangerous), resolvedscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/resolve().(resolved)) || this; |
| 549 |
} |
| 550 |
|
| 551 |
export function _resolvescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_resolve().( |
| 552 |
thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_resolve().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#, |
| 553 |
dangerousscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_resolve().(dangerous)?: boolean, |
| 554 |
resolvedscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_resolve().(resolved)?: NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#[], |
| 555 |
): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath# | undefined | null { |
| 556 |
// detect infinite recursion |
| 557 |
// todo: possibly have a max length on this just to be safe |
| 558 |
if (resolvedscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_resolve().(resolved) && resolvedscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_resolve().(resolved).indexOfscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#indexOf().(this) >= 0) return; |
| 559 |
|
| 560 |
// we store all the paths we've "resolved" in this array to prevent infinite recursion |
| 561 |
resolvedscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_resolve().(resolved) = resolvedscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_resolve().(resolved) || []; |
| 562 |
resolvedscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_resolve().(resolved).pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(this); |
| 563 |
|
| 564 |
if (this.isVariableDeclaratorscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isVariableDeclarator().()) { |
| 565 |
if (this.get("id").isIdentifierscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isIdentifier().()) { |
| 566 |
return this.get("init").resolvescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/resolve().(dangerousscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_resolve().(dangerous), resolvedscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_resolve().(resolved)); |
| 567 |
} else { |
| 568 |
// otherwise it's a request for a pattern and that's a bit more tricky |
| 569 |
} |
| 570 |
} else if (this.isReferencedIdentifierscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`virtual-types-validator.ts`/VirtualTypeNodePathValidators#isReferencedIdentifier().()) { |
| •571 |
// @ts-ignore |
| 572 |
const binding = this.scopescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#scope..getBindingscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#getBinding().(this.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`/Identifier#name.); |
| 573 |
if (!binding) return; |
| 574 |
|
| 575 |
// reassigned so we can't really resolve it |
| 576 |
if (!binding.constantscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#constant.) return; |
| 577 |
|
| 578 |
// todo - lookup module in dependency graph |
| 579 |
if (binding.kindscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#kind. === "module") return; |
| 580 |
|
| 581 |
if (binding.pathscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#path. !== this) { |
| 582 |
const ret = binding.pathscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#path..resolvescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/resolve().(dangerousscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_resolve().(dangerous), resolvedscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_resolve().(resolved)); |
| 583 |
// If the identifier resolves to parent node then we can't really resolve it. |
| 584 |
if (this.findscip-typescript npm @babel/traverse 7.20.13 src/path/`ancestry.ts`/find().(parent => parent.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node. === ret.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node.)) return; |
| 585 |
return ret; |
| 586 |
} |
| •587 |
// @ts-ignore |
| 588 |
} else if (this.isTypeCastExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isTypeCastExpression().()) { |
| 589 |
// @ ts-ignore todo: babel-types |
| •590 |
// @ts-ignore |
| 591 |
return this.get("expression").resolvescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/resolve().(dangerousscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_resolve().(dangerous), resolvedscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_resolve().(resolved)); |
| •592 |
// @ts-ignore |
| 593 |
} else if (dangerousscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_resolve().(dangerous) && this.isMemberExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isMemberExpression().()) { |
| 594 |
// this is dangerous, as non-direct target assignments will mutate it's state |
| 595 |
// making this resolution inaccurate |
| 596 |
|
| •597 |
// @ts-ignore |
| 598 |
const targetKey = this.toComputedKeyscip-typescript npm @babel/traverse 7.20.13 src/path/`conversion.ts`/toComputedKey().(); |
| 599 |
if (!isLiteralscip-typescript npm @babel/types 7.20.7 src/validators/generated/`index.ts`/isLiteral().(targetKey)) return; |
| 600 |
|
| 601 |
// @ts-expect-error todo(flow->ts): NullLiteral |
| 602 |
const targetName = targetKey.value; |
| 603 |
|
| •604 |
// @ts-ignore |
| 605 |
const target = this.get("object").resolvescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/resolve().(dangerousscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_resolve().(dangerous), resolvedscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_resolve().(resolved)); |
| 606 |
|
| 607 |
if (target.isObjectExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isObjectExpression().()) { |
| 608 |
const props = target.get("properties"); |
| 609 |
for (const prop of props as any[]) { |
| 610 |
if (!prop.isProperty()) continue; |
| 611 |
|
| 612 |
const key = prop.get("key"); |
| 613 |
|
| 614 |
// { foo: obj } |
| 615 |
let match = |
| 616 |
prop.isnt("computed") && key.isIdentifier({ namescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/name1:: targetName }); |
| 617 |
|
| 618 |
// { "foo": "obj" } or { ["foo"]: "obj" } |
| 619 |
match = match || key.isLiteral({ valuescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/value1:: targetName }); |
| 620 |
|
| 621 |
if (match) return prop.get("value").resolve(dangerousscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_resolve().(dangerous), resolvedscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_resolve().(resolved)); |
| 622 |
} |
| 623 |
} else if (target.isArrayExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isArrayExpression().() && !isNaNscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/isNaN().(+targetName)) { |
| 624 |
const elems = target.get("elements"); |
| 625 |
const elem = elems[targetName]; |
| 626 |
if (elem) return elem.resolvescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/resolve().(dangerousscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_resolve().(dangerous), resolvedscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/_resolve().(resolved)); |
| 627 |
} |
| 628 |
} |
| 629 |
} |
| 630 |
|
| 631 |
export function isConstantExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isConstantExpression().(thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isConstantExpression().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#): boolean { |
| 632 |
if (this.isIdentifierscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isIdentifier().()) { |
| 633 |
const binding = this.scopescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#scope..getBindingscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#getBinding().(this.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`/Identifier#name.); |
| 634 |
if (!binding) return false; |
| 635 |
return binding.constantscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#constant.; |
| 636 |
} |
| 637 |
|
| 638 |
if (this.isLiteralscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isLiteral().()) { |
| 639 |
if (this.isRegExpLiteralscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isRegExpLiteral().()) { |
| 640 |
return false; |
| 641 |
} |
| 642 |
|
| 643 |
if (this.isTemplateLiteralscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isTemplateLiteral().()) { |
| 644 |
return this.get("expressions").everyscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#every().(expression => |
| 645 |
expression.isConstantExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isConstantExpression().(), |
| 646 |
); |
| 647 |
} |
| 648 |
|
| 649 |
return true; |
| 650 |
} |
| 651 |
|
| 652 |
if (this.isUnaryExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isUnaryExpression().()) { |
| 653 |
if (this.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`/UnaryExpression#operator. !== "void") { |
| 654 |
return false; |
| 655 |
} |
| 656 |
|
| 657 |
return this.get("argument").isConstantExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isConstantExpression().(); |
| 658 |
} |
| 659 |
|
| 660 |
if (this.isBinaryExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isBinaryExpression().()) { |
| 661 |
const { operatorscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/BinaryExpression#operator. } = this.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node.; |
| 662 |
return ( |
| 663 |
operator !== "in" && |
| 664 |
operator !== "instanceof" && |
| 665 |
this.get("left").isConstantExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isConstantExpression().() && |
| 666 |
this.get("right").isConstantExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isConstantExpression().() |
| 667 |
); |
| 668 |
} |
| 669 |
|
| 670 |
return false; |
| 671 |
} |
| 672 |
|
| 673 |
export function isInStrictModescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isInStrictMode().(thisscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isInStrictMode().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#) { |
| 674 |
const start = this.isProgramscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isProgram().() ? this : this.parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath.; |
| 675 |
|
| 676 |
const strictParent = start.findscip-typescript npm @babel/traverse 7.20.13 src/path/`ancestry.ts`/find().(path => { |
| 677 |
if (path.isProgramscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isProgram().({ sourceTypescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/sourceType0:: "module" })) return true; |
| 678 |
|
| 679 |
if (path.isClassscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isClass().()) return true; |
| 680 |
|
| 681 |
if ( |
| 682 |
path.isArrowFunctionExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isArrowFunctionExpression().() && |
| 683 |
!path.get("body").isBlockStatementscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isBlockStatement().() |
| 684 |
) { |
| 685 |
return false; |
| 686 |
} |
| 687 |
|
| 688 |
let body: tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.BlockStatementscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/BlockStatement# | tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Programscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Program#; |
| 689 |
if (path.isFunctionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isFunction().()) { |
| 690 |
body = path.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. as tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.BlockStatementscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/BlockStatement#; |
| 691 |
} else if (path.isProgramscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isProgram().()) { |
| 692 |
body = path.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node.; |
| 693 |
} else { |
| 694 |
return false; |
| 695 |
} |
| 696 |
|
| 697 |
for (const directive of body.directivesscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/BlockStatement#directives.) { |
| 698 |
if (directive.valuescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Directive#value..valuescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/DirectiveLiteral#value. === "use strict") { |
| 699 |
return true; |
| 700 |
} |
| 701 |
} |
| 702 |
}); |
| 703 |
|
| 704 |
return !!strictParent; |
| 705 |
} |