poe-code 14.0.63 → 14.0.65

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.
Files changed (58) hide show
  1. package/dist/index.js +7473 -6816
  2. package/dist/index.js.map +4 -4
  3. package/dist/metafile.json +1 -1
  4. package/package.json +1 -1
  5. package/packages/safe-js/dist/chunks/{chunk-KMTTD3BL.js → chunk-4VT2M7WL.js} +2 -2
  6. package/packages/safe-js/dist/chunks/{chunk-RU2BCN4G.js → chunk-WBWD7ZCM.js} +8215 -7599
  7. package/packages/safe-js/dist/chunks/chunk-WBWD7ZCM.js.map +7 -0
  8. package/packages/safe-js/dist/cli.js +2 -2
  9. package/packages/safe-js/dist/core.js +1 -1
  10. package/packages/safe-js/dist/index.js +2 -2
  11. package/packages/safe-js/dist/index.js.map +1 -1
  12. package/packages/safe-js/dist/interp/async.d.ts +13 -2
  13. package/packages/safe-js/dist/interp/async.js +16 -6
  14. package/packages/safe-js/dist/interp/classes.d.ts +4 -0
  15. package/packages/safe-js/dist/interp/classes.js +176 -0
  16. package/packages/safe-js/dist/interp/exceptions.js +4 -1
  17. package/packages/safe-js/dist/interp/globals/object-array.d.ts +2 -1
  18. package/packages/safe-js/dist/interp/globals/object-array.js +1 -1
  19. package/packages/safe-js/dist/interp/globals/object.js +10 -2
  20. package/packages/safe-js/dist/interp/globals/primitives.js +8 -3
  21. package/packages/safe-js/dist/interp/interpreter.d.ts +1 -1
  22. package/packages/safe-js/dist/interp/interpreter.js +99 -30
  23. package/packages/safe-js/dist/interp/methods/function.d.ts +1 -1
  24. package/packages/safe-js/dist/interp/methods/function.js +33 -16
  25. package/packages/safe-js/dist/interp/object-model.js +25 -11
  26. package/packages/safe-js/dist/interp/patterns.d.ts +1 -1
  27. package/packages/safe-js/dist/interp/patterns.js +1 -1
  28. package/packages/safe-js/dist/interp/values.d.ts +2 -1
  29. package/packages/safe-js/dist/lint/class-elements.d.ts +5 -0
  30. package/packages/safe-js/dist/lint/class-elements.js +20 -0
  31. package/packages/safe-js/dist/lint/rules/AS-async-not-needed.js +16 -0
  32. package/packages/safe-js/dist/lint/rules/AS-destructure-null-default.js +9 -0
  33. package/packages/safe-js/dist/lint/rules/AS-export-import-meta.js +9 -0
  34. package/packages/safe-js/dist/lint/rules/AS-floating-promise.js +9 -0
  35. package/packages/safe-js/dist/lint/rules/AS-frontmatter-field-unused.js +9 -0
  36. package/packages/safe-js/dist/lint/rules/AS-jsdoc-type.js +9 -0
  37. package/packages/safe-js/dist/lint/rules/AS-large-literal.js +9 -0
  38. package/packages/safe-js/dist/lint/rules/AS-missing-async.js +16 -0
  39. package/packages/safe-js/dist/lint/rules/AS-mutating-frozen.js +9 -0
  40. package/packages/safe-js/dist/lint/rules/AS-needless-template.js +9 -0
  41. package/packages/safe-js/dist/lint/rules/AS-shadow-global.js +12 -0
  42. package/packages/safe-js/dist/lint/rules/AS-unbounded-loop.js +11 -0
  43. package/packages/safe-js/dist/lint/rules/AS-unreachable.js +9 -0
  44. package/packages/safe-js/dist/lint/rules/AS-unused-import.js +16 -2
  45. package/packages/safe-js/dist/lint/rules/AS001.js +0 -1
  46. package/packages/safe-js/dist/lint/rules/AS003.js +16 -2
  47. package/packages/safe-js/dist/lint/rules/AS006-007.js +16 -2
  48. package/packages/safe-js/dist/lint/rules/AS009.js +20 -1
  49. package/packages/safe-js/dist/lint/rules/AS010.js +9 -0
  50. package/packages/safe-js/dist/lint/rules/AS011.js +9 -0
  51. package/packages/safe-js/dist/lint/rules/AS015.js +9 -0
  52. package/packages/safe-js/dist/parse/function-source.d.ts +2 -2
  53. package/packages/safe-js/dist/parse/parser.d.ts +42 -2
  54. package/packages/safe-js/dist/parse/parser.js +180 -36
  55. package/packages/safe-js/dist/parse/tokenizer.js +3 -0
  56. package/packages/safe-js/dist/parse.d.ts +1 -1
  57. package/packages/safe-js/dist/chunks/chunk-RU2BCN4G.js.map +0 -7
  58. /package/packages/safe-js/dist/chunks/{chunk-KMTTD3BL.js.map → chunk-4VT2M7WL.js.map} +0 -0
@@ -247,6 +247,46 @@ export type FunctionExpression = BaseNode & {
247
247
  method?: true;
248
248
  params: ArrowFunctionExpression["params"];
249
249
  };
250
+ export type ClassElement = (BaseNode & {
251
+ type: "MethodDefinition";
252
+ computed: boolean;
253
+ key: Expression;
254
+ kind: "constructor" | "method";
255
+ static: boolean;
256
+ value: FunctionExpression;
257
+ }) | (BaseNode & {
258
+ type: "PropertyDefinition";
259
+ computed: boolean;
260
+ key: Expression;
261
+ static: boolean;
262
+ value?: Expression;
263
+ }) | (BaseNode & {
264
+ type: "StaticBlock";
265
+ body: BlockStatement;
266
+ });
267
+ export type ClassBody = BaseNode & {
268
+ type: "ClassBody";
269
+ body: ClassElement[];
270
+ };
271
+ export type ClassDeclaration = BaseNode & {
272
+ type: "ClassDeclaration";
273
+ id: Identifier;
274
+ superClass?: Expression;
275
+ body: ClassBody;
276
+ };
277
+ export type ClassExpression = BaseNode & {
278
+ type: "ClassExpression";
279
+ id?: Identifier;
280
+ superClass?: Expression;
281
+ body: ClassBody;
282
+ };
283
+ export type ClassNode = ClassDeclaration | ClassExpression;
284
+ export type SuperExpression = BaseNode & {
285
+ type: "Super";
286
+ };
287
+ export type NewTargetExpression = BaseNode & {
288
+ type: "NewTargetExpression";
289
+ };
250
290
  export type IfStatement = BaseNode & {
251
291
  type: "IfStatement";
252
292
  test: Expression;
@@ -339,7 +379,7 @@ export type Module = BaseNode & {
339
379
  type: "Module";
340
380
  body: Statement[];
341
381
  };
342
- export type Statement = BlockStatement | BreakStatement | DoWhileStatement | ExportDefaultDeclaration | ExportNamedDeclaration | ImportDeclaration | TryStatement | ContinueStatement | EmptyStatement | ExpressionStatement | FunctionDeclaration | ForInStatement | ForOfStatement | ForStatement | IfStatement | ReturnStatement | SwitchStatement | ThrowStatement | VariableDeclaration | WhileStatement;
382
+ export type Statement = BlockStatement | ClassDeclaration | BreakStatement | DoWhileStatement | ExportDefaultDeclaration | ExportNamedDeclaration | ImportDeclaration | TryStatement | ContinueStatement | EmptyStatement | ExpressionStatement | FunctionDeclaration | ForInStatement | ForOfStatement | ForStatement | IfStatement | ReturnStatement | SwitchStatement | ThrowStatement | VariableDeclaration | WhileStatement;
343
383
  export type ArrowFunctionExpression = BaseNode & {
344
384
  type: "ArrowFunctionExpression";
345
385
  async: boolean;
@@ -348,7 +388,7 @@ export type ArrowFunctionExpression = BaseNode & {
348
388
  params: Array<AssignmentPattern | ArrayPattern | Identifier | ObjectPattern | RestElement>;
349
389
  };
350
390
  export type FunctionNode = ArrowFunctionExpression | FunctionDeclaration | FunctionExpression;
351
- export type Expression = ArrowFunctionExpression | AssignmentExpression | ArrayExpression | AwaitExpression | BinaryExpression | BooleanLiteral | CallExpression | ConditionalExpression | FunctionExpression | Identifier | LogicalExpression | MemberExpression | MetaProperty | NewExpression | NullLiteral | NumericLiteral | ObjectExpression | RegexLiteral | SequenceExpression | StringLiteral | TaggedTemplateExpression | TemplateLiteral | ThisExpression | UnaryExpression | UpdateExpression | UndefinedLiteral | YieldExpression;
391
+ export type Expression = ArrowFunctionExpression | AssignmentExpression | ArrayExpression | AwaitExpression | BinaryExpression | BooleanLiteral | CallExpression | ConditionalExpression | ClassExpression | FunctionExpression | Identifier | LogicalExpression | MemberExpression | MetaProperty | NewExpression | NewTargetExpression | NullLiteral | NumericLiteral | ObjectExpression | RegexLiteral | SequenceExpression | StringLiteral | SuperExpression | TaggedTemplateExpression | TemplateLiteral | ThisExpression | UnaryExpression | UpdateExpression | UndefinedLiteral | YieldExpression;
352
392
  export type ParseResult = Expression | Statement;
353
393
  export declare function parse(source: string, filename?: string, owner?: CompileOwner): ParseResult;
354
394
  export declare function parseModule(source: string, filename?: string, owner?: CompileOwner): Module;
@@ -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.parseArrowFunctionBody(params);
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.withFunctionContext(generator ? "generator" : "normal", () => this.parseBlockStatement(params));
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,132 @@ 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) {
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
+ const body = this.withFunctionContext(generator ? "generator" : "normal", () => this.parseBlockStatement(params));
993
+ return { params, body };
994
+ });
995
+ }
996
+ parseClassElement(derived) {
997
+ const start = this.currentToken();
998
+ let isStatic = false;
999
+ if (start.value === "static" && !["(", "=", ";", "}"].includes(this.peekToken(1).value)) {
1000
+ this.index++;
1001
+ isStatic = true;
1002
+ if (this.currentToken().value === "{") {
1003
+ const body = this.withLexicalContext({
1004
+ newTarget: true, superProperty: true, superCall: false,
1005
+ arguments: false, return: false, await: false, strictAwait: true
1006
+ }, () => this.withFunctionContext("normal", () => this.parseBlockStatement([])));
1007
+ return { type: "StaticBlock", body, span: createSpan(start.start, body.span.end) };
1008
+ }
1009
+ }
1010
+ const methodStart = this.currentToken();
1011
+ let async = false;
1012
+ if (methodStart.value === "async" && !hasLineBreakBetween(methodStart, this.peekToken(1)) &&
1013
+ (this.peekToken(1).value === "*" || this.isObjectMethodStart())) {
1014
+ this.index++;
1015
+ async = true;
1016
+ }
1017
+ const generator = this.consumePunctuator("*") !== undefined;
1018
+ if (async && generator)
1019
+ throw new DisallowedSyntaxError("async generator", methodStart.start);
1020
+ if ((this.currentToken().value === "get" || this.currentToken().value === "set") && this.isObjectMethodStart())
1021
+ throw new DisallowedSyntaxError("class accessor", this.currentToken().start);
1022
+ const computed = this.consumePunctuator("[") !== undefined;
1023
+ const key = computed
1024
+ ? this.parseExpression({ allowSequence: true }).node
1025
+ : this.currentToken().type === "string"
1026
+ ? createStringLiteral(this.tokens[this.index++])
1027
+ : this.currentToken().type === "numeric"
1028
+ ? createNumericLiteral(this.tokens[this.index++])
1029
+ : this.parseIdentifierName();
1030
+ if (computed)
1031
+ this.expectPunctuator("]");
1032
+ const name = computed ? undefined : key.type === "Identifier" ? key.name
1033
+ : key.type === "StringLiteral" || key.type === "NumericLiteral" ? String(key.value) : undefined;
1034
+ if (isStatic && name === "prototype")
1035
+ throw new Error("A static class element cannot be named prototype.");
1036
+ if (this.currentToken().value === "(") {
1037
+ const constructor = !isStatic && name === "constructor";
1038
+ if (constructor && (async || generator))
1039
+ throw new Error("A class constructor cannot be async or a generator.");
1040
+ const { params, body } = this.parseFunctionParts(generator, {
1041
+ newTarget: true, superProperty: true, superCall: constructor && derived,
1042
+ arguments: true, return: true, await: async, strictAwait: true
1043
+ });
1044
+ const value = this.withFunctionSource({
1045
+ type: "FunctionExpression", async, generator, method: true, params, body,
1046
+ span: createSpan(methodStart.start, body.span.end)
1047
+ });
1048
+ return {
1049
+ type: "MethodDefinition", key, computed, static: isStatic,
1050
+ kind: constructor ? "constructor" : "method", value,
1051
+ span: createSpan(start.start, value.span.end)
1052
+ };
1053
+ }
1054
+ if (async || generator)
1055
+ throw unexpectedTokenError(this.currentToken());
1056
+ if (name === "constructor")
1057
+ throw new Error("A class field cannot be named constructor.");
1058
+ const value = this.consumePunctuator("=") === undefined ? undefined : this.withLexicalContext({
1059
+ newTarget: true, superProperty: true, superCall: false,
1060
+ arguments: false, return: false, await: false, strictAwait: true
1061
+ }, () => this.withFunctionContext("normal", () => this.parseExpression().node));
1062
+ const end = value?.span.end ?? key.span.end;
1063
+ if (this.consumePunctuator(";") === undefined && this.currentToken().value !== "}" &&
1064
+ !hasLineBreakBetween(this.previousToken(), this.currentToken()))
1065
+ throw unexpectedTokenError(this.currentToken());
1066
+ return { type: "PropertyDefinition", key, computed, static: isStatic, value, span: createSpan(start.start, end) };
1067
+ }
938
1068
  parseVariableDeclarator(kind) {
939
1069
  const id = this.parseBindingTarget();
940
1070
  let init;
@@ -1544,6 +1674,8 @@ class Parser {
1544
1674
  };
1545
1675
  }
1546
1676
  if (token.type === "keyword" && token.value === "await") {
1677
+ if (!this.lexicalContext.await)
1678
+ throw new DisallowedSyntaxError("await in a class element", token.start);
1547
1679
  if (this.functionContext === "generator") {
1548
1680
  throw new Error(`generators cannot await; use a regular async function at line ${token.start.line}, column ${token.start.column}.`);
1549
1681
  }
@@ -1677,6 +1809,7 @@ class Parser {
1677
1809
  const quasi = createTemplateLiteral(this.currentToken(), {
1678
1810
  allowMalformedEscapes: true,
1679
1811
  functionContext: this.functionContext,
1812
+ lexicalContext: this.lexicalContext,
1680
1813
  source: this.source
1681
1814
  }, this.compilation);
1682
1815
  this.index += 1;
@@ -1714,6 +1847,18 @@ class Parser {
1714
1847
  }
1715
1848
  parsePrimaryExpression() {
1716
1849
  const token = this.currentToken();
1850
+ if (token.value === "class")
1851
+ return { node: this.parseClass(false), parenthesized: false };
1852
+ if (token.value === "super") {
1853
+ const next = this.peekToken(1).value;
1854
+ if (!(next === "(" ? this.lexicalContext.superCall :
1855
+ (next === "." || next === "[") && this.lexicalContext.superProperty))
1856
+ throw new DisallowedSyntaxError("super", token.start);
1857
+ this.index++;
1858
+ return { node: { type: "Super", span: createTokenSpan(token) }, parenthesized: false };
1859
+ }
1860
+ if (token.value === "arguments" && !this.lexicalContext.arguments)
1861
+ throw new DisallowedSyntaxError("arguments in a class element", token.start);
1717
1862
  if (token.type === "keyword" && token.value === "this") {
1718
1863
  this.index += 1;
1719
1864
  return {
@@ -1769,6 +1914,7 @@ class Parser {
1769
1914
  node: createTemplateLiteral(token, {
1770
1915
  allowMalformedEscapes: false,
1771
1916
  functionContext: this.functionContext,
1917
+ lexicalContext: this.lexicalContext,
1772
1918
  source: this.source
1773
1919
  }, this.compilation),
1774
1920
  parenthesized: false
@@ -1815,7 +1961,11 @@ class Parser {
1815
1961
  const newToken = this.currentToken();
1816
1962
  this.index += 1;
1817
1963
  if (this.consumePunctuator(".") !== undefined) {
1818
- throw new DisallowedSyntaxError(newToken.value, newToken.start);
1964
+ const target = this.currentToken();
1965
+ if (target.value !== "target" || !this.lexicalContext.newTarget)
1966
+ throw new DisallowedSyntaxError(newToken.value, newToken.start);
1967
+ this.index++;
1968
+ return { node: { type: "NewTargetExpression", span: createSpan(newToken.start, target.end) }, parenthesized: false };
1819
1969
  }
1820
1970
  let callee = this.parsePrimaryExpression();
1821
1971
  while (true) {
@@ -1855,6 +2005,8 @@ class Parser {
1855
2005
  const optional = this.consumePunctuator("?.");
1856
2006
  if (optional !== undefined)
1857
2007
  throw new DisallowedSyntaxError("new optional chain", optional.start);
2008
+ if (callee.node.type === "Super")
2009
+ throw new DisallowedSyntaxError("new super", newToken.start);
1858
2010
  const args = this.consumePunctuator("(") === undefined ? [] : this.parseArguments();
1859
2011
  const end = this.previousToken();
1860
2012
  return {
@@ -1877,17 +2029,8 @@ class Parser {
1877
2029
  const id = isIdentifierLikeToken(this.currentToken())
1878
2030
  ? this.parseBindingIdentifier()
1879
2031
  : 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
2032
  const generator = generatorToken !== undefined;
1890
- const body = this.withFunctionContext(generator ? "generator" : "normal", () => this.parseBlockStatement(params));
2033
+ const { params, body } = this.parseFunctionParts(generator, ordinaryFunctionContext);
1891
2034
  return this.withFunctionSource({
1892
2035
  type: "FunctionExpression",
1893
2036
  async: asyncToken !== undefined,
@@ -2142,16 +2285,7 @@ class Parser {
2142
2285
  this.peekToken(2).value === "(");
2143
2286
  }
2144
2287
  parseObjectMethod(asyncToken, methodStart) {
2145
- const params = this.withScope(() => {
2146
- const parsedParams = this.parseArrowParameters();
2147
- for (const param of parsedParams) {
2148
- for (const identifier of boundIdentifiers(param)) {
2149
- this.declareBinding(identifier);
2150
- }
2151
- }
2152
- return parsedParams;
2153
- });
2154
- const body = this.withFunctionContext("normal", () => this.parseBlockStatement(params));
2288
+ const { params, body } = this.parseFunctionParts(false, ordinaryFunctionContext);
2155
2289
  return this.withFunctionSource({
2156
2290
  type: "FunctionExpression",
2157
2291
  async: asyncToken !== undefined,
@@ -2578,6 +2712,16 @@ class Parser {
2578
2712
  this.functionContext = previousFunctionContext;
2579
2713
  }
2580
2714
  }
2715
+ withLexicalContext(context, callback) {
2716
+ const previous = this.lexicalContext;
2717
+ this.lexicalContext = context;
2718
+ try {
2719
+ return callback();
2720
+ }
2721
+ finally {
2722
+ this.lexicalContext = previous;
2723
+ }
2724
+ }
2581
2725
  withLoopContext(callback) {
2582
2726
  this.breakableDepth += 1;
2583
2727
  this.loopDepth += 1;
@@ -3046,7 +3190,7 @@ function createTemplateLiteral(token, options, compilation) {
3046
3190
  quasis.push(createTemplateElement(token.start, raw, quasiStart, cursor, false, options));
3047
3191
  const expressionStart = cursor + 2;
3048
3192
  const expressionEnd = findTemplateExpressionEnd(raw, expressionStart);
3049
- expressions.push(parseEmbeddedExpression(raw.slice(expressionStart, expressionEnd), positionWithinRaw(token.start, raw, expressionStart), options.functionContext, options.source, compilation));
3193
+ expressions.push(parseEmbeddedExpression(raw.slice(expressionStart, expressionEnd), positionWithinRaw(token.start, raw, expressionStart), options.functionContext, options.lexicalContext, options.source, compilation));
3050
3194
  quasiStart = expressionEnd + 1;
3051
3195
  cursor = expressionEnd + 1;
3052
3196
  continue;
@@ -3407,13 +3551,13 @@ function decodeHexEscape(value, start) {
3407
3551
  end: index + 2
3408
3552
  };
3409
3553
  }
3410
- function parseEmbeddedExpression(source, base, functionContext, fullSource, compilation) {
3554
+ function parseEmbeddedExpression(source, base, functionContext, lexicalContext, fullSource, compilation) {
3411
3555
  const tokens = tokenize(source, { allowRegexLiterals: true, compilation }).map((token) => ({
3412
3556
  ...token,
3413
3557
  start: rebasePosition(token.start, base),
3414
3558
  end: rebasePosition(token.end, base)
3415
3559
  }));
3416
- return new Parser(tokens, fullSource, compilation, functionContext).parseExpressionOnly();
3560
+ return new Parser(tokens, fullSource, compilation, functionContext, lexicalContext).parseExpressionOnly();
3417
3561
  }
3418
3562
  export function findRegexLiteral(node) {
3419
3563
  if (node === null || node === undefined) {
@@ -1,5 +1,8 @@
1
1
  import { RegexCompileGuard } from "../interp/regex/compile-guard.js";
2
2
  const KEYWORDS = new Set([
3
+ "class",
4
+ "extends",
5
+ "super",
3
6
  "const",
4
7
  "let",
5
8
  "if",
@@ -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";