| 1 |
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`/; |
| 2 |
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`/; |
| 3 |
|
| 4 |
// This file contains Babels metainterpreter that can evaluate static code. |
| 5 |
|
| 6 |
const VALID_CALLEESscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/VALID_CALLEES. = ["String", "Number", "Math"] as const; |
| 7 |
const INVALID_METHODSscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/INVALID_METHODS. = ["random"] as const; |
| 8 |
|
| •9 |
function isValidCalleescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/isValidCallee().(valscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/isValidCallee().(val): string): valscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/isValidCallee().(val) is (typeof VALID_CALLEESscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/VALID_CALLEES.)[number] { |
| 10 |
return VALID_CALLEESscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/VALID_CALLEES..includesscip-typescript npm typescript 5.9.3 lib/`lib.es2016.array.include.d.ts`/ReadonlyArray#includes().( |
| 11 |
// @ts-expect-error val is a string |
| 12 |
valscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/isValidCallee().(val), |
| 13 |
); |
| 14 |
} |
| 15 |
|
| •16 |
function isInvalidMethodscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/isInvalidMethod().(valscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/isInvalidMethod().(val): string): valscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/isInvalidMethod().(val) is (typeof INVALID_METHODSscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/INVALID_METHODS.)[number] { |
| 17 |
return INVALID_METHODSscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/INVALID_METHODS..includesscip-typescript npm typescript 5.9.3 lib/`lib.es2016.array.include.d.ts`/ReadonlyArray#includes().( |
| 18 |
// @ts-expect-error val is a string |
| 19 |
valscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/isInvalidMethod().(val), |
| 20 |
); |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Walk the input `node` and statically evaluate if it's truthy. |
| 25 |
* |
| 26 |
* Returning `true` when we're sure that the expression will evaluate to a |
| 27 |
* truthy value, `false` if we're sure that it will evaluate to a falsy |
| 28 |
* value and `undefined` if we aren't sure. Because of this please do not |
| 29 |
* rely on coercion when using this method and check with === if it's false. |
| 30 |
* |
| 31 |
* For example do: |
| 32 |
* |
| 33 |
* if (t.evaluateTruthy(node) === false) falsyLogic(); |
| 34 |
* |
| 35 |
* **AND NOT** |
| 36 |
* |
| 37 |
* if (!t.evaluateTruthy(node)) falsyLogic(); |
| 38 |
* |
| 39 |
*/ |
| 40 |
|
| 41 |
export function evaluateTruthyscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateTruthy().(thisscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateTruthy().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#): boolean { |
| 42 |
const res = this.evaluatescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluate().(); |
| 43 |
if (res.confidentscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluate().typeLiteral3:confident.) return !!res.valuescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluate().typeLiteral3:value.; |
| 44 |
} |
| 45 |
|
| 46 |
type Statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State# = { |
| 47 |
confidentscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#typeLiteral4:confident.: boolean; |
| 48 |
deoptPathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#typeLiteral4:deoptPath.: NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath# | null; |
| 49 |
seenscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#typeLiteral4:seen.: 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#, Resultscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/Result#>; |
| 50 |
}; |
| 51 |
|
| 52 |
type Resultscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/Result# = { |
| 53 |
resolvedscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/Result#typeLiteral5:resolved.: boolean; |
| 54 |
valuescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/Result#typeLiteral5:value.?: any; |
| 55 |
}; |
| 56 |
/** |
| 57 |
* Deopts the evaluation |
| 58 |
*/ |
| 59 |
function deoptscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/deopt().(pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/deopt().(path): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#, statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/deopt().(state): Statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#) { |
| 60 |
if (!statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/deopt().(state).confidentscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#typeLiteral4:confident.) return; |
| 61 |
statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/deopt().(state).deoptPathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#typeLiteral4:deoptPath. = pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/deopt().(path); |
| 62 |
statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/deopt().(state).confidentscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#typeLiteral4:confident. = false; |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* We wrap the _evaluate method so we can track `seen` nodes, we push an item |
| 67 |
* to the map before we actually evaluate it so we can deopt on self recursive |
| 68 |
* nodes such as: |
| 69 |
* |
| 70 |
* var g = a ? 1 : 2, |
| 71 |
* a = g * this.foo |
| 72 |
*/ |
| 73 |
function evaluateCachedscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateCached().(pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateCached().(path): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#, statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateCached().(state): Statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#): any { |
| 74 |
const { nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node. } = pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateCached().(path); |
| 75 |
const { seenscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#typeLiteral4:seen. } = statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateCached().(state); |
| 76 |
|
| 77 |
if (seen.hasscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/Map#has().(node)) { |
| 78 |
const existing = seen.getscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/Map#get().(node); |
| 79 |
if (existing.resolvedscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/Result#typeLiteral5:resolved.) { |
| 80 |
return existing.valuescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/Result#typeLiteral5:value.; |
| 81 |
} else { |
| 82 |
deoptscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/deopt().(pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateCached().(path), statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateCached().(state)); |
| 83 |
return; |
| 84 |
} |
| 85 |
} else { |
| 86 |
const item: Resultscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/Result# = { resolvedscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/Result#typeLiteral5:resolved.: false }; |
| 87 |
seen.setscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/Map#set().(node, item); |
| 88 |
|
| 89 |
const val = _evaluatescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateCached().(path), statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateCached().(state)); |
| 90 |
if (statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateCached().(state).confidentscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#typeLiteral4:confident.) { |
| 91 |
item.resolvedscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/Result#typeLiteral5:resolved. = true; |
| 92 |
item.valuescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/Result#typeLiteral5:value. = val; |
| 93 |
} |
| 94 |
return val; |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
function _evaluatescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#, statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state): Statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#): any { |
| 99 |
if (!statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state).confidentscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#typeLiteral4:confident.) return; |
| 100 |
|
| 101 |
if (pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).isSequenceExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isSequenceExpression().()) { |
| 102 |
const exprs = pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).get("expressions"); |
| 103 |
return evaluateCachedscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateCached().(exprs[exprs.lengthscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#length. - 1], statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state)); |
| 104 |
} |
| 105 |
|
| 106 |
if ( |
| 107 |
pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).isStringLiteralscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isStringLiteral().() || |
| 108 |
pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).isNumericLiteralscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isNumericLiteral().() || |
| 109 |
pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).isBooleanLiteralscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isBooleanLiteral().() |
| 110 |
) { |
| 111 |
return pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..valuescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/BooleanLiteral#value.; |
| 112 |
} |
| 113 |
|
| 114 |
if (pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).isNullLiteralscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isNullLiteral().()) { |
| 115 |
return null; |
| 116 |
} |
| 117 |
|
| 118 |
if (pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).isTemplateLiteralscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isTemplateLiteral().()) { |
| 119 |
return evaluateQuasisscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateQuasis().(pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path), pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..quasisscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/TemplateLiteral#quasis., statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state)); |
| 120 |
} |
| 121 |
|
| 122 |
if ( |
| 123 |
pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).isTaggedTemplateExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isTaggedTemplateExpression().() && |
| 124 |
pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).get("tag").isMemberExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isMemberExpression().() |
| 125 |
) { |
| 126 |
const object = pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).get("tag.object") as NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#; |
| 127 |
const { |
| 128 |
// @ts-expect-error todo(flow->ts): possible bug, object is can be any expression and so name might be undefined |
| 129 |
nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node.: { name }, |
| 130 |
} = object; |
| 131 |
const property = pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).get("tag.property") as NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#; |
| 132 |
|
| 133 |
if ( |
| 134 |
object.isIdentifierscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isIdentifier().() && |
| 135 |
name === "String" && |
| 136 |
// todo(flow->ts): was changed from getBinding(name, true) |
| 137 |
// should this be hasBinding(name, true) as the binding is never used later? |
| 138 |
!pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).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().(name) && |
| 139 |
property.isIdentifierscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isIdentifier().() && |
| 140 |
property.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. === "raw" |
| 141 |
) { |
| 142 |
return evaluateQuasisscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateQuasis().(pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path), pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..quasiscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/TaggedTemplateExpression#quasi..quasisscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/TemplateLiteral#quasis., statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state), true); |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
if (pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).isConditionalExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isConditionalExpression().()) { |
| 147 |
const testResult = evaluateCachedscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateCached().(pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).get("test"), statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state)); |
| 148 |
if (!statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state).confidentscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#typeLiteral4:confident.) return; |
| 149 |
if (testResult) { |
| 150 |
return evaluateCachedscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateCached().(pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).get("consequent"), statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state)); |
| 151 |
} else { |
| 152 |
return evaluateCachedscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateCached().(pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).get("alternate"), statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state)); |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
if (pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).isExpressionWrapperscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isExpressionWrapper().()) { |
| 157 |
// TypeCastExpression, ExpressionStatement etc |
| 158 |
return evaluateCachedscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateCached().(pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).get("expression"), statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state)); |
| 159 |
} |
| 160 |
|
| 161 |
// "foo".length, "foo"[0] |
| 162 |
if ( |
| 163 |
pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).isMemberExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isMemberExpression().() && |
| 164 |
!pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(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().({ calleescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/callee0:: pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node. }) |
| 165 |
) { |
| 166 |
const property = pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).get("property"); |
| 167 |
const object = pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).get("object"); |
| 168 |
|
| 169 |
if (object.isLiteralscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isLiteral().()) { |
| 170 |
// @ts-expect-error todo(flow->ts): instead of typeof - would it be better to check type of ast node? |
| 171 |
const value = object.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..value; |
| 172 |
const type = typeof value; |
| 173 |
|
| 174 |
let key = null; |
| 175 |
if (pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).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.) { |
| 176 |
key = evaluateCachedscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateCached().(property, statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state)); |
| 177 |
if (!statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state).confidentscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#typeLiteral4:confident.) return; |
| 178 |
} else if (property.isIdentifierscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isIdentifier().()) { |
| 179 |
key = property.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.; |
| 180 |
} |
| 181 |
if ( |
| 182 |
(type === "number" || type === "string") && |
| 183 |
key != null && |
| 184 |
(typeof key === "number" || typeof key === "string") |
| 185 |
) { |
| 186 |
return value[key]; |
| 187 |
} |
| 188 |
} |
| 189 |
} |
| 190 |
|
| 191 |
if (pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).isReferencedIdentifierscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`virtual-types-validator.ts`/VirtualTypeNodePathValidators#isReferencedIdentifier().()) { |
| •192 |
// @ts-ignore |
| 193 |
const binding = pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).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().(pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).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.); |
| 194 |
|
| 195 |
if (binding && binding.constantViolationsscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#constantViolations..lengthscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#length. > 0) { |
| 196 |
return deoptscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/deopt().(binding.pathscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#path., statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state)); |
| 197 |
} |
| 198 |
|
| 199 |
if (binding && pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..startscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/BaseNode#start. < binding.pathscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#path..nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..endscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/BaseNode#end.) { |
| 200 |
return deoptscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/deopt().(binding.pathscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#path., statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state)); |
| 201 |
} |
| 202 |
|
| 203 |
if (binding?.hasValuescip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#hasValue.) { |
| 204 |
return binding.valuescip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#value.; |
| 205 |
} else { |
| •206 |
// @ts-ignore |
| 207 |
if (pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).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. === "undefined") { |
| 208 |
return binding ? deoptscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/deopt().(binding.pathscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#path., statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state)) : undefined; |
| •209 |
// @ts-ignore |
| 210 |
} else if (pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).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. === "Infinity") { |
| 211 |
return binding ? deoptscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/deopt().(binding.pathscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#path., statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state)) : Infinityscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Infinity.; |
| •212 |
// @ts-ignore |
| 213 |
} else if (pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).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. === "NaN") { |
| 214 |
return binding ? deoptscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/deopt().(binding.pathscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#path., statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state)) : NaNscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/NaN.; |
| 215 |
} |
| 216 |
|
| 217 |
const resolved = pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).resolvescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/resolve().(); |
| 218 |
if (resolved === pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path)) { |
| 219 |
return deoptscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/deopt().(pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path), statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state)); |
| 220 |
} else { |
| 221 |
return evaluateCachedscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateCached().(resolved, statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state)); |
| 222 |
} |
| 223 |
} |
| 224 |
} |
| 225 |
|
| •226 |
// @ts-ignore |
| 227 |
if (pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).isUnaryExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isUnaryExpression().({ prefixscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/prefix0:: true })) { |
| •228 |
// @ts-ignore |
| 229 |
if (pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).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") { |
| 230 |
// we don't need to evaluate the argument to know what this will return |
| 231 |
return undefined; |
| 232 |
} |
| 233 |
|
| •234 |
// @ts-ignore |
| 235 |
const argument = pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).get("argument"); |
| 236 |
if ( |
| •237 |
// @ts-ignore |
| 238 |
pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).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. === "typeof" && |
| 239 |
(argument.isFunctionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isFunction().() || argument.isClassscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isClass().()) |
| 240 |
) { |
| 241 |
return "function"; |
| 242 |
} |
| 243 |
|
| 244 |
const arg = evaluateCachedscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateCached().(argument, statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state)); |
| 245 |
if (!statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state).confidentscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#typeLiteral4:confident.) return; |
| •246 |
// @ts-ignore |
| 247 |
switch (pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).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.) { |
| 248 |
case "!": |
| 249 |
return !arg; |
| 250 |
case "+": |
| 251 |
return +arg; |
| 252 |
case "-": |
| 253 |
return -arg; |
| 254 |
case "~": |
| 255 |
return ~arg; |
| 256 |
case "typeof": |
| 257 |
return typeof arg; |
| 258 |
} |
| 259 |
} |
| 260 |
|
| •261 |
// @ts-ignore |
| 262 |
if (pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).isArrayExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isArrayExpression().()) { |
| 263 |
const arr = []; |
| •264 |
// @ts-ignore |
| 265 |
const elems: 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#> = pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).get("elements"); |
| 266 |
for (const elem of elems) { |
| 267 |
const elemValue = elem.evaluatescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluate().(); |
| 268 |
|
| 269 |
if (elemValue.confidentscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluate().typeLiteral3:confident.) { |
| 270 |
arr.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(elemValue.valuescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluate().typeLiteral3:value.); |
| 271 |
} else { |
| 272 |
return deoptscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/deopt().(elemValue.deoptscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluate().typeLiteral3:deopt., statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state)); |
| 273 |
} |
| 274 |
} |
| 275 |
return arr; |
| 276 |
} |
| 277 |
|
| •278 |
// @ts-ignore |
| 279 |
if (pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).isObjectExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isObjectExpression().()) { |
| 280 |
const obj = {}; |
| •281 |
// @ts-ignore |
| 282 |
const props = pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).get("properties"); |
| 283 |
for (const prop of props) { |
| 284 |
if (prop.isObjectMethodscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isObjectMethod().() || prop.isSpreadElementscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isSpreadElement().()) { |
| 285 |
return deoptscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/deopt().(prop, statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state)); |
| 286 |
} |
| 287 |
const keyPath = (prop 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`/.ObjectPropertyscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/ObjectProperty#>).get("key"); |
| 288 |
let key; |
| •289 |
// @ts-ignore |
| 290 |
if (prop.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..computed) { |
| 291 |
key = keyPath.evaluatescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluate().(); |
| 292 |
if (!key.confidentscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluate().typeLiteral3:confident.) { |
| 293 |
return deoptscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/deopt().(key.deoptscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluate().typeLiteral3:deopt., statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state)); |
| 294 |
} |
| 295 |
key = key.valuescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluate().typeLiteral3:value.; |
| 296 |
} else if (keyPath.isIdentifierscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isIdentifier().()) { |
| 297 |
key = keyPath.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.; |
| 298 |
} else { |
| 299 |
key = ( |
| 300 |
keyPath.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`/.StringLiteralscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/StringLiteral# | tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.NumericLiteralscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/NumericLiteral# | tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.BigIntLiteralscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/BigIntLiteral# |
| 301 |
).valuescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/BigIntLiteral#value.; |
| 302 |
} |
| 303 |
const valuePath = (prop 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`/.ObjectPropertyscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/ObjectProperty#>).get("value"); |
| 304 |
let value = valuePath.evaluatescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluate().(); |
| 305 |
if (!value.confidentscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluate().typeLiteral3:confident.) { |
| 306 |
return deoptscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/deopt().(value.deoptscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluate().typeLiteral3:deopt., statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state)); |
| 307 |
} |
| 308 |
value = value.valuescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluate().typeLiteral3:value.; |
| 309 |
// @ts-expect-error key is any type |
| 310 |
obj[key] = value; |
| 311 |
} |
| 312 |
return obj; |
| 313 |
} |
| 314 |
|
| •315 |
// @ts-ignore |
| 316 |
if (pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).isLogicalExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isLogicalExpression().()) { |
| 317 |
// If we are confident that the left side of an && is false, or the left |
| 318 |
// side of an || is true, we can be confident about the entire expression |
| 319 |
const wasConfident = statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state).confidentscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#typeLiteral4:confident.; |
| •320 |
// @ts-ignore |
| 321 |
const left = evaluateCachedscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateCached().(pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).get("left"), statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state)); |
| 322 |
const leftConfident = statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state).confidentscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#typeLiteral4:confident.; |
| 323 |
statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state).confidentscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#typeLiteral4:confident. = wasConfident; |
| •324 |
// @ts-ignore |
| 325 |
const right = evaluateCachedscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateCached().(pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).get("right"), statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state)); |
| 326 |
const rightConfident = statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state).confidentscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#typeLiteral4:confident.; |
| 327 |
|
| •328 |
// @ts-ignore |
| 329 |
switch (pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).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`/LogicalExpression#operator.) { |
| 330 |
case "||": |
| 331 |
// TODO consider having a "truthy type" that doesn't bail on |
| 332 |
// left uncertainty but can still evaluate to truthy. |
| 333 |
statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state).confidentscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#typeLiteral4:confident. = leftConfident && (!!left || rightConfident); |
| 334 |
if (!statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state).confidentscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#typeLiteral4:confident.) return; |
| 335 |
|
| 336 |
return left || right; |
| 337 |
case "&&": |
| 338 |
statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state).confidentscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#typeLiteral4:confident. = leftConfident && (!left || rightConfident); |
| 339 |
if (!statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state).confidentscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#typeLiteral4:confident.) return; |
| 340 |
|
| 341 |
return left && right; |
| 342 |
case "??": |
| 343 |
statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state).confidentscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#typeLiteral4:confident. = leftConfident && (left != null || rightConfident); |
| 344 |
if (!statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state).confidentscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#typeLiteral4:confident.) return; |
| 345 |
|
| 346 |
return left ?? right; |
| 347 |
} |
| 348 |
} |
| 349 |
|
| •350 |
// @ts-ignore |
| 351 |
if (pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).isBinaryExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isBinaryExpression().()) { |
| •352 |
// @ts-ignore |
| 353 |
const left = evaluateCachedscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateCached().(pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).get("left"), statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state)); |
| 354 |
if (!statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state).confidentscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#typeLiteral4:confident.) return; |
| •355 |
// @ts-ignore |
| 356 |
const right = evaluateCachedscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateCached().(pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).get("right"), statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state)); |
| 357 |
if (!statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state).confidentscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#typeLiteral4:confident.) return; |
| 358 |
|
| •359 |
// @ts-ignore |
| 360 |
switch (pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).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`/BinaryExpression#operator.) { |
| 361 |
case "-": |
| 362 |
return left - right; |
| 363 |
case "+": |
| 364 |
return left + right; |
| 365 |
case "/": |
| 366 |
return left / right; |
| 367 |
case "*": |
| 368 |
return left * right; |
| 369 |
case "%": |
| 370 |
return left % right; |
| 371 |
case "**": |
| 372 |
return left ** right; |
| 373 |
case "<": |
| 374 |
return left < right; |
| 375 |
case ">": |
| 376 |
return left > right; |
| 377 |
case "<=": |
| 378 |
return left <= right; |
| 379 |
case ">=": |
| 380 |
return left >= right; |
| 381 |
case "==": |
| 382 |
return left == right; // eslint-disable-line eqeqeq |
| 383 |
case "!=": |
| 384 |
return left != right; |
| 385 |
case "===": |
| 386 |
return left === right; |
| 387 |
case "!==": |
| 388 |
return left !== right; |
| 389 |
case "|": |
| 390 |
return left | right; |
| 391 |
case "&": |
| 392 |
return left & right; |
| 393 |
case "^": |
| 394 |
return left ^ right; |
| 395 |
case "<<": |
| 396 |
return left << right; |
| 397 |
case ">>": |
| 398 |
return left >> right; |
| 399 |
case ">>>": |
| 400 |
return left >>> right; |
| 401 |
} |
| 402 |
} |
| 403 |
|
| •404 |
// @ts-ignore |
| 405 |
if (pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).isCallExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isCallExpression().()) { |
| •406 |
// @ts-ignore |
| 407 |
const callee = pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).get("callee"); |
| 408 |
let context; |
| 409 |
let func; |
| 410 |
|
| 411 |
// Number(1); |
| 412 |
if ( |
| 413 |
callee.isIdentifierscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isIdentifier().() && |
| •414 |
// @ts-ignore |
| 415 |
!pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).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().(callee.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.) && |
| 416 |
isValidCalleescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/isValidCallee().(callee.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.) |
| 417 |
) { |
| •418 |
// @ts-ignore |
| 419 |
func = global[callee.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.]; |
| 420 |
} |
| 421 |
|
| 422 |
if (callee.isMemberExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isMemberExpression().()) { |
| 423 |
const object = callee.get("object"); |
| 424 |
const property = callee.get("property"); |
| 425 |
|
| 426 |
// Math.min(1, 2) |
| 427 |
if ( |
| 428 |
object.isIdentifierscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isIdentifier().() && |
| 429 |
property.isIdentifierscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isIdentifier().() && |
| 430 |
isValidCalleescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/isValidCallee().(object.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.) && |
| 431 |
!isInvalidMethodscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/isInvalidMethod().(property.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.) |
| 432 |
) { |
| •433 |
// @ts-ignore |
| 434 |
context = global[object.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.]; |
| •435 |
// @ts-ignore |
| 436 |
func = context[property.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.]; |
| 437 |
} |
| 438 |
|
| 439 |
// "abc".charCodeAt(4) |
| 440 |
if (object.isLiteralscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isLiteral().() && property.isIdentifierscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isIdentifier().()) { |
| •441 |
// @ts-ignore todo(flow->ts): consider checking ast node type instead of value type (StringLiteral and NumberLiteral) |
| 442 |
const type = typeof object.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..value; |
| 443 |
if (type === "string" || type === "number") { |
| •444 |
// @ts-ignore todo(flow->ts): consider checking ast node type instead of value type |
| 445 |
context = object.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..value; |
| •446 |
const key = property.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.; |
| 447 |
if (Objectscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Object#.hasOwnPropertyscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Object#hasOwnProperty()..callscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/CallableFunction#call().(context, key)) { |
| 448 |
func = context[key as keyof typeof context]; |
| 449 |
} |
| 450 |
} |
| 451 |
} |
| 452 |
} |
| 453 |
|
| 454 |
if (func) { |
| •455 |
// @ts-ignore |
| 456 |
const args = pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path).get("arguments").mapscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#map().(arg => evaluateCachedscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateCached().(arg, statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state))); |
| 457 |
if (!statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state).confidentscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#typeLiteral4:confident.) return; |
| 458 |
|
| 459 |
return func.apply(context, args); |
| 460 |
} |
| 461 |
} |
| 462 |
|
| 463 |
deoptscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/deopt().(pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(path), statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/_evaluate().(state)); |
| 464 |
} |
| 465 |
|
| 466 |
function evaluateQuasisscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateQuasis().( |
| 467 |
pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateQuasis().(path): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.TaggedTemplateExpressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/TaggedTemplateExpression# | tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.TemplateLiteralscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/TemplateLiteral#>, |
| 468 |
quasisscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateQuasis().(quasis): Arrayscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#<any>, |
| 469 |
statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateQuasis().(state): Statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#, |
| 470 |
rawscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateQuasis().(raw) = false, |
| 471 |
) { |
| 472 |
let str = ""; |
| 473 |
|
| 474 |
let i = 0; |
| 475 |
const exprs: 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#<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#>> = pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateQuasis().(path).isTemplateLiteralscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isTemplateLiteral().() |
| 476 |
? pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateQuasis().(path).get("expressions") |
| 477 |
: pathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateQuasis().(path).get("quasi.expressions"); |
| 478 |
|
| 479 |
for (const elem of quasisscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateQuasis().(quasis)) { |
| 480 |
// not confident, evaluated an expression we don't like |
| 481 |
if (!statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateQuasis().(state).confidentscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#typeLiteral4:confident.) break; |
| 482 |
|
| 483 |
// add on element |
| 484 |
str += rawscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateQuasis().(raw) ? elem.value.raw : elem.value.cooked; |
| 485 |
|
| 486 |
// add on interpolated expression if it's present |
| 487 |
const expr = exprs[i++]; |
| 488 |
if (expr) str += Stringscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/String#(evaluateCachedscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateCached().(expr, statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateQuasis().(state))); |
| 489 |
} |
| 490 |
|
| 491 |
if (!statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateQuasis().(state).confidentscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#typeLiteral4:confident.) return; |
| 492 |
return str; |
| 493 |
} |
| 494 |
|
| 495 |
/** |
| 496 |
* Walk the input `node` and statically evaluate it. |
| 497 |
* |
| 498 |
* Returns an object in the form `{ confident, value, deopt }`. `confident` |
| 499 |
* indicates whether or not we had to drop out of evaluating the expression |
| 500 |
* because of hitting an unknown node that we couldn't confidently find the |
| 501 |
* value of, in which case `deopt` is the path of said node. |
| 502 |
* |
| 503 |
* Example: |
| 504 |
* |
| 505 |
* t.evaluate(parse("5 + 5")) // { confident: true, value: 10 } |
| 506 |
* t.evaluate(parse("!true")) // { confident: true, value: false } |
| 507 |
* t.evaluate(parse("foo + foo")) // { confident: false, value: undefined, deopt: NodePath } |
| 508 |
* |
| 509 |
*/ |
| 510 |
|
| 511 |
export function evaluatescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluate().(thisscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluate().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#): { |
| 512 |
confidentscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluate().typeLiteral3:confident.: boolean; |
| 513 |
valuescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluate().typeLiteral3:value.: any; |
| 514 |
deoptscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluate().typeLiteral3:deopt.?: NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#; |
| 515 |
} { |
| 516 |
const state: Statescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State# = { |
| 517 |
confidentscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#typeLiteral4:confident.: true, |
| 518 |
deoptPathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#typeLiteral4:deoptPath.: null, |
| 519 |
seenscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#typeLiteral4:seen.: new Mapscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/Map#(), |
| 520 |
}; |
| 521 |
let value = evaluateCachedscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluateCached().(this, state); |
| 522 |
if (!state.confidentscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#typeLiteral4:confident.) value = undefined; |
| 523 |
|
| 524 |
return { |
| 525 |
confidentscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluate().typeLiteral3:confident.: state.confidentscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#typeLiteral4:confident., |
| 526 |
deoptscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluate().typeLiteral3:deopt.: state.deoptPathscip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/State#typeLiteral4:deoptPath., |
| 527 |
valuescip-typescript npm @babel/traverse 7.20.13 src/path/`evaluation.ts`/evaluate().typeLiteral3:value.: value, |
| 528 |
}; |
| 529 |
} |