rollup 3.28.0 → 4.0.0-10

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.
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v3.28.0
4
- Wed, 09 Aug 2023 05:34:03 GMT - commit e3b614c9d4555248caa43d062f4003859b388434
3
+ Rollup.js v4.0.0-10
4
+ Mon, 21 Aug 2023 15:29:18 GMT - commit 2c7e3e32f5d56c60d92907a9ceacd338aa99ca82
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -12,10 +12,11 @@ import require$$0$1, { win32, posix, isAbsolute as isAbsolute$1, resolve as reso
12
12
  import process$1, { env as env$1 } from 'node:process';
13
13
  import { performance } from 'node:perf_hooks';
14
14
  import { createHash as createHash$1 } from 'node:crypto';
15
+ import native from './native.cjs';
15
16
  import { lstat, realpath, readdir, readFile, mkdir, writeFile } from 'node:fs/promises';
16
17
  import * as tty from 'tty';
17
18
 
18
- var version$1 = "3.28.0";
19
+ var version$1 = "4.0.0-10";
19
20
 
20
21
  const comma = ','.charCodeAt(0);
21
22
  const semicolon = ';'.charCodeAt(0);
@@ -347,7 +348,7 @@ let Chunk$1 = class Chunk {
347
348
  }
348
349
  };
349
350
 
350
- function getBtoa () {
351
+ function getBtoa() {
351
352
  if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
352
353
  return (str) => window.btoa(unescape(encodeURIComponent(str)));
353
354
  } else if (typeof Buffer === 'function') {
@@ -460,6 +461,8 @@ function getLocator$1(source) {
460
461
  };
461
462
  }
462
463
 
464
+ const wordRegex = /\w/;
465
+
463
466
  class Mappings {
464
467
  constructor(hires) {
465
468
  this.hires = hires;
@@ -488,10 +491,29 @@ class Mappings {
488
491
  addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
489
492
  let originalCharIndex = chunk.start;
490
493
  let first = true;
494
+ // when iterating each char, check if it's in a word boundary
495
+ let charInHiresBoundary = false;
491
496
 
492
497
  while (originalCharIndex < chunk.end) {
493
498
  if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
494
- this.rawSegments.push([this.generatedCodeColumn, sourceIndex, loc.line, loc.column]);
499
+ const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
500
+
501
+ if (this.hires === 'boundary') {
502
+ // in hires "boundary", group segments per word boundary than per char
503
+ if (wordRegex.test(original[originalCharIndex])) {
504
+ // for first char in the boundary found, start the boundary by pushing a segment
505
+ if (!charInHiresBoundary) {
506
+ this.rawSegments.push(segment);
507
+ charInHiresBoundary = true;
508
+ }
509
+ } else {
510
+ // for non-word char, end the boundary by pushing a segment
511
+ this.rawSegments.push(segment);
512
+ charInHiresBoundary = false;
513
+ }
514
+ } else {
515
+ this.rawSegments.push(segment);
516
+ }
495
517
  }
496
518
 
497
519
  if (original[originalCharIndex] === '\n') {
@@ -664,7 +686,7 @@ class MagicString {
664
686
  sourceIndex,
665
687
  chunk.content,
666
688
  loc,
667
- chunk.storeName ? names.indexOf(chunk.original) : -1
689
+ chunk.storeName ? names.indexOf(chunk.original) : -1,
668
690
  );
669
691
  } else {
670
692
  mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations);
@@ -675,11 +697,13 @@ class MagicString {
675
697
 
676
698
  return {
677
699
  file: options.file ? options.file.split(/[/\\]/).pop() : undefined,
678
- sources: [options.source ? getRelativePath(options.file || '', options.source) : (options.file || '')],
700
+ sources: [
701
+ options.source ? getRelativePath(options.file || '', options.source) : options.file || '',
702
+ ],
679
703
  sourcesContent: options.includeContent ? [this.original] : undefined,
680
704
  names,
681
705
  mappings: mappings.raw,
682
- x_google_ignoreList: this.ignoreList ? [sourceIndex] : undefined
706
+ x_google_ignoreList: this.ignoreList ? [sourceIndex] : undefined,
683
707
  };
684
708
  }
685
709
 
@@ -793,14 +817,14 @@ class MagicString {
793
817
 
794
818
  insert() {
795
819
  throw new Error(
796
- 'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)'
820
+ 'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)',
797
821
  );
798
822
  }
799
823
 
800
824
  insertLeft(index, content) {
801
825
  if (!warned.insertLeft) {
802
826
  console.warn(
803
- 'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead'
827
+ 'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead',
804
828
  ); // eslint-disable-line no-console
805
829
  warned.insertLeft = true;
806
830
  }
@@ -811,7 +835,7 @@ class MagicString {
811
835
  insertRight(index, content) {
812
836
  if (!warned.insertRight) {
813
837
  console.warn(
814
- 'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead'
838
+ 'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead',
815
839
  ); // eslint-disable-line no-console
816
840
  warned.insertRight = true;
817
841
  }
@@ -870,7 +894,7 @@ class MagicString {
870
894
  if (end > this.original.length) throw new Error('end is out of bounds');
871
895
  if (start === end)
872
896
  throw new Error(
873
- 'Cannot overwrite a zero-length range – use appendLeft or prependRight instead'
897
+ 'Cannot overwrite a zero-length range – use appendLeft or prependRight instead',
874
898
  );
875
899
 
876
900
  this._split(start);
@@ -879,7 +903,7 @@ class MagicString {
879
903
  if (options === true) {
880
904
  if (!warned.storeName) {
881
905
  console.warn(
882
- 'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string'
906
+ 'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string',
883
907
  ); // eslint-disable-line no-console
884
908
  warned.storeName = true;
885
909
  }
@@ -1101,7 +1125,7 @@ class MagicString {
1101
1125
  // zero-length edited chunks are a special case (overlapping replacements)
1102
1126
  const loc = getLocator$1(this.original)(index);
1103
1127
  throw new Error(
1104
- `Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`
1128
+ `Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`,
1105
1129
  );
1106
1130
  }
1107
1131
 
@@ -1260,7 +1284,7 @@ class MagicString {
1260
1284
  this.overwrite(
1261
1285
  match.index,
1262
1286
  match.index + match[0].length,
1263
- getReplacement(match, this.original)
1287
+ getReplacement(match, this.original),
1264
1288
  );
1265
1289
  });
1266
1290
  } else {
@@ -1269,7 +1293,7 @@ class MagicString {
1269
1293
  this.overwrite(
1270
1294
  match.index,
1271
1295
  match.index + match[0].length,
1272
- getReplacement(match, this.original)
1296
+ getReplacement(match, this.original),
1273
1297
  );
1274
1298
  }
1275
1299
  return this;
@@ -1315,7 +1339,7 @@ class MagicString {
1315
1339
 
1316
1340
  if (!searchValue.global) {
1317
1341
  throw new TypeError(
1318
- 'MagicString.prototype.replaceAll called with a non-global RegExp argument'
1342
+ 'MagicString.prototype.replaceAll called with a non-global RegExp argument',
1319
1343
  );
1320
1344
  }
1321
1345
 
@@ -1345,7 +1369,7 @@ let Bundle$1 = class Bundle {
1345
1369
 
1346
1370
  if (!isObject$1(source) || !source.content) {
1347
1371
  throw new Error(
1348
- 'bundle.addSource() takes an object with a `content` property, which should be an instance of MagicString, and an optional `filename`'
1372
+ 'bundle.addSource() takes an object with a `content` property, which should be an instance of MagicString, and an optional `filename`',
1349
1373
  );
1350
1374
  }
1351
1375
 
@@ -1439,7 +1463,7 @@ let Bundle$1 = class Bundle {
1439
1463
  sourceIndex,
1440
1464
  chunk.content,
1441
1465
  loc,
1442
- chunk.storeName ? names.indexOf(chunk.original) : -1
1466
+ chunk.storeName ? names.indexOf(chunk.original) : -1,
1443
1467
  );
1444
1468
  } else {
1445
1469
  mappings.addUneditedChunk(
@@ -1447,7 +1471,7 @@ let Bundle$1 = class Bundle {
1447
1471
  chunk,
1448
1472
  magicString.original,
1449
1473
  loc,
1450
- magicString.sourcemapLocations
1474
+ magicString.sourcemapLocations,
1451
1475
  );
1452
1476
  }
1453
1477
  } else {
@@ -1565,7 +1589,7 @@ let Bundle$1 = class Bundle {
1565
1589
  length() {
1566
1590
  return this.sources.reduce(
1567
1591
  (length, source) => length + source.content.length(),
1568
- this.intro.length
1592
+ this.intro.length,
1569
1593
  );
1570
1594
  }
1571
1595
 
@@ -2254,7 +2278,11 @@ function augmentCodeLocation(properties, pos, source, id) {
2254
2278
  }
2255
2279
  else {
2256
2280
  properties.pos = pos;
2257
- const { line, column } = locate(source, pos, { offsetLine: 1 });
2281
+ const location = locate(source, pos, { offsetLine: 1 });
2282
+ if (!location) {
2283
+ return;
2284
+ }
2285
+ const { line, column } = location;
2258
2286
  properties.loc = { column, file: id, line };
2259
2287
  }
2260
2288
  if (properties.frame === undefined) {
@@ -2341,12 +2369,12 @@ function logChunkNotGeneratedForFileName(name) {
2341
2369
  message: `Plugin error - Unable to get file name for emitted chunk "${name}". You can only get file names once chunks have been generated after the "renderStart" hook.`
2342
2370
  };
2343
2371
  }
2344
- function logChunkInvalid({ fileName, code }, exception) {
2372
+ function logChunkInvalid({ fileName, code }, { pos, message }) {
2345
2373
  const errorProperties = {
2346
2374
  code: CHUNK_INVALID,
2347
- message: `Chunk "${fileName}" is not valid JavaScript: ${exception.message}.`
2375
+ message: `Chunk "${fileName}" is not valid JavaScript: ${message}.`
2348
2376
  };
2349
- augmentCodeLocation(errorProperties, exception.loc, code, fileName);
2377
+ augmentCodeLocation(errorProperties, pos, code, fileName);
2350
2378
  return errorProperties;
2351
2379
  }
2352
2380
  function logCircularDependency(cyclePath) {
@@ -5341,462 +5369,1235 @@ function getMemberReturnExpressionWhenCalled(members, memberName) {
5341
5369
  return [members[memberName].returns, false];
5342
5370
  }
5343
5371
 
5344
- // AST walker module for Mozilla Parser API compatible trees
5345
-
5346
-
5347
- function skipThrough(node, st, c) { c(node, st); }
5348
- function ignore(_node, _st, _c) {}
5349
-
5350
- // Node walkers.
5351
-
5352
- var base$1 = {};
5353
-
5354
- base$1.Program = base$1.BlockStatement = base$1.StaticBlock = function (node, st, c) {
5355
- for (var i = 0, list = node.body; i < list.length; i += 1)
5356
- {
5357
- var stmt = list[i];
5358
-
5359
- c(stmt, st, "Statement");
5360
- }
5361
- };
5362
- base$1.Statement = skipThrough;
5363
- base$1.EmptyStatement = ignore;
5364
- base$1.ExpressionStatement = base$1.ParenthesizedExpression = base$1.ChainExpression =
5365
- function (node, st, c) { return c(node.expression, st, "Expression"); };
5366
- base$1.IfStatement = function (node, st, c) {
5367
- c(node.test, st, "Expression");
5368
- c(node.consequent, st, "Statement");
5369
- if (node.alternate) { c(node.alternate, st, "Statement"); }
5370
- };
5371
- base$1.LabeledStatement = function (node, st, c) { return c(node.body, st, "Statement"); };
5372
- base$1.BreakStatement = base$1.ContinueStatement = ignore;
5373
- base$1.WithStatement = function (node, st, c) {
5374
- c(node.object, st, "Expression");
5375
- c(node.body, st, "Statement");
5376
- };
5377
- base$1.SwitchStatement = function (node, st, c) {
5378
- c(node.discriminant, st, "Expression");
5379
- for (var i$1 = 0, list$1 = node.cases; i$1 < list$1.length; i$1 += 1) {
5380
- var cs = list$1[i$1];
5381
-
5382
- if (cs.test) { c(cs.test, st, "Expression"); }
5383
- for (var i = 0, list = cs.consequent; i < list.length; i += 1)
5384
- {
5385
- var cons = list[i];
5386
-
5387
- c(cons, st, "Statement");
5388
- }
5389
- }
5390
- };
5391
- base$1.SwitchCase = function (node, st, c) {
5392
- if (node.test) { c(node.test, st, "Expression"); }
5393
- for (var i = 0, list = node.consequent; i < list.length; i += 1)
5394
- {
5395
- var cons = list[i];
5396
-
5397
- c(cons, st, "Statement");
5398
- }
5399
- };
5400
- base$1.ReturnStatement = base$1.YieldExpression = base$1.AwaitExpression = function (node, st, c) {
5401
- if (node.argument) { c(node.argument, st, "Expression"); }
5402
- };
5403
- base$1.ThrowStatement = base$1.SpreadElement =
5404
- function (node, st, c) { return c(node.argument, st, "Expression"); };
5405
- base$1.TryStatement = function (node, st, c) {
5406
- c(node.block, st, "Statement");
5407
- if (node.handler) { c(node.handler, st); }
5408
- if (node.finalizer) { c(node.finalizer, st, "Statement"); }
5409
- };
5410
- base$1.CatchClause = function (node, st, c) {
5411
- if (node.param) { c(node.param, st, "Pattern"); }
5412
- c(node.body, st, "Statement");
5413
- };
5414
- base$1.WhileStatement = base$1.DoWhileStatement = function (node, st, c) {
5415
- c(node.test, st, "Expression");
5416
- c(node.body, st, "Statement");
5417
- };
5418
- base$1.ForStatement = function (node, st, c) {
5419
- if (node.init) { c(node.init, st, "ForInit"); }
5420
- if (node.test) { c(node.test, st, "Expression"); }
5421
- if (node.update) { c(node.update, st, "Expression"); }
5422
- c(node.body, st, "Statement");
5423
- };
5424
- base$1.ForInStatement = base$1.ForOfStatement = function (node, st, c) {
5425
- c(node.left, st, "ForInit");
5426
- c(node.right, st, "Expression");
5427
- c(node.body, st, "Statement");
5428
- };
5429
- base$1.ForInit = function (node, st, c) {
5430
- if (node.type === "VariableDeclaration") { c(node, st); }
5431
- else { c(node, st, "Expression"); }
5432
- };
5433
- base$1.DebuggerStatement = ignore;
5434
-
5435
- base$1.FunctionDeclaration = function (node, st, c) { return c(node, st, "Function"); };
5436
- base$1.VariableDeclaration = function (node, st, c) {
5437
- for (var i = 0, list = node.declarations; i < list.length; i += 1)
5438
- {
5439
- var decl = list[i];
5440
-
5441
- c(decl, st);
5442
- }
5443
- };
5444
- base$1.VariableDeclarator = function (node, st, c) {
5445
- c(node.id, st, "Pattern");
5446
- if (node.init) { c(node.init, st, "Expression"); }
5447
- };
5448
-
5449
- base$1.Function = function (node, st, c) {
5450
- if (node.id) { c(node.id, st, "Pattern"); }
5451
- for (var i = 0, list = node.params; i < list.length; i += 1)
5452
- {
5453
- var param = list[i];
5454
-
5455
- c(param, st, "Pattern");
5456
- }
5457
- c(node.body, st, node.expression ? "Expression" : "Statement");
5458
- };
5459
-
5460
- base$1.Pattern = function (node, st, c) {
5461
- if (node.type === "Identifier")
5462
- { c(node, st, "VariablePattern"); }
5463
- else if (node.type === "MemberExpression")
5464
- { c(node, st, "MemberPattern"); }
5465
- else
5466
- { c(node, st); }
5467
- };
5468
- base$1.VariablePattern = ignore;
5469
- base$1.MemberPattern = skipThrough;
5470
- base$1.RestElement = function (node, st, c) { return c(node.argument, st, "Pattern"); };
5471
- base$1.ArrayPattern = function (node, st, c) {
5472
- for (var i = 0, list = node.elements; i < list.length; i += 1) {
5473
- var elt = list[i];
5474
-
5475
- if (elt) { c(elt, st, "Pattern"); }
5476
- }
5477
- };
5478
- base$1.ObjectPattern = function (node, st, c) {
5479
- for (var i = 0, list = node.properties; i < list.length; i += 1) {
5480
- var prop = list[i];
5481
-
5482
- if (prop.type === "Property") {
5483
- if (prop.computed) { c(prop.key, st, "Expression"); }
5484
- c(prop.value, st, "Pattern");
5485
- } else if (prop.type === "RestElement") {
5486
- c(prop.argument, st, "Pattern");
5487
- }
5488
- }
5489
- };
5490
-
5491
- base$1.Expression = skipThrough;
5492
- base$1.ThisExpression = base$1.Super = base$1.MetaProperty = ignore;
5493
- base$1.ArrayExpression = function (node, st, c) {
5494
- for (var i = 0, list = node.elements; i < list.length; i += 1) {
5495
- var elt = list[i];
5496
-
5497
- if (elt) { c(elt, st, "Expression"); }
5498
- }
5499
- };
5500
- base$1.ObjectExpression = function (node, st, c) {
5501
- for (var i = 0, list = node.properties; i < list.length; i += 1)
5502
- {
5503
- var prop = list[i];
5504
-
5505
- c(prop, st);
5506
- }
5507
- };
5508
- base$1.FunctionExpression = base$1.ArrowFunctionExpression = base$1.FunctionDeclaration;
5509
- base$1.SequenceExpression = function (node, st, c) {
5510
- for (var i = 0, list = node.expressions; i < list.length; i += 1)
5511
- {
5512
- var expr = list[i];
5513
-
5514
- c(expr, st, "Expression");
5515
- }
5516
- };
5517
- base$1.TemplateLiteral = function (node, st, c) {
5518
- for (var i = 0, list = node.quasis; i < list.length; i += 1)
5519
- {
5520
- var quasi = list[i];
5521
-
5522
- c(quasi, st);
5523
- }
5524
-
5525
- for (var i$1 = 0, list$1 = node.expressions; i$1 < list$1.length; i$1 += 1)
5526
- {
5527
- var expr = list$1[i$1];
5528
-
5529
- c(expr, st, "Expression");
5530
- }
5531
- };
5532
- base$1.TemplateElement = ignore;
5533
- base$1.UnaryExpression = base$1.UpdateExpression = function (node, st, c) {
5534
- c(node.argument, st, "Expression");
5535
- };
5536
- base$1.BinaryExpression = base$1.LogicalExpression = function (node, st, c) {
5537
- c(node.left, st, "Expression");
5538
- c(node.right, st, "Expression");
5539
- };
5540
- base$1.AssignmentExpression = base$1.AssignmentPattern = function (node, st, c) {
5541
- c(node.left, st, "Pattern");
5542
- c(node.right, st, "Expression");
5543
- };
5544
- base$1.ConditionalExpression = function (node, st, c) {
5545
- c(node.test, st, "Expression");
5546
- c(node.consequent, st, "Expression");
5547
- c(node.alternate, st, "Expression");
5548
- };
5549
- base$1.NewExpression = base$1.CallExpression = function (node, st, c) {
5550
- c(node.callee, st, "Expression");
5551
- if (node.arguments)
5552
- { for (var i = 0, list = node.arguments; i < list.length; i += 1)
5553
- {
5554
- var arg = list[i];
5555
-
5556
- c(arg, st, "Expression");
5557
- } }
5558
- };
5559
- base$1.MemberExpression = function (node, st, c) {
5560
- c(node.object, st, "Expression");
5561
- if (node.computed) { c(node.property, st, "Expression"); }
5562
- };
5563
- base$1.ExportNamedDeclaration = base$1.ExportDefaultDeclaration = function (node, st, c) {
5564
- if (node.declaration)
5565
- { c(node.declaration, st, node.type === "ExportNamedDeclaration" || node.declaration.id ? "Statement" : "Expression"); }
5566
- if (node.source) { c(node.source, st, "Expression"); }
5567
- };
5568
- base$1.ExportAllDeclaration = function (node, st, c) {
5569
- if (node.exported)
5570
- { c(node.exported, st); }
5571
- c(node.source, st, "Expression");
5572
- };
5573
- base$1.ImportDeclaration = function (node, st, c) {
5574
- for (var i = 0, list = node.specifiers; i < list.length; i += 1)
5575
- {
5576
- var spec = list[i];
5577
-
5578
- c(spec, st);
5579
- }
5580
- c(node.source, st, "Expression");
5581
- };
5582
- base$1.ImportExpression = function (node, st, c) {
5583
- c(node.source, st, "Expression");
5584
- };
5585
- base$1.ImportSpecifier = base$1.ImportDefaultSpecifier = base$1.ImportNamespaceSpecifier = base$1.Identifier = base$1.PrivateIdentifier = base$1.Literal = ignore;
5586
-
5587
- base$1.TaggedTemplateExpression = function (node, st, c) {
5588
- c(node.tag, st, "Expression");
5589
- c(node.quasi, st, "Expression");
5590
- };
5591
- base$1.ClassDeclaration = base$1.ClassExpression = function (node, st, c) { return c(node, st, "Class"); };
5592
- base$1.Class = function (node, st, c) {
5593
- if (node.id) { c(node.id, st, "Pattern"); }
5594
- if (node.superClass) { c(node.superClass, st, "Expression"); }
5595
- c(node.body, st);
5596
- };
5597
- base$1.ClassBody = function (node, st, c) {
5598
- for (var i = 0, list = node.body; i < list.length; i += 1)
5599
- {
5600
- var elt = list[i];
5601
-
5602
- c(elt, st);
5603
- }
5604
- };
5605
- base$1.MethodDefinition = base$1.PropertyDefinition = base$1.Property = function (node, st, c) {
5606
- if (node.computed) { c(node.key, st, "Expression"); }
5607
- if (node.value) { c(node.value, st, "Expression"); }
5608
- };
5609
-
5610
- const ArrowFunctionExpression$1 = 'ArrowFunctionExpression';
5611
- const BinaryExpression$1 = 'BinaryExpression';
5612
- const BlockStatement$1 = 'BlockStatement';
5613
- const CallExpression$1 = 'CallExpression';
5614
- const ChainExpression$1 = 'ChainExpression';
5615
- const ConditionalExpression$1 = 'ConditionalExpression';
5616
- const ExportDefaultDeclaration$1 = 'ExportDefaultDeclaration';
5617
- const ExportNamedDeclaration$1 = 'ExportNamedDeclaration';
5618
- const ExpressionStatement$1 = 'ExpressionStatement';
5619
- const FunctionDeclaration$1 = 'FunctionDeclaration';
5620
- const Identifier$1 = 'Identifier';
5621
- const LogicalExpression$1 = 'LogicalExpression';
5622
- const NewExpression$1 = 'NewExpression';
5623
- const Program$1 = 'Program';
5624
- const Property$1 = 'Property';
5625
- const ReturnStatement$1 = 'ReturnStatement';
5626
- const SequenceExpression$1 = 'SequenceExpression';
5627
- const VariableDeclarator$1 = 'VariableDeclarator';
5628
- const VariableDeclaration$1 = 'VariableDeclaration';
5629
-
5630
- // this looks ridiculous, but it prevents sourcemap tooling from mistaking
5631
- // this for an actual sourceMappingURL
5632
- let SOURCEMAPPING_URL = 'sourceMa';
5633
- SOURCEMAPPING_URL += 'ppingURL';
5634
- const whiteSpaceNoNewline = '[ \\f\\r\\t\\v\\u00a0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000\\ufeff]';
5635
- const SOURCEMAPPING_URL_RE = new RegExp(`^#${whiteSpaceNoNewline}+${SOURCEMAPPING_URL}=.+`);
5372
+ const FIXED_STRINGS = [
5373
+ 'var',
5374
+ 'let',
5375
+ 'const',
5376
+ 'init',
5377
+ 'get',
5378
+ 'set',
5379
+ 'constructor',
5380
+ 'method',
5381
+ '-',
5382
+ '+',
5383
+ '!',
5384
+ '~',
5385
+ 'typeof',
5386
+ 'void',
5387
+ 'delete',
5388
+ '++',
5389
+ '--',
5390
+ '==',
5391
+ '!=',
5392
+ '===',
5393
+ '!==',
5394
+ '<',
5395
+ '<=',
5396
+ '>',
5397
+ '>=',
5398
+ '<<',
5399
+ '>>',
5400
+ '>>>',
5401
+ '+',
5402
+ '-',
5403
+ '*',
5404
+ '/',
5405
+ '%',
5406
+ '|',
5407
+ '^',
5408
+ '&',
5409
+ '||',
5410
+ '&&',
5411
+ 'in',
5412
+ 'instanceof',
5413
+ '**',
5414
+ '??',
5415
+ '=',
5416
+ '+=',
5417
+ '-=',
5418
+ '*=',
5419
+ '/=',
5420
+ '%=',
5421
+ '<<=',
5422
+ '>>=',
5423
+ '>>>=',
5424
+ '|=',
5425
+ '^=',
5426
+ '&=',
5427
+ '**=',
5428
+ '&&=',
5429
+ '||=',
5430
+ '??=',
5431
+ 'pure',
5432
+ 'noSideEffects'
5433
+ ];
5636
5434
 
5637
- const ANNOTATION_KEY = '_rollupAnnotations';
5638
- const INVALID_COMMENT_KEY = '_rollupRemoved';
5639
- function handlePureAnnotationsOfNode(node, state, type = node.type) {
5640
- const { annotations, code } = state;
5641
- // eslint-disable-next-line unicorn/consistent-destructuring
5642
- let comment = annotations[state.annotationIndex];
5643
- while (comment && node.start >= comment.end) {
5644
- markPureNode(node, comment, code);
5645
- comment = annotations[++state.annotationIndex];
5646
- }
5647
- if (comment && comment.end <= node.end) {
5648
- base$1[type](node, state, handlePureAnnotationsOfNode);
5649
- // eslint-disable-next-line unicorn/consistent-destructuring
5650
- while ((comment = annotations[state.annotationIndex]) && comment.end <= node.end) {
5651
- ++state.annotationIndex;
5652
- annotateNode(node, comment, false);
5653
- }
5654
- }
5655
- }
5656
- const neitherWithespaceNorBrackets = /[^\s(]/g;
5657
- const noWhitespace = /\S/g;
5658
- function markPureNode(node, comment, code) {
5659
- const annotatedNodes = [];
5660
- let invalidAnnotation;
5661
- const codeInBetween = code.slice(comment.end, node.start);
5662
- if (doesNotMatchOutsideComment(codeInBetween, neitherWithespaceNorBrackets)) {
5663
- const parentStart = node.start;
5664
- while (true) {
5665
- annotatedNodes.push(node);
5666
- switch (node.type) {
5667
- case ExpressionStatement$1:
5668
- case ChainExpression$1: {
5669
- node = node.expression;
5670
- continue;
5671
- }
5672
- case SequenceExpression$1: {
5673
- // if there are parentheses, the annotation would apply to the entire expression
5674
- if (doesNotMatchOutsideComment(code.slice(parentStart, node.start), noWhitespace)) {
5675
- node = node.expressions[0];
5676
- continue;
5677
- }
5678
- invalidAnnotation = true;
5679
- break;
5680
- }
5681
- case ConditionalExpression$1: {
5682
- // if there are parentheses, the annotation would apply to the entire expression
5683
- if (doesNotMatchOutsideComment(code.slice(parentStart, node.start), noWhitespace)) {
5684
- node = node.test;
5685
- continue;
5686
- }
5687
- invalidAnnotation = true;
5688
- break;
5689
- }
5690
- case LogicalExpression$1:
5691
- case BinaryExpression$1: {
5692
- // if there are parentheses, the annotation would apply to the entire expression
5693
- if (doesNotMatchOutsideComment(code.slice(parentStart, node.start), noWhitespace)) {
5694
- node = node.left;
5695
- continue;
5696
- }
5697
- invalidAnnotation = true;
5698
- break;
5699
- }
5700
- case ExportNamedDeclaration$1:
5701
- case ExportDefaultDeclaration$1: {
5702
- node = node.declaration;
5703
- continue;
5704
- }
5705
- case VariableDeclaration$1: {
5706
-
5707
- const declaration = node;
5708
- if (declaration.kind === 'const') {
5709
- // jsdoc only applies to the first declaration
5710
- node = declaration.declarations[0].init;
5711
- continue;
5712
- }
5713
- invalidAnnotation = true;
5714
- break;
5715
- }
5716
- case VariableDeclarator$1: {
5717
- node = node.init;
5718
- continue;
5719
- }
5720
- case FunctionDeclaration$1:
5721
- case ArrowFunctionExpression$1:
5722
- case CallExpression$1:
5723
- case NewExpression$1: {
5724
- break;
5725
- }
5726
- default: {
5727
- invalidAnnotation = true;
5728
- }
5729
- }
5730
- break;
5731
- }
5732
- }
5733
- else {
5734
- invalidAnnotation = true;
5735
- }
5736
- if (invalidAnnotation) {
5737
- annotateNode(node, comment, false);
5738
- }
5739
- else {
5740
- for (const node of annotatedNodes) {
5741
- annotateNode(node, comment, true);
5742
- }
5743
- }
5744
- }
5745
- function doesNotMatchOutsideComment(code, forbiddenChars) {
5746
- let nextMatch;
5747
- while ((nextMatch = forbiddenChars.exec(code)) !== null) {
5748
- if (nextMatch[0] === '/') {
5749
- const charCodeAfterSlash = code.charCodeAt(forbiddenChars.lastIndex);
5750
- if (charCodeAfterSlash === 42 /*"*"*/) {
5751
- forbiddenChars.lastIndex = code.indexOf('*/', forbiddenChars.lastIndex + 1) + 2;
5752
- continue;
5753
- }
5754
- else if (charCodeAfterSlash === 47 /*"/"*/) {
5755
- forbiddenChars.lastIndex = code.indexOf('\n', forbiddenChars.lastIndex + 1) + 1;
5756
- continue;
5435
+ const convertProgram = (buffer, readString) => convertNode(0, new Uint32Array(buffer), readString);
5436
+ const convertNode = (position, buffer, readString) => {
5437
+ const nodeType = buffer[position];
5438
+ const converter = nodeConverters[nodeType];
5439
+ if (!converter) {
5440
+ console.trace();
5441
+ throw new Error(`Unknown node type: ${nodeType}`);
5442
+ }
5443
+ return converter(position + 1, buffer, readString);
5444
+ };
5445
+ /* eslint-disable sort-keys */
5446
+ const nodeConverters = [
5447
+ // index:0; ArrayExpression
5448
+ (position, buffer, readString) => {
5449
+ const start = buffer[position++];
5450
+ const end = buffer[position++];
5451
+ const elements = convertNodeList(position, buffer, readString);
5452
+ return {
5453
+ type: 'ArrayExpression',
5454
+ start,
5455
+ end,
5456
+ elements
5457
+ };
5458
+ },
5459
+ // index:1; ArrayPattern
5460
+ (position, buffer, readString) => {
5461
+ const start = buffer[position++];
5462
+ const end = buffer[position++];
5463
+ const elements = convertNodeList(position, buffer, readString);
5464
+ return {
5465
+ type: 'ArrayPattern',
5466
+ start,
5467
+ end,
5468
+ elements
5469
+ };
5470
+ },
5471
+ // index:2; ArrowFunctionExpression
5472
+ (position, buffer, readString) => {
5473
+ const start = buffer[position++];
5474
+ const end = buffer[position++];
5475
+ const async = !!buffer[position++];
5476
+ const generator = !!buffer[position++];
5477
+ const expression = !!buffer[position++];
5478
+ const parameters = convertNodeList(buffer[position++], buffer, readString);
5479
+ const body = convertNode(buffer[position++], buffer, readString);
5480
+ const annotations = convertAnnotationList(position, buffer);
5481
+ return {
5482
+ type: 'ArrowFunctionExpression',
5483
+ start,
5484
+ end,
5485
+ async,
5486
+ body,
5487
+ expression,
5488
+ generator,
5489
+ id: null,
5490
+ params: parameters,
5491
+ _rollupAnnotations: annotations
5492
+ };
5493
+ },
5494
+ // index:3; AssignmentExpression
5495
+ (position, buffer, readString) => {
5496
+ const start = buffer[position++];
5497
+ const end = buffer[position++];
5498
+ const operator = FIXED_STRINGS[buffer[position++]];
5499
+ const right = convertNode(buffer[position++], buffer, readString);
5500
+ const left = convertNode(position, buffer, readString);
5501
+ return {
5502
+ type: 'AssignmentExpression',
5503
+ start,
5504
+ end,
5505
+ left,
5506
+ operator,
5507
+ right
5508
+ };
5509
+ },
5510
+ // index:4; AssignmentPattern
5511
+ (position, buffer, readString) => {
5512
+ const start = buffer[position++];
5513
+ const end = buffer[position++];
5514
+ const right = convertNode(buffer[position++], buffer, readString);
5515
+ const left = convertNode(position, buffer, readString);
5516
+ return {
5517
+ type: 'AssignmentPattern',
5518
+ start,
5519
+ end,
5520
+ left,
5521
+ right
5522
+ };
5523
+ },
5524
+ // index:5; AwaitExpression
5525
+ (position, buffer, readString) => {
5526
+ const start = buffer[position++];
5527
+ const end = buffer[position++];
5528
+ const argument = convertNode(position, buffer, readString);
5529
+ return {
5530
+ type: 'AwaitExpression',
5531
+ start,
5532
+ argument,
5533
+ end
5534
+ };
5535
+ },
5536
+ // index:6; BinaryExpression
5537
+ (position, buffer, readString) => {
5538
+ const start = buffer[position++];
5539
+ const end = buffer[position++];
5540
+ const operator = FIXED_STRINGS[buffer[position++]];
5541
+ const right = convertNode(buffer[position++], buffer, readString);
5542
+ const left = convertNode(position, buffer, readString);
5543
+ return {
5544
+ type: 'BinaryExpression',
5545
+ start,
5546
+ end,
5547
+ left,
5548
+ operator,
5549
+ right
5550
+ };
5551
+ },
5552
+ // index:7; BlockStatement
5553
+ (position, buffer, readString) => {
5554
+ const start = buffer[position++];
5555
+ const end = buffer[position++];
5556
+ const body = convertNodeList(position, buffer, readString);
5557
+ return {
5558
+ type: 'BlockStatement',
5559
+ start,
5560
+ body,
5561
+ end
5562
+ };
5563
+ },
5564
+ // index:8; BreakStatement
5565
+ (position, buffer, readString) => {
5566
+ const start = buffer[position++];
5567
+ const end = buffer[position++];
5568
+ const labelPosition = buffer[position++];
5569
+ return {
5570
+ type: 'BreakStatement',
5571
+ start,
5572
+ end,
5573
+ label: labelPosition ? convertNode(labelPosition, buffer, readString) : null
5574
+ };
5575
+ },
5576
+ // index:9; CallExpression
5577
+ (position, buffer, readString) => {
5578
+ const start = buffer[position++];
5579
+ const end = buffer[position++];
5580
+ const optional = !!buffer[position++];
5581
+ const callee = convertNode(buffer[position++], buffer, readString);
5582
+ const argumentsList = convertNodeList(buffer[position++], buffer, readString);
5583
+ const annotations = convertAnnotationList(position, buffer);
5584
+ return {
5585
+ type: 'CallExpression',
5586
+ start,
5587
+ end,
5588
+ arguments: argumentsList,
5589
+ callee,
5590
+ optional,
5591
+ ...(annotations.length > 0 ? { _rollupAnnotations: annotations } : {})
5592
+ };
5593
+ },
5594
+ // index:10; CatchClause
5595
+ (position, buffer, readString) => {
5596
+ const start = buffer[position++];
5597
+ const end = buffer[position++];
5598
+ const parameterPosition = buffer[position++];
5599
+ const body = convertNode(buffer[position], buffer, readString);
5600
+ return {
5601
+ type: 'CatchClause',
5602
+ start,
5603
+ end,
5604
+ body,
5605
+ param: parameterPosition ? convertNode(parameterPosition, buffer, readString) : null
5606
+ };
5607
+ },
5608
+ // index:11; ChainExpression
5609
+ (position, buffer, readString) => {
5610
+ const start = buffer[position++];
5611
+ const end = buffer[position++];
5612
+ const expression = convertNode(position, buffer, readString);
5613
+ return {
5614
+ type: 'ChainExpression',
5615
+ start,
5616
+ end,
5617
+ expression
5618
+ };
5619
+ },
5620
+ // index:12; ClassBody
5621
+ (position, buffer, readString) => {
5622
+ const start = buffer[position++];
5623
+ const end = buffer[position++];
5624
+ const body = convertNodeList(position, buffer, readString);
5625
+ return {
5626
+ type: 'ClassBody',
5627
+ start,
5628
+ end,
5629
+ body
5630
+ };
5631
+ },
5632
+ // index:13; ClassDeclaration
5633
+ (position, buffer, readString) => {
5634
+ const start = buffer[position++];
5635
+ const end = buffer[position++];
5636
+ const idPosition = buffer[position++];
5637
+ const superClassPosition = buffer[position++];
5638
+ const body = convertNode(buffer[position], buffer, readString);
5639
+ return {
5640
+ type: 'ClassDeclaration',
5641
+ start,
5642
+ end,
5643
+ body,
5644
+ id: idPosition ? convertNode(idPosition, buffer, readString) : null,
5645
+ superClass: superClassPosition ? convertNode(superClassPosition, buffer, readString) : null
5646
+ };
5647
+ },
5648
+ // index:14; ClassExpression
5649
+ (position, buffer, readString) => {
5650
+ const start = buffer[position++];
5651
+ const end = buffer[position++];
5652
+ const idPosition = buffer[position++];
5653
+ const superClassPosition = buffer[position++];
5654
+ const body = convertNode(buffer[position], buffer, readString);
5655
+ return {
5656
+ type: 'ClassExpression',
5657
+ start,
5658
+ end,
5659
+ body,
5660
+ id: idPosition ? convertNode(idPosition, buffer, readString) : null,
5661
+ superClass: superClassPosition ? convertNode(superClassPosition, buffer, readString) : null
5662
+ };
5663
+ },
5664
+ // index:15; ConditionalExpression
5665
+ (position, buffer, readString) => {
5666
+ const start = buffer[position++];
5667
+ const end = buffer[position++];
5668
+ const consequent = convertNode(buffer[position++], buffer, readString);
5669
+ const alternate = convertNode(buffer[position++], buffer, readString);
5670
+ const test = convertNode(position, buffer, readString);
5671
+ return {
5672
+ type: 'ConditionalExpression',
5673
+ start,
5674
+ end,
5675
+ alternate,
5676
+ consequent,
5677
+ test
5678
+ };
5679
+ },
5680
+ // index:16; ContinueStatement
5681
+ (position, buffer, readString) => {
5682
+ const start = buffer[position++];
5683
+ const end = buffer[position++];
5684
+ const labelPosition = buffer[position];
5685
+ return {
5686
+ type: 'ContinueStatement',
5687
+ start,
5688
+ end,
5689
+ label: labelPosition ? convertNode(labelPosition, buffer, readString) : null
5690
+ };
5691
+ },
5692
+ // index:17; DebuggerStatement
5693
+ (position, buffer) => {
5694
+ const start = buffer[position++];
5695
+ const end = buffer[position++];
5696
+ return {
5697
+ type: 'DebuggerStatement',
5698
+ start,
5699
+ end
5700
+ };
5701
+ },
5702
+ // index:18; DoWhileStatement
5703
+ (position, buffer, readString) => {
5704
+ const start = buffer[position++];
5705
+ const end = buffer[position++];
5706
+ const test = convertNode(buffer[position++], buffer, readString);
5707
+ const body = convertNode(position, buffer, readString);
5708
+ return {
5709
+ type: 'DoWhileStatement',
5710
+ start,
5711
+ end,
5712
+ body,
5713
+ test
5714
+ };
5715
+ },
5716
+ // index:19; EmptyStatement
5717
+ (position, buffer) => {
5718
+ const start = buffer[position++];
5719
+ const end = buffer[position++];
5720
+ return {
5721
+ type: 'EmptyStatement',
5722
+ start,
5723
+ end
5724
+ };
5725
+ },
5726
+ // index:20; ExportAllDeclaration
5727
+ (position, buffer, readString) => {
5728
+ const start = buffer[position++];
5729
+ const end = buffer[position++];
5730
+ const exportedPosition = buffer[position++];
5731
+ const source = convertNode(buffer[position++], buffer, readString);
5732
+ const assertions = convertNodeList(buffer[position], buffer, readString);
5733
+ return {
5734
+ type: 'ExportAllDeclaration',
5735
+ start,
5736
+ end,
5737
+ exported: exportedPosition ? convertNode(exportedPosition, buffer, readString) : null,
5738
+ source,
5739
+ ...(assertions.length > 0 ? { assertions } : {})
5740
+ };
5741
+ },
5742
+ // index:21; ExportDefaultDeclaration
5743
+ (position, buffer, readString) => {
5744
+ const start = buffer[position++];
5745
+ const end = buffer[position++];
5746
+ const declaration = convertNode(position, buffer, readString);
5747
+ return {
5748
+ type: 'ExportDefaultDeclaration',
5749
+ start,
5750
+ end,
5751
+ declaration
5752
+ };
5753
+ },
5754
+ // index:22; ExportNamedDeclaration
5755
+ (position, buffer, readString) => {
5756
+ const start = buffer[position++];
5757
+ const end = buffer[position++];
5758
+ const declarationPosition = buffer[position++];
5759
+ const sourcePosition = buffer[position++];
5760
+ const assertions = convertNodeList(buffer[position++], buffer, readString);
5761
+ const specifiers = convertNodeList(position, buffer, readString);
5762
+ return {
5763
+ type: 'ExportNamedDeclaration',
5764
+ start,
5765
+ end,
5766
+ declaration: declarationPosition
5767
+ ? convertNode(declarationPosition, buffer, readString)
5768
+ : null,
5769
+ source: sourcePosition ? convertNode(sourcePosition, buffer, readString) : null,
5770
+ specifiers,
5771
+ ...(assertions.length > 0 ? { assertions } : {})
5772
+ };
5773
+ },
5774
+ // index:23; ExportSpecifier
5775
+ (position, buffer, readString) => {
5776
+ const start = buffer[position++];
5777
+ const end = buffer[position++];
5778
+ const exportedPosition = buffer[position++];
5779
+ const local = convertNode(position, buffer, readString);
5780
+ const exported = exportedPosition ? convertNode(exportedPosition, buffer, readString) : local;
5781
+ return {
5782
+ type: 'ExportSpecifier',
5783
+ start,
5784
+ end,
5785
+ exported,
5786
+ local
5787
+ };
5788
+ },
5789
+ // index:24; ExpressionStatement
5790
+ (position, buffer, readString) => {
5791
+ const start = buffer[position++];
5792
+ const end = buffer[position++];
5793
+ const directivePosition = buffer[position++];
5794
+ const expression = convertNode(position, buffer, readString);
5795
+ return {
5796
+ type: 'ExpressionStatement',
5797
+ start,
5798
+ end,
5799
+ expression,
5800
+ ...(directivePosition
5801
+ ? { directive: convertString(directivePosition, buffer, readString) }
5802
+ : {})
5803
+ };
5804
+ },
5805
+ // index:25; ForInStatement
5806
+ (position, buffer, readString) => {
5807
+ const start = buffer[position++];
5808
+ const end = buffer[position++];
5809
+ const right = convertNode(buffer[position++], buffer, readString);
5810
+ const body = convertNode(buffer[position++], buffer, readString);
5811
+ const left = convertNode(position, buffer, readString);
5812
+ return {
5813
+ type: 'ForInStatement',
5814
+ start,
5815
+ end,
5816
+ body,
5817
+ left,
5818
+ right
5819
+ };
5820
+ },
5821
+ // index:26; ForOfStatement
5822
+ (position, buffer, readString) => {
5823
+ const start = buffer[position++];
5824
+ const end = buffer[position++];
5825
+ const awaited = !!buffer[position++];
5826
+ const right = convertNode(buffer[position++], buffer, readString);
5827
+ const body = convertNode(buffer[position++], buffer, readString);
5828
+ const left = convertNode(position, buffer, readString);
5829
+ return {
5830
+ type: 'ForOfStatement',
5831
+ start,
5832
+ end,
5833
+ await: awaited,
5834
+ body,
5835
+ left,
5836
+ right
5837
+ };
5838
+ },
5839
+ // index:27; ForStatement
5840
+ (position, buffer, readString) => {
5841
+ const start = buffer[position++];
5842
+ const end = buffer[position++];
5843
+ const initPosition = buffer[position++];
5844
+ const testPosition = buffer[position++];
5845
+ const updatePosition = buffer[position++];
5846
+ const body = convertNode(buffer[position], buffer, readString);
5847
+ return {
5848
+ type: 'ForStatement',
5849
+ start,
5850
+ end,
5851
+ body,
5852
+ init: initPosition ? convertNode(initPosition, buffer, readString) : null,
5853
+ test: testPosition ? convertNode(testPosition, buffer, readString) : null,
5854
+ update: updatePosition ? convertNode(updatePosition, buffer, readString) : null
5855
+ };
5856
+ },
5857
+ // index:28; FunctionDeclaration
5858
+ (position, buffer, readString) => {
5859
+ const start = buffer[position++];
5860
+ const end = buffer[position++];
5861
+ const async = !!buffer[position++];
5862
+ const generator = !!buffer[position++];
5863
+ const idPosition = buffer[position++];
5864
+ const parameters = convertNodeList(buffer[position++], buffer, readString);
5865
+ const body = convertNode(buffer[position++], buffer, readString);
5866
+ const annotations = convertAnnotationList(position, buffer);
5867
+ return {
5868
+ type: 'FunctionDeclaration',
5869
+ start,
5870
+ end,
5871
+ async,
5872
+ body,
5873
+ expression: false,
5874
+ generator,
5875
+ id: idPosition ? convertNode(idPosition, buffer, readString) : null,
5876
+ params: parameters,
5877
+ _rollupAnnotations: annotations
5878
+ };
5879
+ },
5880
+ // index:29; FunctionExpression
5881
+ (position, buffer, readString) => {
5882
+ const start = buffer[position++];
5883
+ const end = buffer[position++];
5884
+ const async = !!buffer[position++];
5885
+ const generator = !!buffer[position++];
5886
+ const idPosition = buffer[position++];
5887
+ const parameters = convertNodeList(buffer[position++], buffer, readString);
5888
+ const body = convertNode(buffer[position++], buffer, readString);
5889
+ const annotations = convertAnnotationList(position, buffer);
5890
+ return {
5891
+ type: 'FunctionExpression',
5892
+ start,
5893
+ end,
5894
+ async,
5895
+ body,
5896
+ expression: false,
5897
+ generator,
5898
+ id: idPosition ? convertNode(idPosition, buffer, readString) : null,
5899
+ params: parameters,
5900
+ _rollupAnnotations: annotations
5901
+ };
5902
+ },
5903
+ // index:30; Identifier
5904
+ (position, buffer, readString) => {
5905
+ const start = buffer[position++];
5906
+ const end = buffer[position++];
5907
+ const name = convertString(position, buffer, readString);
5908
+ return {
5909
+ type: 'Identifier',
5910
+ start,
5911
+ end,
5912
+ name
5913
+ };
5914
+ },
5915
+ // index:31; IfStatement
5916
+ (position, buffer, readString) => {
5917
+ const start = buffer[position++];
5918
+ const end = buffer[position++];
5919
+ const consequent = convertNode(buffer[position++], buffer, readString);
5920
+ const alternatePosition = buffer[position++];
5921
+ const test = convertNode(position, buffer, readString);
5922
+ return {
5923
+ type: 'IfStatement',
5924
+ start,
5925
+ end,
5926
+ alternate: alternatePosition ? convertNode(alternatePosition, buffer, readString) : null,
5927
+ consequent,
5928
+ test
5929
+ };
5930
+ },
5931
+ // index:32; ImportAttribute
5932
+ (position, buffer, readString) => {
5933
+ const start = buffer[position++];
5934
+ const end = buffer[position++];
5935
+ const value = convertNode(buffer[position++], buffer, readString);
5936
+ const key = convertNode(position, buffer, readString);
5937
+ return {
5938
+ type: 'ImportAttribute',
5939
+ start,
5940
+ end,
5941
+ key,
5942
+ value
5943
+ };
5944
+ },
5945
+ // index:33; ImportDeclaration
5946
+ (position, buffer, readString) => {
5947
+ const start = buffer[position++];
5948
+ const end = buffer[position++];
5949
+ const source = convertNode(buffer[position++], buffer, readString);
5950
+ const assertions = convertNodeList(buffer[position++], buffer, readString);
5951
+ const specifiers = convertNodeList(position, buffer, readString);
5952
+ return {
5953
+ type: 'ImportDeclaration',
5954
+ start,
5955
+ end,
5956
+ source,
5957
+ specifiers,
5958
+ ...(assertions.length > 0 ? { assertions } : {})
5959
+ };
5960
+ },
5961
+ // index:34; ImportDefaultSpecifier
5962
+ (position, buffer, readString) => {
5963
+ const start = buffer[position++];
5964
+ const end = buffer[position++];
5965
+ const local = convertNode(position, buffer, readString);
5966
+ return {
5967
+ type: 'ImportDefaultSpecifier',
5968
+ start,
5969
+ end,
5970
+ local
5971
+ };
5972
+ },
5973
+ // index:35; ImportExpression
5974
+ (position, buffer, readString) => {
5975
+ const start = buffer[position++];
5976
+ const end = buffer[position++];
5977
+ const arguments_ = convertNodeList(buffer[position++], buffer, readString);
5978
+ const source = convertNode(position, buffer, readString);
5979
+ return {
5980
+ type: 'ImportExpression',
5981
+ start,
5982
+ end,
5983
+ source,
5984
+ ...(arguments_.length > 0 ? { arguments: arguments_ } : {})
5985
+ };
5986
+ },
5987
+ // index:36; ImportNamespaceSpecifier
5988
+ (position, buffer, readString) => {
5989
+ const start = buffer[position++];
5990
+ const end = buffer[position++];
5991
+ const local = convertNode(position, buffer, readString);
5992
+ return {
5993
+ type: 'ImportNamespaceSpecifier',
5994
+ start,
5995
+ end,
5996
+ local
5997
+ };
5998
+ },
5999
+ // index:37; ImportSpecifier
6000
+ (position, buffer, readString) => {
6001
+ const start = buffer[position++];
6002
+ const end = buffer[position++];
6003
+ const importedPosition = buffer[position++];
6004
+ const local = convertNode(buffer[position], buffer, readString);
6005
+ const imported = importedPosition ? convertNode(importedPosition, buffer, readString) : local;
6006
+ return {
6007
+ type: 'ImportSpecifier',
6008
+ start,
6009
+ end,
6010
+ imported,
6011
+ local
6012
+ };
6013
+ },
6014
+ // index:38; LabeledStatement
6015
+ (position, buffer, readString) => {
6016
+ const start = buffer[position++];
6017
+ const end = buffer[position++];
6018
+ const body = convertNode(buffer[position++], buffer, readString);
6019
+ const label = convertNode(position, buffer, readString);
6020
+ return {
6021
+ type: 'LabeledStatement',
6022
+ start,
6023
+ end,
6024
+ body,
6025
+ label
6026
+ };
6027
+ },
6028
+ // index:39; Literal<string>
6029
+ (position, buffer, readString) => {
6030
+ const start = buffer[position++];
6031
+ const end = buffer[position++];
6032
+ const rawPosition = buffer[position++];
6033
+ const raw = rawPosition ? convertString(rawPosition, buffer, readString) : undefined;
6034
+ const value = convertString(position, buffer, readString);
6035
+ return {
6036
+ type: 'Literal',
6037
+ start,
6038
+ end,
6039
+ raw,
6040
+ value
6041
+ };
6042
+ },
6043
+ // index:40; Literal<boolean>
6044
+ (position, buffer) => {
6045
+ const start = buffer[position++];
6046
+ const end = buffer[position++];
6047
+ const value = !!buffer[position++];
6048
+ return {
6049
+ type: 'Literal',
6050
+ start,
6051
+ end,
6052
+ raw: value ? 'true' : 'false',
6053
+ value
6054
+ };
6055
+ },
6056
+ // index:41; Literal<number>
6057
+ (position, buffer, readString) => {
6058
+ const start = buffer[position++];
6059
+ const end = buffer[position++];
6060
+ const rawPosition = buffer[position++];
6061
+ const raw = rawPosition ? convertString(rawPosition, buffer, readString) : undefined;
6062
+ const value = new DataView(buffer.buffer).getFloat64(position << 2, true);
6063
+ return {
6064
+ type: 'Literal',
6065
+ start,
6066
+ end,
6067
+ raw,
6068
+ value
6069
+ };
6070
+ },
6071
+ // index:42; Literal<null>
6072
+ (position, buffer) => {
6073
+ const start = buffer[position++];
6074
+ const end = buffer[position++];
6075
+ return {
6076
+ type: 'Literal',
6077
+ start,
6078
+ end,
6079
+ raw: 'null',
6080
+ value: null
6081
+ };
6082
+ },
6083
+ // index:43; Literal<RegExp>
6084
+ (position, buffer, readString) => {
6085
+ const start = buffer[position++];
6086
+ const end = buffer[position++];
6087
+ const pattern = convertString(buffer[position++], buffer, readString);
6088
+ const flags = convertString(position, buffer, readString);
6089
+ return {
6090
+ type: 'Literal',
6091
+ start,
6092
+ end,
6093
+ raw: `/${pattern}/${flags}`,
6094
+ regex: {
6095
+ flags,
6096
+ pattern
6097
+ },
6098
+ value: new RegExp(pattern, flags)
6099
+ };
6100
+ },
6101
+ // index:44; Literal<bigint>
6102
+ (position, buffer, readString) => {
6103
+ const start = buffer[position++];
6104
+ const end = buffer[position++];
6105
+ const bigint = convertString(buffer[position++], buffer, readString);
6106
+ const raw = convertString(position, buffer, readString);
6107
+ return {
6108
+ type: 'Literal',
6109
+ start,
6110
+ end,
6111
+ bigint,
6112
+ raw,
6113
+ value: BigInt(bigint)
6114
+ };
6115
+ },
6116
+ // index:45; LogicalExpression
6117
+ (position, buffer, readString) => {
6118
+ const start = buffer[position++];
6119
+ const end = buffer[position++];
6120
+ const operator = FIXED_STRINGS[buffer[position++]];
6121
+ const right = convertNode(buffer[position++], buffer, readString);
6122
+ const left = convertNode(position, buffer, readString);
6123
+ return {
6124
+ type: 'LogicalExpression',
6125
+ start,
6126
+ end,
6127
+ left,
6128
+ operator,
6129
+ right
6130
+ };
6131
+ },
6132
+ // index:46; MemberExpression
6133
+ (position, buffer, readString) => {
6134
+ const start = buffer[position++];
6135
+ const end = buffer[position++];
6136
+ const optional = !!buffer[position++];
6137
+ const computed = !!buffer[position++];
6138
+ const property = convertNode(buffer[position++], buffer, readString);
6139
+ const object = convertNode(position, buffer, readString);
6140
+ return {
6141
+ type: 'MemberExpression',
6142
+ start,
6143
+ end,
6144
+ computed,
6145
+ object,
6146
+ optional,
6147
+ property
6148
+ };
6149
+ },
6150
+ // index:47; MetaProperty
6151
+ (position, buffer, readString) => {
6152
+ const start = buffer[position++];
6153
+ const end = buffer[position++];
6154
+ const property = convertNode(buffer[position++], buffer, readString);
6155
+ const meta = convertNode(position, buffer, readString);
6156
+ return {
6157
+ type: 'MetaProperty',
6158
+ start,
6159
+ end,
6160
+ meta,
6161
+ property
6162
+ };
6163
+ },
6164
+ // index:48; MethodDefinition
6165
+ (position, buffer, readString) => {
6166
+ const start = buffer[position++];
6167
+ const end = buffer[position++];
6168
+ const kind = FIXED_STRINGS[buffer[position++]];
6169
+ const computed = !!buffer[position++];
6170
+ const isStatic = !!buffer[position++];
6171
+ const value = convertNode(buffer[position++], buffer, readString);
6172
+ const key = convertNode(position, buffer, readString);
6173
+ return {
6174
+ type: 'MethodDefinition',
6175
+ start,
6176
+ end,
6177
+ computed,
6178
+ key,
6179
+ kind,
6180
+ static: isStatic,
6181
+ value
6182
+ };
6183
+ },
6184
+ // index:49; NewExpression
6185
+ (position, buffer, readString) => {
6186
+ const start = buffer[position++];
6187
+ const end = buffer[position++];
6188
+ const callee = convertNode(buffer[position++], buffer, readString);
6189
+ const argumentsPosition = buffer[position++];
6190
+ const annotations = convertAnnotationList(position, buffer);
6191
+ return {
6192
+ type: 'NewExpression',
6193
+ start,
6194
+ end,
6195
+ arguments: argumentsPosition ? convertNodeList(argumentsPosition, buffer, readString) : [],
6196
+ callee,
6197
+ ...(annotations.length > 0 ? { _rollupAnnotations: annotations } : {})
6198
+ };
6199
+ },
6200
+ // index:50; ObjectExpression
6201
+ (position, buffer, readString) => {
6202
+ const start = buffer[position++];
6203
+ const end = buffer[position++];
6204
+ const properties = convertNodeList(position, buffer, readString);
6205
+ return {
6206
+ type: 'ObjectExpression',
6207
+ start,
6208
+ end,
6209
+ properties
6210
+ };
6211
+ },
6212
+ // index:51; ObjectPattern
6213
+ (position, buffer, readString) => {
6214
+ const start = buffer[position++];
6215
+ const end = buffer[position++];
6216
+ const properties = convertNodeList(position, buffer, readString);
6217
+ return {
6218
+ type: 'ObjectPattern',
6219
+ start,
6220
+ end,
6221
+ properties
6222
+ };
6223
+ },
6224
+ // index:52; PrivateIdentifier
6225
+ (position, buffer, readString) => {
6226
+ const start = buffer[position++];
6227
+ const end = buffer[position++];
6228
+ const name = convertString(position, buffer, readString);
6229
+ return {
6230
+ type: 'PrivateIdentifier',
6231
+ start,
6232
+ end,
6233
+ name
6234
+ };
6235
+ },
6236
+ // index:53; Program
6237
+ (position, buffer, readString) => {
6238
+ const start = buffer[position++];
6239
+ const end = buffer[position++];
6240
+ const annotations = convertAnnotationList(buffer[position++], buffer);
6241
+ const body = convertNodeList(position, buffer, readString);
6242
+ return {
6243
+ type: 'Program',
6244
+ start,
6245
+ end,
6246
+ body,
6247
+ sourceType: 'module',
6248
+ ...(annotations.length > 0 ? { _rollupRemoved: annotations } : {})
6249
+ };
6250
+ },
6251
+ // index:54; Property
6252
+ (position, buffer, readString) => {
6253
+ const start = buffer[position++];
6254
+ const end = buffer[position++];
6255
+ const kind = FIXED_STRINGS[buffer[position++]];
6256
+ const method = !!buffer[position++];
6257
+ const computed = !!buffer[position++];
6258
+ const shorthand = !!buffer[position++];
6259
+ const key = convertNode(buffer[position++], buffer, readString);
6260
+ const valuePosition = buffer[position];
6261
+ return {
6262
+ type: 'Property',
6263
+ start,
6264
+ end,
6265
+ computed,
6266
+ key,
6267
+ kind,
6268
+ method,
6269
+ shorthand,
6270
+ value: valuePosition ? convertNode(valuePosition, buffer, readString) : key
6271
+ };
6272
+ },
6273
+ // index:55; PropertyDefinition
6274
+ (position, buffer, readString) => {
6275
+ const start = buffer[position++];
6276
+ const end = buffer[position++];
6277
+ const computed = !!buffer[position++];
6278
+ const isStatic = !!buffer[position++];
6279
+ const valuePosition = buffer[position++];
6280
+ const key = convertNode(position, buffer, readString);
6281
+ return {
6282
+ type: 'PropertyDefinition',
6283
+ start,
6284
+ end,
6285
+ computed,
6286
+ key,
6287
+ static: isStatic,
6288
+ value: valuePosition ? convertNode(valuePosition, buffer, readString) : null
6289
+ };
6290
+ },
6291
+ // index:56; RestElement
6292
+ (position, buffer, readString) => {
6293
+ const start = buffer[position++];
6294
+ const end = buffer[position++];
6295
+ const argument = convertNode(position, buffer, readString);
6296
+ return {
6297
+ type: 'RestElement',
6298
+ start,
6299
+ end,
6300
+ argument
6301
+ };
6302
+ },
6303
+ // index:57; ReturnStatement
6304
+ (position, buffer, readString) => {
6305
+ const start = buffer[position++];
6306
+ const end = buffer[position++];
6307
+ const argumentPosition = buffer[position];
6308
+ return {
6309
+ type: 'ReturnStatement',
6310
+ start,
6311
+ end,
6312
+ argument: argumentPosition ? convertNode(argumentPosition, buffer, readString) : null
6313
+ };
6314
+ },
6315
+ // index:58; SequenceExpression
6316
+ (position, buffer, readString) => {
6317
+ const start = buffer[position++];
6318
+ const end = buffer[position++];
6319
+ const expressions = convertNodeList(position, buffer, readString);
6320
+ return {
6321
+ type: 'SequenceExpression',
6322
+ start,
6323
+ end,
6324
+ expressions
6325
+ };
6326
+ },
6327
+ // index:59; SpreadElement
6328
+ (position, buffer, readString) => {
6329
+ const start = buffer[position++];
6330
+ const end = buffer[position++];
6331
+ const argument = convertNode(position, buffer, readString);
6332
+ return {
6333
+ type: 'SpreadElement',
6334
+ start,
6335
+ end,
6336
+ argument
6337
+ };
6338
+ },
6339
+ // index:60; StaticBlock
6340
+ (position, buffer, readString) => {
6341
+ const start = buffer[position++];
6342
+ const end = buffer[position++];
6343
+ const body = convertNodeList(position, buffer, readString);
6344
+ return {
6345
+ type: 'StaticBlock',
6346
+ start,
6347
+ end,
6348
+ body
6349
+ };
6350
+ },
6351
+ // index:61; Super
6352
+ (position, buffer) => {
6353
+ const start = buffer[position++];
6354
+ const end = buffer[position++];
6355
+ return {
6356
+ type: 'Super',
6357
+ start,
6358
+ end
6359
+ };
6360
+ },
6361
+ // index:62; SwitchCase
6362
+ (position, buffer, readString) => {
6363
+ const start = buffer[position++];
6364
+ const end = buffer[position++];
6365
+ const testPosition = buffer[position++];
6366
+ const consequent = convertNodeList(buffer[position], buffer, readString);
6367
+ return {
6368
+ type: 'SwitchCase',
6369
+ start,
6370
+ end,
6371
+ consequent,
6372
+ test: testPosition ? convertNode(testPosition, buffer, readString) : null
6373
+ };
6374
+ },
6375
+ // index:63; SwitchStatement
6376
+ (position, buffer, readString) => {
6377
+ const start = buffer[position++];
6378
+ const end = buffer[position++];
6379
+ const cases = convertNodeList(buffer[position++], buffer, readString);
6380
+ const discriminant = convertNode(position, buffer, readString);
6381
+ return {
6382
+ type: 'SwitchStatement',
6383
+ start,
6384
+ end,
6385
+ cases,
6386
+ discriminant
6387
+ };
6388
+ },
6389
+ // index:64; TaggedTemplateExpression
6390
+ (position, buffer, readString) => {
6391
+ const start = buffer[position++];
6392
+ const end = buffer[position++];
6393
+ const quasi = convertNode(buffer[position++], buffer, readString);
6394
+ const tag = convertNode(position, buffer, readString);
6395
+ return {
6396
+ type: 'TaggedTemplateExpression',
6397
+ start,
6398
+ end,
6399
+ quasi,
6400
+ tag
6401
+ };
6402
+ },
6403
+ // index:65; TemplateElement
6404
+ (position, buffer, readString) => {
6405
+ const start = buffer[position++];
6406
+ const end = buffer[position++];
6407
+ const tail = !!buffer[position++];
6408
+ const cookedPosition = buffer[position++];
6409
+ const raw = convertString(position, buffer, readString);
6410
+ return {
6411
+ type: 'TemplateElement',
6412
+ start,
6413
+ end,
6414
+ tail,
6415
+ value: {
6416
+ cooked: cookedPosition ? convertString(cookedPosition, buffer, readString) : null,
6417
+ raw
5757
6418
  }
5758
- }
5759
- forbiddenChars.lastIndex = 0;
5760
- return false;
6419
+ };
6420
+ },
6421
+ // index:66; TemplateLiteral
6422
+ (position, buffer, readString) => {
6423
+ const start = buffer[position++];
6424
+ const end = buffer[position++];
6425
+ const expressions = convertNodeList(buffer[position++], buffer, readString);
6426
+ const quasis = convertNodeList(position, buffer, readString);
6427
+ return {
6428
+ type: 'TemplateLiteral',
6429
+ start,
6430
+ end,
6431
+ expressions,
6432
+ quasis
6433
+ };
6434
+ },
6435
+ // index:67; ThisExpression
6436
+ (position, buffer) => {
6437
+ const start = buffer[position++];
6438
+ const end = buffer[position++];
6439
+ return {
6440
+ type: 'ThisExpression',
6441
+ start,
6442
+ end
6443
+ };
6444
+ },
6445
+ // index:68; ThrowStatement
6446
+ (position, buffer, readString) => {
6447
+ const start = buffer[position++];
6448
+ const end = buffer[position++];
6449
+ const argument = convertNode(position, buffer, readString);
6450
+ return {
6451
+ type: 'ThrowStatement',
6452
+ start,
6453
+ end,
6454
+ argument
6455
+ };
6456
+ },
6457
+ // index:69; TryStatement
6458
+ (position, buffer, readString) => {
6459
+ const start = buffer[position++];
6460
+ const end = buffer[position++];
6461
+ const handlerPosition = buffer[position++];
6462
+ const finalizerPosition = buffer[position++];
6463
+ const block = convertNode(position, buffer, readString);
6464
+ return {
6465
+ type: 'TryStatement',
6466
+ start,
6467
+ end,
6468
+ block,
6469
+ finalizer: finalizerPosition ? convertNode(finalizerPosition, buffer, readString) : null,
6470
+ handler: handlerPosition ? convertNode(handlerPosition, buffer, readString) : null
6471
+ };
6472
+ },
6473
+ // index:70; UnaryExpression
6474
+ (position, buffer, readString) => {
6475
+ const start = buffer[position++];
6476
+ const end = buffer[position++];
6477
+ const operator = FIXED_STRINGS[buffer[position++]];
6478
+ const argument = convertNode(position, buffer, readString);
6479
+ return {
6480
+ type: 'UnaryExpression',
6481
+ start,
6482
+ end,
6483
+ argument,
6484
+ operator,
6485
+ prefix: true
6486
+ };
6487
+ },
6488
+ // index:71; UpdateExpression
6489
+ (position, buffer, readString) => {
6490
+ const start = buffer[position++];
6491
+ const end = buffer[position++];
6492
+ const prefix = !!buffer[position++];
6493
+ const operator = FIXED_STRINGS[buffer[position++]];
6494
+ const argument = convertNode(position, buffer, readString);
6495
+ return {
6496
+ type: 'UpdateExpression',
6497
+ start,
6498
+ end,
6499
+ argument,
6500
+ operator,
6501
+ prefix
6502
+ };
6503
+ },
6504
+ // index:72; VariableDeclaration
6505
+ (position, buffer, readString) => {
6506
+ const start = buffer[position++];
6507
+ const end = buffer[position++];
6508
+ const kind = FIXED_STRINGS[buffer[position++]];
6509
+ const declarations = convertNodeList(position, buffer, readString);
6510
+ return {
6511
+ type: 'VariableDeclaration',
6512
+ start,
6513
+ end,
6514
+ declarations,
6515
+ kind
6516
+ };
6517
+ },
6518
+ // index:73; VariableDeclarator
6519
+ (position, buffer, readString) => {
6520
+ const start = buffer[position++];
6521
+ const end = buffer[position++];
6522
+ const init_position = buffer[position++];
6523
+ const id = convertNode(position, buffer, readString);
6524
+ return {
6525
+ type: 'VariableDeclarator',
6526
+ start,
6527
+ end,
6528
+ id,
6529
+ init: init_position ? convertNode(init_position, buffer, readString) : null
6530
+ };
6531
+ },
6532
+ // index:74; WhileStatement
6533
+ (position, buffer, readString) => {
6534
+ const start = buffer[position++];
6535
+ const end = buffer[position++];
6536
+ const body = convertNode(buffer[position++], buffer, readString);
6537
+ const test = convertNode(position, buffer, readString);
6538
+ return {
6539
+ type: 'WhileStatement',
6540
+ start,
6541
+ end,
6542
+ body,
6543
+ test
6544
+ };
6545
+ },
6546
+ // index:75; YieldExpression
6547
+ (position, buffer, readString) => {
6548
+ const start = buffer[position++];
6549
+ const end = buffer[position++];
6550
+ const delegate = !!buffer[position++];
6551
+ const argumentPosition = buffer[position];
6552
+ return {
6553
+ type: 'YieldExpression',
6554
+ start,
6555
+ end,
6556
+ argument: argumentPosition ? convertNode(argumentPosition, buffer, readString) : null,
6557
+ delegate
6558
+ };
6559
+ },
6560
+ // index:76; Syntax Error
6561
+ (position, buffer, readString) => {
6562
+ const pos = buffer[position++];
6563
+ const message = convertString(position, buffer, readString);
6564
+ error({
6565
+ pos,
6566
+ message
6567
+ });
5761
6568
  }
5762
- return true;
5763
- }
5764
- const annotationsRegexes = [
5765
- ['pure', /[#@]__PURE__/],
5766
- ['noSideEffects', /[#@]__NO_SIDE_EFFECTS__/]
5767
6569
  ];
5768
- function addAnnotations(comments, esTreeAst, code) {
5769
- const annotations = [];
5770
- const sourceMappingComments = [];
5771
- for (const comment of comments) {
5772
- for (const [annotationType, regex] of annotationsRegexes) {
5773
- if (regex.test(comment.value)) {
5774
- annotations.push({ ...comment, annotationType });
5775
- }
5776
- }
5777
- if (SOURCEMAPPING_URL_RE.test(comment.value)) {
5778
- sourceMappingComments.push(comment);
5779
- }
5780
- }
5781
- for (const comment of sourceMappingComments) {
5782
- annotateNode(esTreeAst, comment, false);
5783
- }
5784
- handlePureAnnotationsOfNode(esTreeAst, {
5785
- annotationIndex: 0,
5786
- annotations,
5787
- code
5788
- });
5789
- }
5790
- function annotateNode(node, comment, valid) {
5791
- const key = valid ? ANNOTATION_KEY : INVALID_COMMENT_KEY;
5792
- const property = node[key];
5793
- if (property) {
5794
- property.push(comment);
5795
- }
5796
- else {
5797
- node[key] = [comment];
5798
- }
5799
- }
6570
+ const convertNodeList = (position, buffer, readString) => {
6571
+ const length = buffer[position++];
6572
+ const list = [];
6573
+ for (let index = 0; index < length; index++) {
6574
+ const nodePosition = buffer[position++];
6575
+ list.push(nodePosition ? convertNode(nodePosition, buffer, readString) : null);
6576
+ }
6577
+ return list;
6578
+ };
6579
+ // TODO Lukas remove old annotation handling code
6580
+ const convertAnnotationList = (position, buffer) => {
6581
+ const length = buffer[position++];
6582
+ const list = [];
6583
+ for (let index = 0; index < length; index++) {
6584
+ list.push(convertAnnotation(buffer[position++], buffer));
6585
+ }
6586
+ return list;
6587
+ };
6588
+ const convertAnnotation = (position, buffer) => {
6589
+ const start = buffer[position++];
6590
+ const end = buffer[position++];
6591
+ const type = FIXED_STRINGS[buffer[position]];
6592
+ return { end, start, type };
6593
+ };
6594
+ const convertString = (position, buffer, readString) => {
6595
+ const length = buffer[position++];
6596
+ const bytePosition = position << 2;
6597
+ return readString(bytePosition, length);
6598
+ };
6599
+ const ANNOTATION_KEY = '_rollupAnnotations';
6600
+ const INVALID_ANNOTATION_KEY = '_rollupRemoved';
5800
6601
 
5801
6602
  const keys = {
5802
6603
  // TODO this should be removed once ImportExpression follows official ESTree
@@ -5921,11 +6722,11 @@ class NodeBase extends ExpressionEntity {
5921
6722
  const annotations = value;
5922
6723
  this.annotations = annotations;
5923
6724
  if (this.context.options.treeshake.annotations) {
5924
- this.annotationNoSideEffects = annotations.some(comment => comment.annotationType === 'noSideEffects');
5925
- this.annotationPure = annotations.some(comment => comment.annotationType === 'pure');
6725
+ this.annotationNoSideEffects = annotations.some(comment => comment.type === 'noSideEffects');
6726
+ this.annotationPure = annotations.some(comment => comment.type === 'pure');
5926
6727
  }
5927
6728
  }
5928
- else if (key === INVALID_COMMENT_KEY) {
6729
+ else if (key === INVALID_ANNOTATION_KEY) {
5929
6730
  for (const { start, end } of value)
5930
6731
  this.context.magicString.remove(start, end);
5931
6732
  }
@@ -5946,6 +6747,13 @@ class NodeBase extends ExpressionEntity {
5946
6747
  }
5947
6748
  }
5948
6749
  }
6750
+ removeAnnotations(code) {
6751
+ if (this.annotations) {
6752
+ for (const annotation of this.annotations) {
6753
+ code.remove(annotation.start, annotation.end);
6754
+ }
6755
+ }
6756
+ }
5949
6757
  render(code, options) {
5950
6758
  for (const key of this.keys) {
5951
6759
  const value = this[key];
@@ -6705,6 +7513,15 @@ class ArrayPattern extends NodeBase {
6705
7513
  }
6706
7514
  }
6707
7515
 
7516
+ const ArrowFunctionExpression$1 = 'ArrowFunctionExpression';
7517
+ const BlockStatement$1 = 'BlockStatement';
7518
+ const CallExpression$1 = 'CallExpression';
7519
+ const ExpressionStatement$1 = 'ExpressionStatement';
7520
+ const Identifier$1 = 'Identifier';
7521
+ const Program$1 = 'Program';
7522
+ const Property$1 = 'Property';
7523
+ const ReturnStatement$1 = 'ReturnStatement';
7524
+
6708
7525
  class LocalVariable extends Variable {
6709
7526
  constructor(name, declarator, init, context) {
6710
7527
  super(name);
@@ -8308,9 +9125,6 @@ class Identifier extends NodeBase {
8308
9125
  this.variable.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
8309
9126
  }
8310
9127
  deoptimizePath(path) {
8311
- if (path.length === 0 && !this.scope.contains(this.name)) {
8312
- this.disallowImportReassignment();
8313
- }
8314
9128
  // We keep conditional chaining because an unknown Node could have an
8315
9129
  // Identifier as property that might be deoptimized by default
8316
9130
  this.variable?.deoptimizePath(path);
@@ -8421,9 +9235,6 @@ class Identifier extends NodeBase {
8421
9235
  this.context.requestTreeshakingPass();
8422
9236
  }
8423
9237
  }
8424
- disallowImportReassignment() {
8425
- return this.context.error(logIllegalImportReassignment(this.name, this.context.module.id), this.start);
8426
- }
8427
9238
  getVariableRespectingTDZ() {
8428
9239
  if (this.isPossibleTDZ()) {
8429
9240
  return UNKNOWN_EXPRESSION;
@@ -8456,26 +9267,7 @@ function closestParentFunctionOrProgram(node) {
8456
9267
 
8457
9268
  function treeshakeNode(node, code, start, end) {
8458
9269
  code.remove(start, end);
8459
- if (node.annotations) {
8460
- for (const annotation of node.annotations) {
8461
- if (annotation.start < start) {
8462
- code.remove(annotation.start, annotation.end);
8463
- }
8464
- else {
8465
- return;
8466
- }
8467
- }
8468
- }
8469
- }
8470
- function removeAnnotations(node, code) {
8471
- if (!node.annotations && node.parent.type === ExpressionStatement$1) {
8472
- node = node.parent;
8473
- }
8474
- if (node.annotations) {
8475
- for (const annotation of node.annotations) {
8476
- code.remove(annotation.start, annotation.end);
8477
- }
8478
- }
9270
+ node.removeAnnotations(code);
8479
9271
  }
8480
9272
 
8481
9273
  const NO_SEMICOLON = { isNoStatement: true };
@@ -8635,6 +9427,9 @@ class ExpressionStatement extends NodeBase {
8635
9427
  logModuleLevelDirective(this.directive, this.context.module.id), this.start);
8636
9428
  }
8637
9429
  }
9430
+ removeAnnotations(code) {
9431
+ this.expression.removeAnnotations(code);
9432
+ }
8638
9433
  render(code, options) {
8639
9434
  super.render(code, options);
8640
9435
  if (this.included)
@@ -9319,6 +10114,9 @@ class BinaryExpression extends NodeBase {
9319
10114
  hasEffectsOnInteractionAtPath(path, { type }) {
9320
10115
  return type !== INTERACTION_ACCESSED || path.length > 1;
9321
10116
  }
10117
+ removeAnnotations(code) {
10118
+ this.left.removeAnnotations(code);
10119
+ }
9322
10120
  render(code, options, { renderedSurroundingElement } = BLANK) {
9323
10121
  this.left.render(code, options, { renderedSurroundingElement });
9324
10122
  this.right.render(code, options);
@@ -9956,6 +10754,9 @@ class ChainExpression extends NodeBase {
9956
10754
  return false;
9957
10755
  return this.expression.hasEffects(context);
9958
10756
  }
10757
+ removeAnnotations(code) {
10758
+ this.expression.removeAnnotations(code);
10759
+ }
9959
10760
  }
9960
10761
 
9961
10762
  class ClassBodyScope extends ChildScope {
@@ -10376,6 +11177,9 @@ class ConditionalExpression extends NodeBase {
10376
11177
  this.alternate.includeCallArguments(context, parameters);
10377
11178
  }
10378
11179
  }
11180
+ removeAnnotations(code) {
11181
+ this.test.removeAnnotations(code);
11182
+ }
10379
11183
  render(code, options, { isCalleeOfRenderedParent, preventASI, renderedParentType, renderedSurroundingElement } = BLANK) {
10380
11184
  const usedBranch = this.getUsedBranch();
10381
11185
  if (this.test.included) {
@@ -10395,7 +11199,7 @@ class ConditionalExpression extends NodeBase {
10395
11199
  if (this.consequent.included) {
10396
11200
  code.remove(colonPos, this.end);
10397
11201
  }
10398
- removeAnnotations(this, code);
11202
+ this.test.removeAnnotations(code);
10399
11203
  usedBranch.render(code, options, {
10400
11204
  isCalleeOfRenderedParent,
10401
11205
  preventASI: true,
@@ -10545,6 +11349,9 @@ class ExportDefaultDeclaration extends NodeBase {
10545
11349
  this.variable = this.scope.addExportDefaultDeclaration(this.declarationName || this.context.getModuleName(), this, this.context);
10546
11350
  this.context.addExport(this);
10547
11351
  }
11352
+ removeAnnotations(code) {
11353
+ this.declaration.removeAnnotations(code);
11354
+ }
10548
11355
  render(code, options, nodeRenderOptions) {
10549
11356
  const { start, end } = nodeRenderOptions;
10550
11357
  const declarationStart = getDeclarationStart(code.original, this.start);
@@ -10621,6 +11428,9 @@ class ExportNamedDeclaration extends NodeBase {
10621
11428
  initialise() {
10622
11429
  this.context.addExport(this);
10623
11430
  }
11431
+ removeAnnotations(code) {
11432
+ this.declaration?.removeAnnotations(code);
11433
+ }
10624
11434
  render(code, options, nodeRenderOptions) {
10625
11435
  const { start, end } = nodeRenderOptions;
10626
11436
  if (this.declaration === null) {
@@ -11194,6 +12004,9 @@ class VariableDeclarator extends NodeBase {
11194
12004
  id.include(context, includeChildrenRecursively);
11195
12005
  }
11196
12006
  }
12007
+ removeAnnotations(code) {
12008
+ this.init?.removeAnnotations(code);
12009
+ }
11197
12010
  render(code, options) {
11198
12011
  const { exportNamesByVariable, snippets: { _, getPropertyAccess } } = options;
11199
12012
  const { end, id, init, start } = this;
@@ -11652,6 +12465,9 @@ class LogicalExpression extends NodeBase {
11652
12465
  usedBranch.include(context, includeChildrenRecursively);
11653
12466
  }
11654
12467
  }
12468
+ removeAnnotations(code) {
12469
+ this.left.removeAnnotations(code);
12470
+ }
11655
12471
  render(code, options, { isCalleeOfRenderedParent, preventASI, renderedParentType, renderedSurroundingElement } = BLANK) {
11656
12472
  if (!this.left.included || !this.right.included) {
11657
12473
  const operatorPos = findFirstOccurrenceOutsideComment(code.original, this.operator, this.left.end);
@@ -11661,11 +12477,11 @@ class LogicalExpression extends NodeBase {
11661
12477
  if (preventASI) {
11662
12478
  removeLineBreaks(code, removePos, this.right.start);
11663
12479
  }
12480
+ this.left.removeAnnotations(code);
11664
12481
  }
11665
12482
  else {
11666
12483
  code.remove(operatorPos, this.end);
11667
12484
  }
11668
- removeAnnotations(this, code);
11669
12485
  this.getUsedBranch().render(code, options, {
11670
12486
  isCalleeOfRenderedParent,
11671
12487
  preventASI,
@@ -12126,6 +12942,9 @@ class SequenceExpression extends NodeBase {
12126
12942
  expression.include(context, includeChildrenRecursively);
12127
12943
  }
12128
12944
  }
12945
+ removeAnnotations(code) {
12946
+ this.expressions[0].removeAnnotations(code);
12947
+ }
12129
12948
  render(code, options, { renderedParentType, isCalleeOfRenderedParent, preventASI } = BLANK) {
12130
12949
  let includedNodes = 0;
12131
12950
  let lastSeparatorPos = null;
@@ -12792,6 +13611,9 @@ class VariableDeclaration extends NodeBase {
12792
13611
  declarator.declareDeclarator(this.kind);
12793
13612
  }
12794
13613
  }
13614
+ removeAnnotations(code) {
13615
+ this.declarations[0].removeAnnotations(code);
13616
+ }
12795
13617
  render(code, options, nodeRenderOptions = BLANK) {
12796
13618
  if (areAllDeclarationsIncludedAndNotExported(this.declarations, options.exportNamesByVariable)) {
12797
13619
  for (const declarator of this.declarations) {
@@ -17570,6 +18392,11 @@ function collapseSourcemap(id, originalCode, originalSourcemap, sourcemapChain,
17570
18392
 
17571
18393
  const createHash = () => createHash$1('sha256');
17572
18394
 
18395
+ // this looks ridiculous, but it prevents sourcemap tooling from mistaking
18396
+ // this for an actual sourceMappingURL
18397
+ let SOURCEMAPPING_URL = 'sourceMa';
18398
+ SOURCEMAPPING_URL += 'ppingURL';
18399
+
17573
18400
  async function renderChunks(chunks, bundle, pluginDriver, outputOptions, log) {
17574
18401
  timeStart('render chunks', 2);
17575
18402
  reserveEntryChunksInBundle(chunks);
@@ -25537,6 +26364,27 @@ class Queue {
25537
26364
  }
25538
26365
  }
25539
26366
 
26367
+ function getReadStringFunction(astBuffer) {
26368
+ let bufferConstructor = null;
26369
+ try {
26370
+ bufferConstructor = Buffer;
26371
+ }
26372
+ catch {
26373
+ /* regardless of error */
26374
+ }
26375
+ if (bufferConstructor && astBuffer instanceof bufferConstructor) {
26376
+ return function readString(start, length) {
26377
+ return astBuffer.toString('utf8', start, start + length);
26378
+ };
26379
+ }
26380
+ else {
26381
+ const textDecoder = new TextDecoder();
26382
+ return function readString(start, length) {
26383
+ return textDecoder.decode(astBuffer.subarray(start, start + length));
26384
+ };
26385
+ }
26386
+ }
26387
+
25540
26388
  function normalizeEntryModules(entryModules) {
25541
26389
  if (Array.isArray(entryModules)) {
25542
26390
  return entryModules.map(id => ({
@@ -25626,15 +26474,60 @@ class Graph {
25626
26474
  return onCommentOrig.call(options, block, text, start, end, ...parameters);
25627
26475
  }
25628
26476
  : comments;
25629
- const ast = this.acornParser.parse(code, {
25630
- ...this.options.acorn,
25631
- ...options
25632
- });
26477
+ // console.time('acorn');
26478
+ // const acornAst = this.acornParser.parse(code, {
26479
+ // ...(this.options.acorn as unknown as acorn.Options),
26480
+ // ...options
26481
+ // });
26482
+ // console.timeEnd('acorn');
26483
+ // console.log('acorn', JSON.stringify(acornAst, null, 2));
26484
+ // let ast: acorn.Node;
26485
+ // let astBuffer: Buffer;
26486
+ // try {
26487
+ // console.time('swc');
26488
+ const astBuffer = native.parse(code);
26489
+ const readString = getReadStringFunction(astBuffer);
26490
+ const ast = convertProgram(astBuffer.buffer, (start, length) => readString(start, length));
26491
+ // console.timeEnd('swc');
26492
+ // console.log('swc', JSON.stringify(ast, null, 2));
26493
+ // assert.deepStrictEqual(
26494
+ // ast,
26495
+ // JSON.parse(
26496
+ // JSON.stringify(acornAst, (_, value) =>
26497
+ // typeof value == 'bigint'
26498
+ // ? `~BigInt${value.toString()}`
26499
+ // : value instanceof RegExp
26500
+ // ? `~RegExp${JSON.stringify({ flags: value.flags, source: value.source })}`
26501
+ // : value
26502
+ // ),
26503
+ // (_, value) =>
26504
+ // typeof value === 'string'
26505
+ // ? value.startsWith('~BigInt')
26506
+ // ? BigInt(value.slice(7))
26507
+ // : value.startsWith('~RegExp')
26508
+ // ? new RegExp(JSON.parse(value.slice(7)).source, JSON.parse(value.slice(7)).flags)
26509
+ // : value
26510
+ // : value
26511
+ // )
26512
+ // );
26513
+ // } catch (error_) {
26514
+ // console.log(JSON.stringify(code));
26515
+ // console.log(
26516
+ // 'Size acorn:',
26517
+ // JSON.stringify(acornAst).length,
26518
+ // ', swc:',
26519
+ // astBuffer!.length,
26520
+ // 'code:',
26521
+ // code.length
26522
+ // );
26523
+ // throw error_;
26524
+ // }
25633
26525
  if (typeof onCommentOrig == 'object') {
25634
26526
  onCommentOrig.push(...comments);
25635
26527
  }
25636
26528
  options.onComment = onCommentOrig;
25637
- addAnnotations(comments, ast, code);
26529
+ // TODO SWC do this in Rust
26530
+ // addAnnotations(comments, ast!, code);
25638
26531
  return ast;
25639
26532
  }
25640
26533
  getCache() {
@@ -25793,6 +26686,8 @@ async function catchUnfinishedHookActions(pluginDriver, callback) {
25793
26686
  }
25794
26687
  }
25795
26688
 
26689
+ async function initWasm() { }
26690
+
25796
26691
  function getLogger(plugins, onLog, watchMode, logLevel) {
25797
26692
  plugins = getSortedValidatedPlugins('onLog', plugins);
25798
26693
  const minimalPriority = logLevelPriority[logLevel];
@@ -26557,6 +27452,7 @@ function rollup(rawInputOptions) {
26557
27452
  async function rollupInternal(rawInputOptions, watcher) {
26558
27453
  const { options: inputOptions, unsetOptions: unsetInputOptions } = await getInputOptions(rawInputOptions, watcher !== null);
26559
27454
  initialiseTimers(inputOptions);
27455
+ await initWasm();
26560
27456
  const graph = new Graph(inputOptions, watcher);
26561
27457
  // remove the cache object from the memory after graph creation (cache is not used anymore)
26562
27458
  const useCache = rawInputOptions.cache !== false;