poe-code 14.0.64 → 14.0.66
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/index.js +8832 -7273
- package/dist/index.js.map +4 -4
- package/dist/metafile.json +1 -1
- package/package.json +1 -1
- package/packages/safe-js/dist/chunks/{chunk-3EXDJDQM.js → chunk-MKTUVVEB.js} +2 -2
- package/packages/safe-js/dist/chunks/{chunk-XO7B4P27.js → chunk-YKISHTWT.js} +4474 -2978
- package/packages/safe-js/dist/chunks/chunk-YKISHTWT.js.map +7 -0
- package/packages/safe-js/dist/cli.js +2 -2
- package/packages/safe-js/dist/core.js +1 -1
- package/packages/safe-js/dist/index.js +2 -2
- package/packages/safe-js/dist/index.js.map +1 -1
- package/packages/safe-js/dist/interp/accessors.d.ts +9 -0
- package/packages/safe-js/dist/interp/accessors.js +68 -0
- package/packages/safe-js/dist/interp/async.d.ts +13 -2
- package/packages/safe-js/dist/interp/async.js +19 -9
- package/packages/safe-js/dist/interp/classes.d.ts +4 -0
- package/packages/safe-js/dist/interp/classes.js +182 -0
- package/packages/safe-js/dist/interp/exceptions.d.ts +1 -1
- package/packages/safe-js/dist/interp/exceptions.js +51 -9
- package/packages/safe-js/dist/interp/globals/collections.js +53 -16
- package/packages/safe-js/dist/interp/globals/console-json.js +41 -26
- package/packages/safe-js/dist/interp/globals/object-array.d.ts +2 -1
- package/packages/safe-js/dist/interp/globals/object-array.js +230 -69
- package/packages/safe-js/dist/interp/globals/object.js +13 -2
- package/packages/safe-js/dist/interp/globals/primitives.js +16 -5
- package/packages/safe-js/dist/interp/interpreter.d.ts +2 -2
- package/packages/safe-js/dist/interp/interpreter.js +168 -61
- package/packages/safe-js/dist/interp/iteration.js +13 -0
- package/packages/safe-js/dist/interp/methods/array.d.ts +1 -1
- package/packages/safe-js/dist/interp/methods/array.js +368 -109
- package/packages/safe-js/dist/interp/methods/function.d.ts +1 -1
- package/packages/safe-js/dist/interp/methods/function.js +56 -20
- package/packages/safe-js/dist/interp/methods/regex.js +1 -1
- package/packages/safe-js/dist/interp/object-model.d.ts +1 -0
- package/packages/safe-js/dist/interp/object-model.js +48 -10
- package/packages/safe-js/dist/interp/patterns.d.ts +3 -3
- package/packages/safe-js/dist/interp/patterns.js +36 -17
- package/packages/safe-js/dist/interp/promise.d.ts +1 -1
- package/packages/safe-js/dist/interp/promise.js +103 -63
- package/packages/safe-js/dist/interp/string-coercion.d.ts +1 -0
- package/packages/safe-js/dist/interp/string-coercion.js +47 -37
- package/packages/safe-js/dist/interp/values.d.ts +4 -2
- package/packages/safe-js/dist/interp/values.js +26 -1
- package/packages/safe-js/dist/lint/class-elements.d.ts +5 -0
- package/packages/safe-js/dist/lint/class-elements.js +20 -0
- package/packages/safe-js/dist/lint/rules/AS-async-not-needed.js +16 -0
- package/packages/safe-js/dist/lint/rules/AS-destructure-null-default.js +9 -0
- package/packages/safe-js/dist/lint/rules/AS-export-import-meta.js +9 -0
- package/packages/safe-js/dist/lint/rules/AS-floating-promise.js +9 -0
- package/packages/safe-js/dist/lint/rules/AS-frontmatter-field-unused.js +9 -0
- package/packages/safe-js/dist/lint/rules/AS-jsdoc-type.js +9 -0
- package/packages/safe-js/dist/lint/rules/AS-large-literal.js +9 -0
- package/packages/safe-js/dist/lint/rules/AS-missing-async.js +16 -0
- package/packages/safe-js/dist/lint/rules/AS-mutating-frozen.js +9 -0
- package/packages/safe-js/dist/lint/rules/AS-needless-template.js +9 -0
- package/packages/safe-js/dist/lint/rules/AS-shadow-global.js +12 -0
- package/packages/safe-js/dist/lint/rules/AS-unbounded-loop.js +11 -0
- package/packages/safe-js/dist/lint/rules/AS-unreachable.js +9 -0
- package/packages/safe-js/dist/lint/rules/AS-unused-import.js +16 -2
- package/packages/safe-js/dist/lint/rules/AS001.js +0 -1
- package/packages/safe-js/dist/lint/rules/AS003.js +16 -2
- package/packages/safe-js/dist/lint/rules/AS006-007.js +16 -2
- package/packages/safe-js/dist/lint/rules/AS009.js +20 -1
- package/packages/safe-js/dist/lint/rules/AS010.js +9 -0
- package/packages/safe-js/dist/lint/rules/AS011.js +9 -0
- package/packages/safe-js/dist/lint/rules/AS015.js +9 -0
- package/packages/safe-js/dist/parse/function-source.d.ts +2 -2
- package/packages/safe-js/dist/parse/parser.d.ts +42 -2
- package/packages/safe-js/dist/parse/parser.js +208 -35
- package/packages/safe-js/dist/parse/tokenizer.js +3 -0
- package/packages/safe-js/dist/parse.d.ts +1 -1
- package/packages/safe-js/dist/chunks/chunk-XO7B4P27.js.map +0 -7
- /package/packages/safe-js/dist/chunks/{chunk-3EXDJDQM.js.map → chunk-MKTUVVEB.js.map} +0 -0
|
@@ -27,6 +27,7 @@ const BITWISE_AND_OPERATORS = new Set(["&"]);
|
|
|
27
27
|
const MAX_UNICODE_CODE_POINT = 0x10ffff;
|
|
28
28
|
const TOP_LEVEL_STATEMENT_KEYWORDS = new Set([
|
|
29
29
|
"break",
|
|
30
|
+
"class",
|
|
30
31
|
"const",
|
|
31
32
|
"continue",
|
|
32
33
|
"do",
|
|
@@ -102,11 +103,16 @@ export function parseExecutableModule(source, filename = "<input>", owner) {
|
|
|
102
103
|
compilation.dispose();
|
|
103
104
|
}
|
|
104
105
|
}
|
|
106
|
+
const ordinaryFunctionContext = {
|
|
107
|
+
newTarget: true, superProperty: false, superCall: false,
|
|
108
|
+
arguments: true, return: true, await: true
|
|
109
|
+
};
|
|
105
110
|
class Parser {
|
|
106
111
|
tokens;
|
|
107
112
|
source;
|
|
108
113
|
compilation;
|
|
109
114
|
functionContext;
|
|
115
|
+
lexicalContext;
|
|
110
116
|
index = 0;
|
|
111
117
|
breakableDepth = 0;
|
|
112
118
|
conditionalExpressionDepth = 0;
|
|
@@ -115,11 +121,12 @@ class Parser {
|
|
|
115
121
|
scopes = [new Map()];
|
|
116
122
|
functionScopes = new WeakSet();
|
|
117
123
|
varNames = new WeakMap();
|
|
118
|
-
constructor(tokens, source, compilation, functionContext = "normal") {
|
|
124
|
+
constructor(tokens, source, compilation, functionContext = "normal", lexicalContext = { ...ordinaryFunctionContext, newTarget: false }) {
|
|
119
125
|
this.tokens = tokens;
|
|
120
126
|
this.source = source;
|
|
121
127
|
this.compilation = compilation;
|
|
122
128
|
this.functionContext = functionContext;
|
|
129
|
+
this.lexicalContext = lexicalContext;
|
|
123
130
|
this.functionScopes.add(this.scopes[0]);
|
|
124
131
|
}
|
|
125
132
|
withFunctionSource(node) {
|
|
@@ -274,7 +281,9 @@ class Parser {
|
|
|
274
281
|
}
|
|
275
282
|
});
|
|
276
283
|
this.expectPunctuator("=>");
|
|
277
|
-
const body = this.
|
|
284
|
+
const body = this.withLexicalContext({
|
|
285
|
+
...this.lexicalContext, return: true, await: isAsync || this.lexicalContext.strictAwait !== true
|
|
286
|
+
}, () => this.parseArrowFunctionBody(params));
|
|
278
287
|
return this.withFunctionSource({
|
|
279
288
|
type: "ArrowFunctionExpression",
|
|
280
289
|
async: isAsync,
|
|
@@ -366,6 +375,10 @@ class Parser {
|
|
|
366
375
|
return this.parseLabeledStatement([token.value], token);
|
|
367
376
|
}
|
|
368
377
|
this.assertAllowedStatementStart(token);
|
|
378
|
+
if (token.value === "class")
|
|
379
|
+
return this.parseClass(true);
|
|
380
|
+
if (token.value === "return" && !this.lexicalContext.return)
|
|
381
|
+
throw new DisallowedSyntaxError("return in a static block", token.start);
|
|
369
382
|
if (token.type === "punctuator" && token.value === "{") {
|
|
370
383
|
return this.parseBlockStatement();
|
|
371
384
|
}
|
|
@@ -914,17 +927,8 @@ class Parser {
|
|
|
914
927
|
}
|
|
915
928
|
const id = this.parseBindingIdentifier();
|
|
916
929
|
this.declareBinding(id, "function");
|
|
917
|
-
const params = this.withScope(() => {
|
|
918
|
-
const parsedParams = this.parseArrowParameters();
|
|
919
|
-
for (const param of parsedParams) {
|
|
920
|
-
for (const identifier of boundIdentifiers(param)) {
|
|
921
|
-
this.declareBinding(identifier);
|
|
922
|
-
}
|
|
923
|
-
}
|
|
924
|
-
return parsedParams;
|
|
925
|
-
});
|
|
926
930
|
const generator = generatorToken !== undefined;
|
|
927
|
-
const body = this.
|
|
931
|
+
const { params, body } = this.parseFunctionParts(generator, ordinaryFunctionContext);
|
|
928
932
|
return this.withFunctionSource({
|
|
929
933
|
type: "FunctionDeclaration",
|
|
930
934
|
async: asyncToken !== undefined,
|
|
@@ -935,6 +939,158 @@ class Parser {
|
|
|
935
939
|
span: createSpan(asyncToken?.start ?? functionToken.start, body.span.end)
|
|
936
940
|
});
|
|
937
941
|
}
|
|
942
|
+
parseClass(declaration) {
|
|
943
|
+
const start = this.expectKeyword("class");
|
|
944
|
+
const id = isIdentifierLikeToken(this.currentToken()) && this.currentToken().value !== "extends"
|
|
945
|
+
? this.parseBindingIdentifier()
|
|
946
|
+
: undefined;
|
|
947
|
+
if (declaration && id === undefined)
|
|
948
|
+
throw unexpectedTokenError(this.currentToken());
|
|
949
|
+
if (declaration)
|
|
950
|
+
this.declareBinding(id);
|
|
951
|
+
return this.withScope(() => {
|
|
952
|
+
if (id !== undefined)
|
|
953
|
+
this.declareBinding(id);
|
|
954
|
+
const superClass = this.consumeKeyword("extends") === undefined
|
|
955
|
+
? undefined
|
|
956
|
+
: this.parseLeftHandSideExpression().node;
|
|
957
|
+
const open = this.expectPunctuator("{");
|
|
958
|
+
const elements = [];
|
|
959
|
+
let constructorSeen = false;
|
|
960
|
+
while (this.consumePunctuator("}") === undefined) {
|
|
961
|
+
if (this.currentToken().type === "eof")
|
|
962
|
+
throw unexpectedTokenError(this.currentToken());
|
|
963
|
+
if (this.consumePunctuator(";") !== undefined)
|
|
964
|
+
continue;
|
|
965
|
+
const element = this.parseClassElement(superClass !== undefined);
|
|
966
|
+
if (element.type === "MethodDefinition" && element.kind === "constructor") {
|
|
967
|
+
if (constructorSeen)
|
|
968
|
+
throw new Error("A class may only have one constructor.");
|
|
969
|
+
constructorSeen = true;
|
|
970
|
+
}
|
|
971
|
+
elements.push(element);
|
|
972
|
+
}
|
|
973
|
+
const body = {
|
|
974
|
+
type: "ClassBody", body: elements,
|
|
975
|
+
span: createSpan(open.start, this.previousToken().end)
|
|
976
|
+
};
|
|
977
|
+
return this.withFunctionSource({
|
|
978
|
+
type: declaration ? "ClassDeclaration" : "ClassExpression",
|
|
979
|
+
id, superClass, body, span: createSpan(start.start, body.span.end)
|
|
980
|
+
});
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
parseFunctionParts(generator, lexicalContext, accessor) {
|
|
984
|
+
return this.withLexicalContext(lexicalContext, () => {
|
|
985
|
+
const params = this.withScope(() => {
|
|
986
|
+
const parsed = this.parseArrowParameters();
|
|
987
|
+
for (const param of parsed)
|
|
988
|
+
for (const identifier of boundIdentifiers(param))
|
|
989
|
+
this.declareBinding(identifier);
|
|
990
|
+
return parsed;
|
|
991
|
+
});
|
|
992
|
+
if (accessor === "get" && params.length !== 0)
|
|
993
|
+
throw new Error("A getter cannot have parameters.");
|
|
994
|
+
if (accessor === "set" && (params.length !== 1 || params[0]?.type === "RestElement"))
|
|
995
|
+
throw new Error("A setter must have exactly one non-rest parameter.");
|
|
996
|
+
const bodyTokenIndex = this.index;
|
|
997
|
+
const body = this.withFunctionContext(generator ? "generator" : "normal", () => this.parseBlockStatement(params));
|
|
998
|
+
if (accessor === "set" && params[0]?.type !== "Identifier") {
|
|
999
|
+
let directiveTokenIndex = bodyTokenIndex + 1;
|
|
1000
|
+
for (const statement of body.body) {
|
|
1001
|
+
const token = this.tokens[directiveTokenIndex];
|
|
1002
|
+
if (statement.type !== "ExpressionStatement" ||
|
|
1003
|
+
statement.expression.type !== "StringLiteral" ||
|
|
1004
|
+
token?.type !== "string" ||
|
|
1005
|
+
statement.span.start.offset !== token.start.offset ||
|
|
1006
|
+
statement.span.end.offset !== token.end.offset)
|
|
1007
|
+
break;
|
|
1008
|
+
if (statement.expression.raw === '"use strict"' || statement.expression.raw === "'use strict'")
|
|
1009
|
+
throw new Error("A setter with a non-simple parameter cannot contain a use strict directive.");
|
|
1010
|
+
directiveTokenIndex += this.tokens[directiveTokenIndex + 1]?.value === ";" ? 2 : 1;
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
return { params, body };
|
|
1014
|
+
});
|
|
1015
|
+
}
|
|
1016
|
+
parseClassElement(derived) {
|
|
1017
|
+
const start = this.currentToken();
|
|
1018
|
+
let isStatic = false;
|
|
1019
|
+
if (start.value === "static" && !["(", "=", ";", "}"].includes(this.peekToken(1).value)) {
|
|
1020
|
+
this.index++;
|
|
1021
|
+
isStatic = true;
|
|
1022
|
+
if (this.currentToken().value === "{") {
|
|
1023
|
+
const body = this.withLexicalContext({
|
|
1024
|
+
newTarget: true, superProperty: true, superCall: false,
|
|
1025
|
+
arguments: false, return: false, await: false, strictAwait: true
|
|
1026
|
+
}, () => this.withFunctionContext("normal", () => this.parseBlockStatement([])));
|
|
1027
|
+
return { type: "StaticBlock", body, span: createSpan(start.start, body.span.end) };
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
const methodStart = this.currentToken();
|
|
1031
|
+
let async = false;
|
|
1032
|
+
if (methodStart.value === "async" && !hasLineBreakBetween(methodStart, this.peekToken(1)) &&
|
|
1033
|
+
(this.peekToken(1).value === "*" || this.isObjectMethodStart())) {
|
|
1034
|
+
this.index++;
|
|
1035
|
+
async = true;
|
|
1036
|
+
}
|
|
1037
|
+
const generator = this.consumePunctuator("*") !== undefined;
|
|
1038
|
+
if (async && generator)
|
|
1039
|
+
throw new DisallowedSyntaxError("async generator", methodStart.start);
|
|
1040
|
+
let accessor;
|
|
1041
|
+
const modifier = this.currentToken();
|
|
1042
|
+
if ((modifier.value === "get" || modifier.value === "set") && this.isObjectMethodStart()) {
|
|
1043
|
+
if (async || generator || modifier.end.offset - modifier.start.offset !== modifier.value.length)
|
|
1044
|
+
throw unexpectedTokenError(modifier);
|
|
1045
|
+
accessor = modifier.value;
|
|
1046
|
+
this.index++;
|
|
1047
|
+
}
|
|
1048
|
+
const computed = this.consumePunctuator("[") !== undefined;
|
|
1049
|
+
const key = computed
|
|
1050
|
+
? this.parseExpression({ allowSequence: true }).node
|
|
1051
|
+
: this.currentToken().type === "string"
|
|
1052
|
+
? createStringLiteral(this.tokens[this.index++])
|
|
1053
|
+
: this.currentToken().type === "numeric"
|
|
1054
|
+
? createNumericLiteral(this.tokens[this.index++])
|
|
1055
|
+
: this.parseIdentifierName();
|
|
1056
|
+
if (computed)
|
|
1057
|
+
this.expectPunctuator("]");
|
|
1058
|
+
const name = computed ? undefined : key.type === "Identifier" ? key.name
|
|
1059
|
+
: key.type === "StringLiteral" || key.type === "NumericLiteral" ? String(key.value) : undefined;
|
|
1060
|
+
if (isStatic && name === "prototype")
|
|
1061
|
+
throw new Error("A static class element cannot be named prototype.");
|
|
1062
|
+
if (this.currentToken().value === "(") {
|
|
1063
|
+
const constructor = !isStatic && name === "constructor";
|
|
1064
|
+
if (constructor && (async || generator || accessor !== undefined))
|
|
1065
|
+
throw new Error("A class constructor must be an ordinary method.");
|
|
1066
|
+
const { params, body } = this.parseFunctionParts(generator, {
|
|
1067
|
+
newTarget: true, superProperty: true, superCall: constructor && derived,
|
|
1068
|
+
arguments: true, return: true, await: async, strictAwait: true
|
|
1069
|
+
}, accessor);
|
|
1070
|
+
const value = this.withFunctionSource({
|
|
1071
|
+
type: "FunctionExpression", async, generator, method: true, params, body,
|
|
1072
|
+
span: createSpan(methodStart.start, body.span.end)
|
|
1073
|
+
});
|
|
1074
|
+
return {
|
|
1075
|
+
type: "MethodDefinition", key, computed, static: isStatic,
|
|
1076
|
+
kind: accessor ?? (constructor ? "constructor" : "method"), value,
|
|
1077
|
+
span: createSpan(start.start, value.span.end)
|
|
1078
|
+
};
|
|
1079
|
+
}
|
|
1080
|
+
if (async || generator)
|
|
1081
|
+
throw unexpectedTokenError(this.currentToken());
|
|
1082
|
+
if (name === "constructor")
|
|
1083
|
+
throw new Error("A class field cannot be named constructor.");
|
|
1084
|
+
const value = this.consumePunctuator("=") === undefined ? undefined : this.withLexicalContext({
|
|
1085
|
+
newTarget: true, superProperty: true, superCall: false,
|
|
1086
|
+
arguments: false, return: false, await: false, strictAwait: true
|
|
1087
|
+
}, () => this.withFunctionContext("normal", () => this.parseExpression().node));
|
|
1088
|
+
const end = value?.span.end ?? key.span.end;
|
|
1089
|
+
if (this.consumePunctuator(";") === undefined && this.currentToken().value !== "}" &&
|
|
1090
|
+
!hasLineBreakBetween(this.previousToken(), this.currentToken()))
|
|
1091
|
+
throw unexpectedTokenError(this.currentToken());
|
|
1092
|
+
return { type: "PropertyDefinition", key, computed, static: isStatic, value, span: createSpan(start.start, end) };
|
|
1093
|
+
}
|
|
938
1094
|
parseVariableDeclarator(kind) {
|
|
939
1095
|
const id = this.parseBindingTarget();
|
|
940
1096
|
let init;
|
|
@@ -1544,6 +1700,8 @@ class Parser {
|
|
|
1544
1700
|
};
|
|
1545
1701
|
}
|
|
1546
1702
|
if (token.type === "keyword" && token.value === "await") {
|
|
1703
|
+
if (!this.lexicalContext.await)
|
|
1704
|
+
throw new DisallowedSyntaxError("await in a class element", token.start);
|
|
1547
1705
|
if (this.functionContext === "generator") {
|
|
1548
1706
|
throw new Error(`generators cannot await; use a regular async function at line ${token.start.line}, column ${token.start.column}.`);
|
|
1549
1707
|
}
|
|
@@ -1677,6 +1835,7 @@ class Parser {
|
|
|
1677
1835
|
const quasi = createTemplateLiteral(this.currentToken(), {
|
|
1678
1836
|
allowMalformedEscapes: true,
|
|
1679
1837
|
functionContext: this.functionContext,
|
|
1838
|
+
lexicalContext: this.lexicalContext,
|
|
1680
1839
|
source: this.source
|
|
1681
1840
|
}, this.compilation);
|
|
1682
1841
|
this.index += 1;
|
|
@@ -1714,6 +1873,18 @@ class Parser {
|
|
|
1714
1873
|
}
|
|
1715
1874
|
parsePrimaryExpression() {
|
|
1716
1875
|
const token = this.currentToken();
|
|
1876
|
+
if (token.value === "class")
|
|
1877
|
+
return { node: this.parseClass(false), parenthesized: false };
|
|
1878
|
+
if (token.value === "super") {
|
|
1879
|
+
const next = this.peekToken(1).value;
|
|
1880
|
+
if (!(next === "(" ? this.lexicalContext.superCall :
|
|
1881
|
+
(next === "." || next === "[") && this.lexicalContext.superProperty))
|
|
1882
|
+
throw new DisallowedSyntaxError("super", token.start);
|
|
1883
|
+
this.index++;
|
|
1884
|
+
return { node: { type: "Super", span: createTokenSpan(token) }, parenthesized: false };
|
|
1885
|
+
}
|
|
1886
|
+
if (token.value === "arguments" && !this.lexicalContext.arguments)
|
|
1887
|
+
throw new DisallowedSyntaxError("arguments in a class element", token.start);
|
|
1717
1888
|
if (token.type === "keyword" && token.value === "this") {
|
|
1718
1889
|
this.index += 1;
|
|
1719
1890
|
return {
|
|
@@ -1769,6 +1940,7 @@ class Parser {
|
|
|
1769
1940
|
node: createTemplateLiteral(token, {
|
|
1770
1941
|
allowMalformedEscapes: false,
|
|
1771
1942
|
functionContext: this.functionContext,
|
|
1943
|
+
lexicalContext: this.lexicalContext,
|
|
1772
1944
|
source: this.source
|
|
1773
1945
|
}, this.compilation),
|
|
1774
1946
|
parenthesized: false
|
|
@@ -1815,7 +1987,11 @@ class Parser {
|
|
|
1815
1987
|
const newToken = this.currentToken();
|
|
1816
1988
|
this.index += 1;
|
|
1817
1989
|
if (this.consumePunctuator(".") !== undefined) {
|
|
1818
|
-
|
|
1990
|
+
const target = this.currentToken();
|
|
1991
|
+
if (target.value !== "target" || !this.lexicalContext.newTarget)
|
|
1992
|
+
throw new DisallowedSyntaxError(newToken.value, newToken.start);
|
|
1993
|
+
this.index++;
|
|
1994
|
+
return { node: { type: "NewTargetExpression", span: createSpan(newToken.start, target.end) }, parenthesized: false };
|
|
1819
1995
|
}
|
|
1820
1996
|
let callee = this.parsePrimaryExpression();
|
|
1821
1997
|
while (true) {
|
|
@@ -1855,6 +2031,8 @@ class Parser {
|
|
|
1855
2031
|
const optional = this.consumePunctuator("?.");
|
|
1856
2032
|
if (optional !== undefined)
|
|
1857
2033
|
throw new DisallowedSyntaxError("new optional chain", optional.start);
|
|
2034
|
+
if (callee.node.type === "Super")
|
|
2035
|
+
throw new DisallowedSyntaxError("new super", newToken.start);
|
|
1858
2036
|
const args = this.consumePunctuator("(") === undefined ? [] : this.parseArguments();
|
|
1859
2037
|
const end = this.previousToken();
|
|
1860
2038
|
return {
|
|
@@ -1877,17 +2055,8 @@ class Parser {
|
|
|
1877
2055
|
const id = isIdentifierLikeToken(this.currentToken())
|
|
1878
2056
|
? this.parseBindingIdentifier()
|
|
1879
2057
|
: undefined;
|
|
1880
|
-
const params = this.withScope(() => {
|
|
1881
|
-
const parsedParams = this.parseArrowParameters();
|
|
1882
|
-
for (const param of parsedParams) {
|
|
1883
|
-
for (const identifier of boundIdentifiers(param)) {
|
|
1884
|
-
this.declareBinding(identifier);
|
|
1885
|
-
}
|
|
1886
|
-
}
|
|
1887
|
-
return parsedParams;
|
|
1888
|
-
});
|
|
1889
2058
|
const generator = generatorToken !== undefined;
|
|
1890
|
-
const body = this.
|
|
2059
|
+
const { params, body } = this.parseFunctionParts(generator, ordinaryFunctionContext);
|
|
1891
2060
|
return this.withFunctionSource({
|
|
1892
2061
|
type: "FunctionExpression",
|
|
1893
2062
|
async: asyncToken !== undefined,
|
|
@@ -2142,16 +2311,10 @@ class Parser {
|
|
|
2142
2311
|
this.peekToken(2).value === "(");
|
|
2143
2312
|
}
|
|
2144
2313
|
parseObjectMethod(asyncToken, methodStart) {
|
|
2145
|
-
const params = this.
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
for (const identifier of boundIdentifiers(param)) {
|
|
2149
|
-
this.declareBinding(identifier);
|
|
2150
|
-
}
|
|
2151
|
-
}
|
|
2152
|
-
return parsedParams;
|
|
2314
|
+
const { params, body } = this.parseFunctionParts(false, {
|
|
2315
|
+
...ordinaryFunctionContext,
|
|
2316
|
+
superProperty: true
|
|
2153
2317
|
});
|
|
2154
|
-
const body = this.withFunctionContext("normal", () => this.parseBlockStatement(params));
|
|
2155
2318
|
return this.withFunctionSource({
|
|
2156
2319
|
type: "FunctionExpression",
|
|
2157
2320
|
async: asyncToken !== undefined,
|
|
@@ -2578,6 +2741,16 @@ class Parser {
|
|
|
2578
2741
|
this.functionContext = previousFunctionContext;
|
|
2579
2742
|
}
|
|
2580
2743
|
}
|
|
2744
|
+
withLexicalContext(context, callback) {
|
|
2745
|
+
const previous = this.lexicalContext;
|
|
2746
|
+
this.lexicalContext = context;
|
|
2747
|
+
try {
|
|
2748
|
+
return callback();
|
|
2749
|
+
}
|
|
2750
|
+
finally {
|
|
2751
|
+
this.lexicalContext = previous;
|
|
2752
|
+
}
|
|
2753
|
+
}
|
|
2581
2754
|
withLoopContext(callback) {
|
|
2582
2755
|
this.breakableDepth += 1;
|
|
2583
2756
|
this.loopDepth += 1;
|
|
@@ -3046,7 +3219,7 @@ function createTemplateLiteral(token, options, compilation) {
|
|
|
3046
3219
|
quasis.push(createTemplateElement(token.start, raw, quasiStart, cursor, false, options));
|
|
3047
3220
|
const expressionStart = cursor + 2;
|
|
3048
3221
|
const expressionEnd = findTemplateExpressionEnd(raw, expressionStart);
|
|
3049
|
-
expressions.push(parseEmbeddedExpression(raw.slice(expressionStart, expressionEnd), positionWithinRaw(token.start, raw, expressionStart), options.functionContext, options.source, compilation));
|
|
3222
|
+
expressions.push(parseEmbeddedExpression(raw.slice(expressionStart, expressionEnd), positionWithinRaw(token.start, raw, expressionStart), options.functionContext, options.lexicalContext, options.source, compilation));
|
|
3050
3223
|
quasiStart = expressionEnd + 1;
|
|
3051
3224
|
cursor = expressionEnd + 1;
|
|
3052
3225
|
continue;
|
|
@@ -3407,13 +3580,13 @@ function decodeHexEscape(value, start) {
|
|
|
3407
3580
|
end: index + 2
|
|
3408
3581
|
};
|
|
3409
3582
|
}
|
|
3410
|
-
function parseEmbeddedExpression(source, base, functionContext, fullSource, compilation) {
|
|
3583
|
+
function parseEmbeddedExpression(source, base, functionContext, lexicalContext, fullSource, compilation) {
|
|
3411
3584
|
const tokens = tokenize(source, { allowRegexLiterals: true, compilation }).map((token) => ({
|
|
3412
3585
|
...token,
|
|
3413
3586
|
start: rebasePosition(token.start, base),
|
|
3414
3587
|
end: rebasePosition(token.end, base)
|
|
3415
3588
|
}));
|
|
3416
|
-
return new Parser(tokens, fullSource, compilation, functionContext).parseExpressionOnly();
|
|
3589
|
+
return new Parser(tokens, fullSource, compilation, functionContext, lexicalContext).parseExpressionOnly();
|
|
3417
3590
|
}
|
|
3418
3591
|
export function findRegexLiteral(node) {
|
|
3419
3592
|
if (node === null || node === undefined) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type ParseResult as ParsedNode } from "./parse/parser.js";
|
|
2
2
|
export { DisallowedSyntaxError } from "./parse/parser.js";
|
|
3
3
|
export declare const parse: (source: string, filename?: string) => ParsedNode;
|
|
4
|
-
export type { ArrayPattern, ArrayExpression, ArrowFunctionExpression, AssignmentExpression, AssignmentPattern, AssignmentProperty, AwaitExpression, BinaryExpression, BlockStatement, BooleanLiteral, BreakStatement, CallExpression, CatchClause, ConditionalExpression, ContinueStatement, DoWhileStatement, EmptyStatement, Expression, ExpressionStatement, ExportDefaultDeclaration, ExportNamedDeclaration, ImportDeclaration, ImportDefaultSpecifier, ImportNamespaceSpecifier, ImportSpecifier, ForInStatement, ForOfStatement, ForStatement, FunctionDeclaration, FunctionExpression, Identifier, IfStatement, LogicalExpression, MemberExpression, MetaProperty, NewExpression, NullLiteral, NumericLiteral, ObjectExpression, ObjectPattern, ParseResult, PatternTarget, Property, RegexLiteral, RestElement, ReturnStatement, SequenceExpression, SourceSpan, SpreadElement, Statement, StringLiteral, SwitchCase, SwitchStatement, TaggedTemplateExpression, TemplateElement, TemplateLiteral, ThisExpression, ThrowStatement, TryStatement, UnaryExpression, UndefinedLiteral, UpdateExpression, UpdateTarget, VariableDeclaration, VariableDeclarationKind, VariableDeclarator, WhileStatement } from "./parse/parser.js";
|
|
4
|
+
export type { ArrayPattern, ArrayExpression, ArrowFunctionExpression, AssignmentExpression, AssignmentPattern, AssignmentProperty, AwaitExpression, BinaryExpression, BlockStatement, BooleanLiteral, BreakStatement, CallExpression, CatchClause, ClassBody, ClassDeclaration, ClassElement, ClassExpression, ClassNode, ConditionalExpression, ContinueStatement, DoWhileStatement, EmptyStatement, Expression, ExpressionStatement, ExportDefaultDeclaration, ExportNamedDeclaration, ImportDeclaration, ImportDefaultSpecifier, ImportNamespaceSpecifier, ImportSpecifier, ForInStatement, ForOfStatement, ForStatement, FunctionDeclaration, FunctionExpression, Identifier, IfStatement, LogicalExpression, MemberExpression, MetaProperty, NewExpression, NewTargetExpression, NullLiteral, NumericLiteral, ObjectExpression, ObjectPattern, ParseResult, PatternTarget, Property, RegexLiteral, RestElement, ReturnStatement, SequenceExpression, SourceSpan, SpreadElement, Statement, StringLiteral, SuperExpression, SwitchCase, SwitchStatement, TaggedTemplateExpression, TemplateElement, TemplateLiteral, ThisExpression, ThrowStatement, TryStatement, UnaryExpression, UndefinedLiteral, UpdateExpression, UpdateTarget, VariableDeclaration, VariableDeclarationKind, VariableDeclarator, WhileStatement } from "./parse/parser.js";
|