@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
package/dist/cjs/sanitize.js
CHANGED
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.isAllowedConstructor = isAllowedConstructor;
|
|
7
7
|
exports.sanitize = sanitize;
|
|
8
|
-
|
|
9
8
|
// Ref https://github.com/tc39/proposal-global
|
|
10
9
|
// In addition, the es6-shim had to switch from Function('return this')()
|
|
11
10
|
// due to CSP concerns, such that the current check to handle browsers,
|
|
@@ -19,40 +18,37 @@ function getGlobal() {
|
|
|
19
18
|
if (typeof self !== "undefined") {
|
|
20
19
|
return self;
|
|
21
20
|
}
|
|
22
|
-
|
|
23
21
|
if (typeof window !== "undefined") {
|
|
24
22
|
return window;
|
|
25
23
|
}
|
|
26
|
-
|
|
27
24
|
if (typeof global !== "undefined") {
|
|
28
25
|
return global;
|
|
29
26
|
}
|
|
30
|
-
|
|
31
27
|
throw new Error("unable to locate global object");
|
|
32
28
|
}
|
|
29
|
+
|
|
33
30
|
/**
|
|
34
31
|
* There are chances to construct a `Function` from a string, etc.
|
|
35
32
|
* ```
|
|
36
33
|
* ((a,b)=>a[b])(()=>1, 'constructor')('console.log(`yo`)')()
|
|
37
34
|
* ```
|
|
38
35
|
*/
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
Object,
|
|
44
|
-
|
|
36
|
+
const reservedObjects = new WeakSet([
|
|
37
|
+
// `Function("...")` is considered *extremely vulnerable*.
|
|
38
|
+
Function,
|
|
39
|
+
// `Object.assign()` is considered vulnerable.
|
|
40
|
+
Object,
|
|
41
|
+
// `prototype` is considered vulnerable.
|
|
42
|
+
Function.prototype, Object.prototype,
|
|
43
|
+
// Global `window` is considered vulnerable, too.
|
|
45
44
|
getGlobal()]);
|
|
46
|
-
|
|
47
45
|
function sanitize(cooked) {
|
|
48
46
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
49
47
|
if (reservedObjects.has(cooked)) {
|
|
50
48
|
throw new TypeError("Cannot access reserved objects such as `Function`.");
|
|
51
49
|
}
|
|
52
50
|
}
|
|
53
|
-
|
|
54
51
|
const allowedConstructors = new WeakSet([Array, Map, Set, URLSearchParams, WeakMap, WeakSet]);
|
|
55
|
-
|
|
56
52
|
function isAllowedConstructor(constructor) {
|
|
57
53
|
// `Date` maybe mocked when running tests for storyboard functions.
|
|
58
54
|
return allowedConstructors.has(constructor) || constructor === Date;
|
package/dist/cjs/sanitize.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sanitize.js","names":["getGlobal","self","window","global","Error","reservedObjects","WeakSet","Function","Object","prototype","sanitize","cooked","has","TypeError","allowedConstructors","Array","Map","Set","URLSearchParams","WeakMap","isAllowedConstructor","constructor","Date"],"sources":["../../src/sanitize.ts"],"sourcesContent":["// Ref https://github.com/tc39/proposal-global\n// In addition, the es6-shim had to switch from Function('return this')()\n// due to CSP concerns, such that the current check to handle browsers,\n// node, web workers, and frames is:\n// istanbul ignore next\n// eslint-disable-next-line @typescript-eslint/ban-types\nfunction getGlobal(): object {\n // the only reliable means to get the global object is\n // `Function('return this')()`\n // However, this causes CSP violations in Chrome apps.\n if (typeof self !== \"undefined\") {\n return self;\n }\n if (typeof window !== \"undefined\") {\n return window;\n }\n if (typeof global !== \"undefined\") {\n return global;\n }\n throw new Error(\"unable to locate global object\");\n}\n\n/**\n * There are chances to construct a `Function` from a string, etc.\n * ```\n * ((a,b)=>a[b])(()=>1, 'constructor')('console.log(`yo`)')()\n * ```\n */\nconst reservedObjects = new WeakSet([\n // `Function(\"...\")` is considered *extremely vulnerable*.\n Function,\n // `Object.assign()` is considered vulnerable.\n Object,\n // `prototype` is considered vulnerable.\n Function.prototype,\n Object.prototype,\n // Global `window` is considered vulnerable, too.\n getGlobal(),\n]);\n\nexport function sanitize(cooked: unknown): void {\n // eslint-disable-next-line @typescript-eslint/ban-types\n if (reservedObjects.has(cooked as object)) {\n throw new TypeError(\"Cannot access reserved objects such as `Function`.\");\n }\n}\n\nconst allowedConstructors = new WeakSet([\n Array,\n Map,\n Set,\n URLSearchParams,\n WeakMap,\n WeakSet,\n]);\n\nexport function isAllowedConstructor(constructor: unknown): boolean {\n // `Date` maybe mocked when running tests for storyboard functions.\n return (\n allowedConstructors.has(constructor as ArrayConstructor) ||\n constructor === Date\n );\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"sanitize.js","names":["getGlobal","self","window","global","Error","reservedObjects","WeakSet","Function","Object","prototype","sanitize","cooked","has","TypeError","allowedConstructors","Array","Map","Set","URLSearchParams","WeakMap","isAllowedConstructor","constructor","Date"],"sources":["../../src/sanitize.ts"],"sourcesContent":["// Ref https://github.com/tc39/proposal-global\n// In addition, the es6-shim had to switch from Function('return this')()\n// due to CSP concerns, such that the current check to handle browsers,\n// node, web workers, and frames is:\n// istanbul ignore next\n// eslint-disable-next-line @typescript-eslint/ban-types\nfunction getGlobal(): object {\n // the only reliable means to get the global object is\n // `Function('return this')()`\n // However, this causes CSP violations in Chrome apps.\n if (typeof self !== \"undefined\") {\n return self;\n }\n if (typeof window !== \"undefined\") {\n return window;\n }\n if (typeof global !== \"undefined\") {\n return global;\n }\n throw new Error(\"unable to locate global object\");\n}\n\n/**\n * There are chances to construct a `Function` from a string, etc.\n * ```\n * ((a,b)=>a[b])(()=>1, 'constructor')('console.log(`yo`)')()\n * ```\n */\nconst reservedObjects = new WeakSet([\n // `Function(\"...\")` is considered *extremely vulnerable*.\n Function,\n // `Object.assign()` is considered vulnerable.\n Object,\n // `prototype` is considered vulnerable.\n Function.prototype,\n Object.prototype,\n // Global `window` is considered vulnerable, too.\n getGlobal(),\n]);\n\nexport function sanitize(cooked: unknown): void {\n // eslint-disable-next-line @typescript-eslint/ban-types\n if (reservedObjects.has(cooked as object)) {\n throw new TypeError(\"Cannot access reserved objects such as `Function`.\");\n }\n}\n\nconst allowedConstructors = new WeakSet([\n Array,\n Map,\n Set,\n URLSearchParams,\n WeakMap,\n WeakSet,\n]);\n\nexport function isAllowedConstructor(constructor: unknown): boolean {\n // `Date` maybe mocked when running tests for storyboard functions.\n return (\n allowedConstructors.has(constructor as ArrayConstructor) ||\n constructor === Date\n );\n}\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,SAAS,GAAW;EAC3B;EACA;EACA;EACA,IAAI,OAAOC,IAAI,KAAK,WAAW,EAAE;IAC/B,OAAOA,IAAI;EACb;EACA,IAAI,OAAOC,MAAM,KAAK,WAAW,EAAE;IACjC,OAAOA,MAAM;EACf;EACA,IAAI,OAAOC,MAAM,KAAK,WAAW,EAAE;IACjC,OAAOA,MAAM;EACf;EACA,MAAM,IAAIC,KAAK,CAAC,gCAAgC,CAAC;AACnD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,eAAe,GAAG,IAAIC,OAAO,CAAC;AAClC;AACAC,QAAQ;AACR;AACAC,MAAM;AACN;AACAD,QAAQ,CAACE,SAAS,EAClBD,MAAM,CAACC,SAAS;AAChB;AACAT,SAAS,EAAE,CACZ,CAAC;AAEK,SAASU,QAAQ,CAACC,MAAe,EAAQ;EAC9C;EACA,IAAIN,eAAe,CAACO,GAAG,CAACD,MAAM,CAAW,EAAE;IACzC,MAAM,IAAIE,SAAS,CAAC,oDAAoD,CAAC;EAC3E;AACF;AAEA,MAAMC,mBAAmB,GAAG,IAAIR,OAAO,CAAC,CACtCS,KAAK,EACLC,GAAG,EACHC,GAAG,EACHC,eAAe,EACfC,OAAO,EACPb,OAAO,CACR,CAAC;AAEK,SAASc,oBAAoB,CAACC,WAAoB,EAAW;EAClE;EACA,OACEP,mBAAmB,CAACF,GAAG,CAACS,WAAW,CAAqB,IACxDA,WAAW,KAAKC,IAAI;AAExB"}
|
package/dist/cjs/traverse.js
CHANGED
|
@@ -6,10 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.collectBoundNames = collectBoundNames;
|
|
7
7
|
exports.collectScopedDeclarations = collectScopedDeclarations;
|
|
8
8
|
exports.containsExpression = containsExpression;
|
|
9
|
-
|
|
10
9
|
function collectBoundNames(root) {
|
|
11
10
|
const names = new Set();
|
|
12
|
-
|
|
13
11
|
const collect = node => {
|
|
14
12
|
if (Array.isArray(node)) {
|
|
15
13
|
for (const n of node) {
|
|
@@ -21,38 +19,28 @@ function collectBoundNames(root) {
|
|
|
21
19
|
case "Identifier":
|
|
22
20
|
names.add(node.name);
|
|
23
21
|
return;
|
|
24
|
-
|
|
25
22
|
case "VariableDeclaration":
|
|
26
23
|
return collect(node.declarations);
|
|
27
|
-
|
|
28
24
|
case "VariableDeclarator":
|
|
29
25
|
return collect(node.id);
|
|
30
|
-
|
|
31
26
|
case "ArrayPattern":
|
|
32
27
|
return collect(node.elements);
|
|
33
|
-
|
|
34
28
|
case "AssignmentPattern":
|
|
35
29
|
return collect(node.left);
|
|
36
|
-
|
|
37
30
|
case "ObjectPattern":
|
|
38
31
|
return collect(node.properties);
|
|
39
|
-
|
|
40
32
|
case "Property":
|
|
41
33
|
return collect(node.value);
|
|
42
|
-
|
|
43
34
|
case "RestElement":
|
|
44
35
|
return collect(node.argument);
|
|
45
|
-
|
|
46
36
|
case "FunctionDeclaration":
|
|
47
37
|
return collect(node.id);
|
|
48
38
|
}
|
|
49
39
|
}
|
|
50
40
|
};
|
|
51
|
-
|
|
52
41
|
collect(root);
|
|
53
42
|
return Array.from(names);
|
|
54
43
|
}
|
|
55
|
-
|
|
56
44
|
function containsExpression(root) {
|
|
57
45
|
const collect = node => {
|
|
58
46
|
if (Array.isArray(node)) {
|
|
@@ -62,31 +50,24 @@ function containsExpression(root) {
|
|
|
62
50
|
switch (node.type) {
|
|
63
51
|
case "ArrayPattern":
|
|
64
52
|
return collect(node.elements);
|
|
65
|
-
|
|
66
53
|
case "AssignmentPattern":
|
|
67
54
|
return true;
|
|
68
|
-
|
|
69
55
|
case "ObjectPattern":
|
|
70
56
|
return collect(node.properties);
|
|
71
|
-
|
|
72
57
|
case "Property":
|
|
73
58
|
return node.computed || collect(node.value);
|
|
74
|
-
|
|
75
59
|
case "RestElement":
|
|
76
60
|
return collect(node.argument);
|
|
77
61
|
}
|
|
78
62
|
}
|
|
79
63
|
};
|
|
80
|
-
|
|
81
64
|
return collect(root);
|
|
82
65
|
}
|
|
83
|
-
|
|
84
66
|
function collectScopedDeclarations(root, options) {
|
|
85
67
|
const declarations = [];
|
|
86
68
|
const nextOptions = {
|
|
87
69
|
var: options.var
|
|
88
70
|
};
|
|
89
|
-
|
|
90
71
|
const collect = (node, options) => {
|
|
91
72
|
if (Array.isArray(node)) {
|
|
92
73
|
for (const n of node) {
|
|
@@ -102,56 +83,44 @@ function collectScopedDeclarations(root, options) {
|
|
|
102
83
|
if (Number(!options.var) ^ Number(options.topLevel)) {
|
|
103
84
|
declarations.push(node);
|
|
104
85
|
}
|
|
105
|
-
|
|
106
86
|
return;
|
|
107
|
-
|
|
108
87
|
case "VariableDeclaration":
|
|
109
88
|
if (Number(!options.var) ^ Number(node.kind === "var")) {
|
|
110
89
|
declarations.push(node);
|
|
111
90
|
}
|
|
112
|
-
|
|
113
91
|
return;
|
|
114
|
-
|
|
115
92
|
case "SwitchCase":
|
|
116
93
|
collect(node.consequent, nextOptions);
|
|
117
94
|
return;
|
|
118
|
-
|
|
119
95
|
case "CatchClause":
|
|
120
96
|
collect(node.body, nextOptions);
|
|
121
97
|
return;
|
|
122
98
|
}
|
|
123
|
-
|
|
124
99
|
if (options.var) {
|
|
125
100
|
switch (node.type) {
|
|
126
101
|
case "BlockStatement":
|
|
127
102
|
collect(node.body, nextOptions);
|
|
128
103
|
return;
|
|
129
|
-
|
|
130
104
|
case "IfStatement":
|
|
131
105
|
collect(node.consequent, nextOptions);
|
|
132
106
|
collect(node.alternate, nextOptions);
|
|
133
107
|
return;
|
|
134
|
-
|
|
135
108
|
case "DoWhileStatement":
|
|
136
109
|
case "WhileStatement":
|
|
137
110
|
collect(node.body, nextOptions);
|
|
138
111
|
return;
|
|
139
|
-
|
|
140
112
|
case "ForStatement":
|
|
141
113
|
collect(node.init, nextOptions);
|
|
142
114
|
collect(node.body, nextOptions);
|
|
143
115
|
return;
|
|
144
|
-
|
|
145
116
|
case "ForInStatement":
|
|
146
117
|
case "ForOfStatement":
|
|
147
118
|
collect(node.left, nextOptions);
|
|
148
119
|
collect(node.body, nextOptions);
|
|
149
120
|
return;
|
|
150
|
-
|
|
151
121
|
case "SwitchStatement":
|
|
152
122
|
collect(node.cases, nextOptions);
|
|
153
123
|
return;
|
|
154
|
-
|
|
155
124
|
case "TryStatement":
|
|
156
125
|
collect(node.block, nextOptions);
|
|
157
126
|
collect(node.handler, nextOptions);
|
|
@@ -161,7 +130,6 @@ function collectScopedDeclarations(root, options) {
|
|
|
161
130
|
}
|
|
162
131
|
}
|
|
163
132
|
};
|
|
164
|
-
|
|
165
133
|
collect(root, options);
|
|
166
134
|
return declarations;
|
|
167
135
|
}
|
package/dist/cjs/traverse.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"traverse.js","names":["collectBoundNames","root","names","Set","collect","node","Array","isArray","n","type","add","name","declarations","id","elements","left","properties","value","argument","from","containsExpression","some","computed","collectScopedDeclarations","options","nextOptions","var","Number","topLevel","push","kind","consequent","body","alternate","init","cases","block","handler","finalizer"],"sources":["../../src/traverse.ts"],"sourcesContent":["import { FunctionDeclaration, VariableDeclaration } from \"@babel/types\";\nimport { EstreeNode, NodeWithBoundNames } from \"./interfaces\";\n\ntype InternalCollect<T = void, O = unknown> = (\n node: EstreeNode | EstreeNode[],\n options?: O\n) => T;\ntype InternalCollectWithOptions<T = void, O = unknown> = (\n node: EstreeNode | EstreeNode[],\n options: O\n) => T;\n\nexport function collectBoundNames(\n root: NodeWithBoundNames | NodeWithBoundNames[]\n): string[] {\n const names = new Set<string>();\n const collect: InternalCollect = (node) => {\n if (Array.isArray(node)) {\n for (const n of node) {\n collect(n);\n }\n } else if (node) {\n // `node` maybe `null` in some cases.\n switch (node.type) {\n case \"Identifier\":\n names.add(node.name);\n return;\n case \"VariableDeclaration\":\n return collect(node.declarations);\n case \"VariableDeclarator\":\n return collect(node.id);\n case \"ArrayPattern\":\n return collect(node.elements);\n case \"AssignmentPattern\":\n return collect(node.left);\n case \"ObjectPattern\":\n return collect(node.properties);\n case \"Property\":\n return collect(node.value);\n case \"RestElement\":\n return collect(node.argument);\n case \"FunctionDeclaration\":\n return collect(node.id);\n }\n }\n };\n collect(root);\n return Array.from(names);\n}\n\nexport function containsExpression(root: EstreeNode | EstreeNode[]): boolean {\n const collect: InternalCollect<boolean> = (node) => {\n if (Array.isArray(node)) {\n return node.some(collect);\n } else if (node) {\n // `node` maybe `null` in some cases.\n switch (node.type) {\n case \"ArrayPattern\":\n return collect(node.elements);\n case \"AssignmentPattern\":\n return true;\n case \"ObjectPattern\":\n return collect(node.properties);\n case \"Property\":\n return node.computed || collect(node.value);\n case \"RestElement\":\n return collect(node.argument);\n }\n }\n };\n return collect(root);\n}\n\ninterface ScopedDeclarationOptions {\n var?: boolean;\n topLevel?: boolean;\n}\n\ntype ScopedDeclaration = VariableDeclaration | FunctionDeclaration;\n\nexport function collectScopedDeclarations(\n root: EstreeNode | EstreeNode[],\n options: ScopedDeclarationOptions\n): ScopedDeclaration[] {\n const declarations: ScopedDeclaration[] = [];\n const nextOptions = { var: options.var };\n const collect: InternalCollectWithOptions<void, ScopedDeclarationOptions> = (\n node,\n options\n ): void => {\n if (Array.isArray(node)) {\n for (const n of node) {\n collect(n, options);\n }\n } else if (node) {\n // `node` maybe `null` in some cases.\n switch (node.type) {\n case \"FunctionDeclaration\":\n // At the top level of a function, or script, function declarations are\n // treated like var declarations rather than like lexical declarations.\n // See https://tc39.es/ecma262/#sec-static-semantics-toplevellexicallydeclarednames\n if (Number(!options.var) ^ Number(options.topLevel)) {\n declarations.push(node);\n }\n return;\n case \"VariableDeclaration\":\n if (Number(!options.var) ^ Number(node.kind === \"var\")) {\n declarations.push(node);\n }\n return;\n case \"SwitchCase\":\n collect(node.consequent, nextOptions);\n return;\n case \"CatchClause\":\n collect(node.body, nextOptions);\n return;\n }\n if (options.var) {\n switch (node.type) {\n case \"BlockStatement\":\n collect(node.body, nextOptions);\n return;\n case \"IfStatement\":\n collect(node.consequent, nextOptions);\n collect(node.alternate, nextOptions);\n return;\n case \"DoWhileStatement\":\n case \"WhileStatement\":\n collect(node.body, nextOptions);\n return;\n case \"ForStatement\":\n collect(node.init, nextOptions);\n collect(node.body, nextOptions);\n return;\n case \"ForInStatement\":\n case \"ForOfStatement\":\n collect(node.left, nextOptions);\n collect(node.body, nextOptions);\n return;\n case \"SwitchStatement\":\n collect(node.cases, nextOptions);\n return;\n case \"TryStatement\":\n collect(node.block, nextOptions);\n collect(node.handler, nextOptions);\n collect(node.finalizer, nextOptions);\n return;\n }\n }\n }\n };\n collect(root, options);\n return declarations;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"traverse.js","names":["collectBoundNames","root","names","Set","collect","node","Array","isArray","n","type","add","name","declarations","id","elements","left","properties","value","argument","from","containsExpression","some","computed","collectScopedDeclarations","options","nextOptions","var","Number","topLevel","push","kind","consequent","body","alternate","init","cases","block","handler","finalizer"],"sources":["../../src/traverse.ts"],"sourcesContent":["import { FunctionDeclaration, VariableDeclaration } from \"@babel/types\";\nimport { EstreeNode, NodeWithBoundNames } from \"./interfaces\";\n\ntype InternalCollect<T = void, O = unknown> = (\n node: EstreeNode | EstreeNode[],\n options?: O\n) => T;\ntype InternalCollectWithOptions<T = void, O = unknown> = (\n node: EstreeNode | EstreeNode[],\n options: O\n) => T;\n\nexport function collectBoundNames(\n root: NodeWithBoundNames | NodeWithBoundNames[]\n): string[] {\n const names = new Set<string>();\n const collect: InternalCollect = (node) => {\n if (Array.isArray(node)) {\n for (const n of node) {\n collect(n);\n }\n } else if (node) {\n // `node` maybe `null` in some cases.\n switch (node.type) {\n case \"Identifier\":\n names.add(node.name);\n return;\n case \"VariableDeclaration\":\n return collect(node.declarations);\n case \"VariableDeclarator\":\n return collect(node.id);\n case \"ArrayPattern\":\n return collect(node.elements);\n case \"AssignmentPattern\":\n return collect(node.left);\n case \"ObjectPattern\":\n return collect(node.properties);\n case \"Property\":\n return collect(node.value);\n case \"RestElement\":\n return collect(node.argument);\n case \"FunctionDeclaration\":\n return collect(node.id);\n }\n }\n };\n collect(root);\n return Array.from(names);\n}\n\nexport function containsExpression(root: EstreeNode | EstreeNode[]): boolean {\n const collect: InternalCollect<boolean> = (node) => {\n if (Array.isArray(node)) {\n return node.some(collect);\n } else if (node) {\n // `node` maybe `null` in some cases.\n switch (node.type) {\n case \"ArrayPattern\":\n return collect(node.elements);\n case \"AssignmentPattern\":\n return true;\n case \"ObjectPattern\":\n return collect(node.properties);\n case \"Property\":\n return node.computed || collect(node.value);\n case \"RestElement\":\n return collect(node.argument);\n }\n }\n };\n return collect(root);\n}\n\ninterface ScopedDeclarationOptions {\n var?: boolean;\n topLevel?: boolean;\n}\n\ntype ScopedDeclaration = VariableDeclaration | FunctionDeclaration;\n\nexport function collectScopedDeclarations(\n root: EstreeNode | EstreeNode[],\n options: ScopedDeclarationOptions\n): ScopedDeclaration[] {\n const declarations: ScopedDeclaration[] = [];\n const nextOptions = { var: options.var };\n const collect: InternalCollectWithOptions<void, ScopedDeclarationOptions> = (\n node,\n options\n ): void => {\n if (Array.isArray(node)) {\n for (const n of node) {\n collect(n, options);\n }\n } else if (node) {\n // `node` maybe `null` in some cases.\n switch (node.type) {\n case \"FunctionDeclaration\":\n // At the top level of a function, or script, function declarations are\n // treated like var declarations rather than like lexical declarations.\n // See https://tc39.es/ecma262/#sec-static-semantics-toplevellexicallydeclarednames\n if (Number(!options.var) ^ Number(options.topLevel)) {\n declarations.push(node);\n }\n return;\n case \"VariableDeclaration\":\n if (Number(!options.var) ^ Number(node.kind === \"var\")) {\n declarations.push(node);\n }\n return;\n case \"SwitchCase\":\n collect(node.consequent, nextOptions);\n return;\n case \"CatchClause\":\n collect(node.body, nextOptions);\n return;\n }\n if (options.var) {\n switch (node.type) {\n case \"BlockStatement\":\n collect(node.body, nextOptions);\n return;\n case \"IfStatement\":\n collect(node.consequent, nextOptions);\n collect(node.alternate, nextOptions);\n return;\n case \"DoWhileStatement\":\n case \"WhileStatement\":\n collect(node.body, nextOptions);\n return;\n case \"ForStatement\":\n collect(node.init, nextOptions);\n collect(node.body, nextOptions);\n return;\n case \"ForInStatement\":\n case \"ForOfStatement\":\n collect(node.left, nextOptions);\n collect(node.body, nextOptions);\n return;\n case \"SwitchStatement\":\n collect(node.cases, nextOptions);\n return;\n case \"TryStatement\":\n collect(node.block, nextOptions);\n collect(node.handler, nextOptions);\n collect(node.finalizer, nextOptions);\n return;\n }\n }\n }\n };\n collect(root, options);\n return declarations;\n}\n"],"mappings":";;;;;;;;AAYO,SAASA,iBAAiB,CAC/BC,IAA+C,EACrC;EACV,MAAMC,KAAK,GAAG,IAAIC,GAAG,EAAU;EAC/B,MAAMC,OAAwB,GAAIC,IAAI,IAAK;IACzC,IAAIC,KAAK,CAACC,OAAO,CAACF,IAAI,CAAC,EAAE;MACvB,KAAK,MAAMG,CAAC,IAAIH,IAAI,EAAE;QACpBD,OAAO,CAACI,CAAC,CAAC;MACZ;IACF,CAAC,MAAM,IAAIH,IAAI,EAAE;MACf;MACA,QAAQA,IAAI,CAACI,IAAI;QACf,KAAK,YAAY;UACfP,KAAK,CAACQ,GAAG,CAACL,IAAI,CAACM,IAAI,CAAC;UACpB;QACF,KAAK,qBAAq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,WAAW,CAAC;YAC/B;UACF,KAAK,aAAa;YAChBrB,OAAO,CAACC,IAAI,CAAC0B,UAAU,EAAEN,WAAW,CAAC;YACrCrB,OAAO,CAACC,IAAI,CAAC4B,SAAS,EAAER,WAAW,CAAC;YACpC;UACF,KAAK,kBAAkB;UACvB,KAAK,gBAAgB;YACnBrB,OAAO,CAACC,IAAI,CAAC2B,IAAI,EAAEP,WAAW,CAAC;YAC/B;UACF,KAAK,cAAc;YACjBrB,OAAO,CAACC,IAAI,CAAC6B,IAAI,EAAET,WAAW,CAAC;YAC/BrB,OAAO,CAACC,IAAI,CAAC2B,IAAI,EAAEP,WAAW,CAAC;YAC/B;UACF,KAAK,gBAAgB;UACrB,KAAK,gBAAgB;YACnBrB,OAAO,CAACC,IAAI,CAACU,IAAI,EAAEU,WAAW,CAAC;YAC/BrB,OAAO,CAACC,IAAI,CAAC2B,IAAI,EAAEP,WAAW,CAAC;YAC/B;UACF,KAAK,iBAAiB;YACpBrB,OAAO,CAACC,IAAI,CAAC8B,KAAK,EAAEV,WAAW,CAAC;YAChC;UACF,KAAK,cAAc;YACjBrB,OAAO,CAACC,IAAI,CAAC+B,KAAK,EAAEX,WAAW,CAAC;YAChCrB,OAAO,CAACC,IAAI,CAACgC,OAAO,EAAEZ,WAAW,CAAC;YAClCrB,OAAO,CAACC,IAAI,CAACiC,SAAS,EAAEb,WAAW,CAAC;YACpC;QAAO;MAEb;IACF;EACF,CAAC;EACDrB,OAAO,CAACH,IAAI,EAAEuB,OAAO,CAAC;EACtB,OAAOZ,YAAY;AACrB"}
|
|
@@ -3,28 +3,22 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
|
3
3
|
export class AnalysisContext {
|
|
4
4
|
constructor() {
|
|
5
5
|
_defineProperty(this, "VariableEnvironment", void 0);
|
|
6
|
-
|
|
7
6
|
_defineProperty(this, "LexicalEnvironment", void 0);
|
|
8
7
|
}
|
|
8
|
+
}
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
// https://tc39.es/ecma262/#sec-environment-records
|
|
12
11
|
export class AnalysisEnvironment {
|
|
13
12
|
constructor(outer) {
|
|
14
13
|
_defineProperty(this, "OuterEnv", void 0);
|
|
15
|
-
|
|
16
14
|
_defineProperty(this, "bindingSet", new Set());
|
|
17
|
-
|
|
18
15
|
this.OuterEnv = outer;
|
|
19
16
|
}
|
|
20
|
-
|
|
21
17
|
HasBinding(name) {
|
|
22
18
|
return this.bindingSet.has(name);
|
|
23
19
|
}
|
|
24
|
-
|
|
25
20
|
CreateBinding(name) {
|
|
26
21
|
this.bindingSet.add(name);
|
|
27
22
|
}
|
|
28
|
-
|
|
29
23
|
}
|
|
30
24
|
//# 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":";AAQA;AACA,OAAO,MAAMA,
|
|
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;AACA,OAAO,MAAMA,eAAe,CAAC;EAAA;IAAA;IAAA;EAAA;AAG7B;;AAEA;AACA,OAAO,MAAMC,mBAAmB,CAAC;EAI/BC,WAAW,CAACC,KAA0B,EAAE;IAAA;IAAA,oCAFV,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"}
|
|
@@ -3,27 +3,20 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
|
3
3
|
export class ExecutionContext {
|
|
4
4
|
constructor() {
|
|
5
5
|
_defineProperty(this, "VariableEnvironment", void 0);
|
|
6
|
-
|
|
7
6
|
_defineProperty(this, "LexicalEnvironment", void 0);
|
|
8
|
-
|
|
9
7
|
_defineProperty(this, "Function", void 0);
|
|
10
8
|
}
|
|
11
|
-
|
|
12
9
|
}
|
|
13
10
|
// https://tc39.es/ecma262/#sec-environment-records
|
|
14
11
|
export class EnvironmentRecord {
|
|
15
12
|
constructor(outer) {
|
|
16
13
|
_defineProperty(this, "OuterEnv", void 0);
|
|
17
|
-
|
|
18
14
|
_defineProperty(this, "bindingMap", new Map());
|
|
19
|
-
|
|
20
15
|
this.OuterEnv = outer;
|
|
21
16
|
}
|
|
22
|
-
|
|
23
17
|
HasBinding(name) {
|
|
24
18
|
return this.bindingMap.has(name);
|
|
25
19
|
}
|
|
26
|
-
|
|
27
20
|
CreateMutableBinding(name, deletable) {
|
|
28
21
|
// Assert: binding does not exist.
|
|
29
22
|
this.bindingMap.set(name, {
|
|
@@ -32,6 +25,7 @@ export class EnvironmentRecord {
|
|
|
32
25
|
});
|
|
33
26
|
return NormalCompletion(undefined);
|
|
34
27
|
}
|
|
28
|
+
|
|
35
29
|
/**
|
|
36
30
|
* Create an immutable binding.
|
|
37
31
|
*
|
|
@@ -39,8 +33,6 @@ export class EnvironmentRecord {
|
|
|
39
33
|
* @param strict - For named function expressions, strict is false, otherwise it's true.
|
|
40
34
|
* @returns CompletionRecord.
|
|
41
35
|
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
36
|
CreateImmutableBinding(name, strict) {
|
|
45
37
|
// Assert: binding does not exist.
|
|
46
38
|
this.bindingMap.set(name, {
|
|
@@ -48,16 +40,16 @@ export class EnvironmentRecord {
|
|
|
48
40
|
});
|
|
49
41
|
return NormalCompletion(undefined);
|
|
50
42
|
}
|
|
51
|
-
|
|
52
43
|
InitializeBinding(name, value) {
|
|
53
|
-
var binding = this.bindingMap.get(name);
|
|
54
|
-
|
|
44
|
+
var binding = this.bindingMap.get(name);
|
|
45
|
+
// Assert: binding exists and uninitialized.
|
|
55
46
|
Object.assign(binding, {
|
|
56
47
|
initialized: true,
|
|
57
48
|
value
|
|
58
49
|
});
|
|
59
50
|
return NormalCompletion(undefined);
|
|
60
51
|
}
|
|
52
|
+
|
|
61
53
|
/**
|
|
62
54
|
* Update a mutable binding value, including function declarations.
|
|
63
55
|
*
|
|
@@ -66,11 +58,9 @@ export class EnvironmentRecord {
|
|
|
66
58
|
* @param strict - For functions, strict is always false, otherwise it depends on strict-mode.
|
|
67
59
|
* @returns
|
|
68
60
|
*/
|
|
69
|
-
|
|
70
|
-
|
|
71
61
|
SetMutableBinding(name, value, strict) {
|
|
72
|
-
var binding = this.bindingMap.get(name);
|
|
73
|
-
|
|
62
|
+
var binding = this.bindingMap.get(name);
|
|
63
|
+
// Assert: binding exists.
|
|
74
64
|
if (!binding.initialized) {
|
|
75
65
|
throw new ReferenceError("".concat(name, " is not initialized"));
|
|
76
66
|
} else if (binding.mutable) {
|
|
@@ -78,20 +68,16 @@ export class EnvironmentRecord {
|
|
|
78
68
|
} else {
|
|
79
69
|
throw new TypeError("Assignment to constant variable");
|
|
80
70
|
}
|
|
81
|
-
|
|
82
71
|
return NormalCompletion(undefined);
|
|
83
72
|
}
|
|
84
|
-
|
|
85
73
|
GetBindingValue(name, strict) {
|
|
86
|
-
var binding = this.bindingMap.get(name);
|
|
87
|
-
|
|
74
|
+
var binding = this.bindingMap.get(name);
|
|
75
|
+
// Assert: binding exists.
|
|
88
76
|
if (!binding.initialized) {
|
|
89
77
|
throw new ReferenceError("".concat(name, " is not initialized"));
|
|
90
78
|
}
|
|
91
|
-
|
|
92
79
|
return binding.value;
|
|
93
80
|
}
|
|
94
|
-
|
|
95
81
|
}
|
|
96
82
|
export class DeclarativeEnvironment extends EnvironmentRecord {}
|
|
97
83
|
export class FunctionEnvironment extends EnvironmentRecord {}
|
|
@@ -103,30 +89,25 @@ export var IsConstructor = Symbol.for("IsConstructor");
|
|
|
103
89
|
// https://tc39.es/ecma262/#sec-reference-record-specification-type
|
|
104
90
|
export class ReferenceRecord {
|
|
105
91
|
/** Whether the reference is in strict mode. */
|
|
92
|
+
|
|
106
93
|
constructor(base, referenceName, strict) {
|
|
107
94
|
_defineProperty(this, "Base", void 0);
|
|
108
|
-
|
|
109
95
|
_defineProperty(this, "ReferenceName", void 0);
|
|
110
|
-
|
|
111
96
|
_defineProperty(this, "Strict", void 0);
|
|
112
|
-
|
|
113
97
|
this.Base = base;
|
|
114
98
|
this.ReferenceName = referenceName;
|
|
115
99
|
this.Strict = strict;
|
|
116
100
|
}
|
|
101
|
+
}
|
|
117
102
|
|
|
118
|
-
|
|
119
|
-
|
|
103
|
+
// https://tc39.es/ecma262/#sec-completion-record-specification-type
|
|
120
104
|
export class CompletionRecord {
|
|
121
105
|
constructor(type, value) {
|
|
122
106
|
_defineProperty(this, "Type", void 0);
|
|
123
|
-
|
|
124
107
|
_defineProperty(this, "Value", void 0);
|
|
125
|
-
|
|
126
108
|
this.Type = type;
|
|
127
109
|
this.Value = value;
|
|
128
110
|
}
|
|
129
|
-
|
|
130
111
|
}
|
|
131
112
|
// https://tc39.es/ecma262/#sec-normalcompletion
|
|
132
113
|
export function NormalCompletion(value) {
|
|
@@ -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":";AAQA;AACA,OAAO,MAAMA,
|
|
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;AACA,OAAO,MAAMA,gBAAgB,CAAC;EAAA;IAAA;IAAA;IAAA;EAAA;AAI9B;AAIA;AACA,OAAO,MAAMC,iBAAiB,CAAC;EAI7BC,WAAW,CAACC,KAAwB,EAAE;IAAA;IAAA,oCAFR,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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