@next-core/cook 2.3.0 → 2.4.0
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.
- package/dist/cjs/ExecutionContext.js +57 -12
- package/dist/cjs/ExecutionContext.js.map +1 -1
- package/dist/cjs/context-free.js +2 -0
- package/dist/cjs/context-free.js.map +1 -1
- package/dist/cjs/cook.js +132 -40
- package/dist/cjs/cook.js.map +1 -1
- package/dist/esm/ExecutionContext.js +56 -9
- package/dist/esm/ExecutionContext.js.map +1 -1
- package/dist/esm/context-free.js +2 -0
- package/dist/esm/context-free.js.map +1 -1
- package/dist/esm/cook.js +133 -41
- package/dist/esm/cook.js.map +1 -1
- package/dist/types/ExecutionContext.d.ts +27 -8
- package/dist/types/cook.d.ts +3 -1
- package/package.json +2 -2
|
@@ -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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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;EAEAG,UAAUA,CAACC,IAAY,EAAW;IAChC,OAAO,IAAI,CAACC,UAAU,CAACC,GAAG,CAACF,IAAI,CAAC;EAClC;EAEAG,oBAAoBA,CAACH,IAAY,EAAEI,SAAkB,EAAoB;IACvE;IACA,IAAI,CAACH,UAAU,CAACI,GAAG,CAACL,IAAI,EAAE;MACxBM,OAAO,EAAE,IAAI;MACbF;IACF,CAAC,CAAC;IACF,OAAOG,gBAAgB,CAACC,SAAS,CAAC;EACpC;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;EACEC,sBAAsBA,CAACT,IAAY,EAAEU,MAAe,EAAoB;IACtE;IACA,IAAI,CAACT,UAAU,CAACI,GAAG,CAACL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":[]}
|
|
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,CAAC;AAClD,OAAO,MAAMC,gBAAgB,GAAGF,MAAM,CAACC,GAAG,CAAC,kBAAkB,CAAC;AAC9D,OAAO,MAAME,cAAc,GAAGH,MAAM,CAACC,GAAG,CAAC,gBAAgB,CAAC;AAC1D,OAAO,MAAMG,WAAW,GAAGJ,MAAM,CAACC,GAAG,CAAC,aAAa,CAAC;AACpD,OAAO,MAAMI,aAAa,GAAGL,MAAM,CAACC,GAAG,CAAC,eAAe,CAAC;AACxD,OAAO,MAAMK,QAAQ,GAAGN,MAAM,CAACC,GAAG,CAAC,UAAU,CAAC;AAC9C,OAAO,MAAMM,YAAY,GAAGP,MAAM,CAACC,GAAG,CAAC,gBAA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AK;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":[]}
|
package/dist/esm/context-free.js
CHANGED
|
@@ -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,qBAAqB,CAACP,MAAM,CACrC,CAAC;EACD,KAAK,MAAMQ,OAAO,IAAIL,IAAI,EAAE;IAC1B,IAAI,CAACF,aAAa,CAACQ,GAAG,CAACD,OAAO,CAAC,EAAE;MAC/B,MAAME,IAAI,GAAGN,MAAM,CAACO,wBAAwB,CAACX,MAAM,EAAEQ,OAAO,CAAC;MAC7D,IAAIE,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEE,UAAU,EAAE;QACpBb,MAAM,CAACS,OAAO,CAAC,GAAIR,M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]}
|
|
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"],"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,2BAA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C,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;
|
|
@@ -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 =
|
|
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
|
-
|
|
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
|
-
|
|
177
|
+
doSanitize(baseValue);
|
|
170
178
|
const result = node.computed ? yield* EvaluatePropertyAccessWithExpressionKey(baseValue, node.property, true) : EvaluatePropertyAccessWithIdentifierKey(baseValue, node.property, true);
|
|
171
|
-
|
|
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
|
-
|
|
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));
|
|
@@ -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) {
|
|
@@ -974,16 +989,16 @@ export function cook(rootAst, codeSource) {
|
|
|
974
989
|
const funcName = codeSource.substring(callee.start, callee.end);
|
|
975
990
|
throw new TypeError(`${funcName} is not a function`);
|
|
976
991
|
}
|
|
977
|
-
if (debug) {
|
|
992
|
+
if (debug || externalSourceForDebug) {
|
|
978
993
|
const debuggerCall = func[DebuggerCall];
|
|
979
994
|
if (debuggerCall) {
|
|
980
995
|
const result = yield* debuggerCall.apply(thisValue, argList);
|
|
981
|
-
|
|
996
|
+
doSanitize(result);
|
|
982
997
|
return NormalCompletion(result);
|
|
983
998
|
}
|
|
984
999
|
}
|
|
985
1000
|
const result = func.apply(thisValue, argList);
|
|
986
|
-
|
|
1001
|
+
doSanitize(result);
|
|
987
1002
|
return NormalCompletion(result);
|
|
988
1003
|
}
|
|
989
1004
|
|
|
@@ -996,7 +1011,7 @@ export function cook(rootAst, codeSource) {
|
|
|
996
1011
|
const constructorName = codeSource.substring(constructExpr.start, constructExpr.end);
|
|
997
1012
|
throw new TypeError(`${constructorName} is not a constructor`);
|
|
998
1013
|
}
|
|
999
|
-
if (!isAllowedConstructor(constructor)) {
|
|
1014
|
+
if (!externalSourceForDebug && !isAllowedConstructor(constructor) && constructor !== ArrayConstructor) {
|
|
1000
1015
|
const constructorName = codeSource.substring(constructExpr.start, constructExpr.end);
|
|
1001
1016
|
throw new TypeError(`${constructorName} is not an allowed constructor`);
|
|
1002
1017
|
}
|
|
@@ -1025,18 +1040,22 @@ export function cook(rootAst, codeSource) {
|
|
|
1025
1040
|
}
|
|
1026
1041
|
|
|
1027
1042
|
// https://tc39.es/ecma262/#sec-ecmascript-function-objects-call-thisargument-argumentslist
|
|
1028
|
-
function* CallFunction(closure, args) {
|
|
1029
|
-
var _hooks$beforeCall
|
|
1043
|
+
function* CallFunction(closure, thisArgument, args) {
|
|
1044
|
+
var _hooks$beforeCall;
|
|
1030
1045
|
(_hooks$beforeCall = hooks.beforeCall) === null || _hooks$beforeCall === void 0 || _hooks$beforeCall.call(hooks, closure[SourceNode]);
|
|
1031
|
-
PrepareForOrdinaryCall(closure);
|
|
1046
|
+
const calleeContext = PrepareForOrdinaryCall(closure);
|
|
1047
|
+
OrdinaryCallBindThis(closure, calleeContext, thisArgument);
|
|
1032
1048
|
const result = yield* OrdinaryCallEvaluateBody(closure, args);
|
|
1033
|
-
if (
|
|
1034
|
-
currentNode =
|
|
1049
|
+
if (debug) {
|
|
1050
|
+
currentNode = {
|
|
1051
|
+
...closure[SourceNode],
|
|
1052
|
+
[DebuggerReturn]: true
|
|
1053
|
+
};
|
|
1054
|
+
yield {
|
|
1055
|
+
type: "return",
|
|
1056
|
+
value: result.Type === "return" ? result.Value : undefined
|
|
1057
|
+
};
|
|
1035
1058
|
}
|
|
1036
|
-
if (debug) yield {
|
|
1037
|
-
type: "return",
|
|
1038
|
-
value: result.Type === "return" ? result.Value : undefined
|
|
1039
|
-
};
|
|
1040
1059
|
executionContextStack.pop();
|
|
1041
1060
|
if (result.Type === "return") {
|
|
1042
1061
|
return result.Value;
|
|
@@ -1048,12 +1067,19 @@ export function cook(rootAst, codeSource) {
|
|
|
1048
1067
|
function PrepareForOrdinaryCall(F) {
|
|
1049
1068
|
const calleeContext = new ExecutionContext();
|
|
1050
1069
|
calleeContext.Function = F;
|
|
1051
|
-
const localEnv = new FunctionEnvironment(F
|
|
1070
|
+
const localEnv = new FunctionEnvironment(F);
|
|
1052
1071
|
calleeContext.VariableEnvironment = localEnv;
|
|
1053
1072
|
calleeContext.LexicalEnvironment = localEnv;
|
|
1054
1073
|
executionContextStack.push(calleeContext);
|
|
1055
1074
|
return calleeContext;
|
|
1056
1075
|
}
|
|
1076
|
+
function OrdinaryCallBindThis(F, calleeContext, thisArgument) {
|
|
1077
|
+
if (F[ThisMode] === Mode.LEXICAL) {
|
|
1078
|
+
return;
|
|
1079
|
+
}
|
|
1080
|
+
const localEnv = calleeContext.LexicalEnvironment;
|
|
1081
|
+
localEnv === null || localEnv === void 0 || localEnv.BindThisValue(thisArgument);
|
|
1082
|
+
}
|
|
1057
1083
|
|
|
1058
1084
|
// https://tc39.es/ecma262/#sec-ordinarycallevaluatebody
|
|
1059
1085
|
function* OrdinaryCallEvaluateBody(F, args) {
|
|
@@ -1081,6 +1107,16 @@ export function cook(rootAst, codeSource) {
|
|
|
1081
1107
|
}
|
|
1082
1108
|
return result;
|
|
1083
1109
|
}
|
|
1110
|
+
function GetThisEnvironment() {
|
|
1111
|
+
let env = getRunningContext().LexicalEnvironment;
|
|
1112
|
+
while (env) {
|
|
1113
|
+
if (env.HasThisBinding()) {
|
|
1114
|
+
return env;
|
|
1115
|
+
}
|
|
1116
|
+
env = env.OuterEnv;
|
|
1117
|
+
}
|
|
1118
|
+
throw new Error("Accessing global this is forbidden");
|
|
1119
|
+
}
|
|
1084
1120
|
|
|
1085
1121
|
// https://tc39.es/ecma262/#sec-isanonymousfunctiondefinition
|
|
1086
1122
|
function IsAnonymousFunctionDefinition(node) {
|
|
@@ -1132,11 +1168,33 @@ export function cook(rootAst, codeSource) {
|
|
|
1132
1168
|
throw new SyntaxError("Var declaration is not recommended, use `let` or `const` instead");
|
|
1133
1169
|
}
|
|
1134
1170
|
}
|
|
1171
|
+
|
|
1172
|
+
// let argumentsObjectNeeded = true;
|
|
1173
|
+
// if (func[ThisMode] === Mode.LEXICAL) {
|
|
1174
|
+
// // NOTE: Arrow functions never have an arguments object.
|
|
1175
|
+
// argumentsObjectNeeded = false;
|
|
1176
|
+
// } else if (parameterNames.includes("arguments")) {
|
|
1177
|
+
// argumentsObjectNeeded = false;
|
|
1178
|
+
// } else if (!hasParameterExpressions && (
|
|
1179
|
+
// varNames.includes("arguments") ||
|
|
1180
|
+
// collectBoundNames(collectScopedDeclarations(code, { var: false })).includes("arguments")
|
|
1181
|
+
// )) {
|
|
1182
|
+
// argumentsObjectNeeded = false;
|
|
1183
|
+
// }
|
|
1184
|
+
// NOTE: In strict mode, no parameter/function/var/lexical names can be "arguments".
|
|
1185
|
+
const argumentsObjectNeeded = !!externalSourceForDebug && func[ThisMode] !== Mode.LEXICAL;
|
|
1135
1186
|
const env = calleeContext.LexicalEnvironment;
|
|
1136
1187
|
for (const paramName of parameterNames) {
|
|
1137
1188
|
// In strict mode, it's guaranteed no duplicate params exist.
|
|
1138
1189
|
env.CreateMutableBinding(paramName, false);
|
|
1139
1190
|
}
|
|
1191
|
+
let parameterBindings = parameterNames;
|
|
1192
|
+
if (argumentsObjectNeeded) {
|
|
1193
|
+
const ao = CreateUnmappedArgumentsObject(args);
|
|
1194
|
+
env.CreateImmutableBinding("arguments", false);
|
|
1195
|
+
env.InitializeBinding("arguments", ao);
|
|
1196
|
+
parameterBindings = parameterNames.concat("arguments");
|
|
1197
|
+
}
|
|
1140
1198
|
const iteratorRecord = CreateListIteratorRecord(args);
|
|
1141
1199
|
yield* IteratorBindingInitialization(formals, iteratorRecord, env);
|
|
1142
1200
|
let varEnv;
|
|
@@ -1144,8 +1202,10 @@ export function cook(rootAst, codeSource) {
|
|
|
1144
1202
|
// NOTE: Only a single Environment Record is needed for the parameters
|
|
1145
1203
|
// and top-level vars.
|
|
1146
1204
|
// `varNames` are unique.
|
|
1205
|
+
const instantiatedVarNames = [...parameterBindings];
|
|
1147
1206
|
for (const n of varNames) {
|
|
1148
|
-
if (!
|
|
1207
|
+
if (!instantiatedVarNames.includes(n)) {
|
|
1208
|
+
instantiatedVarNames.push(n);
|
|
1149
1209
|
env.CreateMutableBinding(n, false);
|
|
1150
1210
|
env.InitializeBinding(n, undefined);
|
|
1151
1211
|
}
|
|
@@ -1158,15 +1218,19 @@ export function cook(rootAst, codeSource) {
|
|
|
1158
1218
|
varEnv = new DeclarativeEnvironment(env);
|
|
1159
1219
|
calleeContext.VariableEnvironment = varEnv;
|
|
1160
1220
|
// `varNames` are unique.
|
|
1221
|
+
const instantiatedVarNames = [];
|
|
1161
1222
|
for (const n of varNames) {
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
initialValue
|
|
1223
|
+
if (!instantiatedVarNames.includes(n)) {
|
|
1224
|
+
instantiatedVarNames.push(n);
|
|
1225
|
+
varEnv.CreateMutableBinding(n, false);
|
|
1226
|
+
let initialValue;
|
|
1227
|
+
if (parameterBindings.includes(n) && !functionNames.includes(n)) {
|
|
1228
|
+
initialValue = env.GetBindingValue(n, false);
|
|
1229
|
+
}
|
|
1230
|
+
varEnv.InitializeBinding(n, initialValue);
|
|
1231
|
+
// NOTE: A var with the same name as a formal parameter initially has
|
|
1232
|
+
// the same value as the corresponding initialized parameter.
|
|
1166
1233
|
}
|
|
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
1234
|
}
|
|
1171
1235
|
}
|
|
1172
1236
|
const lexEnv = varEnv;
|
|
@@ -1191,10 +1255,35 @@ export function cook(rootAst, codeSource) {
|
|
|
1191
1255
|
varEnv.SetMutableBinding(fn, fo, false);
|
|
1192
1256
|
}
|
|
1193
1257
|
}
|
|
1258
|
+
function CreateUnmappedArgumentsObject(args) {
|
|
1259
|
+
const argList = [...args];
|
|
1260
|
+
const argumentObject = {};
|
|
1261
|
+
Object.defineProperty(argumentObject, "length", {
|
|
1262
|
+
value: argList.length,
|
|
1263
|
+
writable: true,
|
|
1264
|
+
configurable: true
|
|
1265
|
+
});
|
|
1266
|
+
for (let index = 0; index < argList.length; index++) {
|
|
1267
|
+
argumentObject[String(index)] = argList[index];
|
|
1268
|
+
}
|
|
1269
|
+
Object.defineProperty(argumentObject, Symbol.iterator, {
|
|
1270
|
+
value: Array.prototype.values,
|
|
1271
|
+
writable: true,
|
|
1272
|
+
configurable: true
|
|
1273
|
+
});
|
|
1274
|
+
const ThrowTypeError = () => {
|
|
1275
|
+
throw new TypeError("'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them");
|
|
1276
|
+
};
|
|
1277
|
+
Object.defineProperty(argumentObject, "callee", {
|
|
1278
|
+
get: ThrowTypeError,
|
|
1279
|
+
set: ThrowTypeError
|
|
1280
|
+
});
|
|
1281
|
+
return argumentObject;
|
|
1282
|
+
}
|
|
1194
1283
|
|
|
1195
1284
|
// https://tc39.es/ecma262/#sec-runtime-semantics-instantiatefunctionobject
|
|
1196
1285
|
function InstantiateFunctionObject(func, scope) {
|
|
1197
|
-
const F = OrdinaryFunctionCreate(func, scope, true);
|
|
1286
|
+
const F = OrdinaryFunctionCreate(func, scope, true, false);
|
|
1198
1287
|
if (func.id) {
|
|
1199
1288
|
SetFunctionName(F, func.id.name);
|
|
1200
1289
|
}
|
|
@@ -1208,12 +1297,12 @@ export function cook(rootAst, codeSource) {
|
|
|
1208
1297
|
const name = functionExpression.id.name;
|
|
1209
1298
|
const funcEnv = new DeclarativeEnvironment(scope);
|
|
1210
1299
|
funcEnv.CreateImmutableBinding(name, false);
|
|
1211
|
-
const closure = OrdinaryFunctionCreate(functionExpression, funcEnv, true);
|
|
1300
|
+
const closure = OrdinaryFunctionCreate(functionExpression, funcEnv, true, false);
|
|
1212
1301
|
SetFunctionName(closure, name);
|
|
1213
1302
|
funcEnv.InitializeBinding(name, closure);
|
|
1214
1303
|
return closure;
|
|
1215
1304
|
} else {
|
|
1216
|
-
const closure = OrdinaryFunctionCreate(functionExpression, scope, true);
|
|
1305
|
+
const closure = OrdinaryFunctionCreate(functionExpression, scope, true, false);
|
|
1217
1306
|
SetFunctionName(closure, name ?? "");
|
|
1218
1307
|
return closure;
|
|
1219
1308
|
}
|
|
@@ -1222,7 +1311,7 @@ export function cook(rootAst, codeSource) {
|
|
|
1222
1311
|
// https://tc39.es/ecma262/#sec-runtime-semantics-instantiatearrowfunctionexpression
|
|
1223
1312
|
function InstantiateArrowFunctionExpression(arrowFunction, name) {
|
|
1224
1313
|
const scope = getRunningContext().LexicalEnvironment;
|
|
1225
|
-
const closure = OrdinaryFunctionCreate(arrowFunction, scope, false);
|
|
1314
|
+
const closure = OrdinaryFunctionCreate(arrowFunction, scope, false, true);
|
|
1226
1315
|
SetFunctionName(closure, name ?? "");
|
|
1227
1316
|
return closure;
|
|
1228
1317
|
}
|
|
@@ -1234,10 +1323,10 @@ export function cook(rootAst, codeSource) {
|
|
|
1234
1323
|
}
|
|
1235
1324
|
|
|
1236
1325
|
// https://tc39.es/ecma262/#sec-ordinaryfunctioncreate
|
|
1237
|
-
function OrdinaryFunctionCreate(sourceNode, scope, isConstructor) {
|
|
1326
|
+
function OrdinaryFunctionCreate(sourceNode, scope, isConstructor, lexicalThis) {
|
|
1238
1327
|
const F = function () {
|
|
1239
1328
|
// eslint-disable-next-line prefer-rest-params
|
|
1240
|
-
return unwind(CallFunction(F, arguments));
|
|
1329
|
+
return unwind(CallFunction(F, this, arguments));
|
|
1241
1330
|
};
|
|
1242
1331
|
Object.defineProperties(F, {
|
|
1243
1332
|
[SourceNode]: {
|
|
@@ -1254,13 +1343,16 @@ export function cook(rootAst, codeSource) {
|
|
|
1254
1343
|
},
|
|
1255
1344
|
[IsConstructor]: {
|
|
1256
1345
|
value: isConstructor
|
|
1346
|
+
},
|
|
1347
|
+
[ThisMode]: {
|
|
1348
|
+
value: lexicalThis ? Mode.LEXICAL : Mode.STRICT
|
|
1257
1349
|
}
|
|
1258
1350
|
});
|
|
1259
|
-
if (debug) {
|
|
1351
|
+
if (debug || externalSourceForDebug) {
|
|
1260
1352
|
Object.defineProperty(F, DebuggerCall, {
|
|
1261
1353
|
value: function () {
|
|
1262
1354
|
// eslint-disable-next-line prefer-rest-params
|
|
1263
|
-
return CallFunction(F, arguments);
|
|
1355
|
+
return CallFunction(F, this, arguments);
|
|
1264
1356
|
}
|
|
1265
1357
|
});
|
|
1266
1358
|
}
|
|
@@ -1334,7 +1426,7 @@ export function cook(rootAst, codeSource) {
|
|
|
1334
1426
|
// Rest element.
|
|
1335
1427
|
if (node.argument.type === "Identifier") {
|
|
1336
1428
|
const lhs = ResolveBinding(node.argument.name, environment);
|
|
1337
|
-
const A =
|
|
1429
|
+
const A = new ArrayConstructor();
|
|
1338
1430
|
let n = 0;
|
|
1339
1431
|
// eslint-disable-next-line no-constant-condition
|
|
1340
1432
|
while (true) {
|
|
@@ -1350,7 +1442,7 @@ export function cook(rootAst, codeSource) {
|
|
|
1350
1442
|
n++;
|
|
1351
1443
|
}
|
|
1352
1444
|
} else {
|
|
1353
|
-
const A =
|
|
1445
|
+
const A = new ArrayConstructor();
|
|
1354
1446
|
let n = 0;
|
|
1355
1447
|
// eslint-disable-next-line no-constant-condition
|
|
1356
1448
|
while (true) {
|