aoc/node_modules/@babel/traverse/lib/path/evaluation.js.map

1 line
26 KiB
Plaintext

{"version":3,"names":["VALID_CALLEES","INVALID_METHODS","isValidCallee","val","includes","isInvalidMethod","evaluateTruthy","res","evaluate","confident","value","deopt","path","state","deoptPath","evaluateCached","node","seen","has","existing","get","resolved","item","set","_evaluate","isSequenceExpression","exprs","length","isStringLiteral","isNumericLiteral","isBooleanLiteral","isNullLiteral","isTemplateLiteral","evaluateQuasis","quasis","isTaggedTemplateExpression","isMemberExpression","object","name","property","isIdentifier","scope","getBinding","quasi","isConditionalExpression","testResult","isExpressionWrapper","parentPath","isCallExpression","callee","isLiteral","type","isReferencedIdentifier","binding","constantViolations","start","end","hasValue","undefined","Infinity","NaN","resolve","isUnaryExpression","prefix","operator","argument","isFunction","isClass","arg","isArrayExpression","arr","elems","elem","elemValue","push","isObjectExpression","obj","props","prop","isObjectMethod","isSpreadElement","keyPath","key","computed","valuePath","isLogicalExpression","wasConfident","left","leftConfident","right","rightConfident","isBinaryExpression","context","func","global","args","map","apply","raw","str","i","cooked","expr","String","Map"],"sources":["../../src/path/evaluation.ts"],"sourcesContent":["import type NodePath from \"./index\";\nimport type * as t from \"@babel/types\";\n\n// This file contains Babels metainterpreter that can evaluate static code.\n\nconst VALID_CALLEES = [\"String\", \"Number\", \"Math\"] as const;\nconst INVALID_METHODS = [\"random\"] as const;\n\nfunction isValidCallee(val: string): val is typeof VALID_CALLEES[number] {\n return VALID_CALLEES.includes(\n // @ts-expect-error val is a string\n val,\n );\n}\n\nfunction isInvalidMethod(val: string): val is typeof INVALID_METHODS[number] {\n return INVALID_METHODS.includes(\n // @ts-expect-error val is a string\n val,\n );\n}\n\n/**\n * Walk the input `node` and statically evaluate if it's truthy.\n *\n * Returning `true` when we're sure that the expression will evaluate to a\n * truthy value, `false` if we're sure that it will evaluate to a falsy\n * value and `undefined` if we aren't sure. Because of this please do not\n * rely on coercion when using this method and check with === if it's false.\n *\n * For example do:\n *\n * if (t.evaluateTruthy(node) === false) falsyLogic();\n *\n * **AND NOT**\n *\n * if (!t.evaluateTruthy(node)) falsyLogic();\n *\n */\n\nexport function evaluateTruthy(this: NodePath): boolean {\n const res = this.evaluate();\n if (res.confident) return !!res.value;\n}\n\ntype State = {\n confident: boolean;\n deoptPath: NodePath | null;\n seen: Map<t.Node, Result>;\n};\n\ntype Result = {\n resolved: boolean;\n value?: any;\n};\n/**\n * Deopts the evaluation\n */\nfunction deopt(path: NodePath, state: State) {\n if (!state.confident) return;\n state.deoptPath = path;\n state.confident = false;\n}\n\n/**\n * We wrap the _evaluate method so we can track `seen` nodes, we push an item\n * to the map before we actually evaluate it so we can deopt on self recursive\n * nodes such as:\n *\n * var g = a ? 1 : 2,\n * a = g * this.foo\n */\nfunction evaluateCached(path: NodePath, state: State): any {\n const { node } = path;\n const { seen } = state;\n\n if (seen.has(node)) {\n const existing = seen.get(node);\n if (existing.resolved) {\n return existing.value;\n } else {\n deopt(path, state);\n return;\n }\n } else {\n const item: Result = { resolved: false };\n seen.set(node, item);\n\n const val = _evaluate(path, state);\n if (state.confident) {\n item.resolved = true;\n item.value = val;\n }\n return val;\n }\n}\n\nfunction _evaluate(path: NodePath, state: State): any {\n if (!state.confident) return;\n\n if (path.isSequenceExpression()) {\n const exprs = path.get(\"expressions\");\n return evaluateCached(exprs[exprs.length - 1], state);\n }\n\n if (\n path.isStringLiteral() ||\n path.isNumericLiteral() ||\n path.isBooleanLiteral()\n ) {\n return path.node.value;\n }\n\n if (path.isNullLiteral()) {\n return null;\n }\n\n if (path.isTemplateLiteral()) {\n return evaluateQuasis(path, path.node.quasis, state);\n }\n\n if (\n path.isTaggedTemplateExpression() &&\n path.get(\"tag\").isMemberExpression()\n ) {\n const object = path.get(\"tag.object\") as NodePath;\n const {\n // @ts-expect-error todo(flow->ts): possible bug, object is can be any expression and so name might be undefined\n node: { name },\n } = object;\n const property = path.get(\"tag.property\") as NodePath;\n\n if (\n object.isIdentifier() &&\n name === \"String\" &&\n // todo(flow->ts): was changed from getBinding(name, true)\n // should this be hasBinding(name, true) as the binding is never used later?\n !path.scope.getBinding(name) &&\n property.isIdentifier() &&\n property.node.name === \"raw\"\n ) {\n return evaluateQuasis(path, path.node.quasi.quasis, state, true);\n }\n }\n\n if (path.isConditionalExpression()) {\n const testResult = evaluateCached(path.get(\"test\"), state);\n if (!state.confident) return;\n if (testResult) {\n return evaluateCached(path.get(\"consequent\"), state);\n } else {\n return evaluateCached(path.get(\"alternate\"), state);\n }\n }\n\n if (path.isExpressionWrapper()) {\n // TypeCastExpression, ExpressionStatement etc\n return evaluateCached(path.get(\"expression\"), state);\n }\n\n // \"foo\".length\n if (\n path.isMemberExpression() &&\n !path.parentPath.isCallExpression({ callee: path.node })\n ) {\n const property = path.get(\"property\");\n const object = path.get(\"object\");\n\n if (object.isLiteral() && property.isIdentifier()) {\n // @ts-expect-error todo(flow->ts): instead of typeof - would it be better to check type of ast node?\n const value = object.node.value;\n const type = typeof value;\n if (type === \"number\" || type === \"string\") {\n return value[property.node.name];\n }\n }\n }\n\n if (path.isReferencedIdentifier()) {\n const binding = path.scope.getBinding(path.node.name);\n\n if (binding && binding.constantViolations.length > 0) {\n return deopt(binding.path, state);\n }\n\n if (binding && path.node.start < binding.path.node.end) {\n return deopt(binding.path, state);\n }\n\n if (binding?.hasValue) {\n return binding.value;\n } else {\n if (path.node.name === \"undefined\") {\n return binding ? deopt(binding.path, state) : undefined;\n } else if (path.node.name === \"Infinity\") {\n return binding ? deopt(binding.path, state) : Infinity;\n } else if (path.node.name === \"NaN\") {\n return binding ? deopt(binding.path, state) : NaN;\n }\n\n const resolved = path.resolve();\n if (resolved === path) {\n return deopt(path, state);\n } else {\n return evaluateCached(resolved, state);\n }\n }\n }\n\n if (path.isUnaryExpression({ prefix: true })) {\n if (path.node.operator === \"void\") {\n // we don't need to evaluate the argument to know what this will return\n return undefined;\n }\n\n const argument = path.get(\"argument\");\n if (\n path.node.operator === \"typeof\" &&\n (argument.isFunction() || argument.isClass())\n ) {\n return \"function\";\n }\n\n const arg = evaluateCached(argument, state);\n if (!state.confident) return;\n switch (path.node.operator) {\n case \"!\":\n return !arg;\n case \"+\":\n return +arg;\n case \"-\":\n return -arg;\n case \"~\":\n return ~arg;\n case \"typeof\":\n return typeof arg;\n }\n }\n\n if (path.isArrayExpression()) {\n const arr = [];\n const elems: Array<NodePath> = path.get(\"elements\");\n for (const elem of elems) {\n const elemValue = elem.evaluate();\n\n if (elemValue.confident) {\n arr.push(elemValue.value);\n } else {\n return deopt(elemValue.deopt, state);\n }\n }\n return arr;\n }\n\n if (path.isObjectExpression()) {\n const obj = {};\n const props = path.get(\"properties\");\n for (const prop of props) {\n if (prop.isObjectMethod() || prop.isSpreadElement()) {\n return deopt(prop, state);\n }\n const keyPath = (prop as NodePath<t.ObjectProperty>).get(\"key\");\n let key;\n // @ts-expect-error todo(flow->ts): type refinement issues ObjectMethod and SpreadElement somehow not excluded\n if (prop.node.computed) {\n key = keyPath.evaluate();\n if (!key.confident) {\n return deopt(key.deopt, state);\n }\n key = key.value;\n } else if (keyPath.isIdentifier()) {\n key = keyPath.node.name;\n } else {\n key = (\n keyPath.node as t.StringLiteral | t.NumericLiteral | t.BigIntLiteral\n ).value;\n }\n const valuePath = (prop as NodePath<t.ObjectProperty>).get(\"value\");\n let value = valuePath.evaluate();\n if (!value.confident) {\n return deopt(value.deopt, state);\n }\n value = value.value;\n // @ts-expect-error key is any type\n obj[key] = value;\n }\n return obj;\n }\n\n if (path.isLogicalExpression()) {\n // If we are confident that the left side of an && is false, or the left\n // side of an || is true, we can be confident about the entire expression\n const wasConfident = state.confident;\n const left = evaluateCached(path.get(\"left\"), state);\n const leftConfident = state.confident;\n state.confident = wasConfident;\n const right = evaluateCached(path.get(\"right\"), state);\n const rightConfident = state.confident;\n\n switch (path.node.operator) {\n case \"||\":\n // TODO consider having a \"truthy type\" that doesn't bail on\n // left uncertainty but can still evaluate to truthy.\n state.confident = leftConfident && (!!left || rightConfident);\n if (!state.confident) return;\n\n return left || right;\n case \"&&\":\n state.confident = leftConfident && (!left || rightConfident);\n if (!state.confident) return;\n\n return left && right;\n case \"??\":\n state.confident = leftConfident && (left != null || rightConfident);\n if (!state.confident) return;\n\n return left ?? right;\n }\n }\n\n if (path.isBinaryExpression()) {\n const left = evaluateCached(path.get(\"left\"), state);\n if (!state.confident) return;\n const right = evaluateCached(path.get(\"right\"), state);\n if (!state.confident) return;\n\n switch (path.node.operator) {\n case \"-\":\n return left - right;\n case \"+\":\n return left + right;\n case \"/\":\n return left / right;\n case \"*\":\n return left * right;\n case \"%\":\n return left % right;\n case \"**\":\n return left ** right;\n case \"<\":\n return left < right;\n case \">\":\n return left > right;\n case \"<=\":\n return left <= right;\n case \">=\":\n return left >= right;\n case \"==\":\n return left == right; // eslint-disable-line eqeqeq\n case \"!=\":\n return left != right;\n case \"===\":\n return left === right;\n case \"!==\":\n return left !== right;\n case \"|\":\n return left | right;\n case \"&\":\n return left & right;\n case \"^\":\n return left ^ right;\n case \"<<\":\n return left << right;\n case \">>\":\n return left >> right;\n case \">>>\":\n return left >>> right;\n }\n }\n\n if (path.isCallExpression()) {\n const callee = path.get(\"callee\");\n let context;\n let func;\n\n // Number(1);\n if (\n callee.isIdentifier() &&\n !path.scope.getBinding(callee.node.name) &&\n isValidCallee(callee.node.name)\n ) {\n func = global[callee.node.name];\n }\n\n if (callee.isMemberExpression()) {\n const object = callee.get(\"object\");\n const property = callee.get(\"property\");\n\n // Math.min(1, 2)\n if (\n object.isIdentifier() &&\n property.isIdentifier() &&\n isValidCallee(object.node.name) &&\n !isInvalidMethod(property.node.name)\n ) {\n context = global[object.node.name];\n // @ts-expect-error property may not exist in context object\n func = context[property.node.name];\n }\n\n // \"abc\".charCodeAt(4)\n if (object.isLiteral() && property.isIdentifier()) {\n // @ts-expect-error todo(flow->ts): consider checking ast node type instead of value type (StringLiteral and NumberLiteral)\n const type = typeof object.node.value;\n if (type === \"string\" || type === \"number\") {\n // @ts-expect-error todo(flow->ts): consider checking ast node type instead of value type\n context = object.node.value;\n func = context[property.node.name];\n }\n }\n }\n\n if (func) {\n const args = path.get(\"arguments\").map(arg => evaluateCached(arg, state));\n if (!state.confident) return;\n\n return func.apply(context, args);\n }\n }\n\n deopt(path, state);\n}\n\nfunction evaluateQuasis(\n path: NodePath<t.TaggedTemplateExpression | t.TemplateLiteral>,\n quasis: Array<any>,\n state: State,\n raw = false,\n) {\n let str = \"\";\n\n let i = 0;\n const exprs = path.get(\"expressions\");\n\n for (const elem of quasis) {\n // not confident, evaluated an expression we don't like\n if (!state.confident) break;\n\n // add on element\n str += raw ? elem.value.raw : elem.value.cooked;\n\n // add on interpolated expression if it's present\n const expr = exprs[i++];\n if (expr) str += String(evaluateCached(expr, state));\n }\n\n if (!state.confident) return;\n return str;\n}\n\n/**\n * Walk the input `node` and statically evaluate it.\n *\n * Returns an object in the form `{ confident, value, deopt }`. `confident`\n * indicates whether or not we had to drop out of evaluating the expression\n * because of hitting an unknown node that we couldn't confidently find the\n * value of, in which case `deopt` is the path of said node.\n *\n * Example:\n *\n * t.evaluate(parse(\"5 + 5\")) // { confident: true, value: 10 }\n * t.evaluate(parse(\"!true\")) // { confident: true, value: false }\n * t.evaluate(parse(\"foo + foo\")) // { confident: false, value: undefined, deopt: NodePath }\n *\n */\n\nexport function evaluate(this: NodePath): {\n confident: boolean;\n value: any;\n deopt?: NodePath;\n} {\n const state: State = {\n confident: true,\n deoptPath: null,\n seen: new Map(),\n };\n let value = evaluateCached(this, state);\n if (!state.confident) value = undefined;\n\n return {\n confident: state.confident,\n deopt: state.deoptPath,\n value: value,\n };\n}\n"],"mappings":";;;;;;;;AAKA,MAAMA,aAAa,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAU;AAC3D,MAAMC,eAAe,GAAG,CAAC,QAAQ,CAAU;AAE3C,SAASC,aAAa,CAACC,GAAW,EAAuC;EACvE,OAAOH,aAAa,CAACI,QAAQ;EAE3BD,GAAG,CACJ;AACH;AAEA,SAASE,eAAe,CAACF,G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