@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
|
@@ -3,9 +3,25 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.IsConstructor = exports.FunctionEnvironment = exports.FormalParameters = exports.ExecutionContext = exports.EnvironmentRecord = exports.Environment = exports.Empty = exports.ECMAScriptCode = exports.DeclarativeEnvironment = exports.DebuggerScope = exports.DebuggerNode = exports.DebuggerCall = exports.CompletionRecord = void 0;
|
|
6
|
+
exports.Mode = exports.IsConstructor = exports.FunctionEnvironment = exports.FormalParameters = exports.ExecutionContext = exports.EnvironmentRecord = exports.Environment = exports.Empty = exports.ECMAScriptCode = exports.DeclarativeEnvironment = exports.DebuggerScope = exports.DebuggerReturn = exports.DebuggerNode = exports.DebuggerCall = exports.CompletionRecord = exports.BindingStatus = void 0;
|
|
7
7
|
exports.NormalCompletion = NormalCompletion;
|
|
8
|
-
exports.SourceNode = exports.ReferenceRecord = void 0;
|
|
8
|
+
exports.ThisMode = exports.SourceNode = exports.ReferenceRecord = void 0;
|
|
9
|
+
let Mode = exports.Mode = /*#__PURE__*/function (Mode) {
|
|
10
|
+
Mode[Mode["LEXICAL"] = 0] = "LEXICAL";
|
|
11
|
+
Mode[Mode["STRICT"] = 1] = "STRICT";
|
|
12
|
+
return Mode;
|
|
13
|
+
}({});
|
|
14
|
+
const SourceNode = exports.SourceNode = Symbol.for("SourceNode");
|
|
15
|
+
const FormalParameters = exports.FormalParameters = Symbol.for("FormalParameters");
|
|
16
|
+
const ECMAScriptCode = exports.ECMAScriptCode = Symbol.for("ECMAScriptCode");
|
|
17
|
+
const Environment = exports.Environment = Symbol.for("Environment");
|
|
18
|
+
const IsConstructor = exports.IsConstructor = Symbol.for("IsConstructor");
|
|
19
|
+
const ThisMode = exports.ThisMode = Symbol.for("ThisMode");
|
|
20
|
+
const DebuggerCall = exports.DebuggerCall = Symbol.for("$DebuggerCall$");
|
|
21
|
+
const DebuggerScope = exports.DebuggerScope = Symbol.for("$DebuggerScope$");
|
|
22
|
+
const DebuggerNode = exports.DebuggerNode = Symbol.for("$DebuggerNode$");
|
|
23
|
+
const DebuggerReturn = exports.DebuggerReturn = Symbol.for("$DebuggerReturn$");
|
|
24
|
+
|
|
9
25
|
// https://tc39.es/ecma262/#sec-execution-contexts
|
|
10
26
|
class ExecutionContext {
|
|
11
27
|
VariableEnvironment;
|
|
@@ -13,10 +29,17 @@ class ExecutionContext {
|
|
|
13
29
|
Function;
|
|
14
30
|
}
|
|
15
31
|
exports.ExecutionContext = ExecutionContext;
|
|
16
|
-
|
|
32
|
+
let BindingStatus = exports.BindingStatus = /*#__PURE__*/function (BindingStatus) {
|
|
33
|
+
BindingStatus[BindingStatus["UNINITIALIZED"] = 0] = "UNINITIALIZED";
|
|
34
|
+
BindingStatus[BindingStatus["LEXICAL"] = 1] = "LEXICAL";
|
|
35
|
+
BindingStatus[BindingStatus["INITIALIZED"] = 2] = "INITIALIZED";
|
|
36
|
+
return BindingStatus;
|
|
37
|
+
}({}); // https://tc39.es/ecma262/#sec-environment-records
|
|
17
38
|
class EnvironmentRecord {
|
|
18
39
|
OuterEnv;
|
|
19
40
|
bindingMap = new Map();
|
|
41
|
+
ThisValue = undefined;
|
|
42
|
+
ThisBindingStatus;
|
|
20
43
|
constructor(outer) {
|
|
21
44
|
this.OuterEnv = outer;
|
|
22
45
|
}
|
|
@@ -84,20 +107,42 @@ class EnvironmentRecord {
|
|
|
84
107
|
}
|
|
85
108
|
return binding.value;
|
|
86
109
|
}
|
|
110
|
+
HasThisBinding() {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
87
113
|
}
|
|
88
114
|
exports.EnvironmentRecord = EnvironmentRecord;
|
|
89
115
|
class DeclarativeEnvironment extends EnvironmentRecord {}
|
|
90
116
|
exports.DeclarativeEnvironment = DeclarativeEnvironment;
|
|
91
|
-
class FunctionEnvironment extends EnvironmentRecord {
|
|
117
|
+
class FunctionEnvironment extends EnvironmentRecord {
|
|
118
|
+
constructor(F) {
|
|
119
|
+
super(F[Environment]);
|
|
120
|
+
if (F[ThisMode] === Mode.LEXICAL) {
|
|
121
|
+
this.ThisBindingStatus = BindingStatus.LEXICAL;
|
|
122
|
+
} else {
|
|
123
|
+
this.ThisBindingStatus = BindingStatus.UNINITIALIZED;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
HasThisBinding() {
|
|
127
|
+
return this.ThisBindingStatus !== BindingStatus.LEXICAL;
|
|
128
|
+
}
|
|
129
|
+
BindThisValue(value) {
|
|
130
|
+
// Assert: envRec.[[ThisBindingStatus]] is not LEXICAL.
|
|
131
|
+
if (this.ThisBindingStatus === BindingStatus.INITIALIZED) {
|
|
132
|
+
throw new Error("This binding has been initialized");
|
|
133
|
+
}
|
|
134
|
+
this.ThisValue = value;
|
|
135
|
+
this.ThisBindingStatus = BindingStatus.INITIALIZED;
|
|
136
|
+
}
|
|
137
|
+
GetThisBinding() {
|
|
138
|
+
// Assert: envRec.[[ThisBindingStatus]] is not LEXICAL.
|
|
139
|
+
if (this.ThisBindingStatus === BindingStatus.UNINITIALIZED) {
|
|
140
|
+
throw new Error("This binding is not initialized");
|
|
141
|
+
}
|
|
142
|
+
return this.ThisValue;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
92
145
|
exports.FunctionEnvironment = FunctionEnvironment;
|
|
93
|
-
const SourceNode = exports.SourceNode = Symbol.for("SourceNode");
|
|
94
|
-
const FormalParameters = exports.FormalParameters = Symbol.for("FormalParameters");
|
|
95
|
-
const ECMAScriptCode = exports.ECMAScriptCode = Symbol.for("ECMAScriptCode");
|
|
96
|
-
const Environment = exports.Environment = Symbol.for("Environment");
|
|
97
|
-
const IsConstructor = exports.IsConstructor = Symbol.for("IsConstructor");
|
|
98
|
-
const DebuggerCall = exports.DebuggerCall = Symbol.for("$DebuggerCall$");
|
|
99
|
-
const DebuggerScope = exports.DebuggerScope = Symbol.for("$DebuggerScope$");
|
|
100
|
-
const DebuggerNode = exports.DebuggerNode = Symbol.for("$DebuggerNode$");
|
|
101
146
|
// https://tc39.es/ecma262/#sec-reference-record-specification-type
|
|
102
147
|
class ReferenceRecord {
|
|
103
148
|
Base;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExecutionContext.js","names":["ExecutionContext","VariableEnvironment","LexicalEnvironment","Function","exports","EnvironmentRecord","OuterEnv","bindingMap","Map","constructor","outer","HasBinding","name","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","Strict","base","referenceName","CompletionRecord","Type","Value","type","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;AACO,MAAMA,gBAAgB,CAAC;EAC5BC,mBAAmB;EACnBC,kBAAkB;EAClBC,QAAQ;AACV;AAACC,OAAA,CAAAJ,gBAAA,GAAAA,gBAAA;AAID;AACO,MAAMK,iBAAiB,CAAC;EACpBC,QAAQ;EACAC,UAAU,GAAG,IAAIC,GAAG,CAAuB,CAAC;EAE7DC,WAAWA,CAACC,KAA2C,EAAE;IACvD,IAAI,CAACJ,QAAQ,GAAGI,KAAK;EACvB;EAEAC,UAAUA,CAACC,IAAY,EAAW;IAChC,OAAO,IAAI,CAACL,UAAU,CAACM,GAAG,CAACD,IAAI,CAAC;EAClC;EAEAE,oBAAoBA,CAACF,IAAY,EAAEG,SAAkB,EAAoB;IACvE;IACA,IAAI,CAACR,UAAU,CAACS,GAAG,CAACJ,IAAI,EAAE;MACxBK,OAAO,EAAE,IAAI;MACbF;IACF,CAAC,CAAC;IACF,OAAOG,gBAAgB,CAACC,SAAS,CAAC;EACpC;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;EACEC,sBAAsBA,CAACR,IAAY,EAAES,MAAe,EAAoB;IACtE;IACA,IAAI,CAACd,UAAU,CAACS,GAAG,CAACJ,IAAI,EAAE;MACxBS;IACF,CAAC,CAAC;IACF,OAAOH,gBAAgB,CAACC,SAAS,CAAC;EACpC;EAEAG,iBAAiBA,CAACV,IAAY,EAAEW,KAAc,EAAoB;IAChE,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nB,OAAA,CAAAgD,gBAAA,GAAAA,gBAAA;AASD;AACO,SAASlC,gBAAgBA,CAACK,KAAc,EAAoB;EACjE,OAAO,IAAI6B,gBAAgB,CAAC,QAAQ,EAAE7B,KAAK,CAAC;AAC9C;AAEO,MAAMiC,KAAK,GAAApD,OAAA,CAAAoD,KAAA,GAAGnB,MAAM,CAAC,kBAAkB,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"ExecutionContext.js","names":["Mode","exports","SourceNode","Symbol","for","FormalParameters","ECMAScriptCode","Environment","IsConstructor","ThisMode","DebuggerCall","DebuggerScope","DebuggerNode","DebuggerReturn","ExecutionContext","VariableEnvironment","LexicalEnvironment","Function","BindingStatus","EnvironmentRecord","OuterEnv","bindingMap","Map","ThisValue","undefined","ThisBindingStatus","constructor","outer","HasBinding","name","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","UNINITIALIZED","BindThisValue","INITIALIZED","Error","GetThisBinding","ReferenceRecord","Base","ReferenceName","Strict","base","referenceName","CompletionRecord","Type","Value","type","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":";;;;;;;;IASYA,IAAI,GAAAC,OAAA,CAAAD,IAAA,0BAAJA,IAAI;EAAJA,IAAI,CAAJA,IAAI;EAAJA,IAAI,CAAJA,IAAI;EAAA,OAAJA,IAAI;AAAA;AAKT,MAAME,UAAU,GAAAD,OAAA,CAAAC,UAAA,GAAGC,MAAM,CAACC,GAAG,CAAC,YAAY,CAAC;AAC3C,MAAMC,gBAAgB,GAAAJ,OAAA,CAAAI,gBAAA,GAAGF,MAAM,CAACC,GAAG,CAAC,kBAAkB,CAAC;AACvD,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IACf;IACA,IAAI,IAAI,CAAClC,iBAAiB,KAAKP,aAAa,CAACqC,aAAa,EAAE;MAC1D,MAAM,IAAIG,KAAK,CAAC,iCAAiC,CAAC;IACpD;IACA,OAAO,IAAI,CAACnC,SAAS;EACvB;AACF;AAACtB,OAAA,CAAAmD,mBAAA,GAAAA,mBAAA;AAkCD;AACO,MAAMQ,eAAe,CAAC;EAClBC,IAAI;EAIJC,aAAa;EACtB;EACSC,MAAM;EAEfrC,WAAWA,CACTsC,IAAuE,EACvEC,aAA0B,EAC1B5B,MAAe,EACf;IACA,IAAI,CAACwB,IAAI,GAAGG,IAAI;IAChB,IAAI,CAACF,aAAa,GAAGG,aAAa;IAClC,IAAI,CAACF,MAAM,GAAG1B,MAAM;EACtB;AACF;;AAEA;AAAApC,OAAA,CAAA2D,eAAA,GAAAA,eAAA;AACO,MAAMM,gBAAgB,CAAC;EACnBC,IAAI;EACJC,KAAK;EAEd1C,WAAWA,CAAC2C,IAA0B,EAAE9B,KAAc,EAAE;IACtD,IAAI,CAAC4B,IAAI,GAAGE,IAAI;IAChB,IAAI,CAACD,KAAK,GAAG7B,KAAK;EACpB;AACF;AAACtC,OAAA,CAAAiE,gBAAA,GAAAA,gBAAA;AASD;AACO,SAAS/B,gBAAgBA,CAACI,KAAc,EAAoB;EACjE,OAAO,IAAI2B,gBAAgB,CAAC,QAAQ,EAAE3B,KAAK,CAAC;AAC9C;AAEO,MAAM+B,KAAK,GAAArE,OAAA,CAAAqE,KAAA,GAAGnE,MAAM,CAAC,kBAAkB,CAAC","ignoreList":[]}
|
package/dist/cjs/context-free.js
CHANGED
|
@@ -177,6 +177,8 @@ function ApplyStringOrNumericBinaryOperator(leftValue, operator, rightValue) {
|
|
|
177
177
|
return leftValue >= rightValue;
|
|
178
178
|
case "<=":
|
|
179
179
|
return leftValue <= rightValue;
|
|
180
|
+
case "in":
|
|
181
|
+
return leftValue in rightValue;
|
|
180
182
|
}
|
|
181
183
|
throw new SyntaxError(`Unsupported binary operator \`${operator}\``);
|
|
182
184
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-free.js","names":["_ExecutionContext","require","_traverse","IsPropertyReference","V","Base","EnvironmentRecord","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","collectBoundNames","CreateImmutableBinding","CreateMutableBinding","LoopContinues","completion","Type","UpdateEmpty","value","Value","Empty","CompletionRecord","GetValue","ReferenceRecord","ReferenceError","GetBindingValue","Strict","ToPropertyKey","arg","String","GetV","P","PutValue","SetMutableBinding","NormalCompletion","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,IAAAA,iBAAA,GAAAC,OAAA;AAOA,IAAAC,SAAA,GAAAD,OAAA;AAEA;AACO,SAASE,mBAAmBA,CAACC,CAAkB,EAAW;EAC/D,OAAOA,CAAC,CAACC,IAAI,KAAK,cAAc,IAAI,EAAED,CAAC,CAACC,IAAI,YAAYC,mCAAiB,CAAC;AAC5E;;AAEA;AACO,SAASC,2BAA2BA,CACzCH,CAAkB,EAClBI,C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,qCAAqCF,QAAQ,IAAI,CAAC;AAC1E;;AAEA;AACO,SAASM,kBAAkBA,CAChC/D,MAAe,EACfyD,QAAqC,EAC5B;EACT,QAAQA,QAAQ;IACd,KAAK,GAAG;MACN,OAAO,CAACzD,MAAM;IAChB,KAAK,GAAG;MACN,OAAO,CAAEA,MAA0B;IACrC,KAAK,GAAG;MACN,OAAO,CAAEA,MAA0B;IACrC,KAAK,MAAM;MACT,OAAOG,SAAS;EACpB;EACA,MAAM,IAAIwD,WAAW,CAAC,gCAAgCF,QAAQ,IAAI,CAAC;AACrE;AAEO,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,KAAK7D,SAAS,EAAE;IAC3C,OAAO,KAAK;EACd;EACA,OAAO,OAAQ6D,MAAM,CAAuBhB,MAAM,CAACC,QAAQ,CAAC,KAAK,UAAU;AAC7E","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"context-free.js","names":["_ExecutionContext","require","_traverse","IsPropertyReference","V","Base","EnvironmentRecord","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","collectBoundNames","CreateImmutableBinding","CreateMutableBinding","LoopContinues","completion","Type","UpdateEmpty","value","Value","Empty","CompletionRecord","GetValue","ReferenceRecord","ReferenceError","GetBindingValue","Strict","ToPropertyKey","arg","String","GetV","P","PutValue","SetMutableBinding","NormalCompletion","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,IAAAA,iBAAA,GAAAC,OAAA;AAOA,IAAAC,SAAA,GAAAD,OAAA;AAEA;AACO,SAASE,mBAAmBA,CAACC,CAAkB,EAAW;EAC/D,OAAOA,CAAC,CAACC,IAAI,KAAK,cAAc,IAAI,EAAED,CAAC,CAACC,IAAI,YAAYC,mCAAiB,CAAC;AAC5E;;AAEA;AACO,SAASC,2BAA2BA,CACzCH,CAAkB,EAClBI,CAAU,EACQ;EAClB,MAAMC,IAAI,GAAGL,CAAC,CAACC,IAAyB;EACxC,OAAOI,IAAI,CAACC,iBAAiB,CAACN,CAAC,CAACO,aAAa,EAAYH,CAAC,CAAC;AAC7D;;AAEA;AACO,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,wBAA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AAE;IAC3C,OAAO,KAAK;EACd;EACA,OAAO,OAAQ6D,MAAM,CAAuBhB,MAAM,CAACC,QAAQ,CAAC,KAAK,UAAU;AAC7E","ignoreList":[]}
|
package/dist/cjs/cook.js
CHANGED
|
@@ -12,11 +12,19 @@ var _traverse = require("./traverse.js");
|
|
|
12
12
|
function cook(rootAst, codeSource, {
|
|
13
13
|
rules,
|
|
14
14
|
debug,
|
|
15
|
+
externalSourceForDebug,
|
|
15
16
|
globalVariables = {},
|
|
17
|
+
// Allow debugger to override Array constructor.
|
|
18
|
+
ArrayConstructor = Array,
|
|
16
19
|
hooks = {}
|
|
17
20
|
} = {}) {
|
|
18
21
|
var _hooks$beforeEvaluate3;
|
|
19
22
|
const expressionOnly = rootAst.type !== "FunctionDeclaration";
|
|
23
|
+
function doSanitize(cooked) {
|
|
24
|
+
if (!externalSourceForDebug) {
|
|
25
|
+
(0, _sanitize.sanitize)(cooked);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
20
28
|
const rootEnv = new _ExecutionContext.DeclarativeEnvironment(null);
|
|
21
29
|
const rootContext = new _ExecutionContext.ExecutionContext();
|
|
22
30
|
rootContext.VariableEnvironment = rootEnv;
|
|
@@ -60,7 +68,7 @@ function cook(rootAst, codeSource, {
|
|
|
60
68
|
case "ArrayExpression":
|
|
61
69
|
{
|
|
62
70
|
// https://tc39.es/ecma262/#sec-array-initializer
|
|
63
|
-
const array =
|
|
71
|
+
const array = new ArrayConstructor();
|
|
64
72
|
for (const element of node.elements) {
|
|
65
73
|
if (!element) {
|
|
66
74
|
array.length += 1;
|
|
@@ -84,7 +92,7 @@ function cook(rootAst, codeSource, {
|
|
|
84
92
|
{
|
|
85
93
|
const leftRef = yield* Evaluate(node.left);
|
|
86
94
|
const leftValue = (0, _contextFree.GetValue)(leftRef);
|
|
87
|
-
const rightRef =
|
|
95
|
+
const rightRef = yield* Evaluate(node.right);
|
|
88
96
|
const rightValue = (0, _contextFree.GetValue)(rightRef);
|
|
89
97
|
if (expressionOnly && node.operator === "|>") {
|
|
90
98
|
// Minimal pipeline operator is supported only in expression-only mode.
|
|
@@ -115,7 +123,7 @@ function cook(rootAst, codeSource, {
|
|
|
115
123
|
optionalChainRef.skipped = true;
|
|
116
124
|
return (0, _ExecutionContext.NormalCompletion)(undefined);
|
|
117
125
|
}
|
|
118
|
-
(
|
|
126
|
+
doSanitize(func);
|
|
119
127
|
if (debug) yield;
|
|
120
128
|
return yield* EvaluateCall(func, ref, node.arguments, node.callee);
|
|
121
129
|
}
|
|
@@ -171,9 +179,9 @@ function cook(rootAst, codeSource, {
|
|
|
171
179
|
optionalChainRef.skipped = true;
|
|
172
180
|
return (0, _ExecutionContext.NormalCompletion)(undefined);
|
|
173
181
|
}
|
|
174
|
-
(
|
|
182
|
+
doSanitize(baseValue);
|
|
175
183
|
const result = node.computed ? yield* EvaluatePropertyAccessWithExpressionKey(baseValue, node.property, true) : EvaluatePropertyAccessWithIdentifierKey(baseValue, node.property, true);
|
|
176
|
-
(
|
|
184
|
+
doSanitize(result);
|
|
177
185
|
return (0, _ExecutionContext.NormalCompletion)(result);
|
|
178
186
|
}
|
|
179
187
|
case "NewExpression":
|
|
@@ -230,7 +238,7 @@ function cook(rootAst, codeSource, {
|
|
|
230
238
|
// https://tc39.es/ecma262/#sec-tagged-templates
|
|
231
239
|
const tagRef = (yield* Evaluate(node.tag)).Value;
|
|
232
240
|
const tagFunc = (0, _contextFree.GetValue)(tagRef);
|
|
233
|
-
(
|
|
241
|
+
doSanitize(tagFunc);
|
|
234
242
|
if (debug) yield;
|
|
235
243
|
return yield* EvaluateCall(tagFunc, tagRef, node.quasi, node.tag);
|
|
236
244
|
}
|
|
@@ -356,9 +364,16 @@ function cook(rootAst, codeSource, {
|
|
|
356
364
|
const exprRef = yield* Evaluate(node.argument);
|
|
357
365
|
v = (0, _contextFree.GetValue)(exprRef);
|
|
358
366
|
}
|
|
359
|
-
currentNode = node;
|
|
360
367
|
return new _ExecutionContext.CompletionRecord("return", v);
|
|
361
368
|
}
|
|
369
|
+
case "ThisExpression":
|
|
370
|
+
{
|
|
371
|
+
if (!externalSourceForDebug) {
|
|
372
|
+
break;
|
|
373
|
+
}
|
|
374
|
+
const envRec = GetThisEnvironment();
|
|
375
|
+
return (0, _ExecutionContext.NormalCompletion)(envRec.GetThisBinding());
|
|
376
|
+
}
|
|
362
377
|
case "ThrowStatement":
|
|
363
378
|
// https://tc39.es/ecma262/#sec-throw-statement
|
|
364
379
|
throw (0, _contextFree.GetValue)(yield* Evaluate(node.argument));
|
|
@@ -902,7 +917,7 @@ function cook(rootAst, codeSource, {
|
|
|
902
917
|
}
|
|
903
918
|
} else {
|
|
904
919
|
// RestElement
|
|
905
|
-
v =
|
|
920
|
+
v = new ArrayConstructor();
|
|
906
921
|
let n = 0;
|
|
907
922
|
// eslint-disable-next-line no-constant-condition
|
|
908
923
|
while (true) {
|
|
@@ -979,16 +994,16 @@ function cook(rootAst, codeSource, {
|
|
|
979
994
|
const funcName = codeSource.substring(callee.start, callee.end);
|
|
980
995
|
throw new TypeError(`${funcName} is not a function`);
|
|
981
996
|
}
|
|
982
|
-
if (debug) {
|
|
997
|
+
if (debug || externalSourceForDebug) {
|
|
983
998
|
const debuggerCall = func[_ExecutionContext.DebuggerCall];
|
|
984
999
|
if (debuggerCall) {
|
|
985
1000
|
const result = yield* debuggerCall.apply(thisValue, argList);
|
|
986
|
-
(
|
|
1001
|
+
doSanitize(result);
|
|
987
1002
|
return (0, _ExecutionContext.NormalCompletion)(result);
|
|
988
1003
|
}
|
|
989
1004
|
}
|
|
990
1005
|
const result = func.apply(thisValue, argList);
|
|
991
|
-
(
|
|
1006
|
+
doSanitize(result);
|
|
992
1007
|
return (0, _ExecutionContext.NormalCompletion)(result);
|
|
993
1008
|
}
|
|
994
1009
|
|
|
@@ -1001,7 +1016,7 @@ function cook(rootAst, codeSource, {
|
|
|
1001
1016
|
const constructorName = codeSource.substring(constructExpr.start, constructExpr.end);
|
|
1002
1017
|
throw new TypeError(`${constructorName} is not a constructor`);
|
|
1003
1018
|
}
|
|
1004
|
-
if (!(0, _sanitize.isAllowedConstructor)(constructor)) {
|
|
1019
|
+
if (!externalSourceForDebug && !(0, _sanitize.isAllowedConstructor)(constructor) && constructor !== ArrayConstructor) {
|
|
1005
1020
|
const constructorName = codeSource.substring(constructExpr.start, constructExpr.end);
|
|
1006
1021
|
throw new TypeError(`${constructorName} is not an allowed constructor`);
|
|
1007
1022
|
}
|
|
@@ -1030,18 +1045,22 @@ function cook(rootAst, codeSource, {
|
|
|
1030
1045
|
}
|
|
1031
1046
|
|
|
1032
1047
|
// https://tc39.es/ecma262/#sec-ecmascript-function-objects-call-thisargument-argumentslist
|
|
1033
|
-
function* CallFunction(closure, args) {
|
|
1034
|
-
var _hooks$beforeCall
|
|
1048
|
+
function* CallFunction(closure, thisArgument, args) {
|
|
1049
|
+
var _hooks$beforeCall;
|
|
1035
1050
|
(_hooks$beforeCall = hooks.beforeCall) === null || _hooks$beforeCall === void 0 || _hooks$beforeCall.call(hooks, closure[_ExecutionContext.SourceNode]);
|
|
1036
|
-
PrepareForOrdinaryCall(closure);
|
|
1051
|
+
const calleeContext = PrepareForOrdinaryCall(closure);
|
|
1052
|
+
OrdinaryCallBindThis(closure, calleeContext, thisArgument);
|
|
1037
1053
|
const result = yield* OrdinaryCallEvaluateBody(closure, args);
|
|
1038
|
-
if (
|
|
1039
|
-
currentNode =
|
|
1054
|
+
if (debug) {
|
|
1055
|
+
currentNode = {
|
|
1056
|
+
...closure[_ExecutionContext.SourceNode],
|
|
1057
|
+
[_ExecutionContext.DebuggerReturn]: true
|
|
1058
|
+
};
|
|
1059
|
+
yield {
|
|
1060
|
+
type: "return",
|
|
1061
|
+
value: result.Type === "return" ? result.Value : undefined
|
|
1062
|
+
};
|
|
1040
1063
|
}
|
|
1041
|
-
if (debug) yield {
|
|
1042
|
-
type: "return",
|
|
1043
|
-
value: result.Type === "return" ? result.Value : undefined
|
|
1044
|
-
};
|
|
1045
1064
|
executionContextStack.pop();
|
|
1046
1065
|
if (result.Type === "return") {
|
|
1047
1066
|
return result.Value;
|
|
@@ -1053,12 +1072,19 @@ function cook(rootAst, codeSource, {
|
|
|
1053
1072
|
function PrepareForOrdinaryCall(F) {
|
|
1054
1073
|
const calleeContext = new _ExecutionContext.ExecutionContext();
|
|
1055
1074
|
calleeContext.Function = F;
|
|
1056
|
-
const localEnv = new _ExecutionContext.FunctionEnvironment(F
|
|
1075
|
+
const localEnv = new _ExecutionContext.FunctionEnvironment(F);
|
|
1057
1076
|
calleeContext.VariableEnvironment = localEnv;
|
|
1058
1077
|
calleeContext.LexicalEnvironment = localEnv;
|
|
1059
1078
|
executionContextStack.push(calleeContext);
|
|
1060
1079
|
return calleeContext;
|
|
1061
1080
|
}
|
|
1081
|
+
function OrdinaryCallBindThis(F, calleeContext, thisArgument) {
|
|
1082
|
+
if (F[_ExecutionContext.ThisMode] === _ExecutionContext.Mode.LEXICAL) {
|
|
1083
|
+
return;
|
|
1084
|
+
}
|
|
1085
|
+
const localEnv = calleeContext.LexicalEnvironment;
|
|
1086
|
+
localEnv === null || localEnv === void 0 || localEnv.BindThisValue(thisArgument);
|
|
1087
|
+
}
|
|
1062
1088
|
|
|
1063
1089
|
// https://tc39.es/ecma262/#sec-ordinarycallevaluatebody
|
|
1064
1090
|
function* OrdinaryCallEvaluateBody(F, args) {
|
|
@@ -1086,6 +1112,16 @@ function cook(rootAst, codeSource, {
|
|
|
1086
1112
|
}
|
|
1087
1113
|
return result;
|
|
1088
1114
|
}
|
|
1115
|
+
function GetThisEnvironment() {
|
|
1116
|
+
let env = getRunningContext().LexicalEnvironment;
|
|
1117
|
+
while (env) {
|
|
1118
|
+
if (env.HasThisBinding()) {
|
|
1119
|
+
return env;
|
|
1120
|
+
}
|
|
1121
|
+
env = env.OuterEnv;
|
|
1122
|
+
}
|
|
1123
|
+
throw new Error("Accessing global this is forbidden");
|
|
1124
|
+
}
|
|
1089
1125
|
|
|
1090
1126
|
// https://tc39.es/ecma262/#sec-isanonymousfunctiondefinition
|
|
1091
1127
|
function IsAnonymousFunctionDefinition(node) {
|
|
@@ -1137,11 +1173,33 @@ function cook(rootAst, codeSource, {
|
|
|
1137
1173
|
throw new SyntaxError("Var declaration is not recommended, use `let` or `const` instead");
|
|
1138
1174
|
}
|
|
1139
1175
|
}
|
|
1176
|
+
|
|
1177
|
+
// let argumentsObjectNeeded = true;
|
|
1178
|
+
// if (func[ThisMode] === Mode.LEXICAL) {
|
|
1179
|
+
// // NOTE: Arrow functions never have an arguments object.
|
|
1180
|
+
// argumentsObjectNeeded = false;
|
|
1181
|
+
// } else if (parameterNames.includes("arguments")) {
|
|
1182
|
+
// argumentsObjectNeeded = false;
|
|
1183
|
+
// } else if (!hasParameterExpressions && (
|
|
1184
|
+
// varNames.includes("arguments") ||
|
|
1185
|
+
// collectBoundNames(collectScopedDeclarations(code, { var: false })).includes("arguments")
|
|
1186
|
+
// )) {
|
|
1187
|
+
// argumentsObjectNeeded = false;
|
|
1188
|
+
// }
|
|
1189
|
+
// NOTE: In strict mode, no parameter/function/var/lexical names can be "arguments".
|
|
1190
|
+
const argumentsObjectNeeded = !!externalSourceForDebug && func[_ExecutionContext.ThisMode] !== _ExecutionContext.Mode.LEXICAL;
|
|
1140
1191
|
const env = calleeContext.LexicalEnvironment;
|
|
1141
1192
|
for (const paramName of parameterNames) {
|
|
1142
1193
|
// In strict mode, it's guaranteed no duplicate params exist.
|
|
1143
1194
|
env.CreateMutableBinding(paramName, false);
|
|
1144
1195
|
}
|
|
1196
|
+
let parameterBindings = parameterNames;
|
|
1197
|
+
if (argumentsObjectNeeded) {
|
|
1198
|
+
const ao = CreateUnmappedArgumentsObject(args);
|
|
1199
|
+
env.CreateImmutableBinding("arguments", false);
|
|
1200
|
+
env.InitializeBinding("arguments", ao);
|
|
1201
|
+
parameterBindings = parameterNames.concat("arguments");
|
|
1202
|
+
}
|
|
1145
1203
|
const iteratorRecord = (0, _contextFree.CreateListIteratorRecord)(args);
|
|
1146
1204
|
yield* IteratorBindingInitialization(formals, iteratorRecord, env);
|
|
1147
1205
|
let varEnv;
|
|
@@ -1149,8 +1207,10 @@ function cook(rootAst, codeSource, {
|
|
|
1149
1207
|
// NOTE: Only a single Environment Record is needed for the parameters
|
|
1150
1208
|
// and top-level vars.
|
|
1151
1209
|
// `varNames` are unique.
|
|
1210
|
+
const instantiatedVarNames = [...parameterBindings];
|
|
1152
1211
|
for (const n of varNames) {
|
|
1153
|
-
if (!
|
|
1212
|
+
if (!instantiatedVarNames.includes(n)) {
|
|
1213
|
+
instantiatedVarNames.push(n);
|
|
1154
1214
|
env.CreateMutableBinding(n, false);
|
|
1155
1215
|
env.InitializeBinding(n, undefined);
|
|
1156
1216
|
}
|
|
@@ -1163,15 +1223,19 @@ function cook(rootAst, codeSource, {
|
|
|
1163
1223
|
varEnv = new _ExecutionContext.DeclarativeEnvironment(env);
|
|
1164
1224
|
calleeContext.VariableEnvironment = varEnv;
|
|
1165
1225
|
// `varNames` are unique.
|
|
1226
|
+
const instantiatedVarNames = [];
|
|
1166
1227
|
for (const n of varNames) {
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
initialValue
|
|
1228
|
+
if (!instantiatedVarNames.includes(n)) {
|
|
1229
|
+
instantiatedVarNames.push(n);
|
|
1230
|
+
varEnv.CreateMutableBinding(n, false);
|
|
1231
|
+
let initialValue;
|
|
1232
|
+
if (parameterBindings.includes(n) && !functionNames.includes(n)) {
|
|
1233
|
+
initialValue = env.GetBindingValue(n, false);
|
|
1234
|
+
}
|
|
1235
|
+
varEnv.InitializeBinding(n, initialValue);
|
|
1236
|
+
// NOTE: A var with the same name as a formal parameter initially has
|
|
1237
|
+
// the same value as the corresponding initialized parameter.
|
|
1171
1238
|
}
|
|
1172
|
-
varEnv.InitializeBinding(n, initialValue);
|
|
1173
|
-
// NOTE: A var with the same name as a formal parameter initially has
|
|
1174
|
-
// the same value as the corresponding initialized parameter.
|
|
1175
1239
|
}
|
|
1176
1240
|
}
|
|
1177
1241
|
const lexEnv = varEnv;
|
|
@@ -1196,10 +1260,35 @@ function cook(rootAst, codeSource, {
|
|
|
1196
1260
|
varEnv.SetMutableBinding(fn, fo, false);
|
|
1197
1261
|
}
|
|
1198
1262
|
}
|
|
1263
|
+
function CreateUnmappedArgumentsObject(args) {
|
|
1264
|
+
const argList = [...args];
|
|
1265
|
+
const argumentObject = {};
|
|
1266
|
+
Object.defineProperty(argumentObject, "length", {
|
|
1267
|
+
value: argList.length,
|
|
1268
|
+
writable: true,
|
|
1269
|
+
configurable: true
|
|
1270
|
+
});
|
|
1271
|
+
for (let index = 0; index < argList.length; index++) {
|
|
1272
|
+
argumentObject[String(index)] = argList[index];
|
|
1273
|
+
}
|
|
1274
|
+
Object.defineProperty(argumentObject, Symbol.iterator, {
|
|
1275
|
+
value: Array.prototype.values,
|
|
1276
|
+
writable: true,
|
|
1277
|
+
configurable: true
|
|
1278
|
+
});
|
|
1279
|
+
const ThrowTypeError = () => {
|
|
1280
|
+
throw new TypeError("'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them");
|
|
1281
|
+
};
|
|
1282
|
+
Object.defineProperty(argumentObject, "callee", {
|
|
1283
|
+
get: ThrowTypeError,
|
|
1284
|
+
set: ThrowTypeError
|
|
1285
|
+
});
|
|
1286
|
+
return argumentObject;
|
|
1287
|
+
}
|
|
1199
1288
|
|
|
1200
1289
|
// https://tc39.es/ecma262/#sec-runtime-semantics-instantiatefunctionobject
|
|
1201
1290
|
function InstantiateFunctionObject(func, scope) {
|
|
1202
|
-
const F = OrdinaryFunctionCreate(func, scope, true);
|
|
1291
|
+
const F = OrdinaryFunctionCreate(func, scope, true, false);
|
|
1203
1292
|
if (func.id) {
|
|
1204
1293
|
SetFunctionName(F, func.id.name);
|
|
1205
1294
|
}
|
|
@@ -1213,12 +1302,12 @@ function cook(rootAst, codeSource, {
|
|
|
1213
1302
|
const name = functionExpression.id.name;
|
|
1214
1303
|
const funcEnv = new _ExecutionContext.DeclarativeEnvironment(scope);
|
|
1215
1304
|
funcEnv.CreateImmutableBinding(name, false);
|
|
1216
|
-
const closure = OrdinaryFunctionCreate(functionExpression, funcEnv, true);
|
|
1305
|
+
const closure = OrdinaryFunctionCreate(functionExpression, funcEnv, true, false);
|
|
1217
1306
|
SetFunctionName(closure, name);
|
|
1218
1307
|
funcEnv.InitializeBinding(name, closure);
|
|
1219
1308
|
return closure;
|
|
1220
1309
|
} else {
|
|
1221
|
-
const closure = OrdinaryFunctionCreate(functionExpression, scope, true);
|
|
1310
|
+
const closure = OrdinaryFunctionCreate(functionExpression, scope, true, false);
|
|
1222
1311
|
SetFunctionName(closure, name ?? "");
|
|
1223
1312
|
return closure;
|
|
1224
1313
|
}
|
|
@@ -1227,7 +1316,7 @@ function cook(rootAst, codeSource, {
|
|
|
1227
1316
|
// https://tc39.es/ecma262/#sec-runtime-semantics-instantiatearrowfunctionexpression
|
|
1228
1317
|
function InstantiateArrowFunctionExpression(arrowFunction, name) {
|
|
1229
1318
|
const scope = getRunningContext().LexicalEnvironment;
|
|
1230
|
-
const closure = OrdinaryFunctionCreate(arrowFunction, scope, false);
|
|
1319
|
+
const closure = OrdinaryFunctionCreate(arrowFunction, scope, false, true);
|
|
1231
1320
|
SetFunctionName(closure, name ?? "");
|
|
1232
1321
|
return closure;
|
|
1233
1322
|
}
|
|
@@ -1239,10 +1328,10 @@ function cook(rootAst, codeSource, {
|
|
|
1239
1328
|
}
|
|
1240
1329
|
|
|
1241
1330
|
// https://tc39.es/ecma262/#sec-ordinaryfunctioncreate
|
|
1242
|
-
function OrdinaryFunctionCreate(sourceNode, scope, isConstructor) {
|
|
1331
|
+
function OrdinaryFunctionCreate(sourceNode, scope, isConstructor, lexicalThis) {
|
|
1243
1332
|
const F = function () {
|
|
1244
1333
|
// eslint-disable-next-line prefer-rest-params
|
|
1245
|
-
return unwind(CallFunction(F, arguments));
|
|
1334
|
+
return unwind(CallFunction(F, this, arguments));
|
|
1246
1335
|
};
|
|
1247
1336
|
Object.defineProperties(F, {
|
|
1248
1337
|
[_ExecutionContext.SourceNode]: {
|
|
@@ -1259,13 +1348,16 @@ function cook(rootAst, codeSource, {
|
|
|
1259
1348
|
},
|
|
1260
1349
|
[_ExecutionContext.IsConstructor]: {
|
|
1261
1350
|
value: isConstructor
|
|
1351
|
+
},
|
|
1352
|
+
[_ExecutionContext.ThisMode]: {
|
|
1353
|
+
value: lexicalThis ? _ExecutionContext.Mode.LEXICAL : _ExecutionContext.Mode.STRICT
|
|
1262
1354
|
}
|
|
1263
1355
|
});
|
|
1264
|
-
if (debug) {
|
|
1356
|
+
if (debug || externalSourceForDebug) {
|
|
1265
1357
|
Object.defineProperty(F, _ExecutionContext.DebuggerCall, {
|
|
1266
1358
|
value: function () {
|
|
1267
1359
|
// eslint-disable-next-line prefer-rest-params
|
|
1268
|
-
return CallFunction(F, arguments);
|
|
1360
|
+
return CallFunction(F, this, arguments);
|
|
1269
1361
|
}
|
|
1270
1362
|
});
|
|
1271
1363
|
}
|
|
@@ -1339,7 +1431,7 @@ function cook(rootAst, codeSource, {
|
|
|
1339
1431
|
// Rest element.
|
|
1340
1432
|
if (node.argument.type === "Identifier") {
|
|
1341
1433
|
const lhs = ResolveBinding(node.argument.name, environment);
|
|
1342
|
-
const A =
|
|
1434
|
+
const A = new ArrayConstructor();
|
|
1343
1435
|
let n = 0;
|
|
1344
1436
|
// eslint-disable-next-line no-constant-condition
|
|
1345
1437
|
while (true) {
|
|
@@ -1355,7 +1447,7 @@ function cook(rootAst, codeSource, {
|
|
|
1355
1447
|
n++;
|
|
1356
1448
|
}
|
|
1357
1449
|
} else {
|
|
1358
|
-
const A =
|
|
1450
|
+
const A = new ArrayConstructor();
|
|
1359
1451
|
let n = 0;
|
|
1360
1452
|
// eslint-disable-next-line no-constant-condition
|
|
1361
1453
|
while (true) {
|