@next-core/cook 1.6.78 → 1.6.80
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/AnalysisContext.js +2 -11
- package/dist/cjs/AnalysisContext.js.map +1 -1
- package/dist/cjs/ExecutionContext.js +11 -37
- package/dist/cjs/ExecutionContext.js.map +1 -1
- package/dist/cjs/context-free.js +30 -71
- package/dist/cjs/context-free.js.map +1 -1
- package/dist/cjs/cook.js +147 -386
- package/dist/cjs/cook.js.map +1 -1
- package/dist/cjs/hasOwnProperty.js +0 -1
- package/dist/cjs/hasOwnProperty.js.map +1 -1
- package/dist/cjs/index.js +0 -14
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/interfaces.js.map +1 -1
- package/dist/cjs/lint.js +0 -21
- package/dist/cjs/lint.js.map +1 -1
- package/dist/cjs/parse.js +0 -8
- package/dist/cjs/parse.js.map +1 -1
- package/dist/cjs/precook.js +6 -74
- package/dist/cjs/precook.js.map +1 -1
- package/dist/cjs/precookFunction.js +0 -3
- package/dist/cjs/precookFunction.js.map +1 -1
- package/dist/cjs/preevaluate.js +2 -6
- package/dist/cjs/preevaluate.js.map +1 -1
- package/dist/cjs/sanitize.js +9 -13
- package/dist/cjs/sanitize.js.map +1 -1
- package/dist/cjs/traverse.js +0 -32
- package/dist/cjs/traverse.js.map +1 -1
- package/dist/esm/AnalysisContext.js +2 -8
- package/dist/esm/AnalysisContext.js.map +1 -1
- package/dist/esm/ExecutionContext.js +11 -30
- package/dist/esm/ExecutionContext.js.map +1 -1
- package/dist/esm/context-free.js +32 -53
- package/dist/esm/context-free.js.map +1 -1
- package/dist/esm/cook.js +145 -411
- package/dist/esm/cook.js.map +1 -1
- package/dist/esm/hasOwnProperty.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/interfaces.js.map +1 -1
- package/dist/esm/lint.js +0 -19
- package/dist/esm/lint.js.map +1 -1
- package/dist/esm/parse.js +0 -6
- package/dist/esm/parse.js.map +1 -1
- package/dist/esm/precook.js +4 -82
- package/dist/esm/precook.js.map +1 -1
- package/dist/esm/precookFunction.js +4 -5
- package/dist/esm/precookFunction.js.map +1 -1
- package/dist/esm/preevaluate.js.map +1 -1
- package/dist/esm/sanitize.js +9 -9
- package/dist/esm/sanitize.js.map +1 -1
- package/dist/esm/traverse.js +0 -29
- package/dist/esm/traverse.js.map +1 -1
- package/dist/types/interfaces.d.ts +2 -0
- package/dist/types/lint.d.ts +3 -4
- package/dist/types/parse.d.ts +3 -3
- package/package.json +6 -6
|
@@ -1,42 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.AnalysisEnvironment = exports.AnalysisContext = void 0;
|
|
9
|
-
|
|
10
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
9
|
// https://tc39.es/ecma262/#sec-execution-contexts
|
|
13
10
|
class AnalysisContext {
|
|
14
11
|
constructor() {
|
|
15
12
|
(0, _defineProperty2.default)(this, "VariableEnvironment", void 0);
|
|
16
13
|
(0, _defineProperty2.default)(this, "LexicalEnvironment", void 0);
|
|
17
14
|
}
|
|
15
|
+
}
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
// https://tc39.es/ecma262/#sec-environment-records
|
|
22
18
|
exports.AnalysisContext = AnalysisContext;
|
|
23
|
-
|
|
24
19
|
class AnalysisEnvironment {
|
|
25
20
|
constructor(outer) {
|
|
26
21
|
(0, _defineProperty2.default)(this, "OuterEnv", void 0);
|
|
27
22
|
(0, _defineProperty2.default)(this, "bindingSet", new Set());
|
|
28
23
|
this.OuterEnv = outer;
|
|
29
24
|
}
|
|
30
|
-
|
|
31
25
|
HasBinding(name) {
|
|
32
26
|
return this.bindingSet.has(name);
|
|
33
27
|
}
|
|
34
|
-
|
|
35
28
|
CreateBinding(name) {
|
|
36
29
|
this.bindingSet.add(name);
|
|
37
30
|
}
|
|
38
|
-
|
|
39
31
|
}
|
|
40
|
-
|
|
41
32
|
exports.AnalysisEnvironment = AnalysisEnvironment;
|
|
42
33
|
//# sourceMappingURL=AnalysisContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnalysisContext.js","names":["AnalysisContext","AnalysisEnvironment","constructor","outer","Set","OuterEnv","HasBinding","name","bindingSet","has","CreateBinding","add"],"sources":["../../src/AnalysisContext.ts"],"sourcesContent":["import {\n ArrowFunctionExpression,\n Expression,\n FunctionDeclaration,\n FunctionExpression,\n Statement,\n} from \"@babel/types\";\n\n// https://tc39.es/ecma262/#sec-execution-contexts\nexport class AnalysisContext {\n VariableEnvironment: AnalysisEnvironment;\n LexicalEnvironment: AnalysisEnvironment;\n}\n\n// https://tc39.es/ecma262/#sec-environment-records\nexport class AnalysisEnvironment {\n readonly OuterEnv: AnalysisEnvironment;\n private readonly bindingSet = new Set<string>();\n\n constructor(outer: AnalysisEnvironment) {\n this.OuterEnv = outer;\n }\n\n HasBinding(name: string): boolean {\n return this.bindingSet.has(name);\n }\n\n CreateBinding(name: string): void {\n this.bindingSet.add(name);\n }\n}\n\nexport interface AnalysisFunctionObject {\n Function: FunctionDeclaration | FunctionExpression | ArrowFunctionExpression;\n FormalParameters: FunctionDeclaration[\"params\"];\n ECMAScriptCode: Statement[] | Expression;\n Environment: AnalysisEnvironment;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"AnalysisContext.js","names":["AnalysisContext","AnalysisEnvironment","constructor","outer","Set","OuterEnv","HasBinding","name","bindingSet","has","CreateBinding","add"],"sources":["../../src/AnalysisContext.ts"],"sourcesContent":["import {\n ArrowFunctionExpression,\n Expression,\n FunctionDeclaration,\n FunctionExpression,\n Statement,\n} from \"@babel/types\";\n\n// https://tc39.es/ecma262/#sec-execution-contexts\nexport class AnalysisContext {\n VariableEnvironment: AnalysisEnvironment;\n LexicalEnvironment: AnalysisEnvironment;\n}\n\n// https://tc39.es/ecma262/#sec-environment-records\nexport class AnalysisEnvironment {\n readonly OuterEnv: AnalysisEnvironment;\n private readonly bindingSet = new Set<string>();\n\n constructor(outer: AnalysisEnvironment) {\n this.OuterEnv = outer;\n }\n\n HasBinding(name: string): boolean {\n return this.bindingSet.has(name);\n }\n\n CreateBinding(name: string): void {\n this.bindingSet.add(name);\n }\n}\n\nexport interface AnalysisFunctionObject {\n Function: FunctionDeclaration | FunctionExpression | ArrowFunctionExpression;\n FormalParameters: FunctionDeclaration[\"params\"];\n ECMAScriptCode: Statement[] | Expression;\n Environment: AnalysisEnvironment;\n}\n"],"mappings":";;;;;;;;AAQA;AACO,MAAMA,eAAe,CAAC;EAAA;IAAA;IAAA;EAAA;AAG7B;;AAEA;AAAA;AACO,MAAMC,mBAAmB,CAAC;EAI/BC,WAAW,CAACC,KAA0B,EAAE;IAAA;IAAA,kDAFV,IAAIC,GAAG,EAAU;IAG7C,IAAI,CAACC,QAAQ,GAAGF,KAAK;EACvB;EAEAG,UAAU,CAACC,IAAY,EAAW;IAChC,OAAO,IAAI,CAACC,UAAU,CAACC,GAAG,CAACF,IAAI,CAAC;EAClC;EAEAG,aAAa,CAACH,IAAY,EAAQ;IAChC,IAAI,CAACC,UAAU,CAACG,GAAG,CAACJ,IAAI,CAAC;EAC3B;AACF;AAAC"}
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.IsConstructor = exports.FunctionEnvironment = exports.FormalParameters = exports.ExecutionContext = exports.EnvironmentRecord = exports.Environment = exports.Empty = exports.ECMAScriptCode = exports.DeclarativeEnvironment = exports.CompletionRecord = void 0;
|
|
9
8
|
exports.NormalCompletion = NormalCompletion;
|
|
10
9
|
exports.SourceNode = exports.ReferenceRecord = void 0;
|
|
11
|
-
|
|
12
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
-
|
|
14
11
|
// https://tc39.es/ecma262/#sec-execution-contexts
|
|
15
12
|
class ExecutionContext {
|
|
16
13
|
constructor() {
|
|
@@ -18,11 +15,8 @@ class ExecutionContext {
|
|
|
18
15
|
(0, _defineProperty2.default)(this, "LexicalEnvironment", void 0);
|
|
19
16
|
(0, _defineProperty2.default)(this, "Function", void 0);
|
|
20
17
|
}
|
|
21
|
-
|
|
22
18
|
}
|
|
23
|
-
|
|
24
19
|
exports.ExecutionContext = ExecutionContext;
|
|
25
|
-
|
|
26
20
|
// https://tc39.es/ecma262/#sec-environment-records
|
|
27
21
|
class EnvironmentRecord {
|
|
28
22
|
constructor(outer) {
|
|
@@ -30,11 +24,9 @@ class EnvironmentRecord {
|
|
|
30
24
|
(0, _defineProperty2.default)(this, "bindingMap", new Map());
|
|
31
25
|
this.OuterEnv = outer;
|
|
32
26
|
}
|
|
33
|
-
|
|
34
27
|
HasBinding(name) {
|
|
35
28
|
return this.bindingMap.has(name);
|
|
36
29
|
}
|
|
37
|
-
|
|
38
30
|
CreateMutableBinding(name, deletable) {
|
|
39
31
|
// Assert: binding does not exist.
|
|
40
32
|
this.bindingMap.set(name, {
|
|
@@ -43,6 +35,7 @@ class EnvironmentRecord {
|
|
|
43
35
|
});
|
|
44
36
|
return NormalCompletion(undefined);
|
|
45
37
|
}
|
|
38
|
+
|
|
46
39
|
/**
|
|
47
40
|
* Create an immutable binding.
|
|
48
41
|
*
|
|
@@ -50,8 +43,6 @@ class EnvironmentRecord {
|
|
|
50
43
|
* @param strict - For named function expressions, strict is false, otherwise it's true.
|
|
51
44
|
* @returns CompletionRecord.
|
|
52
45
|
*/
|
|
53
|
-
|
|
54
|
-
|
|
55
46
|
CreateImmutableBinding(name, strict) {
|
|
56
47
|
// Assert: binding does not exist.
|
|
57
48
|
this.bindingMap.set(name, {
|
|
@@ -59,16 +50,16 @@ class EnvironmentRecord {
|
|
|
59
50
|
});
|
|
60
51
|
return NormalCompletion(undefined);
|
|
61
52
|
}
|
|
62
|
-
|
|
63
53
|
InitializeBinding(name, value) {
|
|
64
|
-
const binding = this.bindingMap.get(name);
|
|
65
|
-
|
|
54
|
+
const binding = this.bindingMap.get(name);
|
|
55
|
+
// Assert: binding exists and uninitialized.
|
|
66
56
|
Object.assign(binding, {
|
|
67
57
|
initialized: true,
|
|
68
58
|
value
|
|
69
59
|
});
|
|
70
60
|
return NormalCompletion(undefined);
|
|
71
61
|
}
|
|
62
|
+
|
|
72
63
|
/**
|
|
73
64
|
* Update a mutable binding value, including function declarations.
|
|
74
65
|
*
|
|
@@ -77,11 +68,9 @@ class EnvironmentRecord {
|
|
|
77
68
|
* @param strict - For functions, strict is always false, otherwise it depends on strict-mode.
|
|
78
69
|
* @returns
|
|
79
70
|
*/
|
|
80
|
-
|
|
81
|
-
|
|
82
71
|
SetMutableBinding(name, value, strict) {
|
|
83
|
-
const binding = this.bindingMap.get(name);
|
|
84
|
-
|
|
72
|
+
const binding = this.bindingMap.get(name);
|
|
73
|
+
// Assert: binding exists.
|
|
85
74
|
if (!binding.initialized) {
|
|
86
75
|
throw new ReferenceError(`${name} is not initialized`);
|
|
87
76
|
} else if (binding.mutable) {
|
|
@@ -89,30 +78,21 @@ class EnvironmentRecord {
|
|
|
89
78
|
} else {
|
|
90
79
|
throw new TypeError(`Assignment to constant variable`);
|
|
91
80
|
}
|
|
92
|
-
|
|
93
81
|
return NormalCompletion(undefined);
|
|
94
82
|
}
|
|
95
|
-
|
|
96
83
|
GetBindingValue(name, strict) {
|
|
97
|
-
const binding = this.bindingMap.get(name);
|
|
98
|
-
|
|
84
|
+
const binding = this.bindingMap.get(name);
|
|
85
|
+
// Assert: binding exists.
|
|
99
86
|
if (!binding.initialized) {
|
|
100
87
|
throw new ReferenceError(`${name} is not initialized`);
|
|
101
88
|
}
|
|
102
|
-
|
|
103
89
|
return binding.value;
|
|
104
90
|
}
|
|
105
|
-
|
|
106
91
|
}
|
|
107
|
-
|
|
108
92
|
exports.EnvironmentRecord = EnvironmentRecord;
|
|
109
|
-
|
|
110
93
|
class DeclarativeEnvironment extends EnvironmentRecord {}
|
|
111
|
-
|
|
112
94
|
exports.DeclarativeEnvironment = DeclarativeEnvironment;
|
|
113
|
-
|
|
114
95
|
class FunctionEnvironment extends EnvironmentRecord {}
|
|
115
|
-
|
|
116
96
|
exports.FunctionEnvironment = FunctionEnvironment;
|
|
117
97
|
const SourceNode = Symbol.for("SourceNode");
|
|
118
98
|
exports.SourceNode = SourceNode;
|
|
@@ -124,10 +104,10 @@ const Environment = Symbol.for("Environment");
|
|
|
124
104
|
exports.Environment = Environment;
|
|
125
105
|
const IsConstructor = Symbol.for("IsConstructor");
|
|
126
106
|
exports.IsConstructor = IsConstructor;
|
|
127
|
-
|
|
128
107
|
// https://tc39.es/ecma262/#sec-reference-record-specification-type
|
|
129
108
|
class ReferenceRecord {
|
|
130
109
|
/** Whether the reference is in strict mode. */
|
|
110
|
+
|
|
131
111
|
constructor(base, referenceName, strict) {
|
|
132
112
|
(0, _defineProperty2.default)(this, "Base", void 0);
|
|
133
113
|
(0, _defineProperty2.default)(this, "ReferenceName", void 0);
|
|
@@ -136,12 +116,10 @@ class ReferenceRecord {
|
|
|
136
116
|
this.ReferenceName = referenceName;
|
|
137
117
|
this.Strict = strict;
|
|
138
118
|
}
|
|
119
|
+
}
|
|
139
120
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
121
|
+
// https://tc39.es/ecma262/#sec-completion-record-specification-type
|
|
143
122
|
exports.ReferenceRecord = ReferenceRecord;
|
|
144
|
-
|
|
145
123
|
class CompletionRecord {
|
|
146
124
|
constructor(type, value) {
|
|
147
125
|
(0, _defineProperty2.default)(this, "Type", void 0);
|
|
@@ -149,16 +127,12 @@ class CompletionRecord {
|
|
|
149
127
|
this.Type = type;
|
|
150
128
|
this.Value = value;
|
|
151
129
|
}
|
|
152
|
-
|
|
153
130
|
}
|
|
154
|
-
|
|
155
131
|
exports.CompletionRecord = CompletionRecord;
|
|
156
|
-
|
|
157
132
|
// https://tc39.es/ecma262/#sec-normalcompletion
|
|
158
133
|
function NormalCompletion(value) {
|
|
159
134
|
return new CompletionRecord("normal", value);
|
|
160
135
|
}
|
|
161
|
-
|
|
162
136
|
const Empty = Symbol("empty completion");
|
|
163
137
|
exports.Empty = Empty;
|
|
164
138
|
//# sourceMappingURL=ExecutionContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExecutionContext.js","names":["ExecutionContext","EnvironmentRecord","constructor","outer","Map","OuterEnv","HasBinding","name","bindingMap","has","CreateMutableBinding","deletable","set","mutable","NormalCompletion","undefined","CreateImmutableBinding","strict","InitializeBinding","value","binding","get","Object","assign","initialized","SetMutableBinding","ReferenceError","TypeError","GetBindingValue","DeclarativeEnvironment","FunctionEnvironment","SourceNode","Symbol","for","FormalParameters","ECMAScriptCode","Environment","IsConstructor","ReferenceRecord","base","referenceName","Base","ReferenceName","Strict","CompletionRecord","type","Type","Value","Empty"],"sources":["../../src/ExecutionContext.ts"],"sourcesContent":["import {\n ArrowFunctionExpression,\n Expression,\n FunctionDeclaration,\n FunctionExpression,\n Statement,\n} from \"@babel/types\";\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;\n private readonly bindingMap = new Map<string, BindingState>();\n\n constructor(outer: EnvironmentRecord) {\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);\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);\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);\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\");\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}\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":"
|
|
1
|
+
{"version":3,"file":"ExecutionContext.js","names":["ExecutionContext","EnvironmentRecord","constructor","outer","Map","OuterEnv","HasBinding","name","bindingMap","has","CreateMutableBinding","deletable","set","mutable","NormalCompletion","undefined","CreateImmutableBinding","strict","InitializeBinding","value","binding","get","Object","assign","initialized","SetMutableBinding","ReferenceError","TypeError","GetBindingValue","DeclarativeEnvironment","FunctionEnvironment","SourceNode","Symbol","for","FormalParameters","ECMAScriptCode","Environment","IsConstructor","ReferenceRecord","base","referenceName","Base","ReferenceName","Strict","CompletionRecord","type","Type","Value","Empty"],"sources":["../../src/ExecutionContext.ts"],"sourcesContent":["import {\n ArrowFunctionExpression,\n Expression,\n FunctionDeclaration,\n FunctionExpression,\n Statement,\n} from \"@babel/types\";\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;\n private readonly bindingMap = new Map<string, BindingState>();\n\n constructor(outer: EnvironmentRecord) {\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);\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);\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);\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\");\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}\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":";;;;;;;;;;AAQA;AACO,MAAMA,gBAAgB,CAAC;EAAA;IAAA;IAAA;IAAA;EAAA;AAI9B;AAAC;AAID;AACO,MAAMC,iBAAiB,CAAC;EAI7BC,WAAW,CAACC,KAAwB,EAAE;IAAA;IAAA,kDAFR,IAAIC,GAAG,EAAwB;IAG3D,IAAI,CAACC,QAAQ,GAAGF,KAAK;EACvB;EAEAG,UAAU,CAACC,IAAY,EAAW;IAChC,OAAO,IAAI,CAACC,UAAU,CAACC,GAAG,CAACF,IAAI,CAAC;EAClC;EAEAG,oBAAoB,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,sBAAsB,CAACT,IAAY,EAAEU,MAAe,EAAoB;IACtE;IACA,IAAI,CAACT,UAAU,CAACI,GAAG,CAACL,IAAI,EAAE;MACxBU;IACF,CAAC,CAAC;IACF,OAAOH,gBAAgB,CAACC,SAAS,CAAC;EACpC;EAEAG,iBAAiB,CAACX,IAAY,EAAEY,KAAc,EAA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AC;AACxD,MAAME,cAAc,GAAGH,MAAM,CAACC,GAAG,CAAC,gBAAgB,CAAC;AAAC;AACpD,MAAMG,WAAW,GAAGJ,MAAM,CAACC,GAAG,CAAC,aAAa,CAAC;AAAC;AAC9C,MAAMI,aAAa,GAAGL,MAAM,CAACC,GAAG,CAAC,eAAe,CAAC;AAAC;AAczD;AACO,MAAMK,eAAe,CAAC;EAM3B;;EAGApC,WAAW,CACTqC,IAAuE,EACvEC,aAA0B,EAC1BvB,MAAe,EACf;IAAA;IAAA;IAAA;IACA,IAAI,CAACwB,IAAI,GAAGF,IAAI;IAChB,IAAI,CAACG,aAAa,GAAGF,aAAa;IAClC,IAAI,CAACG,MAAM,GAAG1B,MAAM;EACtB;AACF;;AAEA;AAAA;AACO,MAAM2B,gBAAgB,CAAC;EAI5B1C,WAAW,CAAC2C,IAA0B,EAAE1B,KAAc,EAAE;IAAA;IAAA;IACtD,IAAI,CAAC2B,IAAI,GAAGD,IAAI;IAChB,IAAI,CAACE,KAAK,GAAG5B,KAAK;EACpB;AACF;AAAC;AASD;AACO,SAASL,gBAAgB,CAACK,KAAc,EAAoB;EACjE,OAAO,IAAIyB,gBAAgB,CAAC,QAAQ,EAAEzB,KAAK,CAAC;AAC9C;AAEO,MAAM6B,KAAK,GAAGhB,MAAM,CAAC,kBAAkB,CAAC;AAAC"}
|
package/dist/cjs/context-free.js
CHANGED
|
@@ -20,47 +20,39 @@ exports.RequireObjectCoercible = RequireObjectCoercible;
|
|
|
20
20
|
exports.ToPropertyKey = ToPropertyKey;
|
|
21
21
|
exports.UpdateEmpty = UpdateEmpty;
|
|
22
22
|
exports.isIterable = isIterable;
|
|
23
|
-
|
|
24
23
|
var _ExecutionContext = require("./ExecutionContext");
|
|
25
|
-
|
|
26
24
|
var _traverse = require("./traverse");
|
|
27
|
-
|
|
28
25
|
// https://tc39.es/ecma262/#sec-ispropertyreference
|
|
29
26
|
function IsPropertyReference(V) {
|
|
30
27
|
return V.Base !== "unresolvable" && !(V.Base instanceof _ExecutionContext.EnvironmentRecord);
|
|
31
|
-
}
|
|
32
|
-
|
|
28
|
+
}
|
|
33
29
|
|
|
30
|
+
// https://tc39.es/ecma262/#sec-initializereferencedbinding
|
|
34
31
|
function InitializeReferencedBinding(V, W) {
|
|
35
32
|
const base = V.Base;
|
|
36
33
|
return base.InitializeBinding(V.ReferenceName, W);
|
|
37
|
-
}
|
|
38
|
-
|
|
34
|
+
}
|
|
39
35
|
|
|
36
|
+
// https://tc39.es/ecma262/#sec-copydataproperties
|
|
40
37
|
function CopyDataProperties(target, source, excludedItems) {
|
|
41
38
|
if (source === undefined || source === null) {
|
|
42
39
|
return target;
|
|
43
40
|
}
|
|
44
|
-
|
|
45
41
|
const keys = Object.getOwnPropertyNames(source).concat(Object.getOwnPropertySymbols(source));
|
|
46
|
-
|
|
47
42
|
for (const nextKey of keys) {
|
|
48
43
|
if (!excludedItems.has(nextKey)) {
|
|
49
44
|
const desc = Object.getOwnPropertyDescriptor(source, nextKey);
|
|
50
|
-
|
|
51
45
|
if (desc !== null && desc !== void 0 && desc.enumerable) {
|
|
52
46
|
target[nextKey] = source[nextKey];
|
|
53
47
|
}
|
|
54
48
|
}
|
|
55
49
|
}
|
|
56
|
-
|
|
57
50
|
return target;
|
|
58
|
-
}
|
|
59
|
-
|
|
51
|
+
}
|
|
60
52
|
|
|
53
|
+
// https://tc39.es/ecma262/#sec-runtime-semantics-fordeclarationbindinginstantiation
|
|
61
54
|
function ForDeclarationBindingInstantiation(forDeclaration, env) {
|
|
62
55
|
const isConst = forDeclaration.kind === "const";
|
|
63
|
-
|
|
64
56
|
for (const name of (0, _traverse.collectBoundNames)(forDeclaration)) {
|
|
65
57
|
if (isConst) {
|
|
66
58
|
env.CreateImmutableBinding(name, true);
|
|
@@ -68,153 +60,128 @@ function ForDeclarationBindingInstantiation(forDeclaration, env) {
|
|
|
68
60
|
env.CreateMutableBinding(name, false);
|
|
69
61
|
}
|
|
70
62
|
}
|
|
71
|
-
}
|
|
72
|
-
|
|
63
|
+
}
|
|
73
64
|
|
|
65
|
+
// https://tc39.es/ecma262/#sec-loopcontinues
|
|
74
66
|
function LoopContinues(completion) {
|
|
75
67
|
return completion.Type === "normal" || completion.Type == "continue";
|
|
76
|
-
}
|
|
77
|
-
|
|
68
|
+
}
|
|
78
69
|
|
|
70
|
+
// https://tc39.es/ecma262/#sec-updateempty
|
|
79
71
|
function UpdateEmpty(completion, value) {
|
|
80
72
|
if (completion.Value !== _ExecutionContext.Empty) {
|
|
81
73
|
return completion;
|
|
82
74
|
}
|
|
83
|
-
|
|
84
75
|
return new _ExecutionContext.CompletionRecord(completion.Type, value);
|
|
85
|
-
}
|
|
86
|
-
|
|
76
|
+
}
|
|
87
77
|
|
|
78
|
+
// https://tc39.es/ecma262/#sec-getvalue
|
|
88
79
|
function GetValue(V) {
|
|
89
80
|
if (V instanceof _ExecutionContext.CompletionRecord) {
|
|
90
81
|
// Assert: V.Type is normal.
|
|
91
82
|
V = V.Value;
|
|
92
83
|
}
|
|
93
|
-
|
|
94
84
|
if (!(V instanceof _ExecutionContext.ReferenceRecord)) {
|
|
95
85
|
return V;
|
|
96
86
|
}
|
|
97
|
-
|
|
98
87
|
if (V.Base === "unresolvable") {
|
|
99
88
|
throw new ReferenceError(`${V.ReferenceName} is not defined`);
|
|
100
89
|
}
|
|
101
|
-
|
|
102
90
|
if (V.Base instanceof _ExecutionContext.EnvironmentRecord) {
|
|
103
91
|
const base = V.Base;
|
|
104
92
|
return base.GetBindingValue(V.ReferenceName, V.Strict);
|
|
105
93
|
}
|
|
106
|
-
|
|
107
94
|
return V.Base[V.ReferenceName];
|
|
108
|
-
}
|
|
109
|
-
|
|
95
|
+
}
|
|
110
96
|
|
|
97
|
+
// https://tc39.es/ecma262/#sec-topropertykey
|
|
111
98
|
function ToPropertyKey(arg) {
|
|
112
99
|
if (typeof arg === "symbol") {
|
|
113
100
|
return arg;
|
|
114
101
|
}
|
|
115
|
-
|
|
116
102
|
return String(arg);
|
|
117
|
-
}
|
|
118
|
-
|
|
103
|
+
}
|
|
119
104
|
|
|
105
|
+
// https://tc39.es/ecma262/#sec-getv
|
|
120
106
|
function GetV(V, P) {
|
|
121
107
|
return V[P];
|
|
122
|
-
}
|
|
123
|
-
|
|
108
|
+
}
|
|
124
109
|
|
|
110
|
+
// https://tc39.es/ecma262/#sec-putvalue
|
|
125
111
|
function PutValue(V, W) {
|
|
126
112
|
// Assert: V is a ReferenceRecord.
|
|
127
113
|
if (V.Base === "unresolvable") {
|
|
128
114
|
throw new ReferenceError(`${V.ReferenceName} is not defined`);
|
|
129
115
|
}
|
|
130
|
-
|
|
131
116
|
if (V.Base instanceof _ExecutionContext.EnvironmentRecord) {
|
|
132
117
|
return V.Base.SetMutableBinding(V.ReferenceName, W, V.Strict);
|
|
133
118
|
}
|
|
134
|
-
|
|
135
119
|
V.Base[V.ReferenceName] = W;
|
|
136
120
|
return (0, _ExecutionContext.NormalCompletion)(undefined);
|
|
137
|
-
}
|
|
138
|
-
|
|
121
|
+
}
|
|
139
122
|
|
|
123
|
+
// https://tc39.es/ecma262/#sec-createlistiteratorRecord
|
|
140
124
|
function CreateListIteratorRecord(args) {
|
|
141
125
|
if (!isIterable(args)) {
|
|
142
126
|
throw new TypeError(`${typeof args} is not iterable`);
|
|
143
127
|
}
|
|
144
|
-
|
|
145
128
|
return args[Symbol.iterator]();
|
|
146
|
-
}
|
|
147
|
-
|
|
129
|
+
}
|
|
148
130
|
|
|
131
|
+
// https://tc39.es/ecma262/#sec-requireobjectcoercible
|
|
149
132
|
function RequireObjectCoercible(arg) {
|
|
150
133
|
if (arg === null || arg === undefined) {
|
|
151
134
|
throw new TypeError("Cannot destructure properties of undefined or null");
|
|
152
135
|
}
|
|
153
|
-
}
|
|
154
|
-
|
|
136
|
+
}
|
|
155
137
|
|
|
138
|
+
// https://tc39.es/ecma262/#sec-getidentifierreference
|
|
156
139
|
function GetIdentifierReference(env, name, strict) {
|
|
157
140
|
if (!env) {
|
|
158
141
|
return new _ExecutionContext.ReferenceRecord("unresolvable", name, strict);
|
|
159
142
|
}
|
|
160
|
-
|
|
161
143
|
if (env.HasBinding(name)) {
|
|
162
144
|
return new _ExecutionContext.ReferenceRecord(env, name, strict);
|
|
163
145
|
}
|
|
164
|
-
|
|
165
146
|
return GetIdentifierReference(env.OuterEnv, name, strict);
|
|
166
|
-
}
|
|
167
|
-
|
|
147
|
+
}
|
|
168
148
|
|
|
149
|
+
// https://tc39.es/ecma262/#sec-applystringornumericbinaryoperator
|
|
169
150
|
function ApplyStringOrNumericBinaryOperator(leftValue, operator, rightValue) {
|
|
170
151
|
switch (operator) {
|
|
171
152
|
case "+":
|
|
172
153
|
return leftValue + rightValue;
|
|
173
|
-
|
|
174
154
|
case "-":
|
|
175
155
|
return leftValue - rightValue;
|
|
176
|
-
|
|
177
156
|
case "/":
|
|
178
157
|
return leftValue / rightValue;
|
|
179
|
-
|
|
180
158
|
case "%":
|
|
181
159
|
return leftValue % rightValue;
|
|
182
|
-
|
|
183
160
|
case "*":
|
|
184
161
|
return leftValue * rightValue;
|
|
185
|
-
|
|
186
162
|
case "**":
|
|
187
163
|
return leftValue ** rightValue;
|
|
188
|
-
|
|
189
164
|
case "==":
|
|
190
165
|
return leftValue == rightValue;
|
|
191
|
-
|
|
192
166
|
case "===":
|
|
193
167
|
return leftValue === rightValue;
|
|
194
|
-
|
|
195
168
|
case "!=":
|
|
196
169
|
return leftValue != rightValue;
|
|
197
|
-
|
|
198
170
|
case "!==":
|
|
199
171
|
return leftValue !== rightValue;
|
|
200
|
-
|
|
201
172
|
case ">":
|
|
202
173
|
return leftValue > rightValue;
|
|
203
|
-
|
|
204
174
|
case "<":
|
|
205
175
|
return leftValue < rightValue;
|
|
206
|
-
|
|
207
176
|
case ">=":
|
|
208
177
|
return leftValue >= rightValue;
|
|
209
|
-
|
|
210
178
|
case "<=":
|
|
211
179
|
return leftValue <= rightValue;
|
|
212
180
|
}
|
|
213
|
-
|
|
214
181
|
throw new SyntaxError(`Unsupported binary operator \`${operator}\``);
|
|
215
|
-
}
|
|
216
|
-
|
|
182
|
+
}
|
|
217
183
|
|
|
184
|
+
// https://tc39.es/ecma262/#sec-assignment-operators
|
|
218
185
|
function ApplyStringOrNumericAssignment(leftValue, operator, rightValue) {
|
|
219
186
|
switch (operator) {
|
|
220
187
|
case "+=":
|
|
@@ -225,38 +192,30 @@ function ApplyStringOrNumericAssignment(leftValue, operator, rightValue) {
|
|
|
225
192
|
case "**=":
|
|
226
193
|
return ApplyStringOrNumericBinaryOperator(leftValue, operator.substr(0, operator.length - 1), rightValue);
|
|
227
194
|
}
|
|
228
|
-
|
|
229
195
|
throw new SyntaxError(`Unsupported assignment operator \`${operator}\``);
|
|
230
|
-
}
|
|
231
|
-
|
|
196
|
+
}
|
|
232
197
|
|
|
198
|
+
// https://tc39.es/ecma262/#sec-unary-operators
|
|
233
199
|
function ApplyUnaryOperator(target, operator) {
|
|
234
200
|
switch (operator) {
|
|
235
201
|
case "!":
|
|
236
202
|
return !target;
|
|
237
|
-
|
|
238
203
|
case "+":
|
|
239
204
|
return +target;
|
|
240
|
-
|
|
241
205
|
case "-":
|
|
242
206
|
return -target;
|
|
243
|
-
|
|
244
207
|
case "void":
|
|
245
208
|
return undefined;
|
|
246
209
|
}
|
|
247
|
-
|
|
248
210
|
throw new SyntaxError(`Unsupported unary operator \`${operator}\``);
|
|
249
211
|
}
|
|
250
|
-
|
|
251
212
|
function isIterable(cooked) {
|
|
252
213
|
if (Array.isArray(cooked)) {
|
|
253
214
|
return true;
|
|
254
215
|
}
|
|
255
|
-
|
|
256
216
|
if (cooked === null || cooked === undefined) {
|
|
257
217
|
return false;
|
|
258
218
|
}
|
|
259
|
-
|
|
260
219
|
return typeof cooked[Symbol.iterator] === "function";
|
|
261
220
|
}
|
|
262
221
|
//# sourceMappingURL=context-free.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-free.js","names":["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\";\nimport { collectBoundNames } from \"./traverse\";\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(V: unknown): 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,\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;\n case \"-\":\n return -target;\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;;AAOA;;AAEA;AACO,SAASA,mBAAT,CAA6BC,CAA7B,EAA0D;EAC/D,OAAOA,CAAC,CAACC,IAAF,KAAW,cAAX,IAA6B,EAAED,CAAC,CAACC,IAAF,YAAkBC,mCAApB,CAApC;AACD,C,CAED;;;AACO,SAASC,2BAAT,CACLH,CADK,EAELI,CAFK,EAGa;EAClB,MAAMC,IAAI,GAAGL,CAAC,CAACC,IAAf;EACA,OAAOI,IAAI,CAACC,iBAAL,CAAuBN,CAAC,CAACO,aAAzB,EAAkDH,CAAlD,CAAP;AACD,C,CAED;;;AACO,SAASI,kBAAT,CACLC,MADK,EAELC,MAFK,EAGLC,aAHK,EAIyB;EAC9B,IAAID,MAAM,KAAKE,SAAX,IAAwBF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;IACF,KAAK,GAAL;MACE,OAAO,CAACA,MAAR;;IACF,KAAK,GAAL;MACE,OAAO,CAACA,MAAR;;IACF,KAAK,MAAL;MACE,OAAOG,SAAP;EARJ;;EAUA,MAAM,IAAIwD,WAAJ,CAAiB,gCAA+BF,QAAS,IAAzD,CAAN;AACD;;AAEM,SAASX,UAAT,CAAoBkB,MAApB,EAA8C;EACnD,IAAIC,KAAK,CAACC,OAAN,CAAcF,MAAd,CAAJ,EAA2B;IACzB,OAAO,IAAP;EACD;;EACD,IAAIA,MAAM,KAAK,IAAX,IAAmBA,MAAM,KAAK7D,SAAlC,EAA6C;IAC3C,OAAO,KAAP;EACD;;EACD,OAAO,OAAQ6D,MAAD,CAA8BhB,MAAM,CAACC,QAArC,CAAP,KAA0D,UAAjE;AACD"}
|
|
1
|
+
{"version":3,"file":"context-free.js","names":["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\";\nimport { collectBoundNames } from \"./traverse\";\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(V: unknown): 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,\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;\n case \"-\":\n return -target;\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;AAOA;AAEA;AACO,SAASA,mBAAmB,CAACC,CAAkB,EAAW;EAC/D,OAAOA,CAAC,CAACC,IAAI,KAAK,cAAc,IAAI,EAAED,CAAC,CAACC,IAAI,YAAYC,mCAAiB,CAAC;AAC5E;;AAEA;AACO,SAASC,2BAA2B,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,kBAAkB,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,CAAC,CACrC;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,MAAM,CAAkCQ,OAAO,CAAC;MACrE;IACF;EACF;EACA,OAAOT,MAAM;AACf;;AAEA;AACO,SAASc,kCAAkC,CAChDC,cAAmC,EACnCC,GAAsB,EAChB;EACN,MAAMC,OAAO,GAAGF,cAAc,CAACG,IAAI,KAAK,OAAO;EAC/C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