UNPKG

ts-evaluator

Version:

An interpreter for Typescript that can evaluate an arbitrary Node within a Typescript AST

1 lines 443 kB
{"version":3,"file":"index.cjs","sources":["../../src/interpreter/environment/ecma/ecma-globals.ts","../../src/interpreter/util/descriptor/merge-descriptors.ts","../../src/interpreter/util/object/subtract.ts","../../src/interpreter/util/loader/require-module.ts","../../src/interpreter/environment/node/node-cjs-globals.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/lexical-environment/lexical-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","../../src/interpreter/evaluate.ts"],"sourcesContent":["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","/* eslint-disable @typescript-eslint/ban-types */\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 == null ? {} : b;\n\tconst normalizedC = c == null ? {} : c;\n\t[a, normalizedB, normalizedC].forEach(item => Object.defineProperties(newObj, Object.getOwnPropertyDescriptors(item)));\n\treturn newObj;\n}\n","/* eslint-disable @typescript-eslint/ban-types */\n\nexport 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 {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);","/* eslint-disable @typescript-eslint/naming-convention */\nimport {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","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 (ex) {\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}","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 const {node, typescript} = options;\n if (!typescript.isExternalModuleNameRelative(moduleSpecifier)) {\n return moduleSpecifier;\n }\n\n const parentPath = node.getSourceFile().fileName;\n return path.join(path.dirname(parentPath), moduleSpecifier);\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 != null && 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\n\t\t// eslint-disable-next-line @typescript-eslint/no-require-imports,@typescript-eslint/no-var-requires\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\t// eslint-disable-next-line @typescript-eslint/no-require-imports,@typescript-eslint/no-var-requires\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.text, options);\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false;\n\t\t} else if (typescript.isNamespaceImport(nextNode)) {\n\t\t\tif (visit(nextNode.name)) {\n\t\t\t\tconst moduleSpecifier = nextNode.parent?.parent?.moduleSpecifier;\n\t\t\t\tif (moduleSpecifier == null || !typescript.isStringLiteralLike(moduleSpecifier)) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\tresult = getImplementationFromExternalFile(name, moduleSpecifier.text, options);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t} else if (typescript.isNamedImports(nextNode)) {\n\t\t\tfor (const importSpecifier of nextNode.elements) {\n\t\t\t\tif (visit(importSpecifier)) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (typescript.isImportSpecifier(nextNode)) {\n\t\t\tif (visit(nextNode.name)) {\n\t\t\t\tconst moduleSpecifier = nextNode.parent?.parent?.parent?.moduleSpecifier;\n\t\t\t\tif (moduleSpecifier == null || !typescript.isStringLiteralLike(moduleSpecifier)) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\tresult = getImplementationFromExternalFile(name, moduleSpecifier.text, options);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t} else if (typescript.isSourceFile(nextNode)) {\n\t\t\tfor (const statement of nextNode.statements) {\n\t\t\t\tif (visit(statement)) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (typescript.isVariableStatement(nextNode)) {\n\t\t\tfor (const declaration of nextNode.declarationList.declarations) {\n\t\t\t\tif (visit(declaration) && (isVarDeclaration(nextNode.declarationList, typescript) || nestingLayer < 1)) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (typescript.isBlock(nextNode)) {\n\t\t\tfor (const statement of nextNode.statements) {\n\t\t\t\tif (visit(statement, nestingLayer + 1)) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (isNamedDeclaration(nextNode, typescript)) {\n\t\t\tif (nextNode.name != null && visit(nextNode.name)) {\n\t\t\t\tresult = nextNode;\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\tconst suceeded = typescript.findAncestor<T>(from, (nextNode): nextNode is T => visit(nextNode));\n\treturn !suceeded ? undefined : (result as T | undefined);\n}\n\nexport function getStatementContext<T extends TS.Declaration = TS.Declaration>(from: TS.Node, 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 (isDeclaration(currentParent, typescript) || typescript.isSourceFile(currentParent)) {\n\t\t\treturn currentParent as T;\n\t\t}\n\t}\n}\n","/**\n * Returns true if the provided value is ObjectLike\n *\n * @param value\n * @returns\n */\nexport function isObjectLike<T>(value: T): boolean {\n\treturn value != null && (typeof value === \"function\" || typeof value === \"object\");\n}\n\n/**\n * Returns true if the given value can be observed\n *\n * @param value\n * @returns\n */\nexport function canBeObserved<T>(value: T): boolean {\n\treturn isObjectLike(value);\n}\n","import type { LexicalEnvironment} from \"../../lexical-environment/lexical-environment.js\";\nimport {getFromLexicalEnvironment} from \"../../lexical-environment/lexical-environment.js\";\n\n/**\n * Returns true if the given function is either Function.prototype.bind, Function.prototype.call, or Function.prototype.apply\n *\n * @param func\n * @param [environment]\n * @return\n */\nexport function isBindCallApply(func: CallableFunction, environment?: LexicalEnvironment): boolean {\n\tswitch (func) {\n\t\tcase Function.prototype.bind:\n\t\tcase Function.prototype.call:\n\t\tcase Function.prototype.apply:\n\t\t\treturn true;\n\t}\n\n\tif (environment != null) {\n\t\tconst _Function = getFromLexicalEnvironment(undefined, environment, \"Function\")!.literal as CallableFunction;\n\t\tswitch (func) {\n\t\t\tcase _Function.prototype.bind:\n\t\t\tcase _Function.prototype.call:\n\t\t\tcase _Function.prototype.apply:\n\t\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n","export const enum PolicyTrapKind {\n\tGET = \"__$$_PROXY_GET\",\n\tAPPLY = \"__$$_PROXY_APPLY\",\n\tCONSTRUCT = \"__$$_PROXY_CONSTRUCT\"\n}\n\n/**\n * Stringifies the given PolicyTrapKind on the given path\n *\n * @param kind\n * @param path\n * @return\n */\nexport function stringifyPolicyTrapKindOnPath(kind: PolicyTrapKind, path: string): string {\n\tswitch (kind) {\n\t\tcase PolicyTrapKind.GET:\n\t\t\treturn `get ${path}`;\n\n\t\tcase PolicyTrapKind.APPLY:\n\t\t\treturn `${path}(...)`;\n\n\t\tcase PolicyTrapKind.CONSTRUCT:\n\t\t\treturn `new ${path}(...)`;\n\t}\n}\n","import type {TS} from \"../../../type/ts.js\";\nimport type {NextEvaluatorOptions} from \"../../evaluator/evaluator-options.js\";\nimport type {EvaluationError} from \"./evaluation-error.js\";\n\ntype EvaluationErrorIntentCallback<T extends EvaluationError> = (node: TS.Node, options: NextEvaluatorOptions) => T;\n\nexport class EvaluationErrorIntent<T extends EvaluationError = EvaluationError> {\n\tconstructor(private readonly intent: EvaluationErrorIntentCallback<T>) {}\n\tconstruct(node: TS.Node, options: NextEvaluatorOptions): T {\n\t\treturn this.intent(node, options);\n\t}\n}\n\nexport function isEvaluationErrorIntent<T extends EvaluationError = EvaluationError>(item: unknown): item is EvaluationErrorIntent<T> {\n\treturn typeof item === \"object\" && item != null && item instanceof EvaluationErrorIntent;\n}\n\nexport function maybeThrow<Value>(node: TS.Node, options: NextEvaluatorOptions, value: Value | EvaluationErrorIntent): Value | EvaluationError {\n\treturn isEvaluationErrorIntent(value) ? options.throwError(value.construct(node, options)) : value;\n}\n","/* eslint-disable @typescript-eslint/ban-types */\nimport {canBeObserved} from \"../util/proxy/can-be-observed.js\";\nimport type {ICreatePolicyProxyOptions} from \"./i-create-policy-proxy-options.js\";\nimport {isBindCallApply} from \"../util/function/is-bind-call-apply.js\";\nimport {PolicyTrapKind} from \"../policy/policy-trap-kind.js\";\nimport type {EvaluationErrorIntent} from \"../error/evaluation-error/evaluation-error-intent.js\";\nimport { isEvaluationErrorIntent} from \"../error/evaluation-error/evaluation-error-intent.js\";\nimport { isEvaluationError } from \"../error/evaluation-error/evaluation-error.js\";\n\n/**\n * Stringifies the given PropertyKey path\n */\nfunction stringifyPath(path: PropertyKey[]): string {\n\treturn path.map(part => (typeof part === \"symbol\" ? part.description : part)).join(\".\");\n}\n\n/**\n * Creates a proxy with hooks to check the given policy\n */\nexport function createPolicyProxy<T extends object>({hook, item, scope, policy}: ICreatePolicyProxyOptions<T, object>): T {\n\t/**\n\t * Creates a trap that captures function invocation\n\t */\n\tfunction createAccessTrap<U extends object>(inputPath: PropertyKey[], currentItem: U): U {\n\t\tconst handleHookResult = (result: boolean | EvaluationErrorIntent, successCallback: CallableFunction) => {\n\t\t\tif (result === false) return;\n\t\t\tif (isEvaluationErrorIntent(result) || isEvaluationError(result)) return result;\n\t\t\treturn successCallback();\n\t\t};\n\n\t\treturn !canBeObserved(currentItem) || isBindCallApply(currentItem as Function)\n\t\t\t? currentItem\n\t\t\t: new Proxy(currentItem, {\n\t\t\t\t\t/**\n\t\t\t\t\t * Constructs a new instance of the given target\n\t\t\t\t\t */\n\t\t\t\t\tconstruct(target: U, argArray: unknown[], newTarget?: Function): object {\n\t\t\t\t\t\treturn handleHookResult(\n\t\t\t\t\t\t\thook({\n\t\t\t\t\t\t\t\tkind: PolicyTrapKind.CONSTRUCT,\n\t\t\t\t\t\t\t\tpolicy,\n\t\t\t\t\t\t\t\tnewTarget,\n\t\t\t\t\t\t\t\targArray,\n\t\t\t\t\t\t\t\ttarget,\n\t\t\t\t\t\t\t\tpath: stringifyPath(inputPath)\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t() => Reflect.construct(target as Function, argArray, newTarget)\n\t\t\t\t\t\t);\n\t\t\t\t\t},\n\n\t\t\t\t\t/**\n\t\t\t\t\t * A trap for a function call. Used to create new proxies for methods on the retrieved module objects\n\t\t\t\t\t */\n\t\t\t\t\tapply(target: U, thisArg: unknown, argArray: unknown[] = []): unknown {\n\t\t\t\t\t\treturn handleHookResult(\n\t\t\t\t\t\t\thook({\n\t\t\t\t\t\t\t\tkind: PolicyTrapKind.APPLY,\n\t\t\t\t\t\t\t\tpolicy,\n\t\t\t\t\t\t\t\tthisArg,\n\t\t\t\t\t\t\t\targArray,\n\t\t\t\t\t\t\t\ttarget,\n\t\t\t\t\t\t\t\tpath: stringifyPath(inputPath)\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t() => Reflect.apply(target as Function, thisArg, argArray)\n\t\t\t\t\t\t);\n\t\t\t\t\t},\n\n\t\t\t\t\t/**\n\t\t\t\t\t * Gets a trap for 'get' accesses\n\t\t\t\t\t */\n\t\t\t\t\tget(target: U, property: string, receiver: unknown): unknown {\n\t\t\t\t\t\tconst newPath = [...inputPath, property];\n\t\t\t\t\t\treturn handleHookResult(\n\t\t\t\t\t\t\thook({\n\t\t\t\t\t\t\t\tkind: PolicyTrapKind.GET,\n\t\t\t\t\t\t\t\tpolicy,\n\t\t\t\t\t\t\t\tpath: stringifyPath(newPath),\n\t\t\t\t\t\t\t\ttarget\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t() => {\n\t\t\t\t\t\t\t\tconst match = Reflect.get(target, property, receiver);\n\n\t\t\t\t\t\t\t\tconst config = Reflect.getOwnPropertyDescriptor(currentItem, property);\n\t\t\t\t\t\t\t\tif (config != null && config.configurable === false && config.writable === false) {\n\t\t\t\t\t\t\t\t\treturn currentItem[property as keyof U];\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn createAccessTrap(newPath, match as object);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t });\n\t}\n\n\treturn !canBeObserved(item) ? item : createAccessTrap([scope], item);\n}\n","/* eslint-disable @typescript-eslint/naming-convention */\nimport {PolicyTrapKind} from \"../policy-trap-kind.js\";\nimport type {TrapConditionMap} from \"../trap-condition-map.js\";\nimport type {NodeBuiltInsAndGlobals} from \"../../environment/node/node-built-ins-and-globals.js\";\n\n/**\n * A Map between built-in modules and the kind of IO operations their members performs\n * @type {TrapConditionMap<NodeBuiltInsAndGlobals>}\n */\nexport const NETWORK_MAP: TrapConditionMap<NodeBuiltInsAndGlobals> = {\n\t\"node:http2\": \"http2\",\n\thttp2: {\n\t\tconnect: {\n\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t},\n\t\tcreateSecureServer: {\n\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t},\n\t\tcreateServer: {\n\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t}\n\t},\n\n\t\"node:https\": \"https\",\n\n\thttps: {\n\t\tcreateServer: {\n\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t},\n\t\trequest: {\n\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t},\n\t\tget: {\n\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t},\n\t\tServer: {\n\t\t\t[PolicyTrapKind.CONSTRUCT]: true\n\t\t},\n\t\tglobalAgent: {\n\t\t\tdestroy: {\n\t\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t\t}\n\t\t},\n\t\tAgent: {\n\t\t\t[PolicyTrapKind.CONSTRUCT]: true\n\t\t}\n\t},\n\n\t\"node:http\": \"http\",\n\n\thttp: {\n\t\tcreateServer: {\n\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t},\n\t\trequest: {\n\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t},\n\t\tget: {\n\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t},\n\t\tServer: {\n\t\t\t[PolicyTrapKind.CONSTRUCT]: true\n\t\t},\n\t\tClientRequest: {\n\t\t\t[PolicyTrapKind.CONSTRUCT]: true\n\t\t},\n\t\tglobalAgent: {\n\t\t\tdestroy: {\n\t\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t\t}\n\t\t},\n\t\tAgent: {\n\t\t\t[PolicyTrapKind.CONSTRUCT]: true\n\t\t}\n\t},\n\n\t\"node:dgram\": \"dgram\",\n\n\tdgram: {\n\t\tcreateSocket: {\n\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t}\n\t},\n\n\t\"node:dns\": \"dns\",\n\n\tdns: {\n\t\tlookup: {\n\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t},\n\t\tlookupService: {\n\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t},\n\t\tresolve: {\n\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t},\n\t\tresolve4: {\n\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t},\n\t\tresolve6: {\n\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t},\n\t\tresolveAny: {\n\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t},\n\t\tresolveCname: {\n\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t},\n\t\tresolveMx: {\n\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t},\n\t\tresolveNaptr: {\n\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t},\n\t\tresolveNs: {\n\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t},\n\t\tresolvePtr: {\n\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t},\n\t\tresolveSoa: {\n\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t},\n\t\tresolveSrv: {\n\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t},\n\t\tresolveTxt: {\n\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t},\n\t\treverse: {\n\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t},\n\t\tResolver: {\n\t\t\t[PolicyTrapKind.CONSTRUCT]: true\n\t\t}\n\t},\n\n\t\"node:net\": \"net\",\n\n\tnet: {\n\t\tcreateServer: {\n\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t},\n\t\tcreateConnection: {\n\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t},\n\t\tconnect: {\n\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t},\n\t\tServer: {\n\t\t\t[PolicyTrapKind.CONSTRUCT]: true\n\t\t}\n\t},\n\n\t\"node:tls\": \"tls\",\n\n\ttls: {\n\t\tcreateServer: {\n\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t},\n\t\tcreateSecureContext: {\n\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t},\n\t\tconnect: {\n\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t},\n\t\tServer: {\n\t\t\t[PolicyTrapKind.CONSTRUCT]: true\n\t\t},\n\t\tTLSSocket: {\n\t\t\t[PolicyTrapKind.CONSTRUCT]: true\n\t\t}\n\t}\n};\n","/* eslint-disable @typescript-eslint/naming-convention */\nimport {PolicyTrapKind} from \"../policy-trap-kind.js\";\nimport type {TrapConditionMap} from \"../trap-condition-map.js\";\nimport {NETWORK_MAP} from \"../network/network-map.js\";\nimport type {NodeBuiltInsAndGlobals} from \"../../environment/node/node-built-ins-and-globals.js\";\n\n/**\n * A Map between built-in identifiers and the members that produce non-deterministic results.\n */\nexport const NONDETERMINISTIC_MAP: TrapConditionMap<NodeBuiltInsAndGlobals> = {\n\t// Any network operation will always be non-deterministic\n\t...NETWORK_MAP,\n\tMath: {\n\t\trandom: {\n\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t}\n\t},\n\tDate: {\n\t\tnow: {\n\t\t\t[PolicyTrapKind.APPLY]: true\n\t\t},\n\t\t// Dates that receive no arguments are nondeterministic since they care about \"now\" and will evaluate to a new value for each invocation\n\t\t[PolicyTrapKind.CONSTRUCT]: (...args) => args.length === 0 && !(args[0] instanceof Date)\n\t}\n};\n","import type {PolicyTrapKind} from \"./policy-trap-kind.js\";\n\nexport type TrapConditionFunction<ConditionType> = (...args: unknown[]) => ConditionType;\nexport type TrapCondition<ConditionType> = ConditionType | TrapConditionFunction<ConditionType>;\n\nexport type PolicyTrapKindToTrapConditionMap<ConditionType> = {\n\t[key in PolicyTrapKind]?: TrapCondition<ConditionType>;\n};\n\nexport type TrapConditionMap<T, ConditionType = boolean> = {\n\t[Key in keyof T]?: TrapConditionMapValue<T[Key], ConditionType, T>;\n};\n\nexport type TrapConditionMemberMap<T, ConditionType> = {\n\t[Key in keyof T]?: TrapConditionMapValue<T[Key], ConditionType, T>;\n};\n\nexport type TrapConditionMapValue<T, ConditionType, Parent = never> =\n\t| TrapCondition<ConditionType>\n\t| TrapConditionMemberMap<T, ConditionType>\n\t| PolicyTrapKindToTrapConditionMap<ConditionType>\n\n\t/**\n\t * Useful if two modules are identical and should follow the same rules\n\t */\n\t| keyof Parent\n\t| undefined;\n\n/**\n * Returns true if the given item is a TrapCondition\n */\nexport function isTrapCondition<ConditionType>(item: unknown, condition: ConditionType): item is TrapCondition<ConditionType> {\n\t// noinspection SuspiciousTypeOfGuard\n\treturn typeof item === typeof condition || typeof item === \"function\";\n}\n\n/**\n * Returns true if the given item is a TrapCondition\n */\nexport function isTrapConditionFunction<T, ConditionType = boolean>(item: TrapConditionMapValue<T, ConditionType>): item is TrapConditionFunction<ConditionType> {\n\treturn typeof item === \"function\";\n}\n","/* eslint-disable @typescript-eslint/ban-types */\nimport type { PolicyTrapKindToTrapConditionMap, TrapCondition, TrapConditionMap, TrapConditionMemberMap} from \"./trap-condition-map.js\";\nimport {isTrapCondition, isTrapConditionFunction} from \"./trap-condition-map.js\";\nimport type {IPolicyProxyApplyHookOptions, IPolicyProxyConstructHookOptions, PolicyProxyHookOptions} from \"../proxy/policy-proxy-hook.js\";\n\n/**\n * Returns true if the given path represents something that is nondeterministic.\n */\nexport function isTrapConditionMet<T extends object, ConditionType = boolean>(\n\tmap: TrapConditionMap<T, ConditionType>,\n\tcondition: ConditionType,\n\titem: PolicyProxyHookOptions<T>\n): boolean {\n\tconst atoms = item.path.split(\".\") as (keyof T)[];\n\treturn walkAtoms(map, condition, item, atoms);\n}\n\n/**\n * Walks all atoms of the given item path\n */\nfunction walkAtoms<T extends object, ConditionType = boolean>(\n\tmap: TrapConditionMap<T, ConditionType> | TrapConditionMemberMap<T, ConditionType>,\n\tmatchCondition: ConditionType,\n\titem: PolicyProxyHookOptions<T>,\n\tatoms: (keyof T)[]\n): boolean {\n\tconst [head, ...tail] = atoms;\n\tif (head == null) return false;\n\n\tconst mapEntry = map[head];\n\n\t// If nothing was matched within the namespace, the trap wasn't matched\n\tif (mapEntry == null) return false;\n\n\tif (typeof mapEntry === \"string\") {\n\t\treturn walkAtoms(map, matchCondition, item, [mapEntry as keyof T, ...tail]);\n\t}\n\n\tif (isTrapCondition<ConditionType>(mapEntry, matchCondition)) {\n\t\treturn handleTrapCondition(mapEntry, matchCondition, item);\n\t} else {\n\t\tconst trapMapMatch = (mapEntry as PolicyTrapKindToTrapConditionMap<ConditionType>)[item.kind];\n\t\tif (trapMapMatch != null) {\n\t\t\treturn handleTrapCondition(trapMapMatch, matchCondition, item);\n\t\t} else {\n\t\t\treturn walkAtoms(mapEntry as TrapConditionMap<T, ConditionType> | TrapConditionMemberMap<T, ConditionT