ts-evaluator
Version:
An interpreter for Typescript that can evaluate an arbitrary Node within a Typescript AST
1 lines • 381 kB
Source Map (JSON)
{"version":3,"sources":["../src/index.ts","../node_modules/.pnpm/tsup@8.3.0_tsx@4.19.1_typescript@5.6.3/node_modules/tsup/assets/cjs_shims.js","../src/interpreter/evaluate.ts","../src/interpreter/lexical-environment/lexical-environment.ts","../src/interpreter/environment/ecma/ecma-globals.ts","../src/interpreter/util/descriptor/merge-descriptors.ts","../src/interpreter/util/object/subtract.ts","../src/interpreter/environment/node/node-cjs-globals.ts","../src/interpreter/util/loader/require-module.ts","../src/interpreter/environment/browser/lib/raf.ts","../src/interpreter/util/loader/optional-peer-dependency-loader.ts","../src/interpreter/environment/browser/browser-globals.ts","../src/interpreter/util/return/return-symbol.ts","../src/interpreter/util/break/break-symbol.ts","../src/interpreter/util/continue/continue-symbol.ts","../src/interpreter/util/this/this-symbol.ts","../src/interpreter/util/super/super-symbol.ts","../src/interpreter/environment/node/node-esm-globals.ts","../src/interpreter/util/declaration/is-declaration.ts","../src/interpreter/util/flags/is-var-declaration.ts","../src/interpreter/error/evaluation-error/evaluation-error.ts","../src/interpreter/error/module-not-found-error/module-not-found-error.ts","../src/interpreter/error/unexpected-node-error/unexpected-node-error.ts","../src/interpreter/util/declaration/get-declaration-name.ts","../src/interpreter/util/module/get-resolved-module-name.ts","../src/interpreter/util/module/get-implementation-for-declaration-within-declaration-file.ts","../src/interpreter/util/node/find-nearest-parent-node-of-kind.ts","../src/interpreter/util/proxy/can-be-observed.ts","../src/interpreter/util/function/is-bind-call-apply.ts","../src/interpreter/policy/policy-trap-kind.ts","../src/interpreter/error/evaluation-error/evaluation-error-intent.ts","../src/interpreter/proxy/create-policy-proxy.ts","../src/interpreter/policy/network/network-map.ts","../src/interpreter/policy/nondeterministic/nondeterministic-map.ts","../src/interpreter/policy/trap-condition-map.ts","../src/interpreter/policy/is-trap-condition-met.ts","../src/interpreter/policy/nondeterministic/is-nondeterministic.ts","../src/interpreter/error/policy-error/policy-error.ts","../src/interpreter/error/policy-error/non-deterministic-error/non-deterministic-error.ts","../src/interpreter/policy/io/io-map.ts","../src/interpreter/policy/io/is-io-read.ts","../src/interpreter/error/policy-error/io-error/io-error.ts","../src/interpreter/policy/io/is-io-write.ts","../src/interpreter/policy/network/is-network-operation.ts","../src/interpreter/error/policy-error/network-error/network-error.ts","../src/interpreter/policy/process/process-map.ts","../src/interpreter/policy/process/is-process-exit-operation.ts","../src/interpreter/error/policy-error/process-error/process-error.ts","../src/interpreter/policy/process/is-process-spawn-child-operation.ts","../src/interpreter/policy/console/console-map.ts","../src/interpreter/policy/console/is-console-operation.ts","../src/interpreter/environment/create-sanitized-environment.ts","../src/interpreter/util/node/is-boolean-literal.ts","../src/interpreter/util/node/is-null-literal.ts","../src/interpreter/evaluator/simple/evaluate-simple-literal.ts","../src/interpreter/error/policy-error/max-ops-exceeded-error/max-ops-exceeded-error.ts","../src/interpreter/evaluator/evaluate-variable-declaration.ts","../src/interpreter/util/node/is-this-expression.ts","../src/interpreter/util/node/is-super-expression.ts","../src/interpreter/lexical-environment/get-dot-path-from-node.ts","../src/interpreter/error/undefined-left-value-error/undefined-left-value-error.ts","../src/interpreter/util/node/get-inner-node.ts","../src/interpreter/util/node/is-node.ts","../src/interpreter/evaluator/evaluate-binary-expression.ts","../src/interpreter/literal/literal.ts","../src/interpreter/error/not-callable-error/not-callable-error.ts","../src/interpreter/util/expression/expression-contains-super-keyword.ts","../src/interpreter/evaluator/evaluate-call-expression.ts","../src/interpreter/evaluator/evaluate-parenthesized-expression.ts","../src/interpreter/lexical-environment/clone-lexical-environment.ts","../src/interpreter/util/modifier/has-modifier.ts","../src/interpreter/evaluator/evaluate-parameter-declarations.ts","../src/interpreter/evaluator/evaluate-arrow-function-expression.ts","../src/interpreter/evaluator/evaluate-string-literal.ts","../src/interpreter/evaluator/evaluate-numeric-literal.ts","../src/interpreter/evaluator/evaluate-boolean-literal.ts","../src/interpreter/evaluator/evaluate-regular-expression-literal.ts","../src/interpreter/evaluator/evaluate-object-literal-expression.ts","../src/interpreter/util/iterable/is-iterable.ts","../src/interpreter/evaluator/evaluate-array-literal-expression.ts","../src/interpreter/error/undefined-identifier-error/undefined-identifier-error.ts","../src/interpreter/evaluator/evaluate-identifier.ts","../src/interpreter/evaluator/evaluate-block.ts","../src/interpreter/evaluator/evaluate-return-statement.ts","../src/interpreter/evaluator/evaluate-variable-declaration-list.ts","../src/interpreter/evaluator/evaluate-variable-statement.ts","../src/interpreter/evaluator/evaluate-prefix-unary-expression.ts","../src/interpreter/evaluator/evaluate-property-access-expression.ts","../src/interpreter/evaluator/evaluate-element-access-expression.ts","../src/interpreter/evaluator/evaluate-computed-property-name.ts","../src/interpreter/evaluator/evaluate-function-declaration.ts","../src/interpreter/evaluator/evaluate-if-statement.ts","../src/interpreter/evaluator/evaluate-expression-statement.ts","../src/interpreter/evaluator/evaluate-template-expression.ts","../src/interpreter/evaluator/evaluate-type-assertion-expression.ts","../src/interpreter/evaluator/evaluate-postfix-unary-expression.ts","../src/interpreter/evaluator/evaluate-new-expression.ts","../src/interpreter/evaluator/evaluate-non-null-expression.ts","../src/interpreter/evaluator/evaluate-as-expression.ts","../src/interpreter/evaluator/evaluate-switch-statement.ts","../src/interpreter/error/async-iterator-not-supported-error/async-iterator-not-supported-error.ts","../src/interpreter/evaluator/evaluate-for-of-statement.ts","../src/interpreter/evaluator/evaluate-this-expression.ts","../src/interpreter/evaluator/evaluate-break-statement.ts","../src/interpreter/evaluator/evaluate-continue-statement.ts","../src/interpreter/evaluator/evaluate-for-statement.ts","../src/interpreter/evaluator/evaluate-while-statement.ts","../src/interpreter/evaluator/evaluate-for-in-statement.ts","../src/interpreter/evaluator/evaluate-function-expression.ts","../src/interpreter/error/missing-catch-or-finally-after-try-error/missing-catch-or-finally-after-try-error.ts","../src/interpreter/evaluator/evaluate-try-statement.ts","../src/interpreter/util/class/generate-class-declaration.ts","../src/interpreter/util/node/modifier-util.ts","../src/interpreter/evaluator/evaluate-class-declaration.ts","../src/interpreter/evaluator/evaluate-constructor-declaration.ts","../src/interpreter/evaluator/evaluate-super-expression.ts","../src/interpreter/evaluator/evaluate-spread-element.ts","../src/interpreter/evaluator/evaluate-class-expression.ts","../src/interpreter/evaluator/evaluate-null-literal.ts","../src/interpreter/evaluator/evaluate-void-expression.ts","../src/interpreter/evaluator/evaluate-type-of-expression.ts","../src/interpreter/evaluator/evaluate-big-int-literal.ts","../src/interpreter/evaluator/evaluate-enum-declaration.ts","../src/interpreter/evaluator/evaluate-source-file-as-namespace-object.ts","../src/interpreter/evaluator/evaluate-module-declaration.ts","../src/interpreter/evaluator/evaluate-import-declaration.ts","../src/interpreter/evaluator/evaluate-throw-statement.ts","../src/interpreter/evaluator/evaluate-import-equals-declaration.ts","../src/interpreter/error/policy-error/max-op-duration-exceeded-error/max-op-duration-exceeded-error.ts","../src/interpreter/evaluator/evaluate-await-expression.ts","../src/interpreter/evaluator/evaluate-conditional-expression.ts","../src/interpreter/util/static/in-static-context.ts","../src/interpreter/evaluator/evaluate-method-declaration.ts","../src/interpreter/evaluator/evaluate-property-declaration.ts","../src/interpreter/evaluator/evaluate-get-accessor-declaration.ts","../src/interpreter/evaluator/evaluate-type-alias-declaration.ts","../src/interpreter/evaluator/evaluate-interface-declaration.ts","../src/interpreter/evaluator/evaluate-import-clause.ts","../src/interpreter/evaluator/evaluate-import-specifier.ts","../src/interpreter/evaluator/evaluate-namespace-import.ts","../src/interpreter/error/unexpected-syntax-error/unexpected-syntax-error.ts","../src/interpreter/evaluator/evaluate-meta-property.ts","../src/interpreter/evaluator/evaluate-node.ts","../src/interpreter/stack/traversal-stack/statement-traversal-stack.ts","../src/interpreter/evaluator/evaluate-statement.ts","../src/interpreter/evaluator/evaluate-expression.ts","../src/interpreter/evaluator/evaluate-declaration.ts","../src/interpreter/evaluator/evaluate-binding-name.ts","../src/interpreter/evaluator/evaluate-set-accessor-declaration.ts","../src/interpreter/evaluator/evaluate-property-assignment.ts","../src/interpreter/evaluator/evaluate-parameter-declaration.ts","../src/interpreter/evaluator/evaluate-shorthand-property-assignment.ts","../src/interpreter/evaluator/evaluate-spread-assignment.ts","../src/interpreter/evaluator/evaluate-array-binding-pattern.ts","../src/interpreter/evaluator/evaluate-binding-element.ts","../src/interpreter/evaluator/evaluate-object-binding-pattern.ts","../src/interpreter/evaluator/evaluate-case-block.ts","../src/interpreter/evaluator/evaluate-case-clause.ts","../src/interpreter/evaluator/evaluate-default-clause.ts","../src/interpreter/evaluator/evaluate-catch-clause.ts","../src/interpreter/evaluator/evaluate-omitted-expression.ts","../src/interpreter/util/tslib/tslib-util.ts","../src/interpreter/evaluator/evaluate-decorator.ts","../src/interpreter/evaluator/evaluate-enum-member.ts","../src/interpreter/evaluator/evaluate-node-with-argument.ts","../src/interpreter/evaluator/evaluate-property-name.ts","../src/interpreter/evaluator/evaluate-node-with-value.ts","../src/interpreter/evaluator/node-evaluator/create-node-evaluator.ts","../src/interpreter/logger/log-level.ts","../src/interpreter/util/syntax-kind/stringify-syntax-kind.ts","../src/interpreter/logger/logger.ts","../src/interpreter/util/expression/is-expression.ts","../src/interpreter/util/statement/is-statement.ts","../src/interpreter/stack/stack.ts","../src/interpreter/util/reporting/report-error.ts","../src/interpreter/reporting/reported-error-set.ts"],"sourcesContent":["export {evaluate} from \"./interpreter/evaluate.js\";\nexport type {EvaluateResult} from \"./interpreter/evaluate-result.js\";\nexport type {EvaluateOptions} from \"./interpreter/evaluate-options.js\";\n\n// Logging\nexport * from \"./interpreter/logger/log-level.js\";\n\n// Environment\nexport type * from \"./interpreter/environment/environment-preset-kind.js\";\nexport type * from \"./interpreter/environment/i-environment.js\";\n\n// Errors\nexport * from \"./interpreter/error/evaluation-error/evaluation-error.js\";\nexport * from \"./interpreter/error/missing-catch-or-finally-after-try-error/missing-catch-or-finally-after-try-error.js\";\nexport * from \"./interpreter/error/module-not-found-error/module-not-found-error.js\";\nexport * from \"./interpreter/error/not-callable-error/not-callable-error.js\";\nexport * from \"./interpreter/error/policy-error/policy-error.js\";\nexport * from \"./interpreter/error/undefined-identifier-error/undefined-identifier-error.js\";\nexport * from \"./interpreter/error/undefined-left-value-error/undefined-left-value-error.js\";\nexport * from \"./interpreter/error/unexpected-syntax-error/unexpected-syntax-error.js\";\nexport * from \"./interpreter/error/unexpected-node-error/unexpected-node-error.js\";\nexport * from \"./interpreter/error/policy-error/io-error/io-error.js\";\nexport * from \"./interpreter/error/policy-error/max-ops-exceeded-error/max-ops-exceeded-error.js\";\nexport * from \"./interpreter/error/policy-error/max-op-duration-exceeded-error/max-op-duration-exceeded-error.js\";\nexport * from \"./interpreter/error/policy-error/network-error/network-error.js\";\nexport * from \"./interpreter/error/policy-error/non-deterministic-error/non-deterministic-error.js\";\nexport * from \"./interpreter/error/policy-error/process-error/process-error.js\";\n\n// Reporting\nexport type {BindingReportCallback, IReportingOptions, ReportingOptions} from \"./interpreter/reporting/i-reporting-options.js\";\n","// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () =>\n typeof document === 'undefined'\n ? new URL(`file:${__filename}`).href\n : (document.currentScript && document.currentScript.src) ||\n new URL('main.js', document.baseURI).href\n\nexport const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()\n","import * as TSModule from \"typescript\";\nimport type {EvaluateOptions} from \"./evaluate-options.js\";\nimport {createLexicalEnvironment} from \"./lexical-environment/lexical-environment.js\";\nimport type {EvaluateResult} from \"./evaluate-result.js\";\nimport {evaluateSimpleLiteral} from \"./evaluator/simple/evaluate-simple-literal.js\";\nimport {createNodeEvaluator} from \"./evaluator/node-evaluator/create-node-evaluator.js\";\nimport {LogLevelKind} from \"./logger/log-level.js\";\nimport {Logger} from \"./logger/logger.js\";\nimport {createStatementTraversalStack} from \"./stack/traversal-stack/statement-traversal-stack.js\";\nimport {isExpression} from \"./util/expression/is-expression.js\";\nimport type {Literal} from \"./literal/literal.js\";\nimport {isStatement} from \"./util/statement/is-statement.js\";\nimport type {Stack} from \"./stack/stack.js\";\nimport {createStack} from \"./stack/stack.js\";\nimport {isDeclaration} from \"./util/declaration/is-declaration.js\";\nimport {UnexpectedNodeError} from \"./error/unexpected-node-error/unexpected-node-error.js\";\nimport type {EvaluatePolicySanitized} from \"./policy/evaluate-policy.js\";\nimport {reportError} from \"./util/reporting/report-error.js\";\nimport {createReportedErrorSet} from \"./reporting/reported-error-set.js\";\nimport type {ReportingOptionsSanitized} from \"./reporting/i-reporting-options.js\";\nimport type {EvaluationError, ThrowError} from \"./error/evaluation-error/evaluation-error.js\";\nimport type {ICreateNodeEvaluatorOptions} from \"./evaluator/node-evaluator/i-create-node-evaluator-options.js\";\n/**\n * Will get a literal value for the given Expression, ExpressionStatement, or Declaration.\n */\nexport function evaluate({\n\ttypeChecker,\n\tnode,\n\tenvironment: {preset = \"NODE\", extra = {}} = {},\n\tmoduleOverrides = {},\n\ttypescript = TSModule,\n\tlogLevel = LogLevelKind.SILENT,\n\tpolicy: {\n\t\tdeterministic = false,\n\t\tnetwork = false,\n\t\tconsole = false,\n\t\tmaxOps = Infinity,\n\t\tmaxOpDuration = Infinity,\n\t\tio = {\n\t\t\tread: true,\n\t\t\twrite: false\n\t\t},\n\t\tprocess = {\n\t\t\texit: false,\n\t\t\tspawnChild: false\n\t\t}\n\t} = {},\n\treporting: reportingInput = {}\n}: EvaluateOptions): EvaluateResult {\n\t// Take the simple path first. This may be far more performant than building up an environment\n\tconst simpleLiteralResult = evaluateSimpleLiteral(node, typescript);\n\tif (simpleLiteralResult.success) return simpleLiteralResult;\n\n\t// Otherwise, build an environment and get to work\n\t// Sanitize the evaluation policy based on the input options\n\tconst policy: EvaluatePolicySanitized = {\n\t\tdeterministic,\n\t\tmaxOps,\n\t\tmaxOpDuration,\n\t\tnetwork,\n\t\tconsole,\n\t\tio: {\n\t\t\tread: typeof io === \"boolean\" ? io : io.read,\n\t\t\twrite: typeof io === \"boolean\" ? io : io.write\n\t\t},\n\t\tprocess: {\n\t\t\texit: typeof process === \"boolean\" ? process : process.exit,\n\t\t\tspawnChild: typeof process === \"boolean\" ? process : process.spawnChild\n\t\t}\n\t};\n\n\t// Sanitize the Reporting options based on the input options\n\tconst reporting: ReportingOptionsSanitized = {\n\t\t...reportingInput,\n\t\treportedErrorSet: createReportedErrorSet()\n\t};\n\n\t/**\n\t * The error that has been thrown most recently.\n\t * We can' just throw errors internally, as some tools may patch error handling\n\t * and treat them as uncaught exceptions, which breaks the behavior of evaluate,\n\t * which never throws and instead returns a record with a {success: false, reason: Error} value.\n\t */\n\tlet error: EvaluationError | undefined;\n\n\t// Prepare a logger\n\tconst logger = new Logger(logLevel);\n\n\tconst throwError: ThrowError = ex => {\n\t\t// Report the Error\n\t\treportError(reporting, ex, ex.node);\n\t\terror = ex;\n\t\treturn error;\n\t};\n\n\t// Prepare the initial environment\n\tconst environment = createLexicalEnvironment({\n\t\tinputEnvironment: {\n\t\t\tpreset,\n\t\t\textra\n\t\t},\n\t\tstartingNode: node,\n\t\tpolicy\n\t});\n\n\t// Prepare a Stack\n\tconst stack: Stack = createStack();\n\n\tconst statementTraversalStack = createStatementTraversalStack();\n\n\tconst nodeEvaluatorOptions: ICreateNodeEvaluatorOptions = {\n\t\tpolicy,\n\t\ttypeChecker,\n\t\ttypescript,\n\t\tlogger,\n\t\tstack,\n\t\tmoduleOverrides,\n\t\treporting,\n\t\tthrowError,\n\t\tenvironment,\n\t\tstatementTraversalStack,\n\t\tgetCurrentError: () => error\n\t};\n\n\t// Prepare a NodeEvaluator\n\tconst nodeEvaluator = createNodeEvaluator(nodeEvaluatorOptions);\n\n\ttry {\n\t\tlet value: Literal;\n\t\tif (isExpression(node, typescript)) {\n\t\t\tvalue = nodeEvaluator.expression(node, nodeEvaluatorOptions);\n\t\t} else if (isStatement(node, typescript)) {\n\t\t\tnodeEvaluator.statement(node, nodeEvaluatorOptions);\n\t\t\tvalue = stack.pop();\n\t\t} else if (isDeclaration(node, typescript)) {\n\t\t\tnodeEvaluator.declaration(node, nodeEvaluatorOptions);\n\t\t\tvalue = stack.pop();\n\t\t}\n\n\t\t// Otherwise, produce an UnexpectedNodeError\n\t\telse {\n\t\t\tthrowError(new UnexpectedNodeError({node, environment, typescript}));\n\t\t}\n\n\t\tif (error != null) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\treason: error\n\t\t\t};\n\t\t} else {\n\t\t\t// Log the value before returning\n\t\t\tlogger.logResult(value);\n\n\t\t\treturn {\n\t\t\t\tsuccess: true,\n\t\t\t\tvalue\n\t\t\t};\n\t\t}\n\t} catch (reason) {\n\t\tthrowError(reason as EvaluationError);\n\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\treason: reason as EvaluationError\n\t\t};\n\t}\n}\n","import objectPath from \"object-path\";\nimport type {IndexLiteral, Literal, LiteralMatch} from \"../literal/literal.js\";\nimport {ECMA_GLOBALS} from \"../environment/ecma/ecma-globals.js\";\nimport {NODE_CJS_GLOBALS} from \"../environment/node/node-cjs-globals.js\";\nimport type {EnvironmentPresetKind} from \"../environment/environment-preset-kind.js\";\nimport {BROWSER_GLOBALS} from \"../environment/browser/browser-globals.js\";\nimport {mergeDescriptors} from \"../util/descriptor/merge-descriptors.js\";\nimport type {ISetInLexicalEnvironmentOptions} from \"./i-set-in-lexical-environment-options.js\";\nimport {RETURN_SYMBOL} from \"../util/return/return-symbol.js\";\nimport {BREAK_SYMBOL} from \"../util/break/break-symbol.js\";\nimport {CONTINUE_SYMBOL} from \"../util/continue/continue-symbol.js\";\nimport {THIS_SYMBOL} from \"../util/this/this-symbol.js\";\nimport {SUPER_SYMBOL} from \"../util/super/super-symbol.js\";\nimport type {ICreateLexicalEnvironmentOptions} from \"./i-create-lexical-environment-options.js\";\nimport type {TS} from \"../../type/ts.js\";\nimport {NODE_ESM_GLOBALS} from \"../environment/node/node-esm-globals.js\";\nimport {getStatementContext} from \"../util/node/find-nearest-parent-node-of-kind.js\";\nimport {createSanitizedEnvironment} from \"../environment/create-sanitized-environment.js\";\n\nexport interface LexicalEnvironment {\n\tparentEnv: LexicalEnvironment | undefined;\n\tenv: IndexLiteral;\n\tstartingNode: TS.Node;\n\tpreset?: EnvironmentPresetKind;\n}\n\n/**\n * Gets a value from a Lexical Environment\n */\nexport function getRelevantDictFromLexicalEnvironment(env: LexicalEnvironment, path: string): LexicalEnvironment[\"env\"] | undefined {\n\tconst [firstBinding] = path.split(\".\");\n\tif (firstBinding == null) return undefined;\n\tif (objectPath.has(env.env, firstBinding)) return env.env;\n\tif (env.parentEnv != null) return getRelevantDictFromLexicalEnvironment(env.parentEnv, path);\n\treturn undefined;\n}\n\n/**\n * Gets the EnvironmentPresetKind for the given LexicalEnvironment\n */\nexport function getPresetForLexicalEnvironment(env: LexicalEnvironment): EnvironmentPresetKind {\n\tif (env.preset != null) return env.preset;\n\telse if (env.parentEnv != null) return getPresetForLexicalEnvironment(env.parentEnv);\n\telse return \"NONE\";\n}\n\n/**\n * Gets a value from a Lexical Environment\n */\nexport function findLexicalEnvironmentUp(from: LexicalEnvironment, path: string): LexicalEnvironment | undefined {\n\tconst [firstBinding] = path.split(\".\");\n\tif (firstBinding == null) return undefined;\n\tif (objectPath.has(from.env, firstBinding)) return from;\n\tif (from.parentEnv != null) return findLexicalEnvironmentUp(from.parentEnv, path);\n\treturn undefined;\n}\n\nexport function findLexicalEnvironmentInSameContext(from: LexicalEnvironment, node: TS.Node, typescript: typeof TS): LexicalEnvironment | undefined {\n\tconst startingNodeContext = getStatementContext(from.startingNode, typescript);\n\tconst nodeContext = getStatementContext(node, typescript);\n\n\tif (startingNodeContext?.pos === nodeContext?.pos) {\n\t\treturn from;\n\t}\n\n\tif (from.parentEnv == null) {\n\t\treturn undefined;\n\t}\n\n\treturn findLexicalEnvironmentInSameContext(from.parentEnv, node, typescript);\n}\n\n/**\n * Gets a value from a Lexical Environment\n */\nexport function getFromLexicalEnvironment(node: TS.Node | undefined, env: LexicalEnvironment, path: string): LiteralMatch | undefined {\n\tconst [firstBinding] = path.split(\".\");\n\tif (firstBinding == null) return undefined;\n\n\tif (objectPath.has(env.env, firstBinding)) {\n\t\tconst literal = objectPath.get(env.env, path);\n\t\tswitch (path) {\n\t\t\t// If we're in a Node environment, the \"__dirname\" and \"__filename\" meta-properties should report the current directory or file of the SourceFile and not the parent process\n\t\t\tcase \"__dirname\":\n\t\t\tcase \"__filename\": {\n\t\t\t\tconst preset = getPresetForLexicalEnvironment(env);\n\t\t\t\treturn (preset === \"NODE\" || preset === \"NODE_CJS\") && typeof literal === \"function\" && node != null ? {literal: literal(node.getSourceFile().fileName)} : {literal};\n\t\t\t}\n\t\t\tcase \"import.meta\": {\n\t\t\t\tconst preset = getPresetForLexicalEnvironment(env);\n\t\t\t\treturn (preset === \"NODE_ESM\" || preset === \"BROWSER\" || preset === \"ECMA\") &&\n\t\t\t\t\ttypeof literal === \"object\" &&\n\t\t\t\t\tliteral != null &&\n\t\t\t\t\ttypeof literal.url === \"function\" &&\n\t\t\t\t\tnode != null\n\t\t\t\t\t? {literal: {url: literal.url(node.getSourceFile().fileName)}}\n\t\t\t\t\t: {literal};\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\treturn {literal};\n\t\t}\n\t}\n\n\tif (env.parentEnv != null) return getFromLexicalEnvironment(node, env.parentEnv, path);\n\treturn undefined;\n}\n\n/**\n * Returns true if a path maps to an identifier that has been declared within the Lexical Environment\n */\nexport function hasInLexicalEnvironment(node: TS.Node | undefined, env: LexicalEnvironment, path: string): boolean {\n\tconst [firstBinding] = path.split(\".\");\n\tif (firstBinding == null) return false;\n\n\tif (objectPath.has(env.env, firstBinding)) {\n\t\treturn true;\n\t}\n\n\tif (env.parentEnv != null) {\n\t\treturn hasInLexicalEnvironment(node, env.parentEnv, path);\n\t}\n\treturn false;\n}\n\n/**\n * Returns true if the given lexical environment contains a value on the given path that equals the given literal\n */\nexport function pathInLexicalEnvironmentEquals(node: TS.Node, env: LexicalEnvironment, equals: Literal, ...matchPaths: string[]): boolean {\n\treturn matchPaths.some(path => {\n\t\tconst match = getFromLexicalEnvironment(node, env, path);\n\t\treturn match == null ? false : match.literal === equals;\n\t});\n}\n\n/**\n * Returns true if the given value represents an internal symbol\n */\nexport function isInternalSymbol(value: Literal): boolean {\n\tswitch (value) {\n\t\tcase RETURN_SYMBOL:\n\t\tcase BREAK_SYMBOL:\n\t\tcase CONTINUE_SYMBOL:\n\t\tcase THIS_SYMBOL:\n\t\tcase SUPER_SYMBOL:\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\n/**\n * Gets a value from a Lexical Environment\n */\nexport function setInLexicalEnvironment({environment, path, value, reporting, node, newBinding = false}: ISetInLexicalEnvironmentOptions): void {\n\tconst [firstBinding] = path.split(\".\");\n\tif (firstBinding == null) return undefined;\n\n\tif (objectPath.has(environment.env, firstBinding) || newBinding || environment.parentEnv == null) {\n\t\t// If the value didn't change, do no more\n\t\tif (objectPath.has(environment.env, path) && objectPath.get(environment.env, path) === value) return;\n\n\t\t// Otherwise, mutate it\n\t\tobjectPath.set(environment.env, path, value);\n\n\t\t// Inform reporting hooks if any is given\n\t\tif (reporting.reportBindings != null && !isInternalSymbol(path)) {\n\t\t\treporting.reportBindings({path, value, node});\n\t\t}\n\t} else {\n\t\tlet currentParentEnv: LexicalEnvironment | undefined = environment.parentEnv;\n\n\t\twhile (currentParentEnv != null) {\n\t\t\tif (objectPath.has(currentParentEnv.env, firstBinding)) {\n\t\t\t\t// If the value didn't change, do no more\n\t\t\t\tif (objectPath.has(currentParentEnv.env, path) && objectPath.get(currentParentEnv.env, path) === value) return;\n\n\t\t\t\t// Otherwise, mutate it\n\t\t\t\tobjectPath.set(currentParentEnv.env, path, value);\n\n\t\t\t\t// Inform reporting hooks if any is given\n\t\t\t\tif (reporting.reportBindings != null && !isInternalSymbol(path)) {\n\t\t\t\t\treporting.reportBindings({path, value, node});\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t} else {\n\t\t\t\tif (currentParentEnv.parentEnv == null) {\n\t\t\t\t\t// Otherwise, mutate it\n\t\t\t\t\tobjectPath.set(currentParentEnv.env, path, value);\n\n\t\t\t\t\t// Inform reporting hooks if any is given\n\t\t\t\t\tif (reporting.reportBindings != null && !isInternalSymbol(path)) {\n\t\t\t\t\t\treporting.reportBindings({path, value, node});\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tcurrentParentEnv = currentParentEnv.parentEnv;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Clears a binding from a Lexical Environment\n */\nexport function clearBindingFromLexicalEnvironment(env: LexicalEnvironment, path: string): void {\n\tconst [firstBinding] = path.split(\".\");\n\tif (firstBinding == null) return undefined;\n\n\tif (objectPath.has(env.env, firstBinding)) {\n\t\tobjectPath.del(env.env, path);\n\t} else {\n\t\tlet currentParentEnv: LexicalEnvironment | undefined = env.parentEnv;\n\t\twhile (currentParentEnv != null) {\n\t\t\tif (objectPath.has(currentParentEnv.env, firstBinding)) {\n\t\t\t\tobjectPath.del(currentParentEnv.env, path);\n\t\t\t\treturn;\n\t\t\t} else {\n\t\t\t\tcurrentParentEnv = currentParentEnv.parentEnv;\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport function simplifyEnvironment(environment: LexicalEnvironment, typescript: typeof TS): Record<string, unknown> {\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tconst {arguments: _arguments, ...rest} = environment.env;\n\n\tconst strippedEnv = Object.fromEntries(Object.entries(rest).filter(([key]) => !(key in globalThis)));\n\n\treturn {\n\t\t...(environment.preset == null ? {} : {preset: environment.preset}),\n\t\tparentEnv: environment.parentEnv == null ? undefined : simplifyEnvironment(environment.parentEnv, typescript),\n\t\tenv: environment.preset != null ? strippedEnv : rest,\n\t\tstartingNode: typescript.SyntaxKind[environment.startingNode.kind]\n\t};\n}\n\n/**\n * Creates a Lexical Environment\n */\nexport function createLexicalEnvironment({inputEnvironment: {extra, preset}, startingNode, policy}: ICreateLexicalEnvironmentOptions): LexicalEnvironment {\n\tlet env: IndexLiteral;\n\n\tswitch (preset) {\n\t\tcase \"NONE\":\n\t\t\tenv = mergeDescriptors(extra);\n\t\t\tbreak;\n\n\t\tcase \"ECMA\":\n\t\t\tenv = mergeDescriptors(ECMA_GLOBALS(), extra);\n\t\t\tbreak;\n\n\t\tcase \"NODE\":\n\t\tcase \"NODE_CJS\":\n\t\t\tenv = mergeDescriptors(NODE_CJS_GLOBALS(), extra);\n\t\t\tbreak;\n\n\t\tcase \"NODE_ESM\":\n\t\t\tenv = mergeDescriptors(NODE_ESM_GLOBALS(), extra);\n\t\t\tbreak;\n\n\t\tcase \"BROWSER\":\n\t\t\tenv = mergeDescriptors(BROWSER_GLOBALS(), extra);\n\t\t\tbreak;\n\n\t\tdefault:\n\t\t\tenv = {};\n\t\t\tbreak;\n\t}\n\n\treturn {\n\t\tparentEnv: undefined,\n\t\tpreset,\n\t\tstartingNode,\n\t\tenv: createSanitizedEnvironment({\n\t\t\tpolicy,\n\t\t\tenv\n\t\t})\n\t};\n}\n","import type {IndexLiteral} from \"../../literal/literal.js\";\n\nexport const ECMA_GLOBALS = () => {\n\t/* eslint-disable @typescript-eslint/naming-convention */\n\tconst base: IndexLiteral = {\n\t\tInfinity,\n\t\tNaN,\n\t\tundefined,\n\t\tisNaN,\n\t\tparseFloat,\n\t\tparseInt,\n\t\tdecodeURI,\n\t\tdecodeURIComponent,\n\t\tencodeURI,\n\t\tencodeURIComponent,\n\t\tArray,\n\t\tBoolean,\n\t\tDate,\n\t\tError,\n\t\tEvalError,\n\t\tNumber,\n\t\tObject,\n\t\tRangeError,\n\t\tReferenceError,\n\t\tRegExp,\n\t\tString,\n\t\tSyntaxError,\n\t\tTypeError,\n\t\tURIError,\n\t\tJSON,\n\t\tMath,\n\t\tescape,\n\t\tunescape,\n\t\t// eslint-disable-next-line no-eval\n\t\teval,\n\t\tFunction\n\t\t/* eslint-enable @typescript-eslint/naming-convention */\n\t};\n\n\ttry {\n\t\tbase.AggregateError = AggregateError;\n\t} catch {}\n\n\ttry {\n\t\tbase.FinalizationRegistry = FinalizationRegistry;\n\t} catch {}\n\n\ttry {\n\t\tbase.WeakRef = WeakRef;\n\t} catch {}\n\n\ttry {\n\t\tbase.BigInt = BigInt;\n\t} catch {}\n\n\ttry {\n\t\tbase.Reflect = Reflect;\n\t} catch {}\n\n\ttry {\n\t\tbase.WeakMap = WeakMap;\n\t} catch {}\n\n\ttry {\n\t\tbase.WeakSet = WeakSet;\n\t} catch {}\n\n\ttry {\n\t\tbase.Set = Set;\n\t} catch {}\n\n\ttry {\n\t\tbase.Map = Map;\n\t} catch {}\n\n\ttry {\n\t\tbase.Uint8Array = Uint8Array;\n\t} catch {}\n\n\ttry {\n\t\tbase.BigUint64Array = BigUint64Array;\n\t} catch {}\n\n\ttry {\n\t\tbase.BigInt64Array = BigInt64Array;\n\t} catch {}\n\n\ttry {\n\t\tbase.Atomics = Atomics;\n\t} catch {}\n\n\ttry {\n\t\tbase.SharedArrayBuffer = SharedArrayBuffer;\n\t} catch {}\n\n\ttry {\n\t\tbase.WebAssembly = WebAssembly;\n\t} catch {}\n\n\ttry {\n\t\tbase.Uint8ClampedArray = Uint8ClampedArray;\n\t} catch {}\n\n\ttry {\n\t\tbase.Uint16Array = Uint16Array;\n\t} catch {}\n\n\ttry {\n\t\tbase.Uint32Array = Uint32Array;\n\t} catch {}\n\n\ttry {\n\t\tbase.Intl = Intl;\n\t} catch {}\n\n\ttry {\n\t\tbase.Int8Array = Int8Array;\n\t} catch {}\n\n\ttry {\n\t\tbase.Int16Array = Int16Array;\n\t} catch {}\n\n\ttry {\n\t\tbase.Int32Array = Int32Array;\n\t} catch {}\n\n\ttry {\n\t\tbase.Float32Array = Float32Array;\n\t} catch {}\n\n\ttry {\n\t\tbase.Float64Array = Float64Array;\n\t} catch {}\n\n\ttry {\n\t\tbase.ArrayBuffer = ArrayBuffer;\n\t} catch {}\n\n\ttry {\n\t\tbase.DataView = DataView;\n\t} catch {}\n\n\ttry {\n\t\tbase.isFinite = isFinite;\n\t} catch {}\n\n\ttry {\n\t\tbase.Promise = Promise;\n\t} catch {}\n\n\ttry {\n\t\tbase.Proxy = Proxy;\n\t} catch {}\n\n\ttry {\n\t\tbase.Symbol = Symbol;\n\t} catch {}\n\n\treturn base;\n};\n","/**\n * Merges all of the given descriptors\n */\nexport function mergeDescriptors<A extends object>(a: A): A;\nexport function mergeDescriptors<A extends object, B extends object>(a: A, b: B): A & B;\nexport function mergeDescriptors<A extends object, B extends object, C extends object>(a: A, b: B, c: C): A & B & C;\nexport function mergeDescriptors<A extends object, B extends object, C extends object>(a: A, b?: B, c?: C): A & B & C {\n\tconst newObj = {} as A & B & C;\n\tconst normalizedB = b ?? {};\n\tconst normalizedC = c ?? {};\n\t[a, normalizedB, normalizedC].forEach(item => Object.defineProperties(newObj, Object.getOwnPropertyDescriptors(item)));\n\treturn newObj;\n}\n","export type Subtract<T, K extends Partial<T>> = {\n\t[Key in Exclude<keyof T, keyof K>]: T[Key];\n};\n\n/**\n * Excludes the properties of B from A\n */\nexport function subtract<A extends object, B extends Partial<A>>(a: A, b: B): Subtract<A, B> {\n\tconst newA = {} as Exclude<A, keyof B>;\n\tObject.getOwnPropertyNames(a).forEach(name => {\n\t\tif (!(name in b)) {\n\t\t\tObject.defineProperty(newA, name, Object.getOwnPropertyDescriptor(a, name)!);\n\t\t}\n\t});\n\treturn newA;\n}\n","import {mergeDescriptors} from \"../../util/descriptor/merge-descriptors.js\";\nimport {ECMA_GLOBALS} from \"../ecma/ecma-globals.js\";\nimport {subtract} from \"../../util/object/subtract.js\";\nimport path from \"crosspath\";\nimport {requireModule} from \"../../util/loader/require-module.js\";\n\nexport const NODE_CJS_GLOBALS = () => {\n\tconst ecmaGlobals = ECMA_GLOBALS();\n\tconst merged = mergeDescriptors(subtract(global, ecmaGlobals), ecmaGlobals, {\n\t\trequire: requireModule,\n\t\tprocess,\n\t\t__dirname: (fileName: string) => path.native.normalize(path.native.dirname(fileName)),\n\t\t__filename: (fileName: string) => path.native.normalize(fileName)\n\t});\n\n\tObject.defineProperties(merged, {\n\t\tglobal: {\n\t\t\tget(): typeof merged {\n\t\t\t\treturn merged;\n\t\t\t}\n\t\t},\n\t\tglobalThis: {\n\t\t\tget(): typeof merged {\n\t\t\t\treturn merged;\n\t\t\t}\n\t\t}\n\t});\n\n\treturn merged;\n};\n","import {createRequire} from \"module\";\n\n// Until import.meta.resolve becomes stable, we'll have to do this instead\nexport const requireModule = createRequire(import.meta.url);\n","export interface IRafImplementationNamespace {\n\trequestAnimationFrame(callback: FrameRequestCallback): number;\n\tcancelAnimationFrame(handle: number): void;\n}\n\n/**\n * Returns an object containing the properties that are relevant to 'requestAnimationFrame' and 'requestIdleCallback'\n */\nexport function rafImplementation(global: typeof window): IRafImplementationNamespace {\n\tlet lastTime = 0;\n\n\tconst _requestAnimationFrame = function requestAnimationFrame(callback: FrameRequestCallback): number {\n\t\tconst currTime = new Date().getTime();\n\n\t\tconst timeToCall = Math.max(0, 16 - (currTime - lastTime));\n\n\t\tconst id = global.setTimeout(function () {\n\t\t\tcallback(currTime + timeToCall);\n\t\t}, timeToCall);\n\n\t\tlastTime = currTime + timeToCall;\n\n\t\treturn id;\n\t};\n\n\tconst _cancelAnimationFrame = function cancelAnimationFrame(id: number): void {\n\t\tclearTimeout(id);\n\t};\n\n\treturn {\n\t\trequestAnimationFrame: _requestAnimationFrame,\n\t\tcancelAnimationFrame: _cancelAnimationFrame\n\t};\n}\n","import type {JSDOM} from \"../../../type/jsdom.js\";\nimport {requireModule} from \"./require-module.js\";\n\n/**\n * The jsdom module is optionally imported on-demand as needed\n */\nlet jsdomModule: typeof JSDOM | undefined;\n\nexport function loadJsdom(required: true): typeof JSDOM;\nexport function loadJsdom(required: false): typeof JSDOM | undefined;\nexport function loadJsdom(required?: boolean): typeof JSDOM | undefined;\nexport function loadJsdom(required = false): typeof JSDOM | undefined {\n\treturn (jsdomModule ??= loadModules(\"evaluate against a browser environment\", required, \"jsdom\"));\n}\n\nfunction loadModules<T = never>(description: string, required: boolean, moduleSpecifier = description): T | undefined {\n\ttry {\n\t\treturn requireModule(moduleSpecifier) as T;\n\t} catch {\n\t\tif (required) {\n\t\t\tthrow new ReferenceError(`You must install the peer dependency '${moduleSpecifier}' in order to ${description} with ts-evaluator`);\n\t\t}\n\t\treturn undefined;\n\t}\n}\n","import {rafImplementation} from \"./lib/raf.js\";\nimport {loadJsdom} from \"../../util/loader/optional-peer-dependency-loader.js\";\nimport {subtract} from \"../../util/object/subtract.js\";\nimport {ECMA_GLOBALS} from \"../ecma/ecma-globals.js\";\n\nexport const BROWSER_GLOBALS = () => {\n\tconst {JSDOM} = loadJsdom(true);\n\tconst {window} = new JSDOM(\"\", {url: \"https://example.com\"});\n\n\tconst ecmaGlobals = ECMA_GLOBALS();\n\n\t// Add requestAnimationFrame/cancelAnimationFrame if missing\n\tif (window.requestAnimationFrame == null) {\n\t\tconst raf = rafImplementation(window as unknown as Window & typeof globalThis);\n\t\tObject.defineProperties(window, Object.getOwnPropertyDescriptors(raf));\n\t}\n\n\t// Add all missing Ecma Globals to the JSDOM window\n\tconst missingEcmaGlobals = subtract(ecmaGlobals, window);\n\tif (Object.keys(missingEcmaGlobals).length > 0) {\n\t\tObject.defineProperties(window, Object.getOwnPropertyDescriptors(ecmaGlobals));\n\t}\n\n\treturn window;\n};\n","export const RETURN_SYMBOL = \"[return]\";\n","export const BREAK_SYMBOL = \"[break]\";\n","export const CONTINUE_SYMBOL = \"[continue]\";\n","export const THIS_SYMBOL = \"this\";\n","export const SUPER_SYMBOL = \"super\";\n","import {mergeDescriptors} from \"../../util/descriptor/merge-descriptors.js\";\nimport {ECMA_GLOBALS} from \"../ecma/ecma-globals.js\";\nimport {subtract} from \"../../util/object/subtract.js\";\nimport path from \"crosspath\";\nexport const NODE_ESM_GLOBALS = () => {\n\tconst ecmaGlobals = ECMA_GLOBALS();\n\tconst merged = mergeDescriptors(subtract(global, ecmaGlobals), ecmaGlobals, {\n\t\timport: {\n\t\t\tmeta: {\n\t\t\t\turl: (fileName: string) => {\n\t\t\t\t\tconst normalized = path.normalize(fileName);\n\t\t\t\t\treturn `file:///${normalized.startsWith(`/`) ? normalized.slice(1) : normalized}`;\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tprocess\n\t});\n\n\tObject.defineProperties(merged, {\n\t\tglobal: {\n\t\t\tget(): typeof merged {\n\t\t\t\treturn merged;\n\t\t\t}\n\t\t},\n\t\tglobalThis: {\n\t\t\tget(): typeof merged {\n\t\t\t\treturn merged;\n\t\t\t}\n\t\t}\n\t});\n\n\treturn merged;\n};\n","import type {TS} from \"../../../type/ts.js\";\n\n/**\n * Returns true if the given Node is a Declaration\n * Uses an internal non-exposed Typescript helper to decide whether or not the Node is a declaration\n */\nexport function isDeclaration(node: TS.Node, typescript: typeof TS): node is TS.Declaration {\n\treturn (typescript as unknown as {isDeclaration(node: TS.Node): boolean}).isDeclaration(node);\n}\n\nexport function isNamedDeclaration(node: TS.Node | TS.NamedDeclaration, typescript: typeof TS): node is TS.NamedDeclaration {\n\tif (typescript.isPropertyAccessExpression(node)) return false;\n\treturn \"name\" in node && node.name != null;\n}\n","import type {TS} from \"../../../type/ts.js\";\n\n/**\n * Returns true if the given VariableDeclarationList is declared with a 'var' keyword\n */\nexport function isVarDeclaration(declarationList: TS.VariableDeclarationList, typescript: typeof TS): boolean {\n\treturn declarationList.flags !== typescript.NodeFlags.Const && declarationList.flags !== typescript.NodeFlags.Let;\n}\n","import type {IEvaluationErrorOptions} from \"./i-evaluation-error-options.js\";\nimport type {TS} from \"../../../type/ts.js\";\nimport type {LexicalEnvironment} from \"../../lexical-environment/lexical-environment.js\";\n\nexport type ThrowError = (error: EvaluationError) => EvaluationError;\n\n/**\n * A Base class for EvaluationErrors\n */\nexport class EvaluationError extends Error {\n\t/**\n\t * The node that caused or thew the error\n\t */\n\treadonly node: TS.Node;\n\treadonly environment: LexicalEnvironment;\n\n\tconstructor({node, environment, message}: IEvaluationErrorOptions) {\n\t\tsuper(message);\n\t\tError.captureStackTrace(this, this.constructor);\n\t\tthis.node = node;\n\t\tthis.environment = environment;\n\t}\n}\n\nexport function isEvaluationError(item: unknown): item is EvaluationError {\n\treturn typeof item === \"object\" && item != null && item instanceof EvaluationError;\n}\n","import {EvaluationError} from \"../evaluation-error/evaluation-error.js\";\nimport type {IModuleNotFoundErrorOptions} from \"./i-module-not-found-error-options.js\";\n\n/**\n * An Error that can be thrown when a moduleSpecifier couldn't be resolved\n */\nexport class ModuleNotFoundError extends EvaluationError {\n\t/**\n\t * The path/moduleName that could not be resolved\n\t */\n\treadonly path: string;\n\n\tconstructor({path, node, environment, message = `Module '${path}' could not be resolved'`}: IModuleNotFoundErrorOptions) {\n\t\tsuper({message, environment, node});\n\t\tthis.path = path;\n\t}\n}\n","import {EvaluationError} from \"../evaluation-error/evaluation-error.js\";\nimport type {IUnexpectedNodeErrorOptions} from \"./i-unexpected-node-error-options.js\";\n\n/**\n * An Error that can be thrown when an unexpected node is encountered\n */\nexport class UnexpectedNodeError extends EvaluationError {\n\tconstructor({node, environment, typescript, message = `Unexpected Node: '${typescript.SyntaxKind[node.kind]}'`}: IUnexpectedNodeErrorOptions) {\n\t\tsuper({message, node, environment});\n\t}\n}\n","import type {EvaluatorOptions} from \"../../evaluator/evaluator-options.js\";\nimport {UnexpectedNodeError} from \"../../error/unexpected-node-error/unexpected-node-error.js\";\nimport type {TS} from \"../../../type/ts.js\";\nimport type {EvaluationError} from \"../../error/evaluation-error/evaluation-error.js\";\n\n/**\n * Gets the name of the given declaration\n */\nexport function getDeclarationName(options: EvaluatorOptions<TS.Declaration>): string | number | EvaluationError | undefined {\n\tconst {node, evaluate, environment, typescript, throwError} = options;\n\tconst name = typescript.getNameOfDeclaration(node);\n\tif (name == null) return undefined;\n\n\tif (typescript.isIdentifier(name)) {\n\t\treturn name.text;\n\t} else if (typescript.isPrivateIdentifier?.(name)) {\n\t\treturn name.text;\n\t} else if (typescript.isStringLiteralLike(name)) {\n\t\treturn name.text;\n\t} else if (typescript.isNumericLiteral(name)) {\n\t\treturn Number(name.text);\n\t} else if (typescript.isComputedPropertyName(name)) {\n\t\treturn evaluate.expression(name.expression, options) as ReturnType<typeof getDeclarationName>;\n\t} else {\n\t\treturn throwError(new UnexpectedNodeError({node: name, environment, typescript}));\n\t}\n}\n","import path from \"crosspath\";\nimport type {TS} from \"../../../type/ts.js\";\nimport type {EvaluatorOptions} from \"../../evaluator/evaluator-options.js\";\n\nexport function getResolvedModuleName(moduleSpecifier: string, options: EvaluatorOptions<TS.Node>): string {\n\tconst {node, typescript} = options;\n\tif (!typescript.isExternalModuleNameRelative(moduleSpecifier)) {\n\t\treturn moduleSpecifier;\n\t}\n\n\tconst parentPath = node.getSourceFile().fileName;\n\treturn path.join(path.dirname(parentPath), moduleSpecifier);\n}\n","import {findNearestParentNodeOfKind} from \"../node/find-nearest-parent-node-of-kind.js\";\nimport type {Literal} from \"../../literal/literal.js\";\nimport {ModuleNotFoundError} from \"../../error/module-not-found-error/module-not-found-error.js\";\nimport {UnexpectedNodeError} from \"../../error/unexpected-node-error/unexpected-node-error.js\";\nimport type {EvaluatorOptions} from \"../../evaluator/evaluator-options.js\";\nimport {getDeclarationName} from \"../declaration/get-declaration-name.js\";\nimport {isEvaluationError} from \"../../error/evaluation-error/evaluation-error.js\";\nimport {getFromLexicalEnvironment} from \"../../lexical-environment/lexical-environment.js\";\nimport type {TS} from \"../../../type/ts.js\";\nimport {getResolvedModuleName} from \"./get-resolved-module-name.js\";\n\n/**\n * Gets an implementation for the given declaration that lives within a declaration file\n */\nexport function getImplementationForDeclarationWithinDeclarationFile(options: EvaluatorOptions<TS.Declaration>): Literal {\n\tconst {node, typescript, throwError, environment} = options;\n\tconst name = getDeclarationName(options);\n\n\tif (isEvaluationError(name)) {\n\t\treturn name;\n\t}\n\n\tif (name == null) {\n\t\treturn throwError(new UnexpectedNodeError({node, environment, typescript}));\n\t}\n\n\t// First see if it lives within the lexical environment\n\tconst matchInLexicalEnvironment = getFromLexicalEnvironment(node, options.environment, name as string);\n\t// If so, return it\n\tif (matchInLexicalEnvironment?.literal != null) {\n\t\treturn matchInLexicalEnvironment.literal;\n\t}\n\n\t// Otherwise, expect it to be something that is require'd on demand\n\tconst require = getFromLexicalEnvironment(node, options.environment, \"require\")!.literal as NodeRequire;\n\n\tconst moduleDeclaration = typescript.isModuleDeclaration(node)\n\t\t? node\n\t\t: findNearestParentNodeOfKind<TS.ModuleDeclaration>(node, typescript.SyntaxKind.ModuleDeclaration, typescript);\n\tif (moduleDeclaration == null) {\n\t\treturn throwError(new UnexpectedNodeError({node, environment, typescript}));\n\t}\n\tconst moduleSpecifier = moduleDeclaration.name.text;\n\tconst resolvedModuleSpecifier = getResolvedModuleName(moduleSpecifier, options);\n\ttry {\n\t\tconst module = options.moduleOverrides?.[moduleSpecifier] ?? options.moduleOverrides?.[resolvedModuleSpecifier] ?? require(resolvedModuleSpecifier);\n\t\treturn typescript.isModuleDeclaration(node) ? module : (module[name] ?? module);\n\t} catch (ex) {\n\t\tif (isEvaluationError(ex)) return ex;\n\t\telse return throwError(new ModuleNotFoundError({node: moduleDeclaration, environment, path: resolvedModuleSpecifier}));\n\t}\n}\n\nexport function getImplementationFromExternalFile(name: string, moduleSpecifier: string, options: EvaluatorOptions<TS.Node>): Literal {\n\tconst {node, throwError, environment} = options;\n\n\tconst require = getFromLexicalEnvironment(node, options.environment, \"require\")!.literal as NodeRequire;\n\tconst resolvedModuleSpecifier = getResolvedModuleName(moduleSpecifier, options);\n\n\ttry {\n\t\tconst module = options.moduleOverrides?.[moduleSpecifier] ?? options.moduleOverrides?.[resolvedModuleSpecifier] ?? require(resolvedModuleSpecifier);\n\t\treturn module[name] ?? module.default ?? module;\n\t} catch (ex) {\n\t\tif (isEvaluationError(ex)) return ex;\n\t\telse return throwError(new ModuleNotFoundError({node, environment, path: resolvedModuleSpecifier}));\n\t}\n}\n","import type {TS} from \"../../../type/ts.js\";\nimport type {EvaluatorOptions} from \"../../evaluator/evaluator-options.js\";\nimport type {Literal} from \"../../literal/literal.js\";\nimport {isDeclaration, isNamedDeclaration} from \"../declaration/is-declaration.js\";\nimport {isVarDeclaration} from \"../flags/is-var-declaration.js\";\nimport {getImplementationFromExternalFile} from \"../module/get-implementation-for-declaration-within-declaration-file.js\";\n\n/**\n * Finds the nearest parent node of the given kind from the given Node\n */\nexport function findNearestParentNodeOfKind<T extends TS.Node>(from: TS.Node, kind: TS.SyntaxKind, typescript: typeof TS): T | undefined {\n\tlet currentParent = from;\n\twhile (true) {\n\t\tcurrentParent = currentParent.parent;\n\t\tif (currentParent == null) return undefined;\n\t\tif (currentParent.kind === kind) {\n\t\t\tconst combinedNodeFlags = typescript.getCombinedNodeFlags(currentParent);\n\t\t\tconst isNamespace = (combinedNodeFlags & typescript.NodeFlags.Namespace) !== 0 || (combinedNodeFlags & typescript.NodeFlags.NestedNamespace) !== 0;\n\t\t\tif (!isNamespace) return currentParent as T;\n\t\t}\n\n\t\tif (typescript.isSourceFile(currentParent)) return undefined;\n\t}\n}\n\n/**\n * Finds the nearest parent node with the given name from the given Node\n */\nexport function findNearestParentNodeWithName<T extends TS.Node>(\n\tfrom: TS.Node,\n\tname: string,\n\toptions: EvaluatorOptions<T>,\n\tvisitedRoots = new WeakSet<TS.Node>()\n): T | Literal | undefined {\n\tconst {typescript} = options;\n\tlet result: TS.Node | Literal | undefined;\n\n\tfunction visit(nextNode: TS.Node, nestingLayer = 0): boolean {\n\t\tif (visitedRoots.has(nextNode)) return false;\n\t\tvisitedRoots.add(nextNode);\n\n\t\tif (typescript.isIdentifier(nextNode)) {\n\t\t\tif (nextNode.text === name) {\n\t\t\t\tresult = nextNode;\n\t\t\t\treturn true;\n\t\t\t}\n\t\t} else if (typescript.isShorthandPropertyAssignment(nextNode)) {\n\t\t\treturn false;\n\t\t} else if (typescript.isPropertyAssignment(nextNode)) {\n\t\t\treturn false;\n\t\t} else if (typescript.isImportDeclaration(nextNode)) {\n\t\t\tif (nextNode.importClause != null) {\n\t\t\t\tif (nextNode.importClause.name != null && visit(nextNode.importClause.name)) {\n\t\t\t\t\tconst moduleSpecifier = nextNode.moduleSpecifier;\n\t\t\t\t\tif (moduleSpecifier != null && typescript.isStringLiteralLike(moduleSpecifier)) {\n\t\t\t\t\t\tresult = getImplementationFromExternalFile(name, moduleSpecifier.text, options);\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t} else if (nextNode.importClause.namedBindings != null && visit(nextNode.importClause.namedBindings)) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false;\n\t\t} else if (typescript.isImportEqualsDeclaration(nextNode)) {\n\t\t\tif (nextNode.name != null && visit(nextNode.name)) {\n\t\t\t\tif (typescript.isIdentifier(nextNode.moduleReference)) {\n\t\t\t\t\tresult = findNearestParentNodeWithName(nextNode.parent, nextNode.moduleReference.text, options, visitedRoots);\n\t\t\t\t\treturn result != null;\n\t\t\t\t} else if (typescript.isQualifiedName(nextNode.moduleReference)) {\n\t\t\t\t\treturn false;\n\t\t\t\t} else {\n\t\t\t\t\tconst moduleSpecifier = nextNode.moduleReference.expression;\n\t\t\t\t\tif (moduleSpecifier != null && typescript.isStringLiteralLike(moduleSpecifier)) {\n\t\t\t\t\t\tresult = getImplementationFromExternalFile(name, moduleSpecifier.