meriyah 7.0.0 → 7.1.1

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/meriyah.mjs CHANGED
@@ -1,4 +1,4 @@
1
- var version$1 = "7.0.0";
1
+ var version$1 = "7.1.1";
2
2
 
3
3
  const unicodeLookup = ((compressed, lookup) => {
4
4
  const result = new Uint32Array(69632);
@@ -805,6 +805,7 @@ class ParseError extends SyntaxError {
805
805
  this.description = description;
806
806
  }
807
807
  }
808
+ const isParseError = (error) => error instanceof ParseError;
808
809
 
809
810
  function getOwnProperty(object, key) {
810
811
  return Object.hasOwn(object, key) ? object[key] : undefined;
@@ -1547,7 +1548,7 @@ function parseEscape(parser, context, first, isTemplate = 0) {
1547
1548
  }
1548
1549
  case 56:
1549
1550
  case 57:
1550
- if (isTemplate || !parser.options.webcompat || context & 1)
1551
+ if (isTemplate || context & 1)
1551
1552
  return -3;
1552
1553
  parser.flags |= 4096;
1553
1554
  default:
@@ -2003,7 +2004,7 @@ function scanSingleToken(parser, context, state) {
2003
2004
  advanceChar(parser);
2004
2005
  if (parser.currentChar === 61) {
2005
2006
  advanceChar(parser);
2006
- return 4194344;
2007
+ return 4718632;
2007
2008
  }
2008
2009
  return 8913465;
2009
2010
  }
@@ -2046,7 +2047,7 @@ function scanSingleToken(parser, context, state) {
2046
2047
  advanceChar(parser);
2047
2048
  if (parser.currentChar === 61) {
2048
2049
  advanceChar(parser);
2049
- return 4194345;
2050
+ return 4718633;
2050
2051
  }
2051
2052
  return 8913720;
2052
2053
  }
@@ -2062,7 +2063,7 @@ function scanSingleToken(parser, context, state) {
2062
2063
  advanceChar(parser);
2063
2064
  if (parser.currentChar === 61) {
2064
2065
  advanceChar(parser);
2065
- return 4194346;
2066
+ return 4718634;
2066
2067
  }
2067
2068
  return 276824445;
2068
2069
  }
@@ -4541,10 +4542,22 @@ function rescanJSXIdentifier(parser) {
4541
4542
  return parser.getToken();
4542
4543
  }
4543
4544
 
4545
+ function normalizeRanges(ranges) {
4546
+ if (!ranges)
4547
+ return undefined;
4548
+ if (ranges === true)
4549
+ return { start: true, end: true, range: true };
4550
+ return {
4551
+ start: ranges.start ?? false,
4552
+ end: ranges.end ?? false,
4553
+ range: ranges.range ?? false,
4554
+ };
4555
+ }
4544
4556
  function normalizeOptions(rawOptions) {
4545
4557
  const options = {
4546
4558
  validateRegex: true,
4547
4559
  ...rawOptions,
4560
+ ranges: normalizeRanges(rawOptions.ranges),
4548
4561
  };
4549
4562
  if (options.module && !options.sourceType) {
4550
4563
  options.sourceType = 'module';
@@ -4728,8 +4741,9 @@ class Parser {
4728
4741
  currentChar = 0;
4729
4742
  exportedNames = new Set();
4730
4743
  exportedBindings = new Set();
4731
- assignable = 1;
4744
+ assignable = 0;
4732
4745
  destructible = 0;
4746
+ strictReservedRange = null;
4733
4747
  leadingDecorators = { decorators: [] };
4734
4748
  constructor(source, rawOptions = {}) {
4735
4749
  this.source = source;
@@ -4786,11 +4800,15 @@ class Parser {
4786
4800
  return { index: this.index, line: this.line, column: this.column };
4787
4801
  }
4788
4802
  finishNode(node, start, end) {
4789
- if (this.options.ranges) {
4790
- node.start = start.index;
4803
+ const { ranges } = this.options;
4804
+ if (ranges) {
4791
4805
  const endIndex = end ? end.index : this.startIndex;
4792
- node.end = endIndex;
4793
- node.range = [start.index, endIndex];
4806
+ if (ranges.start)
4807
+ node.start = start.index;
4808
+ if (ranges.end)
4809
+ node.end = endIndex;
4810
+ if (ranges.range)
4811
+ node.range = [start.index, endIndex];
4794
4812
  }
4795
4813
  if (this.options.loc) {
4796
4814
  node.loc = {
@@ -4841,8 +4859,14 @@ class Parser {
4841
4859
  return this.cloneLocationInformation({ ...original }, original);
4842
4860
  }
4843
4861
  cloneLocationInformation(node, original) {
4844
- if (this.options.ranges) {
4845
- node.range = [...original.range];
4862
+ const { ranges } = this.options;
4863
+ if (ranges) {
4864
+ if (ranges.start)
4865
+ node.start = original.start;
4866
+ if (ranges.end)
4867
+ node.end = original.end;
4868
+ if (ranges.range)
4869
+ node.range = [...original.range];
4846
4870
  }
4847
4871
  if (this.options.loc) {
4848
4872
  node.loc = {
@@ -4860,10 +4884,14 @@ function pushComment(comments, options) {
4860
4884
  type,
4861
4885
  value,
4862
4886
  };
4863
- if (options.ranges) {
4864
- comment.start = start;
4865
- comment.end = end;
4866
- comment.range = [start, end];
4887
+ const { ranges } = options;
4888
+ if (ranges) {
4889
+ if (ranges.start)
4890
+ comment.start = start;
4891
+ if (ranges.end)
4892
+ comment.end = end;
4893
+ if (ranges.range)
4894
+ comment.range = [start, end];
4867
4895
  }
4868
4896
  if (options.loc) {
4869
4897
  comment.loc = loc;
@@ -4876,10 +4904,14 @@ function pushToken(tokens, options) {
4876
4904
  const token = {
4877
4905
  token: type,
4878
4906
  };
4879
- if (options.ranges) {
4880
- token.start = start;
4881
- token.end = end;
4882
- token.range = [start, end];
4907
+ const { ranges } = options;
4908
+ if (ranges) {
4909
+ if (ranges.start)
4910
+ token.start = start;
4911
+ if (ranges.end)
4912
+ token.end = end;
4913
+ if (ranges.range)
4914
+ token.range = [start, end];
4883
4915
  }
4884
4916
  if (options.loc) {
4885
4917
  token.loc = loc;
@@ -5518,7 +5550,7 @@ function parseVariableDeclaration(parser, context, scope, privateScope, kind, or
5518
5550
  if (parser.getToken() === 1077936155) {
5519
5551
  nextToken(parser, context | 32);
5520
5552
  init = parseExpression(parser, context, privateScope, 1, 0, parser.tokenStart);
5521
- if (origin & 32 || (token & 2097152) === 0) {
5553
+ if (origin & 32) {
5522
5554
  if (parser.getToken() === 471156 ||
5523
5555
  (parser.getToken() === 8673330 &&
5524
5556
  (token & 2097152 || (kind & 4) === 0 || context & 1))) {
@@ -6017,6 +6049,8 @@ function parseAssignmentExpression(parser, context, privateScope, inGroup, isPat
6017
6049
  if ((token & 4194304) === 4194304) {
6018
6050
  if (parser.assignable & 2)
6019
6051
  parser.report(26);
6052
+ if ((token & 524288) === 524288 && parser.assignable & 4)
6053
+ parser.report(26);
6020
6054
  if ((!isPattern && token === 1077936155 && left.type === 'ArrayExpression') ||
6021
6055
  left.type === 'ObjectExpression') {
6022
6056
  reinterpretToPattern(parser, left);
@@ -6263,8 +6297,12 @@ function parseFunctionBody(parser, context, scope, privateScope, origin, funcNam
6263
6297
  }
6264
6298
  if (parser.flags & 512)
6265
6299
  parser.report(119);
6266
- if (parser.flags & 256)
6300
+ if (parser.flags & 256) {
6301
+ if (parser.strictReservedRange) {
6302
+ throw new ParseError(parser.strictReservedRange[0], parser.strictReservedRange[1], 118);
6303
+ }
6267
6304
  parser.report(118);
6305
+ }
6268
6306
  }
6269
6307
  }
6270
6308
  parser.flags =
@@ -6349,6 +6387,10 @@ function parseMemberOrUpdateExpression(parser, context, privateScope, expr, inGr
6349
6387
  break;
6350
6388
  }
6351
6389
  case 69271571: {
6390
+ if ((parser.flags & 8192) === 8192) {
6391
+ parser.flags = (parser.flags | 8192) ^ 8192;
6392
+ return expr;
6393
+ }
6352
6394
  let restoreHasOptionalChaining = false;
6353
6395
  if ((parser.flags & 2048) === 2048) {
6354
6396
  restoreHasOptionalChaining = true;
@@ -6382,7 +6424,12 @@ function parseMemberOrUpdateExpression(parser, context, privateScope, expr, inGr
6382
6424
  parser.flags = (parser.flags | 2048) ^ 2048;
6383
6425
  }
6384
6426
  const args = parseArguments(parser, context, privateScope, inGroup);
6385
- parser.assignable = 2;
6427
+ if (!(context & 1) && parser.options.webcompat) {
6428
+ parser.assignable = 4;
6429
+ }
6430
+ else {
6431
+ parser.assignable = 2;
6432
+ }
6386
6433
  expr = parser.finishNode({
6387
6434
  type: 'CallExpression',
6388
6435
  callee: expr,
@@ -6450,7 +6497,12 @@ function parseOptionalChain(parser, context, privateScope, expr, start) {
6450
6497
  }
6451
6498
  else if (parser.getToken() === 67174411) {
6452
6499
  const args = parseArguments(parser, context, privateScope, 0);
6453
- parser.assignable = 2;
6500
+ if (!(context & 1) && parser.options.webcompat) {
6501
+ parser.assignable = 4;
6502
+ }
6503
+ else {
6504
+ parser.assignable = 2;
6505
+ }
6454
6506
  node = parser.finishNode({
6455
6507
  type: 'CallExpression',
6456
6508
  callee: expr,
@@ -6777,11 +6829,16 @@ function parseTemplateElement(parser, cooked, raw, start, tail) {
6777
6829
  tail,
6778
6830
  }, start);
6779
6831
  const tailSize = tail ? 1 : 2;
6780
- if (parser.options.ranges) {
6781
- node.start += 1;
6782
- node.range[0] += 1;
6783
- node.end -= tailSize;
6784
- node.range[1] -= tailSize;
6832
+ const { ranges } = parser.options;
6833
+ if (ranges) {
6834
+ if (ranges.start)
6835
+ node.start += 1;
6836
+ if (ranges.end)
6837
+ node.end -= tailSize;
6838
+ if (ranges.range) {
6839
+ node.range[0] += 1;
6840
+ node.range[1] -= tailSize;
6841
+ }
6785
6842
  }
6786
6843
  if (parser.options.loc) {
6787
6844
  node.loc.start.column += 1;
@@ -7055,9 +7112,9 @@ function parseArrayExpressionOrPattern(parser, context, scope, privateScope, ski
7055
7112
  }
7056
7113
  else if (parser.getToken() !== 1077936155) {
7057
7114
  destructible |=
7058
- parser.assignable & 2
7059
- ? 16
7060
- : 32;
7115
+ parser.assignable & 1
7116
+ ? 32
7117
+ : 16;
7061
7118
  }
7062
7119
  }
7063
7120
  }
@@ -7087,9 +7144,9 @@ function parseArrayExpressionOrPattern(parser, context, scope, privateScope, ski
7087
7144
  }
7088
7145
  else if (parser.getToken() !== 1077936155) {
7089
7146
  destructible |=
7090
- parser.assignable & 2
7091
- ? 16
7092
- : 32;
7147
+ parser.assignable & 1
7148
+ ? 32
7149
+ : 16;
7093
7150
  }
7094
7151
  }
7095
7152
  }
@@ -7206,7 +7263,7 @@ function parseSpreadOrRestElement(parser, context, scope, privateScope, closingT
7206
7263
  if (parser.destructible & 8)
7207
7264
  parser.report(71);
7208
7265
  argument = parseMemberOrUpdateExpression(parser, context, privateScope, argument, inGroup, 0, tokenStart);
7209
- destructible |= parser.assignable & 2 ? 16 : 0;
7266
+ destructible |= parser.assignable & 1 ? 0 : 16;
7210
7267
  if ((parser.getToken() & 4194304) === 4194304) {
7211
7268
  if (parser.getToken() !== 1077936155)
7212
7269
  destructible |= 16;
@@ -7220,9 +7277,9 @@ function parseSpreadOrRestElement(parser, context, scope, privateScope, closingT
7220
7277
  argument = parseConditionalExpression(parser, context, privateScope, argument, tokenStart);
7221
7278
  }
7222
7279
  destructible |=
7223
- parser.assignable & 2
7224
- ? 16
7225
- : 32;
7280
+ parser.assignable & 1
7281
+ ? 32
7282
+ : 16;
7226
7283
  }
7227
7284
  }
7228
7285
  else {
@@ -7251,7 +7308,9 @@ function parseSpreadOrRestElement(parser, context, scope, privateScope, closingT
7251
7308
  argument = parseAssignmentExpression(parser, context, privateScope, inGroup, isPattern, tokenStart, argument);
7252
7309
  }
7253
7310
  destructible |=
7254
- parser.assignable & 1 ? 32 : 16;
7311
+ parser.assignable & 1
7312
+ ? 32
7313
+ : 16;
7255
7314
  }
7256
7315
  parser.destructible = destructible;
7257
7316
  if (parser.getToken() !== closingToken && parser.getToken() !== 18)
@@ -7443,7 +7502,9 @@ function parseObjectLiteralOrPattern(parser, context, scope, privateScope, skipI
7443
7502
  : parseObjectLiteralOrPattern(parser, context, scope, privateScope, 0, inGroup, isPattern, kind, origin);
7444
7503
  destructible = parser.destructible;
7445
7504
  parser.assignable =
7446
- destructible & 16 ? 2 : 1;
7505
+ destructible & 16
7506
+ ? 2
7507
+ : 1;
7447
7508
  if (parser.getToken() === 18 || parser.getToken() === 1074790415) {
7448
7509
  if (parser.assignable & 2)
7449
7510
  destructible |= 16;
@@ -7465,9 +7526,9 @@ function parseObjectLiteralOrPattern(parser, context, scope, privateScope, skipI
7465
7526
  value = parseConditionalExpression(parser, context, privateScope, value, tokenStart);
7466
7527
  }
7467
7528
  destructible |=
7468
- parser.assignable & 2
7469
- ? 16
7470
- : 32;
7529
+ parser.assignable & 1
7530
+ ? 32
7531
+ : 16;
7471
7532
  }
7472
7533
  }
7473
7534
  }
@@ -7624,7 +7685,9 @@ function parseObjectLiteralOrPattern(parser, context, scope, privateScope, skipI
7624
7685
  : parseObjectLiteralOrPattern(parser, context, scope, privateScope, 0, inGroup, isPattern, kind, origin);
7625
7686
  destructible = parser.destructible;
7626
7687
  parser.assignable =
7627
- destructible & 16 ? 2 : 1;
7688
+ destructible & 16
7689
+ ? 2
7690
+ : 1;
7628
7691
  if (parser.getToken() === 18 || parser.getToken() === 1074790415) {
7629
7692
  if (parser.assignable & 2) {
7630
7693
  destructible |= 16;
@@ -7644,9 +7707,9 @@ function parseObjectLiteralOrPattern(parser, context, scope, privateScope, skipI
7644
7707
  value = parseConditionalExpression(parser, context, privateScope, value, tokenStart);
7645
7708
  }
7646
7709
  destructible |=
7647
- parser.assignable & 2
7648
- ? 16
7649
- : 32;
7710
+ parser.assignable & 1
7711
+ ? 32
7712
+ : 16;
7650
7713
  }
7651
7714
  }
7652
7715
  }
@@ -7675,7 +7738,7 @@ function parseObjectLiteralOrPattern(parser, context, scope, privateScope, skipI
7675
7738
  else if (parser.getToken() === 67174411) {
7676
7739
  state |= 1;
7677
7740
  value = parseMethodDefinition(parser, context, privateScope, state, inGroup, parser.tokenStart);
7678
- destructible = parser.assignable | 16;
7741
+ destructible = 16;
7679
7742
  }
7680
7743
  else {
7681
7744
  parser.report(134);
@@ -7695,11 +7758,11 @@ function parseObjectLiteralOrPattern(parser, context, scope, privateScope, skipI
7695
7758
  value = parseMemberOrUpdateExpression(parser, context, privateScope, value, inGroup, 0, tokenStart);
7696
7759
  if ((parser.getToken() & 4194304) === 4194304) {
7697
7760
  destructible |=
7698
- parser.assignable & 2
7699
- ? 16
7700
- : token === 1077936155
7761
+ parser.assignable & 1
7762
+ ? token === 1077936155
7701
7763
  ? 0
7702
- : 32;
7764
+ : 32
7765
+ : 16;
7703
7766
  value = parseAssignmentExpressionOrPattern(parser, context, privateScope, inGroup, isPattern, tokenStart, value);
7704
7767
  }
7705
7768
  else if (parser.getToken() === 18 || parser.getToken() === 1074790415) {
@@ -7730,7 +7793,9 @@ function parseObjectLiteralOrPattern(parser, context, scope, privateScope, skipI
7730
7793
  : parseObjectLiteralOrPattern(parser, context, scope, privateScope, 0, inGroup, isPattern, kind, origin);
7731
7794
  destructible = parser.destructible;
7732
7795
  parser.assignable =
7733
- destructible & 16 ? 2 : 1;
7796
+ destructible & 16
7797
+ ? 2
7798
+ : 1;
7734
7799
  if (parser.getToken() === 18 || parser.getToken() === 1074790415) {
7735
7800
  if (parser.assignable & 2)
7736
7801
  destructible |= 16;
@@ -7755,9 +7820,9 @@ function parseObjectLiteralOrPattern(parser, context, scope, privateScope, skipI
7755
7820
  value = parseConditionalExpression(parser, context, privateScope, value, tokenStart);
7756
7821
  }
7757
7822
  destructible |=
7758
- parser.assignable & 2
7759
- ? 16
7760
- : 32;
7823
+ parser.assignable & 1
7824
+ ? 32
7825
+ : 16;
7761
7826
  }
7762
7827
  }
7763
7828
  }
@@ -7863,6 +7928,7 @@ function parseMethodFormals(parser, context, scope, privateScope, kind, type, in
7863
7928
  consume(parser, context, 67174411);
7864
7929
  const params = [];
7865
7930
  parser.flags = (parser.flags | 128) ^ 128;
7931
+ parser.strictReservedRange = null;
7866
7932
  if (parser.getToken() === 16) {
7867
7933
  if (kind & 512) {
7868
7934
  parser.report(37, 'Setter', 'one', '');
@@ -7886,6 +7952,7 @@ function parseMethodFormals(parser, context, scope, privateScope, kind, type, in
7886
7952
  if ((context & 1) === 0) {
7887
7953
  if ((parser.getToken() & 36864) === 36864) {
7888
7954
  parser.flags |= 256;
7955
+ parser.strictReservedRange ??= [tokenStart, parser.currentLocation];
7889
7956
  }
7890
7957
  if ((parser.getToken() & 537079808) === 537079808) {
7891
7958
  parser.flags |= 512;
@@ -8170,6 +8237,7 @@ function parseArrowFunctionExpression(parser, context, scope, privateScope, para
8170
8237
  if ((parser.flags & 1) === 0) {
8171
8238
  parser.report(116);
8172
8239
  }
8240
+ parser.flags |= 8192;
8173
8241
  break;
8174
8242
  case 67108877:
8175
8243
  case 67174409:
@@ -8200,6 +8268,7 @@ function parseArrowFunctionExpression(parser, context, scope, privateScope, para
8200
8268
  function parseFormalParametersOrFormalList(parser, context, scope, privateScope, inGroup, kind) {
8201
8269
  consume(parser, context, 67174411);
8202
8270
  parser.flags = (parser.flags | 128) ^ 128;
8271
+ parser.strictReservedRange = null;
8203
8272
  const params = [];
8204
8273
  if (consumeOpt(parser, context, 16))
8205
8274
  return params;
@@ -8213,6 +8282,7 @@ function parseFormalParametersOrFormalList(parser, context, scope, privateScope,
8213
8282
  if ((context & 1) === 0) {
8214
8283
  if ((token & 36864) === 36864) {
8215
8284
  parser.flags |= 256;
8285
+ parser.strictReservedRange ??= [tokenStart, parser.currentLocation];
8216
8286
  }
8217
8287
  if ((token & 537079808) === 537079808) {
8218
8288
  parser.flags |= 512;
@@ -8362,6 +8432,12 @@ function parseAsyncArrowOrCallExpression(parser, context, privateScope, callee,
8362
8432
  parser.report(48);
8363
8433
  return parseParenthesizedArrow(parser, context, scope, privateScope, [], canAssign, 1, start);
8364
8434
  }
8435
+ if (!(context & 1) && parser.options.webcompat) {
8436
+ parser.assignable = 4;
8437
+ }
8438
+ else {
8439
+ parser.assignable = 2;
8440
+ }
8365
8441
  return parser.finishNode({
8366
8442
  type: 'CallExpression',
8367
8443
  callee,
@@ -8435,7 +8511,7 @@ function parseAsyncArrowOrCallExpression(parser, context, privateScope, callee,
8435
8511
  }
8436
8512
  else {
8437
8513
  expr = parseExpression(parser, context, privateScope, 1, 0, tokenStart);
8438
- destructible = parser.assignable;
8514
+ destructible = 0;
8439
8515
  params.push(expr);
8440
8516
  while (consumeOpt(parser, context | 32, 18)) {
8441
8517
  params.push(parseExpression(parser, context, privateScope, 1, 0, tokenStart));
@@ -8443,7 +8519,12 @@ function parseAsyncArrowOrCallExpression(parser, context, privateScope, callee,
8443
8519
  destructible |= parser.assignable;
8444
8520
  consume(parser, context, 16);
8445
8521
  parser.destructible = destructible | 16;
8446
- parser.assignable = 2;
8522
+ if (!(context & 1) && parser.options.webcompat) {
8523
+ parser.assignable = 4;
8524
+ }
8525
+ else {
8526
+ parser.assignable = 2;
8527
+ }
8447
8528
  return parser.finishNode({
8448
8529
  type: 'CallExpression',
8449
8530
  callee,
@@ -8481,7 +8562,12 @@ function parseAsyncArrowOrCallExpression(parser, context, privateScope, callee,
8481
8562
  if (destructible & 8) {
8482
8563
  parser.report(62);
8483
8564
  }
8484
- parser.assignable = 2;
8565
+ if (!(context & 1) && parser.options.webcompat) {
8566
+ parser.assignable = 4;
8567
+ }
8568
+ else {
8569
+ parser.assignable = 2;
8570
+ }
8485
8571
  return parser.finishNode({
8486
8572
  type: 'CallExpression',
8487
8573
  callee,
@@ -9205,4 +9291,4 @@ function parse(source, options) {
9205
9291
  return parseSource(source, options);
9206
9292
  }
9207
9293
 
9208
- export { parse, parseModule, parseScript, version };
9294
+ export { isParseError, parse, parseModule, parseScript, version };