@next-core/cook 2.3.0 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,20 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ export let Mode = /*#__PURE__*/function (Mode) {
3
+ Mode[Mode["LEXICAL"] = 0] = "LEXICAL";
4
+ Mode[Mode["STRICT"] = 1] = "STRICT";
5
+ return Mode;
6
+ }({});
7
+ export const SourceNode = Symbol.for("SourceNode");
8
+ export const FormalParameters = Symbol.for("FormalParameters");
9
+ export const ECMAScriptCode = Symbol.for("ECMAScriptCode");
10
+ export const Environment = Symbol.for("Environment");
11
+ export const IsConstructor = Symbol.for("IsConstructor");
12
+ export const ThisMode = Symbol.for("ThisMode");
13
+ export const DebuggerCall = Symbol.for("$DebuggerCall$");
14
+ export const DebuggerScope = Symbol.for("$DebuggerScope$");
15
+ export const DebuggerNode = Symbol.for("$DebuggerNode$");
16
+ export const DebuggerReturn = Symbol.for("$DebuggerReturn$");
17
+
2
18
  // https://tc39.es/ecma262/#sec-execution-contexts
3
19
  export class ExecutionContext {
4
20
  constructor() {
@@ -7,11 +23,20 @@ export class ExecutionContext {
7
23
  _defineProperty(this, "Function", void 0);
8
24
  }
9
25
  }
26
+ export let BindingStatus = /*#__PURE__*/function (BindingStatus) {
27
+ BindingStatus[BindingStatus["UNINITIALIZED"] = 0] = "UNINITIALIZED";
28
+ BindingStatus[BindingStatus["LEXICAL"] = 1] = "LEXICAL";
29
+ BindingStatus[BindingStatus["INITIALIZED"] = 2] = "INITIALIZED";
30
+ return BindingStatus;
31
+ }({});
32
+
10
33
  // https://tc39.es/ecma262/#sec-environment-records
11
34
  export class EnvironmentRecord {
12
35
  constructor(outer) {
13
36
  _defineProperty(this, "OuterEnv", void 0);
14
37
  _defineProperty(this, "bindingMap", new Map());
38
+ _defineProperty(this, "ThisValue", undefined);
39
+ _defineProperty(this, "ThisBindingStatus", void 0);
15
40
  this.OuterEnv = outer;
16
41
  }
17
42
  HasBinding(name) {
@@ -78,17 +103,39 @@ export class EnvironmentRecord {
78
103
  }
79
104
  return binding.value;
80
105
  }
106
+ HasThisBinding() {
107
+ return false;
108
+ }
81
109
  }
82
110
  export class DeclarativeEnvironment extends EnvironmentRecord {}
83
- export class FunctionEnvironment extends EnvironmentRecord {}
84
- export const SourceNode = Symbol.for("SourceNode");
85
- export const FormalParameters = Symbol.for("FormalParameters");
86
- export const ECMAScriptCode = Symbol.for("ECMAScriptCode");
87
- export const Environment = Symbol.for("Environment");
88
- export const IsConstructor = Symbol.for("IsConstructor");
89
- export const DebuggerCall = Symbol.for("$DebuggerCall$");
90
- export const DebuggerScope = Symbol.for("$DebuggerScope$");
91
- export const DebuggerNode = Symbol.for("$DebuggerNode$");
111
+ export class FunctionEnvironment extends EnvironmentRecord {
112
+ constructor(F) {
113
+ super(F[Environment]);
114
+ if (F[ThisMode] === Mode.LEXICAL) {
115
+ this.ThisBindingStatus = BindingStatus.LEXICAL;
116
+ } else {
117
+ this.ThisBindingStatus = BindingStatus.UNINITIALIZED;
118
+ }
119
+ }
120
+ HasThisBinding() {
121
+ return this.ThisBindingStatus !== BindingStatus.LEXICAL;
122
+ }
123
+ BindThisValue(value) {
124
+ // Assert: envRec.[[ThisBindingStatus]] is not LEXICAL.
125
+ if (this.ThisBindingStatus === BindingStatus.INITIALIZED) {
126
+ throw new Error("This binding has been initialized");
127
+ }
128
+ this.ThisValue = value;
129
+ this.ThisBindingStatus = BindingStatus.INITIALIZED;
130
+ }
131
+ GetThisBinding() {
132
+ // Assert: envRec.[[ThisBindingStatus]] is not LEXICAL.
133
+ if (this.ThisBindingStatus === BindingStatus.UNINITIALIZED) {
134
+ throw new Error("This binding is not initialized");
135
+ }
136
+ return this.ThisValue;
137
+ }
138
+ }
92
139
  // https://tc39.es/ecma262/#sec-reference-record-specification-type
93
140
  export class ReferenceRecord {
94
141
  constructor(base, referenceName, strict) {
@@ -1 +1 @@
1
- {"version":3,"file":"ExecutionContext.js","names":["ExecutionContext","constructor","_defineProperty","EnvironmentRecord","outer","Map","OuterEnv","HasBinding","name","bindingMap","has","CreateMutableBinding","deletable","set","mutable","NormalCompletion","undefined","CreateImmutableBinding","strict","InitializeBinding","value","binding","get","Object","assign","initialized","SetMutableBinding","_strict","ReferenceError","TypeError","GetBindingValue","DeclarativeEnvironment","FunctionEnvironment","SourceNode","Symbol","for","FormalParameters","ECMAScriptCode","Environment","IsConstructor","DebuggerCall","DebuggerScope","DebuggerNode","ReferenceRecord","base","referenceName","Base","ReferenceName","Strict","CompletionRecord","type","Type","Value","Empty"],"sources":["../../src/ExecutionContext.ts"],"sourcesContent":["import type {\n ArrowFunctionExpression,\n Expression,\n FunctionDeclaration,\n FunctionExpression,\n Statement,\n} from \"@babel/types\";\nimport type { EstreeNode } from \"./interfaces.js\";\n\n// https://tc39.es/ecma262/#sec-execution-contexts\nexport class ExecutionContext {\n VariableEnvironment?: EnvironmentRecord;\n LexicalEnvironment?: EnvironmentRecord;\n Function?: FunctionObject;\n}\n\nexport type EnvironmentRecordType = \"function\" | \"declarative\";\n\n// https://tc39.es/ecma262/#sec-environment-records\nexport class EnvironmentRecord {\n readonly OuterEnv: EnvironmentRecord | null | undefined;\n private readonly bindingMap = new Map<string, BindingState>();\n\n constructor(outer: EnvironmentRecord | null | undefined) {\n this.OuterEnv = outer;\n }\n\n HasBinding(name: string): boolean {\n return this.bindingMap.has(name);\n }\n\n CreateMutableBinding(name: string, deletable: boolean): CompletionRecord {\n // Assert: binding does not exist.\n this.bindingMap.set(name, {\n mutable: true,\n deletable,\n });\n return NormalCompletion(undefined);\n }\n\n /**\n * Create an immutable binding.\n *\n * @param name - The binding name.\n * @param strict - For named function expressions, strict is false, otherwise it's true.\n * @returns CompletionRecord.\n */\n CreateImmutableBinding(name: string, strict: boolean): CompletionRecord {\n // Assert: binding does not exist.\n this.bindingMap.set(name, {\n strict,\n });\n return NormalCompletion(undefined);\n }\n\n InitializeBinding(name: string, value: unknown): CompletionRecord {\n const binding = this.bindingMap.get(name) as BindingState;\n // Assert: binding exists and uninitialized.\n Object.assign<BindingState, Partial<BindingState>>(binding, {\n initialized: true,\n value,\n });\n return NormalCompletion(undefined);\n }\n\n /**\n * Update a mutable binding value, including function declarations.\n *\n * @param name - The binding name.\n * @param value - The binding value.\n * @param strict - For functions, strict is always false, otherwise it depends on strict-mode.\n * @returns\n */\n SetMutableBinding(\n name: string,\n value: unknown,\n _strict?: boolean\n ): CompletionRecord {\n const binding = this.bindingMap.get(name) as BindingState;\n // Assert: binding exists.\n if (!binding.initialized) {\n throw new ReferenceError(`${name} is not initialized`);\n } else if (binding.mutable) {\n binding.value = value;\n } else {\n throw new TypeError(`Assignment to constant variable`);\n }\n return NormalCompletion(undefined);\n }\n\n GetBindingValue(name: string, _strict?: boolean): unknown {\n const binding = this.bindingMap.get(name) as BindingState;\n // Assert: binding exists.\n if (!binding.initialized) {\n throw new ReferenceError(`${name} is not initialized`);\n }\n return binding.value;\n }\n}\n\nexport class DeclarativeEnvironment extends EnvironmentRecord {}\n\nexport class FunctionEnvironment extends EnvironmentRecord {}\n\nexport interface BindingState {\n initialized?: boolean;\n value?: unknown;\n mutable?: boolean;\n\n /** This is used for mutable bindings only. */\n deletable?: boolean;\n\n /**\n * This is used for immutable bindings only.\n * For named function expressions, `strict` is false,\n * otherwise it's true.\n */\n strict?: boolean;\n}\n\nexport const SourceNode = Symbol.for(\"SourceNode\");\nexport const FormalParameters = Symbol.for(\"FormalParameters\");\nexport const ECMAScriptCode = Symbol.for(\"ECMAScriptCode\");\nexport const Environment = Symbol.for(\"Environment\");\nexport const IsConstructor = Symbol.for(\"IsConstructor\");\nexport const DebuggerCall = Symbol.for(\"$DebuggerCall$\");\nexport const DebuggerScope = Symbol.for(\"$DebuggerScope$\");\nexport const DebuggerNode = Symbol.for(\"$DebuggerNode$\");\n\nexport interface FunctionObject {\n (...args: unknown[]): unknown;\n [SourceNode]:\n | FunctionDeclaration\n | FunctionExpression\n | ArrowFunctionExpression;\n [FormalParameters]: FunctionDeclaration[\"params\"];\n [ECMAScriptCode]: Statement[] | Expression;\n [Environment]: EnvironmentRecord;\n [IsConstructor]: boolean;\n [DebuggerCall]?: (...args: unknown[]) => IterableIterator<unknown>;\n [DebuggerScope]?: () => EnvironmentRecord | null | undefined;\n [DebuggerNode]?: () => EstreeNode | undefined;\n}\n\n// https://tc39.es/ecma262/#sec-reference-record-specification-type\nexport class ReferenceRecord {\n readonly Base:\n | Record<PropertyKey, unknown>\n | EnvironmentRecord\n | \"unresolvable\";\n readonly ReferenceName: PropertyKey;\n /** Whether the reference is in strict mode. */\n readonly Strict?: boolean;\n\n constructor(\n base: Record<PropertyKey, unknown> | EnvironmentRecord | \"unresolvable\",\n referenceName: PropertyKey,\n strict: boolean\n ) {\n this.Base = base;\n this.ReferenceName = referenceName;\n this.Strict = strict;\n }\n}\n\n// https://tc39.es/ecma262/#sec-completion-record-specification-type\nexport class CompletionRecord {\n readonly Type: CompletionRecordType;\n readonly Value: unknown;\n\n constructor(type: CompletionRecordType, value: unknown) {\n this.Type = type;\n this.Value = value;\n }\n}\n\nexport type CompletionRecordType =\n | \"normal\"\n | \"break\"\n | \"continue\"\n | \"return\"\n | \"throw\";\n\n// https://tc39.es/ecma262/#sec-normalcompletion\nexport function NormalCompletion(value: unknown): CompletionRecord {\n return new CompletionRecord(\"normal\", value);\n}\n\nexport const Empty = Symbol(\"empty completion\");\n\nexport interface OptionalChainRef {\n skipped?: boolean;\n}\n"],"mappings":";AASA;AACA,OAAO,MAAMA,gBAAgB,CAAC;EAAAC,YAAA;IAAAC,eAAA;IAAAA,eAAA;IAAAA,eAAA;EAAA;AAI9B;AAIA;AACA,OAAO,MAAMC,iBAAiB,CAAC;EAI7BF,WAAWA,CAACG,KAA2C,EAAE;IAAAF,eAAA;IAAAA,eAAA,qBAF3B,IAAIG,GAAG,CAAuB,CAAC;IAG3D,IAAI,CAACC,QAAQ,GAAGF,KAAK;EACvB;EAE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MAAM,GAAG9B,MAAM;EACtB;AACF;;AAEA;AACA,OAAO,MAAM+B,gBAAgB,CAAC;EAI5BhD,WAAWA,CAACiD,IAA0B,EAAE9B,KAAc,EAAE;IAAAlB,eAAA;IAAAA,eAAA;IACtD,IAAI,CAACiD,IAAI,GAAGD,IAAI;IAChB,IAAI,CAACE,KAAK,GAAGhC,KAAK;EACpB;AACF;AASA;AACA,OAAO,SAASL,gBAAgBA,CAACK,KAAc,EAAoB;EACjE,OAAO,IAAI6B,gBAAgB,CAAC,QAAQ,EAAE7B,KAAK,CAAC;AAC9C;AAEA,OAAO,MAAMiC,KAAK,GAAGnB,MAAM,CAAC,kBAAkB,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"ExecutionContext.js","names":["Mode","SourceNode","Symbol","for","FormalParameters","ECMAScriptCode","Environment","IsConstructor","ThisMode","DebuggerCall","DebuggerScope","DebuggerNode","DebuggerReturn","ExecutionContext","constructor","_defineProperty","BindingStatus","EnvironmentRecord","outer","Map","undefined","OuterEnv","HasBinding","name","bindingMap","has","CreateMutableBinding","deletable","set","mutable","NormalCompletion","CreateImmutableBinding","strict","InitializeBinding","value","binding","get","Object","assign","initialized","SetMutableBinding","_strict","ReferenceError","TypeError","GetBindingValue","HasThisBinding","DeclarativeEnvironment","FunctionEnvironment","F","LEXICAL","ThisBindingStatus","UNINITIALIZED","BindThisValue","INITIALIZED","Error","ThisValue","GetThisBinding","ReferenceRecord","base","referenceName","Base","ReferenceName","Strict","CompletionRecord","type","Type","Value","Empty"],"sources":["../../src/ExecutionContext.ts"],"sourcesContent":["import type {\n ArrowFunctionExpression,\n Expression,\n FunctionDeclaration,\n FunctionExpression,\n Statement,\n} from \"@babel/types\";\nimport type { EstreeNode } from \"./interfaces.js\";\n\nexport enum Mode {\n LEXICAL,\n STRICT,\n}\n\nexport const SourceNode = Symbol.for(\"SourceNode\");\nexport const FormalParameters = Symbol.for(\"FormalParameters\");\nexport const ECMAScriptCode = Symbol.for(\"ECMAScriptCode\");\nexport const Environment = Symbol.for(\"Environment\");\nexport const IsConstructor = Symbol.for(\"IsConstructor\");\nexport const ThisMode = Symbol.for(\"ThisMode\");\nexport const DebuggerCall = Symbol.for(\"$DebuggerCall$\");\nexport const DebuggerScope = Symbol.for(\"$DebuggerScope$\");\nexport const DebuggerNode = Symbol.for(\"$DebuggerNode$\");\nexport const DebuggerReturn = Symbol.for(\"$DebuggerReturn$\");\n\n// https://tc39.es/ecma262/#sec-execution-contexts\nexport class ExecutionContext {\n VariableEnvironment?: EnvironmentRecord;\n LexicalEnvironment?: EnvironmentRecord;\n Function?: FunctionObject;\n}\n\nexport type EnvironmentRecordType = \"function\" | \"declarative\";\n\nexport enum BindingStatus {\n UNINITIALIZED,\n LEXICAL,\n INITIALIZED,\n}\n\n// https://tc39.es/ecma262/#sec-environment-records\nexport class EnvironmentRecord {\n readonly OuterEnv: EnvironmentRecord | null | undefined;\n private readonly bindingMap = new Map<string, BindingState>();\n protected ThisValue: unknown = undefined;\n protected ThisBindingStatus: BindingStatus | undefined;\n\n constructor(outer: EnvironmentRecord | null | undefined) {\n this.OuterEnv = outer;\n }\n\n HasBinding(name: string): boolean {\n return this.bindingMap.has(name);\n }\n\n CreateMutableBinding(name: string, deletable: boolean): CompletionRecord {\n // Assert: binding does not exist.\n this.bindingMap.set(name, {\n mutable: true,\n deletable,\n });\n return NormalCompletion(undefined);\n }\n\n /**\n * Create an immutable binding.\n *\n * @param name - The binding name.\n * @param strict - For named function expressions, strict is false, otherwise it's true.\n * @returns CompletionRecord.\n */\n CreateImmutableBinding(name: string, strict: boolean): CompletionRecord {\n // Assert: binding does not exist.\n this.bindingMap.set(name, {\n strict,\n });\n return NormalCompletion(undefined);\n }\n\n InitializeBinding(name: string, value: unknown): CompletionRecord {\n const binding = this.bindingMap.get(name) as BindingState;\n // Assert: binding exists and uninitialized.\n Object.assign<BindingState, Partial<BindingState>>(binding, {\n initialized: true,\n value,\n });\n return NormalCompletion(undefined);\n }\n\n /**\n * Update a mutable binding value, including function declarations.\n *\n * @param name - The binding name.\n * @param value - The binding value.\n * @param strict - For functions, strict is always false, otherwise it depends on strict-mode.\n * @returns\n */\n SetMutableBinding(\n name: string,\n value: unknown,\n _strict?: boolean\n ): CompletionRecord {\n const binding = this.bindingMap.get(name) as BindingState;\n // Assert: binding exists.\n if (!binding.initialized) {\n throw new ReferenceError(`${name} is not initialized`);\n } else if (binding.mutable) {\n binding.value = value;\n } else {\n throw new TypeError(`Assignment to constant variable`);\n }\n return NormalCompletion(undefined);\n }\n\n GetBindingValue(name: string, _strict?: boolean): unknown {\n const binding = this.bindingMap.get(name) as BindingState;\n // Assert: binding exists.\n if (!binding.initialized) {\n throw new ReferenceError(`${name} is not initialized`);\n }\n return binding.value;\n }\n\n HasThisBinding() {\n return false;\n }\n}\n\nexport class DeclarativeEnvironment extends EnvironmentRecord {}\n\nexport class FunctionEnvironment extends EnvironmentRecord {\n constructor(F: FunctionObject) {\n super(F[Environment]);\n if (F[ThisMode] === Mode.LEXICAL) {\n this.ThisBindingStatus = BindingStatus.LEXICAL;\n } else {\n this.ThisBindingStatus = BindingStatus.UNINITIALIZED;\n }\n }\n\n HasThisBinding() {\n return this.ThisBindingStatus !== BindingStatus.LEXICAL;\n }\n\n BindThisValue(value: unknown) {\n // Assert: envRec.[[ThisBindingStatus]] is not LEXICAL.\n if (this.ThisBindingStatus === BindingStatus.INITIALIZED) {\n throw new Error(\"This binding has been initialized\");\n }\n this.ThisValue = value;\n this.ThisBindingStatus = BindingStatus.INITIALIZED;\n }\n\n GetThisBinding() {\n // Assert: envRec.[[ThisBindingStatus]] is not LEXICAL.\n if (this.ThisBindingStatus === BindingStatus.UNINITIALIZED) {\n throw new Error(\"This binding is not initialized\");\n }\n return this.ThisValue;\n }\n}\n\nexport interface BindingState {\n initialized?: boolean;\n value?: unknown;\n mutable?: boolean;\n\n /** This is used for mutable bindings only. */\n deletable?: boolean;\n\n /**\n * This is used for immutable bindings only.\n * For named function expressions, `strict` is false,\n * otherwise it's true.\n */\n strict?: boolean;\n}\n\nexport interface FunctionObject {\n (...args: unknown[]): unknown;\n [SourceNode]:\n | FunctionDeclaration\n | FunctionExpression\n | ArrowFunctionExpression;\n [FormalParameters]: FunctionDeclaration[\"params\"];\n [ECMAScriptCode]: Statement[] | Expression;\n [Environment]: EnvironmentRecord;\n [IsConstructor]: boolean;\n [ThisMode]?: Mode;\n [DebuggerCall]?: (...args: unknown[]) => IterableIterator<unknown>;\n [DebuggerScope]?: () => EnvironmentRecord | null | undefined;\n [DebuggerNode]?: () => EstreeNode | undefined;\n}\n\n// https://tc39.es/ecma262/#sec-reference-record-specification-type\nexport class ReferenceRecord {\n readonly Base:\n | Record<PropertyKey, unknown>\n | EnvironmentRecord\n | \"unresolvable\";\n readonly ReferenceName: PropertyKey;\n /** Whether the reference is in strict mode. */\n readonly Strict?: boolean;\n\n constructor(\n base: Record<PropertyKey, unknown> | EnvironmentRecord | \"unresolvable\",\n referenceName: PropertyKey,\n strict: boolean\n ) {\n this.Base = base;\n this.ReferenceName = referenceName;\n this.Strict = strict;\n }\n}\n\n// https://tc39.es/ecma262/#sec-completion-record-specification-type\nexport class CompletionRecord {\n readonly Type: CompletionRecordType;\n readonly Value: unknown;\n\n constructor(type: CompletionRecordType, value: unknown) {\n this.Type = type;\n this.Value = value;\n }\n}\n\nexport type CompletionRecordType =\n | \"normal\"\n | \"break\"\n | \"continue\"\n | \"return\"\n | \"throw\";\n\n// https://tc39.es/ecma262/#sec-normalcompletion\nexport function NormalCompletion(value: unknown): CompletionRecord {\n return new CompletionRecord(\"normal\", value);\n}\n\nexport const Empty = Symbol(\"empty completion\");\n\nexport interface OptionalChainRef {\n skipped?: boolean;\n}\n"],"mappings":";AASA,WAAYA,IAAI,0BAAJA,IAAI;EAAJA,IAAI,CAAJA,IAAI;EAAJA,IAAI,CAAJA,IAAI;EAAA,OAAJA,IAAI;AAAA;AAKhB,OAAO,MAAMC,UAAU,GAAGC,MAAM,CAACC,GAAG,CAAC,YAAY,CA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WA,CACT4C,IAAuE,EACvEC,aAA0B,EAC1B3B,MAAe,EACf;IAAAjB,eAAA;IAAAA,eAAA;IAPF;IAAAA,eAAA;IAQE,IAAI,CAAC6C,IAAI,GAAGF,IAAI;IAChB,IAAI,CAACG,aAAa,GAAGF,aAAa;IAClC,IAAI,CAACG,MAAM,GAAG9B,MAAM;EACtB;AACF;;AAEA;AACA,OAAO,MAAM+B,gBAAgB,CAAC;EAI5BjD,WAAWA,CAACkD,IAA0B,EAAE9B,KAAc,EAAE;IAAAnB,eAAA;IAAAA,eAAA;IACtD,IAAI,CAACkD,IAAI,GAAGD,IAAI;IAChB,IAAI,CAACE,KAAK,GAAGhC,KAAK;EACpB;AACF;AASA;AACA,OAAO,SAASJ,gBAAgBA,CAACI,KAAc,EAAoB;EACjE,OAAO,IAAI6B,gBAAgB,CAAC,QAAQ,EAAE7B,KAAK,CAAC;AAC9C;AAEA,OAAO,MAAMiC,KAAK,GAAGjE,MAAM,CAAC,kBAAkB,CAAC","ignoreList":[]}
@@ -156,6 +156,8 @@ export function ApplyStringOrNumericBinaryOperator(leftValue, operator, rightVal
156
156
  return leftValue >= rightValue;
157
157
  case "<=":
158
158
  return leftValue <= rightValue;
159
+ case "in":
160
+ return leftValue in rightValue;
159
161
  }
160
162
  throw new SyntaxError(`Unsupported binary operator \`${operator}\``);
161
163
  }
@@ -1 +1 @@
1
- {"version":3,"file":"context-free.js","names":["CompletionRecord","Empty","EnvironmentRecord","NormalCompletion","ReferenceRecord","collectBoundNames","IsPropertyReference","V","Base","InitializeReferencedBinding","W","base","InitializeBinding","ReferenceName","CopyDataProperties","target","source","excludedItems","undefined","keys","Object","getOwnPropertyNames","concat","getOwnPropertySymbols","nextKey","has","desc","getOwnPropertyDescriptor","enumerable","ForDeclarationBindingInstantiation","forDeclaration","env","isConst","kind","name","CreateImmutableBinding","CreateMutableBinding","LoopContinues","completion","Type","UpdateEmpty","value","Value","GetValue","ReferenceError","GetBindingValue","Strict","ToPropertyKey","arg","String","GetV","P","PutValue","SetMutableBinding","CreateListIteratorRecord","args","isIterable","TypeError","Symbol","iterator","RequireObjectCoercible","GetIdentifierReference","strict","HasBinding","OuterEnv","ApplyStringOrNumericBinaryOperator","leftValue","operator","rightValue","SyntaxError","ApplyStringOrNumericAssignment","substr","length","ApplyUnaryOperator","cooked","Array","isArray"],"sources":["../../src/context-free.ts"],"sourcesContent":["import {\n BinaryExpression,\n UnaryExpression,\n VariableDeclaration,\n} from \"@babel/types\";\nimport {\n CompletionRecord,\n Empty,\n EnvironmentRecord,\n NormalCompletion,\n ReferenceRecord,\n} from \"./ExecutionContext.js\";\nimport { collectBoundNames } from \"./traverse.js\";\n\n// https://tc39.es/ecma262/#sec-ispropertyreference\nexport function IsPropertyReference(V: ReferenceRecord): boolean {\n return V.Base !== \"unresolvable\" && !(V.Base instanceof EnvironmentRecord);\n}\n\n// https://tc39.es/ecma262/#sec-initializereferencedbinding\nexport function InitializeReferencedBinding(\n V: ReferenceRecord,\n W: unknown\n): CompletionRecord {\n const base = V.Base as EnvironmentRecord;\n return base.InitializeBinding(V.ReferenceName as string, W);\n}\n\n// https://tc39.es/ecma262/#sec-copydataproperties\nexport function CopyDataProperties(\n target: Record<PropertyKey, unknown>,\n source: unknown,\n excludedItems: Set<PropertyKey>\n): Record<PropertyKey, unknown> {\n if (source === undefined || source === null) {\n return target;\n }\n const keys = (Object.getOwnPropertyNames(source) as PropertyKey[]).concat(\n Object.getOwnPropertySymbols(source)\n );\n for (const nextKey of keys) {\n if (!excludedItems.has(nextKey)) {\n const desc = Object.getOwnPropertyDescriptor(source, nextKey);\n if (desc?.enumerable) {\n target[nextKey] = (source as Record<PropertyKey, unknown>)[nextKey];\n }\n }\n }\n return target;\n}\n\n// https://tc39.es/ecma262/#sec-runtime-semantics-fordeclarationbindinginstantiation\nexport function ForDeclarationBindingInstantiation(\n forDeclaration: VariableDeclaration,\n env: EnvironmentRecord\n): void {\n const isConst = forDeclaration.kind === \"const\";\n for (const name of collectBoundNames(forDeclaration)) {\n if (isConst) {\n env.CreateImmutableBinding(name, true);\n } else {\n env.CreateMutableBinding(name, false);\n }\n }\n}\n\n// https://tc39.es/ecma262/#sec-loopcontinues\nexport function LoopContinues(completion: CompletionRecord): boolean {\n return completion.Type === \"normal\" || completion.Type == \"continue\";\n}\n\n// https://tc39.es/ecma262/#sec-updateempty\nexport function UpdateEmpty(\n completion: CompletionRecord,\n value: unknown\n): CompletionRecord {\n if (completion.Value !== Empty) {\n return completion;\n }\n return new CompletionRecord(completion.Type, value);\n}\n\n// https://tc39.es/ecma262/#sec-getvalue\nexport function GetValue(\n V: CompletionRecord | ReferenceRecord | unknown\n): unknown {\n if (V instanceof CompletionRecord) {\n // Assert: V.Type is normal.\n V = V.Value;\n }\n if (!(V instanceof ReferenceRecord)) {\n return V;\n }\n if (V.Base === \"unresolvable\") {\n throw new ReferenceError(`${V.ReferenceName as string} is not defined`);\n }\n if (V.Base instanceof EnvironmentRecord) {\n const base = V.Base as EnvironmentRecord;\n return base.GetBindingValue(V.ReferenceName as string, V.Strict);\n }\n return V.Base[V.ReferenceName];\n}\n\n// https://tc39.es/ecma262/#sec-topropertykey\nexport function ToPropertyKey(arg: unknown): string | symbol {\n if (typeof arg === \"symbol\") {\n return arg;\n }\n return String(arg);\n}\n\n// https://tc39.es/ecma262/#sec-getv\nexport function GetV(V: unknown, P: PropertyKey): unknown {\n return (V as Record<PropertyKey, unknown>)[P];\n}\n\n// https://tc39.es/ecma262/#sec-putvalue\nexport function PutValue(V: ReferenceRecord, W: unknown): CompletionRecord {\n // Assert: V is a ReferenceRecord.\n if (V.Base === \"unresolvable\") {\n throw new ReferenceError(`${V.ReferenceName as string} is not defined`);\n }\n if (V.Base instanceof EnvironmentRecord) {\n return V.Base.SetMutableBinding(V.ReferenceName as string, W, V.Strict);\n }\n V.Base[V.ReferenceName] = W;\n return NormalCompletion(undefined);\n}\n\n// https://tc39.es/ecma262/#sec-createlistiteratorRecord\nexport function CreateListIteratorRecord(\n args: Iterable<unknown>\n): Iterator<unknown> {\n if (!isIterable(args)) {\n throw new TypeError(`${typeof args} is not iterable`);\n }\n return args[Symbol.iterator]();\n}\n\n// https://tc39.es/ecma262/#sec-requireobjectcoercible\nexport function RequireObjectCoercible(arg: unknown): void {\n if (arg === null || arg === undefined) {\n throw new TypeError(\"Cannot destructure properties of undefined or null\");\n }\n}\n\n// https://tc39.es/ecma262/#sec-getidentifierreference\nexport function GetIdentifierReference(\n env: EnvironmentRecord | null | undefined,\n name: string,\n strict: boolean\n): ReferenceRecord {\n if (!env) {\n return new ReferenceRecord(\"unresolvable\", name, strict);\n }\n if (env.HasBinding(name)) {\n return new ReferenceRecord(env, name, strict);\n }\n return GetIdentifierReference(env.OuterEnv, name, strict);\n}\n\n// https://tc39.es/ecma262/#sec-applystringornumericbinaryoperator\nexport function ApplyStringOrNumericBinaryOperator(\n leftValue: number,\n operator: BinaryExpression[\"operator\"] | \"|>\",\n rightValue: number\n): unknown {\n switch (operator) {\n case \"+\":\n return leftValue + rightValue;\n case \"-\":\n return leftValue - rightValue;\n case \"/\":\n return leftValue / rightValue;\n case \"%\":\n return leftValue % rightValue;\n case \"*\":\n return leftValue * rightValue;\n case \"**\":\n return leftValue ** rightValue;\n case \"==\":\n return leftValue == rightValue;\n case \"===\":\n return leftValue === rightValue;\n case \"!=\":\n return leftValue != rightValue;\n case \"!==\":\n return leftValue !== rightValue;\n case \">\":\n return leftValue > rightValue;\n case \"<\":\n return leftValue < rightValue;\n case \">=\":\n return leftValue >= rightValue;\n case \"<=\":\n return leftValue <= rightValue;\n }\n throw new SyntaxError(`Unsupported binary operator \\`${operator}\\``);\n}\n\n// https://tc39.es/ecma262/#sec-assignment-operators\nexport function ApplyStringOrNumericAssignment(\n leftValue: string | number,\n operator: string,\n rightValue: string | number\n): unknown {\n switch (operator) {\n case \"+=\":\n case \"-=\":\n case \"*=\":\n case \"/=\":\n case \"%=\":\n case \"**=\":\n return ApplyStringOrNumericBinaryOperator(\n leftValue as number,\n operator.substr(0, operator.length - 1) as BinaryExpression[\"operator\"],\n rightValue as number\n );\n }\n\n throw new SyntaxError(`Unsupported assignment operator \\`${operator}\\``);\n}\n\n// https://tc39.es/ecma262/#sec-unary-operators\nexport function ApplyUnaryOperator(\n target: unknown,\n operator: UnaryExpression[\"operator\"]\n): unknown {\n switch (operator) {\n case \"!\":\n return !target;\n case \"+\":\n return +(target as string | number);\n case \"-\":\n return -(target as string | number);\n case \"void\":\n return undefined;\n }\n throw new SyntaxError(`Unsupported unary operator \\`${operator}\\``);\n}\n\nexport function isIterable(cooked: unknown): boolean {\n if (Array.isArray(cooked)) {\n return true;\n }\n if (cooked === null || cooked === undefined) {\n return false;\n }\n return typeof (cooked as Iterable<unknown>)[Symbol.iterator] === \"function\";\n}\n"],"mappings":"AAKA,SACEA,gBAAgB,EAChBC,KAAK,EACLC,iBAAiB,EACjBC,gBAAgB,EAChBC,eAAe,QACV,uBAAuB;AAC9B,SAASC,iBAAiB,QAAQ,eAAe;;AAEjD;AACA,OAAO,SAASC,mBAAmBA,CAACC,CAAkB,EAAW;EAC/D,OAAOA,CAAC,CAACC,IAAI,KAAK,cAAc,IAAI,EAAED,CAAC,CAACC,IAAI,YAAYN,iBAAiB,CAAC;AAC5E;;AAEA;AACA,OAAO,SAASO,2BAA2BA,CACzCF,CAAkB,EAClBG,CAAU,EACQ;EAClB,MAAMC,IAAI,GAAGJ,CAAC,CAACC,IAAyB;EACxC,OAAOG,IAAI,CAACC,iBAAiB,CAACL,CAAC,CAACM,aAAa,EAAYH,CAAC,CAAC;AAC7D;;AAEA;AACA,OAAO,SAASI,kBAAkBA,CAChCC,MAAoC,EACpCC,MAAe,EACfC,aAA+B,EACD;EAC9B,IAAID,MAAM,KAAKE,SAAS,IAAIF,MAAM,KAAK,IAAI,EAAE;IAC3C,OAAOD,MAAM;EACf;EACA,MAAMI,IAAI,GAAIC,MAAM,CAACC,mBAAmB,CAACL,MAAM,CAAC,CAAmBM,MAAM,CACvEF,MAAM,CAACG,qB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AAQ,IAAI,CAAC;AACrE;AAEA,OAAO,SAASX,UAAUA,CAACkB,MAAe,EAAW;EACnD,IAAIC,KAAK,CAACC,OAAO,CAACF,MAAM,CAAC,EAAE;IACzB,OAAO,IAAI;EACb;EACA,IAAIA,MAAM,KAAK,IAAI,IAAIA,MAAM,KAAKxD,SAAS,EAAE;IAC3C,OAAO,KAAK;EACd;EACA,OAAO,OAAQwD,MAAM,CAAuBhB,MAAM,CAACC,QAAQ,CAAC,KAAK,UAAU;AAC7E","ignoreList":[]}
1
+ {"version":3,"file":"context-free.js","names":["CompletionRecord","Empty","EnvironmentRecord","NormalCompletion","ReferenceRecord","collectBoundNames","IsPropertyReference","V","Base","InitializeReferencedBinding","W","base","InitializeBinding","ReferenceName","CopyDataProperties","target","source","excludedItems","undefined","keys","Object","getOwnPropertyNames","concat","getOwnPropertySymbols","nextKey","has","desc","getOwnPropertyDescriptor","enumerable","ForDeclarationBindingInstantiation","forDeclaration","env","isConst","kind","name","CreateImmutableBinding","CreateMutableBinding","LoopContinues","completion","Type","UpdateEmpty","value","Value","GetValue","ReferenceError","GetBindingValue","Strict","ToPropertyKey","arg","String","GetV","P","PutValue","SetMutableBinding","CreateListIteratorRecord","args","isIterable","TypeError","Symbol","iterator","RequireObjectCoercible","GetIdentifierReference","strict","HasBinding","OuterEnv","ApplyStringOrNumericBinaryOperator","leftValue","operator","rightValue","SyntaxError","ApplyStringOrNumericAssignment","substr","length","ApplyUnaryOperator","cooked","Array","isArray"],"sources":["../../src/context-free.ts"],"sourcesContent":["import {\n BinaryExpression,\n UnaryExpression,\n VariableDeclaration,\n} from \"@babel/types\";\nimport {\n CompletionRecord,\n Empty,\n EnvironmentRecord,\n NormalCompletion,\n ReferenceRecord,\n} from \"./ExecutionContext.js\";\nimport { collectBoundNames } from \"./traverse.js\";\n\n// https://tc39.es/ecma262/#sec-ispropertyreference\nexport function IsPropertyReference(V: ReferenceRecord): boolean {\n return V.Base !== \"unresolvable\" && !(V.Base instanceof EnvironmentRecord);\n}\n\n// https://tc39.es/ecma262/#sec-initializereferencedbinding\nexport function InitializeReferencedBinding(\n V: ReferenceRecord,\n W: unknown\n): CompletionRecord {\n const base = V.Base as EnvironmentRecord;\n return base.InitializeBinding(V.ReferenceName as string, W);\n}\n\n// https://tc39.es/ecma262/#sec-copydataproperties\nexport function CopyDataProperties(\n target: Record<PropertyKey, unknown>,\n source: unknown,\n excludedItems: Set<PropertyKey>\n): Record<PropertyKey, unknown> {\n if (source === undefined || source === null) {\n return target;\n }\n const keys = (Object.getOwnPropertyNames(source) as PropertyKey[]).concat(\n Object.getOwnPropertySymbols(source)\n );\n for (const nextKey of keys) {\n if (!excludedItems.has(nextKey)) {\n const desc = Object.getOwnPropertyDescriptor(source, nextKey);\n if (desc?.enumerable) {\n target[nextKey] = (source as Record<PropertyKey, unknown>)[nextKey];\n }\n }\n }\n return target;\n}\n\n// https://tc39.es/ecma262/#sec-runtime-semantics-fordeclarationbindinginstantiation\nexport function ForDeclarationBindingInstantiation(\n forDeclaration: VariableDeclaration,\n env: EnvironmentRecord\n): void {\n const isConst = forDeclaration.kind === \"const\";\n for (const name of collectBoundNames(forDeclaration)) {\n if (isConst) {\n env.CreateImmutableBinding(name, true);\n } else {\n env.CreateMutableBinding(name, false);\n }\n }\n}\n\n// https://tc39.es/ecma262/#sec-loopcontinues\nexport function LoopContinues(completion: CompletionRecord): boolean {\n return completion.Type === \"normal\" || completion.Type == \"continue\";\n}\n\n// https://tc39.es/ecma262/#sec-updateempty\nexport function UpdateEmpty(\n completion: CompletionRecord,\n value: unknown\n): CompletionRecord {\n if (completion.Value !== Empty) {\n return completion;\n }\n return new CompletionRecord(completion.Type, value);\n}\n\n// https://tc39.es/ecma262/#sec-getvalue\nexport function GetValue(\n V: CompletionRecord | ReferenceRecord | unknown\n): unknown {\n if (V instanceof CompletionRecord) {\n // Assert: V.Type is normal.\n V = V.Value;\n }\n if (!(V instanceof ReferenceRecord)) {\n return V;\n }\n if (V.Base === \"unresolvable\") {\n throw new ReferenceError(`${V.ReferenceName as string} is not defined`);\n }\n if (V.Base instanceof EnvironmentRecord) {\n const base = V.Base as EnvironmentRecord;\n return base.GetBindingValue(V.ReferenceName as string, V.Strict);\n }\n return V.Base[V.ReferenceName];\n}\n\n// https://tc39.es/ecma262/#sec-topropertykey\nexport function ToPropertyKey(arg: unknown): string | symbol {\n if (typeof arg === \"symbol\") {\n return arg;\n }\n return String(arg);\n}\n\n// https://tc39.es/ecma262/#sec-getv\nexport function GetV(V: unknown, P: PropertyKey): unknown {\n return (V as Record<PropertyKey, unknown>)[P];\n}\n\n// https://tc39.es/ecma262/#sec-putvalue\nexport function PutValue(V: ReferenceRecord, W: unknown): CompletionRecord {\n // Assert: V is a ReferenceRecord.\n if (V.Base === \"unresolvable\") {\n throw new ReferenceError(`${V.ReferenceName as string} is not defined`);\n }\n if (V.Base instanceof EnvironmentRecord) {\n return V.Base.SetMutableBinding(V.ReferenceName as string, W, V.Strict);\n }\n V.Base[V.ReferenceName] = W;\n return NormalCompletion(undefined);\n}\n\n// https://tc39.es/ecma262/#sec-createlistiteratorRecord\nexport function CreateListIteratorRecord(\n args: Iterable<unknown>\n): Iterator<unknown> {\n if (!isIterable(args)) {\n throw new TypeError(`${typeof args} is not iterable`);\n }\n return args[Symbol.iterator]();\n}\n\n// https://tc39.es/ecma262/#sec-requireobjectcoercible\nexport function RequireObjectCoercible(arg: unknown): void {\n if (arg === null || arg === undefined) {\n throw new TypeError(\"Cannot destructure properties of undefined or null\");\n }\n}\n\n// https://tc39.es/ecma262/#sec-getidentifierreference\nexport function GetIdentifierReference(\n env: EnvironmentRecord | null | undefined,\n name: string,\n strict: boolean\n): ReferenceRecord {\n if (!env) {\n return new ReferenceRecord(\"unresolvable\", name, strict);\n }\n if (env.HasBinding(name)) {\n return new ReferenceRecord(env, name, strict);\n }\n return GetIdentifierReference(env.OuterEnv, name, strict);\n}\n\n// https://tc39.es/ecma262/#sec-applystringornumericbinaryoperator\nexport function ApplyStringOrNumericBinaryOperator(\n leftValue: number,\n operator: BinaryExpression[\"operator\"] | \"|>\",\n rightValue: number\n): unknown {\n switch (operator) {\n case \"+\":\n return leftValue + rightValue;\n case \"-\":\n return leftValue - rightValue;\n case \"/\":\n return leftValue / rightValue;\n case \"%\":\n return leftValue % rightValue;\n case \"*\":\n return leftValue * rightValue;\n case \"**\":\n return leftValue ** rightValue;\n case \"==\":\n return leftValue == rightValue;\n case \"===\":\n return leftValue === rightValue;\n case \"!=\":\n return leftValue != rightValue;\n case \"!==\":\n return leftValue !== rightValue;\n case \">\":\n return leftValue > rightValue;\n case \"<\":\n return leftValue < rightValue;\n case \">=\":\n return leftValue >= rightValue;\n case \"<=\":\n return leftValue <= rightValue;\n case \"in\":\n return leftValue in (rightValue as unknown as Record<number, unknown>);\n }\n throw new SyntaxError(`Unsupported binary operator \\`${operator}\\``);\n}\n\n// https://tc39.es/ecma262/#sec-assignment-operators\nexport function ApplyStringOrNumericAssignment(\n leftValue: string | number,\n operator: string,\n rightValue: string | number\n): unknown {\n switch (operator) {\n case \"+=\":\n case \"-=\":\n case \"*=\":\n case \"/=\":\n case \"%=\":\n case \"**=\":\n return ApplyStringOrNumericBinaryOperator(\n leftValue as number,\n operator.substr(0, operator.length - 1) as BinaryExpression[\"operator\"],\n rightValue as number\n );\n }\n\n throw new SyntaxError(`Unsupported assignment operator \\`${operator}\\``);\n}\n\n// https://tc39.es/ecma262/#sec-unary-operators\nexport function ApplyUnaryOperator(\n target: unknown,\n operator: UnaryExpression[\"operator\"]\n): unknown {\n switch (operator) {\n case \"!\":\n return !target;\n case \"+\":\n return +(target as string | number);\n case \"-\":\n return -(target as string | number);\n case \"void\":\n return undefined;\n }\n throw new SyntaxError(`Unsupported unary operator \\`${operator}\\``);\n}\n\nexport function isIterable(cooked: unknown): boolean {\n if (Array.isArray(cooked)) {\n return true;\n }\n if (cooked === null || cooked === undefined) {\n return false;\n }\n return typeof (cooked as Iterable<unknown>)[Symbol.iterator] === \"function\";\n}\n"],"mapp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AS,IAAKE,UAAiD;EAC1E;EACA,MAAM,IAAIC,WAAW,CAAC,iCAAiCF,QAAQ,IAAI,CAAC;AACtE;;AAEA;AACA,OAAO,SAASG,8BAA8BA,CAC5CJ,SAA0B,EAC1BC,QAAgB,EAChBC,UAA2B,EAClB;EACT,QAAQD,QAAQ;IACd,KAAK,IAAI;IACT,KAAK,IAAI;IACT,KAAK,IAAI;IACT,KAAK,IAAI;IACT,KAAK,IAAI;IACT,KAAK,KAAK;MACR,OAAOF,kCAAkC,CACvCC,SAAS,EACTC,QAAQ,CAACI,MAAM,CAAC,CAAC,EAAEJ,QAAQ,CAACK,MAAM,GAAG,CAAC,CAAC,EACvCJ,UACF,CAAC;EACL;EAEA,MAAM,IAAIC,WAAW,CAAC,qCAAqCF,QAAQ,IAAI,CAAC;AAC1E;;AAEA;AACA,OAAO,SAASM,kBAAkBA,CAChC1D,MAAe,EACfoD,QAAqC,EAC5B;EACT,QAAQA,QAAQ;IACd,KAAK,GAAG;MACN,OAAO,CAACpD,MAAM;IAChB,KAAK,GAAG;MACN,OAAO,CAAEA,MAA0B;IACrC,KAAK,GAAG;MACN,OAAO,CAAEA,MAA0B;IACrC,KAAK,MAAM;MACT,OAAOG,SAAS;EACpB;EACA,MAAM,IAAImD,WAAW,CAAC,gCAAgCF,QAAQ,IAAI,CAAC;AACrE;AAEA,OAAO,SAASX,UAAUA,CAACkB,MAAe,EAAW;EACnD,IAAIC,KAAK,CAACC,OAAO,CAACF,MAAM,CAAC,EAAE;IACzB,OAAO,IAAI;EACb;EACA,IAAIA,MAAM,KAAK,IAAI,IAAIA,MAAM,KAAKxD,SAAS,EAAE;IAC3C,OAAO,KAAK;EACd;EACA,OAAO,OAAQwD,MAAM,CAAuBhB,MAAM,CAACC,QAAQ,CAAC,KAAK,UAAU;AAC7E","ignoreList":[]}
package/dist/esm/cook.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ApplyStringOrNumericAssignment, CreateListIteratorRecord, ApplyStringOrNumericBinaryOperator, GetV, GetValue, InitializeReferencedBinding, IsPropertyReference, LoopContinues, PutValue, RequireObjectCoercible, ToPropertyKey, UpdateEmpty, ApplyUnaryOperator, GetIdentifierReference, ForDeclarationBindingInstantiation, CopyDataProperties } from "./context-free.js";
2
- import { CompletionRecord, DebuggerCall, DebuggerNode, DebuggerScope, DeclarativeEnvironment, ECMAScriptCode, Empty, Environment, ExecutionContext, FormalParameters, FunctionEnvironment, IsConstructor, NormalCompletion, ReferenceRecord, SourceNode } from "./ExecutionContext.js";
2
+ import { CompletionRecord, DebuggerCall, DebuggerNode, DebuggerReturn, DebuggerScope, DeclarativeEnvironment, ECMAScriptCode, Empty, Environment, ExecutionContext, FormalParameters, FunctionEnvironment, IsConstructor, NormalCompletion, ReferenceRecord, SourceNode, Mode, ThisMode } from "./ExecutionContext.js";
3
3
  import { sanitize, isAllowedConstructor } from "./sanitize.js";
4
4
  import { collectBoundNames, collectScopedDeclarations, containsExpression } from "./traverse.js";
5
5
  /** For next-core internal usage only. */
@@ -8,10 +8,18 @@ export function cook(rootAst, codeSource) {
8
8
  let {
9
9
  rules,
10
10
  debug,
11
+ externalSourceForDebug,
11
12
  globalVariables = {},
13
+ // Allow debugger to override Array constructor.
14
+ ArrayConstructor = Array,
12
15
  hooks = {}
13
16
  } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
14
17
  const expressionOnly = rootAst.type !== "FunctionDeclaration";
18
+ function doSanitize(cooked) {
19
+ if (!externalSourceForDebug) {
20
+ sanitize(cooked);
21
+ }
22
+ }
15
23
  const rootEnv = new DeclarativeEnvironment(null);
16
24
  const rootContext = new ExecutionContext();
17
25
  rootContext.VariableEnvironment = rootEnv;
@@ -47,7 +55,7 @@ export function cook(rootAst, codeSource) {
47
55
  var _hooks$beforeEvaluate, _hooks$beforeBranch2;
48
56
  (_hooks$beforeEvaluate = hooks.beforeEvaluate) === null || _hooks$beforeEvaluate === void 0 || _hooks$beforeEvaluate.call(hooks, node);
49
57
  currentNode = node;
50
- if (debug && (forceYield || node.type.endsWith("Statement") && node.type !== "TryStatement" && node.type !== "BlockStatement" && node.type !== "ForStatement" && node.type !== "ForInStatement" && node.type !== "ForOfStatement")) {
58
+ if (debug && (forceYield || node.type.endsWith("Statement") && !(node.type === "ExpressionStatement" && (node.expression.type === "CallExpression" || node.expression.type === "TaggedTemplateExpression")) && node.type !== "TryStatement" && node.type !== "BlockStatement" && node.type !== "DoWhileStatement" && node.type !== "WhileStatement" && node.type !== "ForStatement" && node.type !== "ForInStatement" && node.type !== "ForOfStatement")) {
51
59
  yield;
52
60
  }
53
61
  // Expressions:
@@ -55,7 +63,7 @@ export function cook(rootAst, codeSource) {
55
63
  case "ArrayExpression":
56
64
  {
57
65
  // https://tc39.es/ecma262/#sec-array-initializer
58
- const array = [];
66
+ const array = new ArrayConstructor();
59
67
  for (const element of node.elements) {
60
68
  if (!element) {
61
69
  array.length += 1;
@@ -79,7 +87,7 @@ export function cook(rootAst, codeSource) {
79
87
  {
80
88
  const leftRef = yield* Evaluate(node.left);
81
89
  const leftValue = GetValue(leftRef);
82
- const rightRef = (yield* Evaluate(node.right)).Value;
90
+ const rightRef = yield* Evaluate(node.right);
83
91
  const rightValue = GetValue(rightRef);
84
92
  if (expressionOnly && node.operator === "|>") {
85
93
  // Minimal pipeline operator is supported only in expression-only mode.
@@ -110,7 +118,7 @@ export function cook(rootAst, codeSource) {
110
118
  optionalChainRef.skipped = true;
111
119
  return NormalCompletion(undefined);
112
120
  }
113
- sanitize(func);
121
+ doSanitize(func);
114
122
  if (debug) yield;
115
123
  return yield* EvaluateCall(func, ref, node.arguments, node.callee);
116
124
  }
@@ -166,9 +174,9 @@ export function cook(rootAst, codeSource) {
166
174
  optionalChainRef.skipped = true;
167
175
  return NormalCompletion(undefined);
168
176
  }
169
- sanitize(baseValue);
177
+ doSanitize(baseValue);
170
178
  const result = node.computed ? yield* EvaluatePropertyAccessWithExpressionKey(baseValue, node.property, true) : EvaluatePropertyAccessWithIdentifierKey(baseValue, node.property, true);
171
- sanitize(result);
179
+ doSanitize(result);
172
180
  return NormalCompletion(result);
173
181
  }
174
182
  case "NewExpression":
@@ -225,7 +233,7 @@ export function cook(rootAst, codeSource) {
225
233
  // https://tc39.es/ecma262/#sec-tagged-templates
226
234
  const tagRef = (yield* Evaluate(node.tag)).Value;
227
235
  const tagFunc = GetValue(tagRef);
228
- sanitize(tagFunc);
236
+ doSanitize(tagFunc);
229
237
  if (debug) yield;
230
238
  return yield* EvaluateCall(tagFunc, tagRef, node.quasi, node.tag);
231
239
  }
@@ -351,9 +359,16 @@ export function cook(rootAst, codeSource) {
351
359
  const exprRef = yield* Evaluate(node.argument);
352
360
  v = GetValue(exprRef);
353
361
  }
354
- currentNode = node;
355
362
  return new CompletionRecord("return", v);
356
363
  }
364
+ case "ThisExpression":
365
+ {
366
+ if (!externalSourceForDebug) {
367
+ break;
368
+ }
369
+ const envRec = GetThisEnvironment();
370
+ return NormalCompletion(envRec.GetThisBinding());
371
+ }
357
372
  case "ThrowStatement":
358
373
  // https://tc39.es/ecma262/#sec-throw-statement
359
374
  throw GetValue(yield* Evaluate(node.argument));
@@ -568,7 +583,7 @@ export function cook(rootAst, codeSource) {
568
583
  let V;
569
584
  // eslint-disable-next-line no-constant-condition
570
585
  while (true) {
571
- const exprValue = GetValue(yield* Evaluate(node.test));
586
+ const exprValue = GetValue(yield* Evaluate(node.test, undefined, true));
572
587
  if (!exprValue) {
573
588
  return NormalCompletion(V);
574
589
  }
@@ -595,7 +610,7 @@ export function cook(rootAst, codeSource) {
595
610
  if (stmtResult.Value !== Empty) {
596
611
  V = stmtResult.Value;
597
612
  }
598
- const exprValue = GetValue(yield* Evaluate(node.test));
613
+ const exprValue = GetValue(yield* Evaluate(node.test, undefined, true));
599
614
  if (!exprValue) {
600
615
  return NormalCompletion(V);
601
616
  }
@@ -897,7 +912,7 @@ export function cook(rootAst, codeSource) {
897
912
  }
898
913
  } else {
899
914
  // RestElement
900
- v = [];
915
+ v = new ArrayConstructor();
901
916
  let n = 0;
902
917
  // eslint-disable-next-line no-constant-condition
903
918
  while (true) {
@@ -932,6 +947,7 @@ export function cook(rootAst, codeSource) {
932
947
 
933
948
  // https://tc39.es/ecma262/#sec-evaluate-property-access-with-identifier-key
934
949
  function EvaluatePropertyAccessWithIdentifierKey(baseValue, identifier, strict) {
950
+ currentNode = identifier;
935
951
  const propertyNameString = identifier.name;
936
952
  return new ReferenceRecord(baseValue, propertyNameString, strict);
937
953
  }
@@ -974,16 +990,16 @@ export function cook(rootAst, codeSource) {
974
990
  const funcName = codeSource.substring(callee.start, callee.end);
975
991
  throw new TypeError(`${funcName} is not a function`);
976
992
  }
977
- if (debug) {
993
+ if (debug || externalSourceForDebug) {
978
994
  const debuggerCall = func[DebuggerCall];
979
995
  if (debuggerCall) {
980
996
  const result = yield* debuggerCall.apply(thisValue, argList);
981
- sanitize(result);
997
+ doSanitize(result);
982
998
  return NormalCompletion(result);
983
999
  }
984
1000
  }
985
1001
  const result = func.apply(thisValue, argList);
986
- sanitize(result);
1002
+ doSanitize(result);
987
1003
  return NormalCompletion(result);
988
1004
  }
989
1005
 
@@ -996,7 +1012,7 @@ export function cook(rootAst, codeSource) {
996
1012
  const constructorName = codeSource.substring(constructExpr.start, constructExpr.end);
997
1013
  throw new TypeError(`${constructorName} is not a constructor`);
998
1014
  }
999
- if (!isAllowedConstructor(constructor)) {
1015
+ if (!externalSourceForDebug && !isAllowedConstructor(constructor) && constructor !== ArrayConstructor) {
1000
1016
  const constructorName = codeSource.substring(constructExpr.start, constructExpr.end);
1001
1017
  throw new TypeError(`${constructorName} is not an allowed constructor`);
1002
1018
  }
@@ -1025,18 +1041,22 @@ export function cook(rootAst, codeSource) {
1025
1041
  }
1026
1042
 
1027
1043
  // https://tc39.es/ecma262/#sec-ecmascript-function-objects-call-thisargument-argumentslist
1028
- function* CallFunction(closure, args) {
1029
- var _hooks$beforeCall, _currentNode;
1044
+ function* CallFunction(closure, thisArgument, args) {
1045
+ var _hooks$beforeCall;
1030
1046
  (_hooks$beforeCall = hooks.beforeCall) === null || _hooks$beforeCall === void 0 || _hooks$beforeCall.call(hooks, closure[SourceNode]);
1031
- PrepareForOrdinaryCall(closure);
1047
+ const calleeContext = PrepareForOrdinaryCall(closure);
1048
+ OrdinaryCallBindThis(closure, calleeContext, thisArgument);
1032
1049
  const result = yield* OrdinaryCallEvaluateBody(closure, args);
1033
- if (((_currentNode = currentNode) === null || _currentNode === void 0 ? void 0 : _currentNode.type) !== "ReturnStatement") {
1034
- currentNode = closure[SourceNode];
1050
+ if (debug) {
1051
+ currentNode = {
1052
+ ...closure[SourceNode],
1053
+ [DebuggerReturn]: true
1054
+ };
1055
+ yield {
1056
+ type: "return",
1057
+ value: result.Type === "return" ? result.Value : undefined
1058
+ };
1035
1059
  }
1036
- if (debug) yield {
1037
- type: "return",
1038
- value: result.Type === "return" ? result.Value : undefined
1039
- };
1040
1060
  executionContextStack.pop();
1041
1061
  if (result.Type === "return") {
1042
1062
  return result.Value;
@@ -1048,12 +1068,19 @@ export function cook(rootAst, codeSource) {
1048
1068
  function PrepareForOrdinaryCall(F) {
1049
1069
  const calleeContext = new ExecutionContext();
1050
1070
  calleeContext.Function = F;
1051
- const localEnv = new FunctionEnvironment(F[Environment]);
1071
+ const localEnv = new FunctionEnvironment(F);
1052
1072
  calleeContext.VariableEnvironment = localEnv;
1053
1073
  calleeContext.LexicalEnvironment = localEnv;
1054
1074
  executionContextStack.push(calleeContext);
1055
1075
  return calleeContext;
1056
1076
  }
1077
+ function OrdinaryCallBindThis(F, calleeContext, thisArgument) {
1078
+ if (F[ThisMode] === Mode.LEXICAL) {
1079
+ return;
1080
+ }
1081
+ const localEnv = calleeContext.LexicalEnvironment;
1082
+ localEnv === null || localEnv === void 0 || localEnv.BindThisValue(thisArgument);
1083
+ }
1057
1084
 
1058
1085
  // https://tc39.es/ecma262/#sec-ordinarycallevaluatebody
1059
1086
  function* OrdinaryCallEvaluateBody(F, args) {
@@ -1081,6 +1108,16 @@ export function cook(rootAst, codeSource) {
1081
1108
  }
1082
1109
  return result;
1083
1110
  }
1111
+ function GetThisEnvironment() {
1112
+ let env = getRunningContext().LexicalEnvironment;
1113
+ while (env) {
1114
+ if (env.HasThisBinding()) {
1115
+ return env;
1116
+ }
1117
+ env = env.OuterEnv;
1118
+ }
1119
+ throw new Error("Accessing global this is forbidden");
1120
+ }
1084
1121
 
1085
1122
  // https://tc39.es/ecma262/#sec-isanonymousfunctiondefinition
1086
1123
  function IsAnonymousFunctionDefinition(node) {
@@ -1132,11 +1169,33 @@ export function cook(rootAst, codeSource) {
1132
1169
  throw new SyntaxError("Var declaration is not recommended, use `let` or `const` instead");
1133
1170
  }
1134
1171
  }
1172
+
1173
+ // let argumentsObjectNeeded = true;
1174
+ // if (func[ThisMode] === Mode.LEXICAL) {
1175
+ // // NOTE: Arrow functions never have an arguments object.
1176
+ // argumentsObjectNeeded = false;
1177
+ // } else if (parameterNames.includes("arguments")) {
1178
+ // argumentsObjectNeeded = false;
1179
+ // } else if (!hasParameterExpressions && (
1180
+ // varNames.includes("arguments") ||
1181
+ // collectBoundNames(collectScopedDeclarations(code, { var: false })).includes("arguments")
1182
+ // )) {
1183
+ // argumentsObjectNeeded = false;
1184
+ // }
1185
+ // NOTE: In strict mode, no parameter/function/var/lexical names can be "arguments".
1186
+ const argumentsObjectNeeded = !!externalSourceForDebug && func[ThisMode] !== Mode.LEXICAL;
1135
1187
  const env = calleeContext.LexicalEnvironment;
1136
1188
  for (const paramName of parameterNames) {
1137
1189
  // In strict mode, it's guaranteed no duplicate params exist.
1138
1190
  env.CreateMutableBinding(paramName, false);
1139
1191
  }
1192
+ let parameterBindings = parameterNames;
1193
+ if (argumentsObjectNeeded) {
1194
+ const ao = CreateUnmappedArgumentsObject(args);
1195
+ env.CreateImmutableBinding("arguments", false);
1196
+ env.InitializeBinding("arguments", ao);
1197
+ parameterBindings = parameterNames.concat("arguments");
1198
+ }
1140
1199
  const iteratorRecord = CreateListIteratorRecord(args);
1141
1200
  yield* IteratorBindingInitialization(formals, iteratorRecord, env);
1142
1201
  let varEnv;
@@ -1144,8 +1203,10 @@ export function cook(rootAst, codeSource) {
1144
1203
  // NOTE: Only a single Environment Record is needed for the parameters
1145
1204
  // and top-level vars.
1146
1205
  // `varNames` are unique.
1206
+ const instantiatedVarNames = [...parameterBindings];
1147
1207
  for (const n of varNames) {
1148
- if (!parameterNames.includes(n)) {
1208
+ if (!instantiatedVarNames.includes(n)) {
1209
+ instantiatedVarNames.push(n);
1149
1210
  env.CreateMutableBinding(n, false);
1150
1211
  env.InitializeBinding(n, undefined);
1151
1212
  }
@@ -1158,15 +1219,19 @@ export function cook(rootAst, codeSource) {
1158
1219
  varEnv = new DeclarativeEnvironment(env);
1159
1220
  calleeContext.VariableEnvironment = varEnv;
1160
1221
  // `varNames` are unique.
1222
+ const instantiatedVarNames = [];
1161
1223
  for (const n of varNames) {
1162
- varEnv.CreateMutableBinding(n, false);
1163
- let initialValue;
1164
- if (parameterNames.includes(n) && !functionNames.includes(n)) {
1165
- initialValue = env.GetBindingValue(n, false);
1224
+ if (!instantiatedVarNames.includes(n)) {
1225
+ instantiatedVarNames.push(n);
1226
+ varEnv.CreateMutableBinding(n, false);
1227
+ let initialValue;
1228
+ if (parameterBindings.includes(n) && !functionNames.includes(n)) {
1229
+ initialValue = env.GetBindingValue(n, false);
1230
+ }
1231
+ varEnv.InitializeBinding(n, initialValue);
1232
+ // NOTE: A var with the same name as a formal parameter initially has
1233
+ // the same value as the corresponding initialized parameter.
1166
1234
  }
1167
- varEnv.InitializeBinding(n, initialValue);
1168
- // NOTE: A var with the same name as a formal parameter initially has
1169
- // the same value as the corresponding initialized parameter.
1170
1235
  }
1171
1236
  }
1172
1237
  const lexEnv = varEnv;
@@ -1191,10 +1256,35 @@ export function cook(rootAst, codeSource) {
1191
1256
  varEnv.SetMutableBinding(fn, fo, false);
1192
1257
  }
1193
1258
  }
1259
+ function CreateUnmappedArgumentsObject(args) {
1260
+ const argList = [...args];
1261
+ const argumentObject = {};
1262
+ Object.defineProperty(argumentObject, "length", {
1263
+ value: argList.length,
1264
+ writable: true,
1265
+ configurable: true
1266
+ });
1267
+ for (let index = 0; index < argList.length; index++) {
1268
+ argumentObject[String(index)] = argList[index];
1269
+ }
1270
+ Object.defineProperty(argumentObject, Symbol.iterator, {
1271
+ value: Array.prototype.values,
1272
+ writable: true,
1273
+ configurable: true
1274
+ });
1275
+ const ThrowTypeError = () => {
1276
+ throw new TypeError("'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them");
1277
+ };
1278
+ Object.defineProperty(argumentObject, "callee", {
1279
+ get: ThrowTypeError,
1280
+ set: ThrowTypeError
1281
+ });
1282
+ return argumentObject;
1283
+ }
1194
1284
 
1195
1285
  // https://tc39.es/ecma262/#sec-runtime-semantics-instantiatefunctionobject
1196
1286
  function InstantiateFunctionObject(func, scope) {
1197
- const F = OrdinaryFunctionCreate(func, scope, true);
1287
+ const F = OrdinaryFunctionCreate(func, scope, true, false);
1198
1288
  if (func.id) {
1199
1289
  SetFunctionName(F, func.id.name);
1200
1290
  }
@@ -1208,12 +1298,12 @@ export function cook(rootAst, codeSource) {
1208
1298
  const name = functionExpression.id.name;
1209
1299
  const funcEnv = new DeclarativeEnvironment(scope);
1210
1300
  funcEnv.CreateImmutableBinding(name, false);
1211
- const closure = OrdinaryFunctionCreate(functionExpression, funcEnv, true);
1301
+ const closure = OrdinaryFunctionCreate(functionExpression, funcEnv, true, false);
1212
1302
  SetFunctionName(closure, name);
1213
1303
  funcEnv.InitializeBinding(name, closure);
1214
1304
  return closure;
1215
1305
  } else {
1216
- const closure = OrdinaryFunctionCreate(functionExpression, scope, true);
1306
+ const closure = OrdinaryFunctionCreate(functionExpression, scope, true, false);
1217
1307
  SetFunctionName(closure, name ?? "");
1218
1308
  return closure;
1219
1309
  }
@@ -1222,7 +1312,7 @@ export function cook(rootAst, codeSource) {
1222
1312
  // https://tc39.es/ecma262/#sec-runtime-semantics-instantiatearrowfunctionexpression
1223
1313
  function InstantiateArrowFunctionExpression(arrowFunction, name) {
1224
1314
  const scope = getRunningContext().LexicalEnvironment;
1225
- const closure = OrdinaryFunctionCreate(arrowFunction, scope, false);
1315
+ const closure = OrdinaryFunctionCreate(arrowFunction, scope, false, true);
1226
1316
  SetFunctionName(closure, name ?? "");
1227
1317
  return closure;
1228
1318
  }
@@ -1234,10 +1324,10 @@ export function cook(rootAst, codeSource) {
1234
1324
  }
1235
1325
 
1236
1326
  // https://tc39.es/ecma262/#sec-ordinaryfunctioncreate
1237
- function OrdinaryFunctionCreate(sourceNode, scope, isConstructor) {
1327
+ function OrdinaryFunctionCreate(sourceNode, scope, isConstructor, lexicalThis) {
1238
1328
  const F = function () {
1239
1329
  // eslint-disable-next-line prefer-rest-params
1240
- return unwind(CallFunction(F, arguments));
1330
+ return unwind(CallFunction(F, this, arguments));
1241
1331
  };
1242
1332
  Object.defineProperties(F, {
1243
1333
  [SourceNode]: {
@@ -1254,13 +1344,16 @@ export function cook(rootAst, codeSource) {
1254
1344
  },
1255
1345
  [IsConstructor]: {
1256
1346
  value: isConstructor
1347
+ },
1348
+ [ThisMode]: {
1349
+ value: lexicalThis ? Mode.LEXICAL : Mode.STRICT
1257
1350
  }
1258
1351
  });
1259
- if (debug) {
1352
+ if (debug || externalSourceForDebug) {
1260
1353
  Object.defineProperty(F, DebuggerCall, {
1261
1354
  value: function () {
1262
1355
  // eslint-disable-next-line prefer-rest-params
1263
- return CallFunction(F, arguments);
1356
+ return CallFunction(F, this, arguments);
1264
1357
  }
1265
1358
  });
1266
1359
  }
@@ -1334,7 +1427,7 @@ export function cook(rootAst, codeSource) {
1334
1427
  // Rest element.
1335
1428
  if (node.argument.type === "Identifier") {
1336
1429
  const lhs = ResolveBinding(node.argument.name, environment);
1337
- const A = [];
1430
+ const A = new ArrayConstructor();
1338
1431
  let n = 0;
1339
1432
  // eslint-disable-next-line no-constant-condition
1340
1433
  while (true) {
@@ -1350,7 +1443,7 @@ export function cook(rootAst, codeSource) {
1350
1443
  n++;
1351
1444
  }
1352
1445
  } else {
1353
- const A = [];
1446
+ const A = new ArrayConstructor();
1354
1447
  let n = 0;
1355
1448
  // eslint-disable-next-line no-constant-condition
1356
1449
  while (true) {