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.
@@ -4,7 +4,7 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.meriyah = {}));
5
5
  })(this, (function (exports) { 'use strict';
6
6
 
7
- var version$1 = "7.0.0";
7
+ var version$1 = "7.1.1";
8
8
 
9
9
  const unicodeLookup = ((compressed, lookup) => {
10
10
  const result = new Uint32Array(69632);
@@ -811,6 +811,7 @@
811
811
  this.description = description;
812
812
  }
813
813
  }
814
+ const isParseError = (error) => error instanceof ParseError;
814
815
 
815
816
  function getOwnProperty(object, key) {
816
817
  return Object.hasOwn(object, key) ? object[key] : undefined;
@@ -1553,7 +1554,7 @@
1553
1554
  }
1554
1555
  case 56:
1555
1556
  case 57:
1556
- if (isTemplate || !parser.options.webcompat || context & 1)
1557
+ if (isTemplate || context & 1)
1557
1558
  return -3;
1558
1559
  parser.flags |= 4096;
1559
1560
  default:
@@ -2009,7 +2010,7 @@
2009
2010
  advanceChar(parser);
2010
2011
  if (parser.currentChar === 61) {
2011
2012
  advanceChar(parser);
2012
- return 4194344;
2013
+ return 4718632;
2013
2014
  }
2014
2015
  return 8913465;
2015
2016
  }
@@ -2052,7 +2053,7 @@
2052
2053
  advanceChar(parser);
2053
2054
  if (parser.currentChar === 61) {
2054
2055
  advanceChar(parser);
2055
- return 4194345;
2056
+ return 4718633;
2056
2057
  }
2057
2058
  return 8913720;
2058
2059
  }
@@ -2068,7 +2069,7 @@
2068
2069
  advanceChar(parser);
2069
2070
  if (parser.currentChar === 61) {
2070
2071
  advanceChar(parser);
2071
- return 4194346;
2072
+ return 4718634;
2072
2073
  }
2073
2074
  return 276824445;
2074
2075
  }
@@ -4547,10 +4548,22 @@
4547
4548
  return parser.getToken();
4548
4549
  }
4549
4550
 
4551
+ function normalizeRanges(ranges) {
4552
+ if (!ranges)
4553
+ return undefined;
4554
+ if (ranges === true)
4555
+ return { start: true, end: true, range: true };
4556
+ return {
4557
+ start: ranges.start ?? false,
4558
+ end: ranges.end ?? false,
4559
+ range: ranges.range ?? false,
4560
+ };
4561
+ }
4550
4562
  function normalizeOptions(rawOptions) {
4551
4563
  const options = {
4552
4564
  validateRegex: true,
4553
4565
  ...rawOptions,
4566
+ ranges: normalizeRanges(rawOptions.ranges),
4554
4567
  };
4555
4568
  if (options.module && !options.sourceType) {
4556
4569
  options.sourceType = 'module';
@@ -4734,8 +4747,9 @@
4734
4747
  currentChar = 0;
4735
4748
  exportedNames = new Set();
4736
4749
  exportedBindings = new Set();
4737
- assignable = 1;
4750
+ assignable = 0;
4738
4751
  destructible = 0;
4752
+ strictReservedRange = null;
4739
4753
  leadingDecorators = { decorators: [] };
4740
4754
  constructor(source, rawOptions = {}) {
4741
4755
  this.source = source;
@@ -4792,11 +4806,15 @@
4792
4806
  return { index: this.index, line: this.line, column: this.column };
4793
4807
  }
4794
4808
  finishNode(node, start, end) {
4795
- if (this.options.ranges) {
4796
- node.start = start.index;
4809
+ const { ranges } = this.options;
4810
+ if (ranges) {
4797
4811
  const endIndex = end ? end.index : this.startIndex;
4798
- node.end = endIndex;
4799
- node.range = [start.index, endIndex];
4812
+ if (ranges.start)
4813
+ node.start = start.index;
4814
+ if (ranges.end)
4815
+ node.end = endIndex;
4816
+ if (ranges.range)
4817
+ node.range = [start.index, endIndex];
4800
4818
  }
4801
4819
  if (this.options.loc) {
4802
4820
  node.loc = {
@@ -4847,8 +4865,14 @@
4847
4865
  return this.cloneLocationInformation({ ...original }, original);
4848
4866
  }
4849
4867
  cloneLocationInformation(node, original) {
4850
- if (this.options.ranges) {
4851
- node.range = [...original.range];
4868
+ const { ranges } = this.options;
4869
+ if (ranges) {
4870
+ if (ranges.start)
4871
+ node.start = original.start;
4872
+ if (ranges.end)
4873
+ node.end = original.end;
4874
+ if (ranges.range)
4875
+ node.range = [...original.range];
4852
4876
  }
4853
4877
  if (this.options.loc) {
4854
4878
  node.loc = {
@@ -4866,10 +4890,14 @@
4866
4890
  type,
4867
4891
  value,
4868
4892
  };
4869
- if (options.ranges) {
4870
- comment.start = start;
4871
- comment.end = end;
4872
- comment.range = [start, end];
4893
+ const { ranges } = options;
4894
+ if (ranges) {
4895
+ if (ranges.start)
4896
+ comment.start = start;
4897
+ if (ranges.end)
4898
+ comment.end = end;
4899
+ if (ranges.range)
4900
+ comment.range = [start, end];
4873
4901
  }
4874
4902
  if (options.loc) {
4875
4903
  comment.loc = loc;
@@ -4882,10 +4910,14 @@
4882
4910
  const token = {
4883
4911
  token: type,
4884
4912
  };
4885
- if (options.ranges) {
4886
- token.start = start;
4887
- token.end = end;
4888
- token.range = [start, end];
4913
+ const { ranges } = options;
4914
+ if (ranges) {
4915
+ if (ranges.start)
4916
+ token.start = start;
4917
+ if (ranges.end)
4918
+ token.end = end;
4919
+ if (ranges.range)
4920
+ token.range = [start, end];
4889
4921
  }
4890
4922
  if (options.loc) {
4891
4923
  token.loc = loc;
@@ -5524,7 +5556,7 @@
5524
5556
  if (parser.getToken() === 1077936155) {
5525
5557
  nextToken(parser, context | 32);
5526
5558
  init = parseExpression(parser, context, privateScope, 1, 0, parser.tokenStart);
5527
- if (origin & 32 || (token & 2097152) === 0) {
5559
+ if (origin & 32) {
5528
5560
  if (parser.getToken() === 471156 ||
5529
5561
  (parser.getToken() === 8673330 &&
5530
5562
  (token & 2097152 || (kind & 4) === 0 || context & 1))) {
@@ -6023,6 +6055,8 @@
6023
6055
  if ((token & 4194304) === 4194304) {
6024
6056
  if (parser.assignable & 2)
6025
6057
  parser.report(26);
6058
+ if ((token & 524288) === 524288 && parser.assignable & 4)
6059
+ parser.report(26);
6026
6060
  if ((!isPattern && token === 1077936155 && left.type === 'ArrayExpression') ||
6027
6061
  left.type === 'ObjectExpression') {
6028
6062
  reinterpretToPattern(parser, left);
@@ -6269,8 +6303,12 @@
6269
6303
  }
6270
6304
  if (parser.flags & 512)
6271
6305
  parser.report(119);
6272
- if (parser.flags & 256)
6306
+ if (parser.flags & 256) {
6307
+ if (parser.strictReservedRange) {
6308
+ throw new ParseError(parser.strictReservedRange[0], parser.strictReservedRange[1], 118);
6309
+ }
6273
6310
  parser.report(118);
6311
+ }
6274
6312
  }
6275
6313
  }
6276
6314
  parser.flags =
@@ -6355,6 +6393,10 @@
6355
6393
  break;
6356
6394
  }
6357
6395
  case 69271571: {
6396
+ if ((parser.flags & 8192) === 8192) {
6397
+ parser.flags = (parser.flags | 8192) ^ 8192;
6398
+ return expr;
6399
+ }
6358
6400
  let restoreHasOptionalChaining = false;
6359
6401
  if ((parser.flags & 2048) === 2048) {
6360
6402
  restoreHasOptionalChaining = true;
@@ -6388,7 +6430,12 @@
6388
6430
  parser.flags = (parser.flags | 2048) ^ 2048;
6389
6431
  }
6390
6432
  const args = parseArguments(parser, context, privateScope, inGroup);
6391
- parser.assignable = 2;
6433
+ if (!(context & 1) && parser.options.webcompat) {
6434
+ parser.assignable = 4;
6435
+ }
6436
+ else {
6437
+ parser.assignable = 2;
6438
+ }
6392
6439
  expr = parser.finishNode({
6393
6440
  type: 'CallExpression',
6394
6441
  callee: expr,
@@ -6456,7 +6503,12 @@
6456
6503
  }
6457
6504
  else if (parser.getToken() === 67174411) {
6458
6505
  const args = parseArguments(parser, context, privateScope, 0);
6459
- parser.assignable = 2;
6506
+ if (!(context & 1) && parser.options.webcompat) {
6507
+ parser.assignable = 4;
6508
+ }
6509
+ else {
6510
+ parser.assignable = 2;
6511
+ }
6460
6512
  node = parser.finishNode({
6461
6513
  type: 'CallExpression',
6462
6514
  callee: expr,
@@ -6783,11 +6835,16 @@
6783
6835
  tail,
6784
6836
  }, start);
6785
6837
  const tailSize = tail ? 1 : 2;
6786
- if (parser.options.ranges) {
6787
- node.start += 1;
6788
- node.range[0] += 1;
6789
- node.end -= tailSize;
6790
- node.range[1] -= tailSize;
6838
+ const { ranges } = parser.options;
6839
+ if (ranges) {
6840
+ if (ranges.start)
6841
+ node.start += 1;
6842
+ if (ranges.end)
6843
+ node.end -= tailSize;
6844
+ if (ranges.range) {
6845
+ node.range[0] += 1;
6846
+ node.range[1] -= tailSize;
6847
+ }
6791
6848
  }
6792
6849
  if (parser.options.loc) {
6793
6850
  node.loc.start.column += 1;
@@ -7061,9 +7118,9 @@
7061
7118
  }
7062
7119
  else if (parser.getToken() !== 1077936155) {
7063
7120
  destructible |=
7064
- parser.assignable & 2
7065
- ? 16
7066
- : 32;
7121
+ parser.assignable & 1
7122
+ ? 32
7123
+ : 16;
7067
7124
  }
7068
7125
  }
7069
7126
  }
@@ -7093,9 +7150,9 @@
7093
7150
  }
7094
7151
  else if (parser.getToken() !== 1077936155) {
7095
7152
  destructible |=
7096
- parser.assignable & 2
7097
- ? 16
7098
- : 32;
7153
+ parser.assignable & 1
7154
+ ? 32
7155
+ : 16;
7099
7156
  }
7100
7157
  }
7101
7158
  }
@@ -7212,7 +7269,7 @@
7212
7269
  if (parser.destructible & 8)
7213
7270
  parser.report(71);
7214
7271
  argument = parseMemberOrUpdateExpression(parser, context, privateScope, argument, inGroup, 0, tokenStart);
7215
- destructible |= parser.assignable & 2 ? 16 : 0;
7272
+ destructible |= parser.assignable & 1 ? 0 : 16;
7216
7273
  if ((parser.getToken() & 4194304) === 4194304) {
7217
7274
  if (parser.getToken() !== 1077936155)
7218
7275
  destructible |= 16;
@@ -7226,9 +7283,9 @@
7226
7283
  argument = parseConditionalExpression(parser, context, privateScope, argument, tokenStart);
7227
7284
  }
7228
7285
  destructible |=
7229
- parser.assignable & 2
7230
- ? 16
7231
- : 32;
7286
+ parser.assignable & 1
7287
+ ? 32
7288
+ : 16;
7232
7289
  }
7233
7290
  }
7234
7291
  else {
@@ -7257,7 +7314,9 @@
7257
7314
  argument = parseAssignmentExpression(parser, context, privateScope, inGroup, isPattern, tokenStart, argument);
7258
7315
  }
7259
7316
  destructible |=
7260
- parser.assignable & 1 ? 32 : 16;
7317
+ parser.assignable & 1
7318
+ ? 32
7319
+ : 16;
7261
7320
  }
7262
7321
  parser.destructible = destructible;
7263
7322
  if (parser.getToken() !== closingToken && parser.getToken() !== 18)
@@ -7449,7 +7508,9 @@
7449
7508
  : parseObjectLiteralOrPattern(parser, context, scope, privateScope, 0, inGroup, isPattern, kind, origin);
7450
7509
  destructible = parser.destructible;
7451
7510
  parser.assignable =
7452
- destructible & 16 ? 2 : 1;
7511
+ destructible & 16
7512
+ ? 2
7513
+ : 1;
7453
7514
  if (parser.getToken() === 18 || parser.getToken() === 1074790415) {
7454
7515
  if (parser.assignable & 2)
7455
7516
  destructible |= 16;
@@ -7471,9 +7532,9 @@
7471
7532
  value = parseConditionalExpression(parser, context, privateScope, value, tokenStart);
7472
7533
  }
7473
7534
  destructible |=
7474
- parser.assignable & 2
7475
- ? 16
7476
- : 32;
7535
+ parser.assignable & 1
7536
+ ? 32
7537
+ : 16;
7477
7538
  }
7478
7539
  }
7479
7540
  }
@@ -7630,7 +7691,9 @@
7630
7691
  : parseObjectLiteralOrPattern(parser, context, scope, privateScope, 0, inGroup, isPattern, kind, origin);
7631
7692
  destructible = parser.destructible;
7632
7693
  parser.assignable =
7633
- destructible & 16 ? 2 : 1;
7694
+ destructible & 16
7695
+ ? 2
7696
+ : 1;
7634
7697
  if (parser.getToken() === 18 || parser.getToken() === 1074790415) {
7635
7698
  if (parser.assignable & 2) {
7636
7699
  destructible |= 16;
@@ -7650,9 +7713,9 @@
7650
7713
  value = parseConditionalExpression(parser, context, privateScope, value, tokenStart);
7651
7714
  }
7652
7715
  destructible |=
7653
- parser.assignable & 2
7654
- ? 16
7655
- : 32;
7716
+ parser.assignable & 1
7717
+ ? 32
7718
+ : 16;
7656
7719
  }
7657
7720
  }
7658
7721
  }
@@ -7681,7 +7744,7 @@
7681
7744
  else if (parser.getToken() === 67174411) {
7682
7745
  state |= 1;
7683
7746
  value = parseMethodDefinition(parser, context, privateScope, state, inGroup, parser.tokenStart);
7684
- destructible = parser.assignable | 16;
7747
+ destructible = 16;
7685
7748
  }
7686
7749
  else {
7687
7750
  parser.report(134);
@@ -7701,11 +7764,11 @@
7701
7764
  value = parseMemberOrUpdateExpression(parser, context, privateScope, value, inGroup, 0, tokenStart);
7702
7765
  if ((parser.getToken() & 4194304) === 4194304) {
7703
7766
  destructible |=
7704
- parser.assignable & 2
7705
- ? 16
7706
- : token === 1077936155
7767
+ parser.assignable & 1
7768
+ ? token === 1077936155
7707
7769
  ? 0
7708
- : 32;
7770
+ : 32
7771
+ : 16;
7709
7772
  value = parseAssignmentExpressionOrPattern(parser, context, privateScope, inGroup, isPattern, tokenStart, value);
7710
7773
  }
7711
7774
  else if (parser.getToken() === 18 || parser.getToken() === 1074790415) {
@@ -7736,7 +7799,9 @@
7736
7799
  : parseObjectLiteralOrPattern(parser, context, scope, privateScope, 0, inGroup, isPattern, kind, origin);
7737
7800
  destructible = parser.destructible;
7738
7801
  parser.assignable =
7739
- destructible & 16 ? 2 : 1;
7802
+ destructible & 16
7803
+ ? 2
7804
+ : 1;
7740
7805
  if (parser.getToken() === 18 || parser.getToken() === 1074790415) {
7741
7806
  if (parser.assignable & 2)
7742
7807
  destructible |= 16;
@@ -7761,9 +7826,9 @@
7761
7826
  value = parseConditionalExpression(parser, context, privateScope, value, tokenStart);
7762
7827
  }
7763
7828
  destructible |=
7764
- parser.assignable & 2
7765
- ? 16
7766
- : 32;
7829
+ parser.assignable & 1
7830
+ ? 32
7831
+ : 16;
7767
7832
  }
7768
7833
  }
7769
7834
  }
@@ -7869,6 +7934,7 @@
7869
7934
  consume(parser, context, 67174411);
7870
7935
  const params = [];
7871
7936
  parser.flags = (parser.flags | 128) ^ 128;
7937
+ parser.strictReservedRange = null;
7872
7938
  if (parser.getToken() === 16) {
7873
7939
  if (kind & 512) {
7874
7940
  parser.report(37, 'Setter', 'one', '');
@@ -7892,6 +7958,7 @@
7892
7958
  if ((context & 1) === 0) {
7893
7959
  if ((parser.getToken() & 36864) === 36864) {
7894
7960
  parser.flags |= 256;
7961
+ parser.strictReservedRange ??= [tokenStart, parser.currentLocation];
7895
7962
  }
7896
7963
  if ((parser.getToken() & 537079808) === 537079808) {
7897
7964
  parser.flags |= 512;
@@ -8176,6 +8243,7 @@
8176
8243
  if ((parser.flags & 1) === 0) {
8177
8244
  parser.report(116);
8178
8245
  }
8246
+ parser.flags |= 8192;
8179
8247
  break;
8180
8248
  case 67108877:
8181
8249
  case 67174409:
@@ -8206,6 +8274,7 @@
8206
8274
  function parseFormalParametersOrFormalList(parser, context, scope, privateScope, inGroup, kind) {
8207
8275
  consume(parser, context, 67174411);
8208
8276
  parser.flags = (parser.flags | 128) ^ 128;
8277
+ parser.strictReservedRange = null;
8209
8278
  const params = [];
8210
8279
  if (consumeOpt(parser, context, 16))
8211
8280
  return params;
@@ -8219,6 +8288,7 @@
8219
8288
  if ((context & 1) === 0) {
8220
8289
  if ((token & 36864) === 36864) {
8221
8290
  parser.flags |= 256;
8291
+ parser.strictReservedRange ??= [tokenStart, parser.currentLocation];
8222
8292
  }
8223
8293
  if ((token & 537079808) === 537079808) {
8224
8294
  parser.flags |= 512;
@@ -8368,6 +8438,12 @@
8368
8438
  parser.report(48);
8369
8439
  return parseParenthesizedArrow(parser, context, scope, privateScope, [], canAssign, 1, start);
8370
8440
  }
8441
+ if (!(context & 1) && parser.options.webcompat) {
8442
+ parser.assignable = 4;
8443
+ }
8444
+ else {
8445
+ parser.assignable = 2;
8446
+ }
8371
8447
  return parser.finishNode({
8372
8448
  type: 'CallExpression',
8373
8449
  callee,
@@ -8441,7 +8517,7 @@
8441
8517
  }
8442
8518
  else {
8443
8519
  expr = parseExpression(parser, context, privateScope, 1, 0, tokenStart);
8444
- destructible = parser.assignable;
8520
+ destructible = 0;
8445
8521
  params.push(expr);
8446
8522
  while (consumeOpt(parser, context | 32, 18)) {
8447
8523
  params.push(parseExpression(parser, context, privateScope, 1, 0, tokenStart));
@@ -8449,7 +8525,12 @@
8449
8525
  destructible |= parser.assignable;
8450
8526
  consume(parser, context, 16);
8451
8527
  parser.destructible = destructible | 16;
8452
- parser.assignable = 2;
8528
+ if (!(context & 1) && parser.options.webcompat) {
8529
+ parser.assignable = 4;
8530
+ }
8531
+ else {
8532
+ parser.assignable = 2;
8533
+ }
8453
8534
  return parser.finishNode({
8454
8535
  type: 'CallExpression',
8455
8536
  callee,
@@ -8487,7 +8568,12 @@
8487
8568
  if (destructible & 8) {
8488
8569
  parser.report(62);
8489
8570
  }
8490
- parser.assignable = 2;
8571
+ if (!(context & 1) && parser.options.webcompat) {
8572
+ parser.assignable = 4;
8573
+ }
8574
+ else {
8575
+ parser.assignable = 2;
8576
+ }
8491
8577
  return parser.finishNode({
8492
8578
  type: 'CallExpression',
8493
8579
  callee,
@@ -9211,6 +9297,7 @@
9211
9297
  return parseSource(source, options);
9212
9298
  }
9213
9299
 
9300
+ exports.isParseError = isParseError;
9214
9301
  exports.parse = parse;
9215
9302
  exports.parseModule = parseModule;
9216
9303
  exports.parseScript = parseScript;