rollup 2.36.1 → 2.38.0

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 v2.36.1
4
- Wed, 06 Jan 2021 14:06:54 GMT - commit d6600638c61b5eb7f389681d5fa4af9a1b95823e
3
+ Rollup.js v2.38.0
4
+ Fri, 22 Jan 2021 16:26:00 GMT - commit 889fa5267ad93cc706fdbff2024e9c4d4f273749
5
5
 
6
6
 
7
7
  https://github.com/rollup/rollup
@@ -10,16 +10,16 @@
10
10
  */
11
11
  'use strict';
12
12
 
13
- var fs = require('fs');
14
13
  var sysPath = require('path');
15
14
  var crypto = require('crypto');
15
+ var fs = require('fs');
16
16
  var require$$0$1 = require('events');
17
17
 
18
18
  function _interopNamespaceDefaultOnly(e) {
19
19
  return {__proto__: null, 'default': e};
20
20
  }
21
21
 
22
- var version = "2.36.1";
22
+ var version = "2.38.0";
23
23
 
24
24
  function ensureArray(items) {
25
25
  if (Array.isArray(items)) {
@@ -1609,11 +1609,11 @@ function findFirstOccurrenceOutsideComment(code, searchString, start = 0) {
1609
1609
  }
1610
1610
  }
1611
1611
  }
1612
- const WHITESPACE = /\s/;
1612
+ const NON_WHITESPACE = /\S/g;
1613
1613
  function findNonWhiteSpace(code, index) {
1614
- while (index < code.length && WHITESPACE.test(code[index]))
1615
- index++;
1616
- return index;
1614
+ NON_WHITESPACE.lastIndex = index;
1615
+ const result = NON_WHITESPACE.exec(code);
1616
+ return result.index;
1617
1617
  }
1618
1618
  // This assumes "code" only contains white-space and comments
1619
1619
  // Returns position of line-comment if applicable
@@ -2274,6 +2274,34 @@ function getMemberReturnExpressionWhenCalled(members, memberName) {
2274
2274
  : new members[memberName].returns();
2275
2275
  }
2276
2276
 
2277
+ const BROKEN_FLOW_NONE = 0;
2278
+ const BROKEN_FLOW_BREAK_CONTINUE = 1;
2279
+ const BROKEN_FLOW_ERROR_RETURN_LABEL = 2;
2280
+ function createInclusionContext() {
2281
+ return {
2282
+ brokenFlow: BROKEN_FLOW_NONE,
2283
+ includedCallArguments: new Set(),
2284
+ includedLabels: new Set()
2285
+ };
2286
+ }
2287
+ function createHasEffectsContext() {
2288
+ return {
2289
+ accessed: new PathTracker(),
2290
+ assigned: new PathTracker(),
2291
+ brokenFlow: BROKEN_FLOW_NONE,
2292
+ called: new DiscriminatedPathTracker(),
2293
+ ignore: {
2294
+ breaks: false,
2295
+ continues: false,
2296
+ labels: new Set(),
2297
+ returnAwaitYield: false
2298
+ },
2299
+ includedLabels: new Set(),
2300
+ instantiated: new DiscriminatedPathTracker(),
2301
+ replacedVariableInits: new Map()
2302
+ };
2303
+ }
2304
+
2277
2305
  class Variable {
2278
2306
  constructor(name) {
2279
2307
  this.alwaysRendered = false;
@@ -2335,191 +2363,6 @@ class Variable {
2335
2363
  }
2336
2364
  }
2337
2365
 
2338
- class ExternalVariable extends Variable {
2339
- constructor(module, name) {
2340
- super(name);
2341
- this.module = module;
2342
- this.isNamespace = name === '*';
2343
- this.referenced = false;
2344
- }
2345
- addReference(identifier) {
2346
- this.referenced = true;
2347
- if (this.name === 'default' || this.name === '*') {
2348
- this.module.suggestName(identifier.name);
2349
- }
2350
- }
2351
- include() {
2352
- if (!this.included) {
2353
- this.included = true;
2354
- this.module.used = true;
2355
- }
2356
- }
2357
- }
2358
-
2359
- const BLANK = Object.freeze(Object.create(null));
2360
- const EMPTY_OBJECT = Object.freeze({});
2361
- const EMPTY_ARRAY = Object.freeze([]);
2362
-
2363
- const reservedWords = 'break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield enum await implements package protected static interface private public'.split(' ');
2364
- const builtins = 'Infinity NaN undefined null true false eval uneval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Symbol Error EvalError InternalError RangeError ReferenceError SyntaxError TypeError URIError Number Math Date String RegExp Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array Map Set WeakMap WeakSet SIMD ArrayBuffer DataView JSON Promise Generator GeneratorFunction Reflect Proxy Intl'.split(' ');
2365
- const blacklisted = new Set(reservedWords.concat(builtins));
2366
- const illegalCharacters = /[^$_a-zA-Z0-9]/g;
2367
- const startsWithDigit = (str) => /\d/.test(str[0]);
2368
- function isLegal(str) {
2369
- if (startsWithDigit(str) || blacklisted.has(str)) {
2370
- return false;
2371
- }
2372
- return !illegalCharacters.test(str);
2373
- }
2374
- function makeLegal(str) {
2375
- str = str.replace(/-(\w)/g, (_, letter) => letter.toUpperCase()).replace(illegalCharacters, '_');
2376
- if (startsWithDigit(str) || blacklisted.has(str))
2377
- str = `_${str}`;
2378
- return str || '_';
2379
- }
2380
-
2381
- class ExternalModule {
2382
- constructor(options, id, hasModuleSideEffects, meta) {
2383
- this.options = options;
2384
- this.id = id;
2385
- this.defaultVariableName = '';
2386
- this.dynamicImporters = [];
2387
- this.importers = [];
2388
- this.mostCommonSuggestion = 0;
2389
- this.namespaceVariableName = '';
2390
- this.reexported = false;
2391
- this.renderPath = undefined;
2392
- this.renormalizeRenderPath = false;
2393
- this.used = false;
2394
- this.variableName = '';
2395
- this.execIndex = Infinity;
2396
- this.suggestedVariableName = makeLegal(id.split(/[\\/]/).pop());
2397
- this.nameSuggestions = Object.create(null);
2398
- this.declarations = Object.create(null);
2399
- this.exportedVariables = new Map();
2400
- const module = this;
2401
- this.info = {
2402
- ast: null,
2403
- code: null,
2404
- dynamicallyImportedIds: EMPTY_ARRAY,
2405
- get dynamicImporters() {
2406
- return module.dynamicImporters.sort();
2407
- },
2408
- hasModuleSideEffects,
2409
- id,
2410
- implicitlyLoadedAfterOneOf: EMPTY_ARRAY,
2411
- implicitlyLoadedBefore: EMPTY_ARRAY,
2412
- importedIds: EMPTY_ARRAY,
2413
- get importers() {
2414
- return module.importers.sort();
2415
- },
2416
- isEntry: false,
2417
- isExternal: true,
2418
- meta,
2419
- syntheticNamedExports: false
2420
- };
2421
- }
2422
- getVariableForExportName(name) {
2423
- let declaration = this.declarations[name];
2424
- if (declaration)
2425
- return declaration;
2426
- this.declarations[name] = declaration = new ExternalVariable(this, name);
2427
- this.exportedVariables.set(declaration, name);
2428
- return declaration;
2429
- }
2430
- setRenderPath(options, inputBase) {
2431
- this.renderPath =
2432
- typeof options.paths === 'function' ? options.paths(this.id) : options.paths[this.id];
2433
- if (!this.renderPath) {
2434
- if (!isAbsolute(this.id)) {
2435
- this.renderPath = this.id;
2436
- }
2437
- else {
2438
- this.renderPath = normalize(sysPath.relative(inputBase, this.id));
2439
- this.renormalizeRenderPath = true;
2440
- }
2441
- }
2442
- return this.renderPath;
2443
- }
2444
- suggestName(name) {
2445
- if (!this.nameSuggestions[name])
2446
- this.nameSuggestions[name] = 0;
2447
- this.nameSuggestions[name] += 1;
2448
- if (this.nameSuggestions[name] > this.mostCommonSuggestion) {
2449
- this.mostCommonSuggestion = this.nameSuggestions[name];
2450
- this.suggestedVariableName = name;
2451
- }
2452
- }
2453
- warnUnusedImports() {
2454
- const unused = Object.keys(this.declarations).filter(name => {
2455
- if (name === '*')
2456
- return false;
2457
- const declaration = this.declarations[name];
2458
- return !declaration.included && !this.reexported && !declaration.referenced;
2459
- });
2460
- if (unused.length === 0)
2461
- return;
2462
- const names = unused.length === 1
2463
- ? `'${unused[0]}' is`
2464
- : `${unused
2465
- .slice(0, -1)
2466
- .map(name => `'${name}'`)
2467
- .join(', ')} and '${unused.slice(-1)}' are`;
2468
- this.options.onwarn({
2469
- code: 'UNUSED_EXTERNAL_IMPORT',
2470
- message: `${names} imported from external module '${this.id}' but never used`,
2471
- names: unused,
2472
- source: this.id
2473
- });
2474
- }
2475
- }
2476
-
2477
- function markModuleAndImpureDependenciesAsExecuted(baseModule) {
2478
- baseModule.isExecuted = true;
2479
- const modules = [baseModule];
2480
- const visitedModules = new Set();
2481
- for (const module of modules) {
2482
- for (const dependency of [...module.dependencies, ...module.implicitlyLoadedBefore]) {
2483
- if (!(dependency instanceof ExternalModule) &&
2484
- !dependency.isExecuted &&
2485
- (dependency.info.hasModuleSideEffects || module.implicitlyLoadedBefore.has(dependency)) &&
2486
- !visitedModules.has(dependency.id)) {
2487
- dependency.isExecuted = true;
2488
- visitedModules.add(dependency.id);
2489
- modules.push(dependency);
2490
- }
2491
- }
2492
- }
2493
- }
2494
-
2495
- const BROKEN_FLOW_NONE = 0;
2496
- const BROKEN_FLOW_BREAK_CONTINUE = 1;
2497
- const BROKEN_FLOW_ERROR_RETURN_LABEL = 2;
2498
- function createInclusionContext() {
2499
- return {
2500
- brokenFlow: BROKEN_FLOW_NONE,
2501
- includedCallArguments: new Set(),
2502
- includedLabels: new Set()
2503
- };
2504
- }
2505
- function createHasEffectsContext() {
2506
- return {
2507
- accessed: new PathTracker(),
2508
- assigned: new PathTracker(),
2509
- brokenFlow: BROKEN_FLOW_NONE,
2510
- called: new DiscriminatedPathTracker(),
2511
- ignore: {
2512
- breaks: false,
2513
- continues: false,
2514
- labels: new Set(),
2515
- returnAwaitYield: false
2516
- },
2517
- includedLabels: new Set(),
2518
- instantiated: new DiscriminatedPathTracker(),
2519
- replacedVariableInits: new Map()
2520
- };
2521
- }
2522
-
2523
2366
  // To avoid infinite recursions
2524
2367
  const MAX_PATH_DEPTH = 7;
2525
2368
  class LocalVariable extends Variable {
@@ -2642,9 +2485,6 @@ class LocalVariable extends Variable {
2642
2485
  include() {
2643
2486
  if (!this.included) {
2644
2487
  this.included = true;
2645
- if (!this.module.isExecuted) {
2646
- markModuleAndImpureDependenciesAsExecuted(this.module);
2647
- }
2648
2488
  for (const declaration of this.declarations) {
2649
2489
  // If node is a default export, it can save a tree-shaking run to include the full declaration now
2650
2490
  if (!declaration.included)
@@ -2849,6 +2689,7 @@ class NodeBase {
2849
2689
  this.context.magicString.addSourcemapLocation(this.start);
2850
2690
  this.context.magicString.addSourcemapLocation(this.end);
2851
2691
  }
2692
+ addExportedVariables(_variables, _exportNamesByVariable) { }
2852
2693
  /**
2853
2694
  * Override this to bind assignments to variables and do any initialisations that
2854
2695
  * require the scopes to be populated with variables.
@@ -2875,9 +2716,6 @@ class NodeBase {
2875
2716
  createScope(parentScope) {
2876
2717
  this.scope = parentScope;
2877
2718
  }
2878
- declare(_kind, _init) {
2879
- return [];
2880
- }
2881
2719
  deoptimizePath(_path) { }
2882
2720
  getLiteralValueAtPath(_path, _recursionTracker, _origin) {
2883
2721
  return UnknownValue;
@@ -2927,14 +2765,14 @@ class NodeBase {
2927
2765
  }
2928
2766
  }
2929
2767
  }
2768
+ includeAllDeclaredVariables(context, includeChildrenRecursively) {
2769
+ this.include(context, includeChildrenRecursively);
2770
+ }
2930
2771
  includeCallArguments(context, args) {
2931
2772
  for (const arg of args) {
2932
2773
  arg.include(context, false);
2933
2774
  }
2934
2775
  }
2935
- includeWithAllDeclaredVariables(includeChildrenRecursively, context) {
2936
- this.include(context, includeChildrenRecursively);
2937
- }
2938
2776
  /**
2939
2777
  * Override to perform special initialisation steps after the scope is initialised
2940
2778
  */
@@ -2987,9 +2825,6 @@ class NodeBase {
2987
2825
  shouldBeIncluded(context) {
2988
2826
  return this.included || (!context.brokenFlow && this.hasEffects(createHasEffectsContext()));
2989
2827
  }
2990
- toString() {
2991
- return this.context.code.slice(this.start, this.end);
2992
- }
2993
2828
  }
2994
2829
 
2995
2830
  class ClassNode extends NodeBase {
@@ -3238,6 +3073,10 @@ function isReference(node, parent) {
3238
3073
  return false;
3239
3074
  }
3240
3075
 
3076
+ const BLANK = Object.freeze(Object.create(null));
3077
+ const EMPTY_OBJECT = Object.freeze({});
3078
+ const EMPTY_ARRAY = Object.freeze([]);
3079
+
3241
3080
  const ValueProperties = Symbol('Value Properties');
3242
3081
  const PURE = { pure: true };
3243
3082
  const IMPURE = { pure: false };
@@ -4205,7 +4044,7 @@ class Identifier$1 extends NodeBase {
4205
4044
  if (!this.included) {
4206
4045
  this.included = true;
4207
4046
  if (this.variable !== null) {
4208
- this.context.includeVariable(this.variable);
4047
+ this.context.includeVariableInModule(this.variable);
4209
4048
  }
4210
4049
  }
4211
4050
  }
@@ -4397,7 +4236,7 @@ class ExportDefaultDeclaration extends NodeBase {
4397
4236
  include(context, includeChildrenRecursively) {
4398
4237
  super.include(context, includeChildrenRecursively);
4399
4238
  if (includeChildrenRecursively) {
4400
- this.context.includeVariable(this.variable);
4239
+ this.context.includeVariableInModule(this.variable);
4401
4240
  }
4402
4241
  }
4403
4242
  initialise() {
@@ -4480,9 +4319,8 @@ class ExportDefaultVariable extends LocalVariable {
4480
4319
  constructor(name, exportDefaultDeclaration, context) {
4481
4320
  super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, context);
4482
4321
  this.hasId = false;
4483
- // Not initialised during construction
4484
4322
  this.originalId = null;
4485
- this.originalVariableAndDeclarationModules = null;
4323
+ this.originalVariable = null;
4486
4324
  const declaration = exportDefaultDeclaration.declaration;
4487
4325
  if ((declaration instanceof FunctionDeclaration || declaration instanceof ClassDeclaration) &&
4488
4326
  declaration.id) {
@@ -4510,6 +4348,14 @@ class ExportDefaultVariable extends LocalVariable {
4510
4348
  return original.getBaseVariableName();
4511
4349
  }
4512
4350
  }
4351
+ getDirectOriginalVariable() {
4352
+ return this.originalId &&
4353
+ (this.hasId ||
4354
+ !(this.originalId.variable.isReassigned ||
4355
+ this.originalId.variable instanceof UndefinedVariable))
4356
+ ? this.originalId.variable
4357
+ : null;
4358
+ }
4513
4359
  getName() {
4514
4360
  const original = this.getOriginalVariable();
4515
4361
  if (original === this) {
@@ -4520,34 +4366,17 @@ class ExportDefaultVariable extends LocalVariable {
4520
4366
  }
4521
4367
  }
4522
4368
  getOriginalVariable() {
4523
- return this.getOriginalVariableAndDeclarationModules().original;
4524
- }
4525
- getOriginalVariableAndDeclarationModules() {
4526
- if (this.originalVariableAndDeclarationModules === null) {
4527
- if (!this.originalId ||
4528
- (!this.hasId &&
4529
- (this.originalId.variable.isReassigned ||
4530
- this.originalId.variable instanceof UndefinedVariable))) {
4531
- this.originalVariableAndDeclarationModules = { modules: [], original: this };
4532
- }
4533
- else {
4534
- const assignedOriginal = this.originalId.variable;
4535
- if (assignedOriginal instanceof ExportDefaultVariable) {
4536
- const { modules, original } = assignedOriginal.getOriginalVariableAndDeclarationModules();
4537
- this.originalVariableAndDeclarationModules = {
4538
- modules: modules.concat(this.module),
4539
- original
4540
- };
4541
- }
4542
- else {
4543
- this.originalVariableAndDeclarationModules = {
4544
- modules: [this.module],
4545
- original: assignedOriginal
4546
- };
4547
- }
4548
- }
4549
- }
4550
- return this.originalVariableAndDeclarationModules;
4369
+ if (this.originalVariable)
4370
+ return this.originalVariable;
4371
+ let original = this;
4372
+ let currentVariable;
4373
+ const checkedVariables = new Set();
4374
+ do {
4375
+ checkedVariables.add(original);
4376
+ currentVariable = original;
4377
+ original = currentVariable.getDirectOriginalVariable();
4378
+ } while (original instanceof ExportDefaultVariable && !checkedVariables.has(original));
4379
+ return (this.originalVariable = original || currentVariable);
4551
4380
  }
4552
4381
  }
4553
4382
 
@@ -4660,897 +4489,1081 @@ class NamespaceVariable extends Variable {
4660
4489
  }
4661
4490
  NamespaceVariable.prototype.isNamespace = true;
4662
4491
 
4663
- class SyntheticNamedExportVariable extends Variable {
4664
- constructor(context, name, syntheticNamespace) {
4665
- super(name);
4666
- this.context = context;
4667
- this.module = context.module;
4668
- this.syntheticNamespace = syntheticNamespace;
4669
- }
4670
- getBaseVariable() {
4671
- let baseVariable = this.syntheticNamespace;
4672
- if (baseVariable instanceof ExportDefaultVariable) {
4673
- baseVariable = baseVariable.getOriginalVariable();
4674
- }
4675
- if (baseVariable instanceof SyntheticNamedExportVariable) {
4676
- baseVariable = baseVariable.getBaseVariable();
4677
- }
4678
- return baseVariable;
4679
- }
4680
- getBaseVariableName() {
4681
- return this.syntheticNamespace.getBaseVariableName();
4682
- }
4683
- getName() {
4684
- const name = this.name;
4685
- return `${this.syntheticNamespace.getName()}${getPropertyAccess(name)}`;
4492
+ function spaces(i) {
4493
+ let result = '';
4494
+ while (i--)
4495
+ result += ' ';
4496
+ return result;
4497
+ }
4498
+ function tabsToSpaces(str) {
4499
+ return str.replace(/^\t+/, match => match.split('\t').join(' '));
4500
+ }
4501
+ function getCodeFrame(source, line, column) {
4502
+ let lines = source.split('\n');
4503
+ const frameStart = Math.max(0, line - 3);
4504
+ let frameEnd = Math.min(line + 2, lines.length);
4505
+ lines = lines.slice(frameStart, frameEnd);
4506
+ while (!/\S/.test(lines[lines.length - 1])) {
4507
+ lines.pop();
4508
+ frameEnd -= 1;
4686
4509
  }
4687
- include() {
4688
- if (!this.included) {
4689
- this.included = true;
4690
- this.context.includeVariable(this.syntheticNamespace);
4510
+ const digits = String(frameEnd).length;
4511
+ return lines
4512
+ .map((str, i) => {
4513
+ const isErrorLine = frameStart + i + 1 === line;
4514
+ let lineNum = String(i + frameStart + 1);
4515
+ while (lineNum.length < digits)
4516
+ lineNum = ` ${lineNum}`;
4517
+ if (isErrorLine) {
4518
+ const indicator = spaces(digits + 2 + tabsToSpaces(str.slice(0, column)).length) + '^';
4519
+ return `${lineNum}: ${tabsToSpaces(str)}\n${indicator}`;
4691
4520
  }
4692
- }
4693
- setRenderNames(baseName, name) {
4694
- super.setRenderNames(baseName, name);
4695
- }
4521
+ return `${lineNum}: ${tabsToSpaces(str)}`;
4522
+ })
4523
+ .join('\n');
4696
4524
  }
4697
- const getPropertyAccess = (name) => {
4698
- return !RESERVED_NAMES[name] && /^(?!\d)[\w$]+$/.test(name)
4699
- ? `.${name}`
4700
- : `[${JSON.stringify(name)}]`;
4701
- };
4702
4525
 
4703
- function removeJsExtension(name) {
4704
- return name.endsWith('.js') ? name.slice(0, -3) : name;
4526
+ function error(base) {
4527
+ if (!(base instanceof Error))
4528
+ base = Object.assign(new Error(base.message), base);
4529
+ throw base;
4705
4530
  }
4706
-
4707
- function getCompleteAmdId(options, chunkId) {
4708
- if (!options.autoId) {
4709
- return options.id || '';
4531
+ function augmentCodeLocation(props, pos, source, id) {
4532
+ if (typeof pos === 'object') {
4533
+ const { line, column } = pos;
4534
+ props.loc = { file: id, line, column };
4710
4535
  }
4711
4536
  else {
4712
- return `${options.basePath ? options.basePath + '/' : ''}${removeJsExtension(chunkId)}`;
4537
+ props.pos = pos;
4538
+ const { line, column } = locate(source, pos, { offsetLine: 1 });
4539
+ props.loc = { file: id, line, column };
4540
+ }
4541
+ if (props.frame === undefined) {
4542
+ const { line, column } = props.loc;
4543
+ props.frame = getCodeFrame(source, line, column);
4713
4544
  }
4714
4545
  }
4715
-
4716
- const INTEROP_DEFAULT_VARIABLE = '_interopDefault';
4717
- const INTEROP_DEFAULT_LEGACY_VARIABLE = '_interopDefaultLegacy';
4718
- const INTEROP_NAMESPACE_VARIABLE = '_interopNamespace';
4719
- const INTEROP_NAMESPACE_DEFAULT_VARIABLE = '_interopNamespaceDefault';
4720
- const INTEROP_NAMESPACE_DEFAULT_ONLY_VARIABLE = '_interopNamespaceDefaultOnly';
4721
- const defaultInteropHelpersByInteropType = {
4722
- auto: INTEROP_DEFAULT_VARIABLE,
4723
- default: null,
4724
- defaultOnly: null,
4725
- esModule: null,
4726
- false: null,
4727
- true: INTEROP_DEFAULT_LEGACY_VARIABLE
4728
- };
4729
- function isDefaultAProperty(interopType, externalLiveBindings) {
4730
- return (interopType === 'esModule' ||
4731
- (externalLiveBindings && (interopType === 'auto' || interopType === 'true')));
4546
+ var Errors;
4547
+ (function (Errors) {
4548
+ Errors["ALREADY_CLOSED"] = "ALREADY_CLOSED";
4549
+ Errors["ASSET_NOT_FINALISED"] = "ASSET_NOT_FINALISED";
4550
+ Errors["ASSET_NOT_FOUND"] = "ASSET_NOT_FOUND";
4551
+ Errors["ASSET_SOURCE_ALREADY_SET"] = "ASSET_SOURCE_ALREADY_SET";
4552
+ Errors["ASSET_SOURCE_MISSING"] = "ASSET_SOURCE_MISSING";
4553
+ Errors["BAD_LOADER"] = "BAD_LOADER";
4554
+ Errors["CANNOT_EMIT_FROM_OPTIONS_HOOK"] = "CANNOT_EMIT_FROM_OPTIONS_HOOK";
4555
+ Errors["CHUNK_NOT_GENERATED"] = "CHUNK_NOT_GENERATED";
4556
+ Errors["CIRCULAR_REEXPORT"] = "CIRCULAR_REEXPORT";
4557
+ Errors["CYCLIC_CROSS_CHUNK_REEXPORT"] = "CYCLIC_CROSS_CHUNK_REEXPORT";
4558
+ Errors["DEPRECATED_FEATURE"] = "DEPRECATED_FEATURE";
4559
+ Errors["EXTERNAL_SYNTHETIC_EXPORTS"] = "EXTERNAL_SYNTHETIC_EXPORTS";
4560
+ Errors["FILE_NAME_CONFLICT"] = "FILE_NAME_CONFLICT";
4561
+ Errors["FILE_NOT_FOUND"] = "FILE_NOT_FOUND";
4562
+ Errors["INPUT_HOOK_IN_OUTPUT_PLUGIN"] = "INPUT_HOOK_IN_OUTPUT_PLUGIN";
4563
+ Errors["INVALID_CHUNK"] = "INVALID_CHUNK";
4564
+ Errors["INVALID_EXPORT_OPTION"] = "INVALID_EXPORT_OPTION";
4565
+ Errors["INVALID_EXTERNAL_ID"] = "INVALID_EXTERNAL_ID";
4566
+ Errors["INVALID_OPTION"] = "INVALID_OPTION";
4567
+ Errors["INVALID_PLUGIN_HOOK"] = "INVALID_PLUGIN_HOOK";
4568
+ Errors["INVALID_ROLLUP_PHASE"] = "INVALID_ROLLUP_PHASE";
4569
+ Errors["MISSING_EXPORT"] = "MISSING_EXPORT";
4570
+ Errors["MISSING_IMPLICIT_DEPENDANT"] = "MISSING_IMPLICIT_DEPENDANT";
4571
+ Errors["MIXED_EXPORTS"] = "MIXED_EXPORTS";
4572
+ Errors["NAMESPACE_CONFLICT"] = "NAMESPACE_CONFLICT";
4573
+ Errors["NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE"] = "NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE";
4574
+ Errors["PLUGIN_ERROR"] = "PLUGIN_ERROR";
4575
+ Errors["PREFER_NAMED_EXPORTS"] = "PREFER_NAMED_EXPORTS";
4576
+ Errors["SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT"] = "SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT";
4577
+ Errors["UNEXPECTED_NAMED_IMPORT"] = "UNEXPECTED_NAMED_IMPORT";
4578
+ Errors["UNRESOLVED_ENTRY"] = "UNRESOLVED_ENTRY";
4579
+ Errors["UNRESOLVED_IMPORT"] = "UNRESOLVED_IMPORT";
4580
+ Errors["VALIDATION_ERROR"] = "VALIDATION_ERROR";
4581
+ })(Errors || (Errors = {}));
4582
+ function errAssetNotFinalisedForFileName(name) {
4583
+ return {
4584
+ code: Errors.ASSET_NOT_FINALISED,
4585
+ message: `Plugin error - Unable to get file name for asset "${name}". Ensure that the source is set and that generate is called first.`
4586
+ };
4732
4587
  }
4733
- const namespaceInteropHelpersByInteropType = {
4734
- auto: INTEROP_NAMESPACE_VARIABLE,
4735
- default: INTEROP_NAMESPACE_DEFAULT_VARIABLE,
4736
- defaultOnly: INTEROP_NAMESPACE_DEFAULT_ONLY_VARIABLE,
4737
- esModule: null,
4738
- false: null,
4739
- true: INTEROP_NAMESPACE_VARIABLE
4740
- };
4741
- function canDefaultBeTakenFromNamespace(interopType, externalLiveBindings) {
4742
- return (isDefaultAProperty(interopType, externalLiveBindings) &&
4743
- defaultInteropHelpersByInteropType[interopType] === INTEROP_DEFAULT_VARIABLE);
4588
+ function errCannotEmitFromOptionsHook() {
4589
+ return {
4590
+ code: Errors.CANNOT_EMIT_FROM_OPTIONS_HOOK,
4591
+ message: `Cannot emit files or set asset sources in the "outputOptions" hook, use the "renderStart" hook instead.`
4592
+ };
4744
4593
  }
4745
- function getDefaultOnlyHelper() {
4746
- return INTEROP_NAMESPACE_DEFAULT_ONLY_VARIABLE;
4594
+ function errChunkNotGeneratedForFileName(name) {
4595
+ return {
4596
+ code: Errors.CHUNK_NOT_GENERATED,
4597
+ message: `Plugin error - Unable to get file name for chunk "${name}". Ensure that generate is called first.`
4598
+ };
4747
4599
  }
4748
- function getHelpersBlock(usedHelpers, accessedGlobals, _, n, s, t, liveBindings, freeze, namespaceToStringTag) {
4749
- return HELPER_NAMES.map(variable => usedHelpers.has(variable) || accessedGlobals.has(variable)
4750
- ? HELPER_GENERATORS[variable](_, n, s, t, liveBindings, freeze, namespaceToStringTag, usedHelpers)
4751
- : '').join('');
4600
+ function errCircularReexport(exportName, importedModule) {
4601
+ return {
4602
+ code: Errors.CIRCULAR_REEXPORT,
4603
+ id: importedModule,
4604
+ message: `"${exportName}" cannot be exported from ${relativeId(importedModule)} as it is a reexport that references itself.`
4605
+ };
4752
4606
  }
4753
- const HELPER_GENERATORS = {
4754
- [INTEROP_DEFAULT_VARIABLE]: (_, n, s, _t, liveBindings) => `function ${INTEROP_DEFAULT_VARIABLE}${_}(e)${_}{${_}return ` +
4755
- `e${_}&&${_}e.__esModule${_}?${_}` +
4756
- `${liveBindings ? getDefaultLiveBinding(_) : getDefaultStatic(_)}${s}${_}}${n}${n}`,
4757
- [INTEROP_DEFAULT_LEGACY_VARIABLE]: (_, n, s, _t, liveBindings) => `function ${INTEROP_DEFAULT_LEGACY_VARIABLE}${_}(e)${_}{${_}return ` +
4758
- `e${_}&&${_}typeof e${_}===${_}'object'${_}&&${_}'default'${_}in e${_}?${_}` +
4759
- `${liveBindings ? getDefaultLiveBinding(_) : getDefaultStatic(_)}${s}${_}}${n}${n}`,
4760
- [INTEROP_NAMESPACE_VARIABLE]: (_, n, s, t, liveBindings, freeze, namespaceToStringTag, usedHelpers) => `function ${INTEROP_NAMESPACE_VARIABLE}(e)${_}{${n}` +
4761
- (usedHelpers.has(INTEROP_NAMESPACE_DEFAULT_VARIABLE)
4762
- ? `${t}return e${_}&&${_}e.__esModule${_}?${_}e${_}:${_}${INTEROP_NAMESPACE_DEFAULT_VARIABLE}(e)${s}${n}`
4763
- : `${t}if${_}(e${_}&&${_}e.__esModule)${_}return e;${n}` +
4764
- createNamespaceObject(_, n, t, t, liveBindings, freeze, namespaceToStringTag)) +
4765
- `}${n}${n}`,
4766
- [INTEROP_NAMESPACE_DEFAULT_VARIABLE]: (_, n, _s, t, liveBindings, freeze, namespaceToStringTag) => `function ${INTEROP_NAMESPACE_DEFAULT_VARIABLE}(e)${_}{${n}` +
4767
- createNamespaceObject(_, n, t, t, liveBindings, freeze, namespaceToStringTag) +
4768
- `}${n}${n}`,
4769
- [INTEROP_NAMESPACE_DEFAULT_ONLY_VARIABLE]: (_, n, _s, t, _liveBindings, freeze, namespaceToStringTag) => `function ${INTEROP_NAMESPACE_DEFAULT_ONLY_VARIABLE}(e)${_}{${n}` +
4770
- `${t}return ${getFrozen(`{__proto__: null,${namespaceToStringTag ? `${_}[Symbol.toStringTag]:${_}'Module',` : ''}${_}'default':${_}e}`, freeze)};${n}` +
4771
- `}${n}${n}`
4772
- };
4773
- function getDefaultLiveBinding(_) {
4774
- return `e${_}:${_}{${_}'default':${_}e${_}}`;
4607
+ function errCyclicCrossChunkReexport(exportName, exporter, reexporter, importer) {
4608
+ return {
4609
+ code: Errors.CYCLIC_CROSS_CHUNK_REEXPORT,
4610
+ exporter,
4611
+ importer,
4612
+ message: `Export "${exportName}" of module ${relativeId(exporter)} was reexported through module ${relativeId(reexporter)} while both modules are dependencies of each other and will end up in different chunks by current Rollup settings. This scenario is not well supported at the moment as it will produce a circular dependency between chunks and will likely lead to broken execution order.\nEither change the import in ${relativeId(importer)} to point directly to the exporting module or do not use "preserveModules" to ensure these modules end up in the same chunk.`,
4613
+ reexporter
4614
+ };
4775
4615
  }
4776
- function getDefaultStatic(_) {
4777
- return `e['default']${_}:${_}e`;
4616
+ function errAssetReferenceIdNotFoundForSetSource(assetReferenceId) {
4617
+ return {
4618
+ code: Errors.ASSET_NOT_FOUND,
4619
+ message: `Plugin error - Unable to set the source for unknown asset "${assetReferenceId}".`
4620
+ };
4778
4621
  }
4779
- function createNamespaceObject(_, n, t, i, liveBindings, freeze, namespaceToStringTag) {
4780
- return (`${i}var n${_}=${_}${namespaceToStringTag
4781
- ? `{__proto__:${_}null,${_}[Symbol.toStringTag]:${_}'Module'}`
4782
- : 'Object.create(null)'};${n}` +
4783
- `${i}if${_}(e)${_}{${n}` +
4784
- `${i}${t}Object.keys(e).forEach(function${_}(k)${_}{${n}` +
4785
- (liveBindings ? copyPropertyLiveBinding : copyPropertyStatic)(_, n, t, i + t + t) +
4786
- `${i}${t}});${n}` +
4787
- `${i}}${n}` +
4788
- `${i}n['default']${_}=${_}e;${n}` +
4789
- `${i}return ${getFrozen('n', freeze)};${n}`);
4622
+ function errAssetSourceAlreadySet(name) {
4623
+ return {
4624
+ code: Errors.ASSET_SOURCE_ALREADY_SET,
4625
+ message: `Unable to set the source for asset "${name}", source already set.`
4626
+ };
4790
4627
  }
4791
- function copyPropertyLiveBinding(_, n, t, i) {
4792
- return (`${i}if${_}(k${_}!==${_}'default')${_}{${n}` +
4793
- `${i}${t}var d${_}=${_}Object.getOwnPropertyDescriptor(e,${_}k);${n}` +
4794
- `${i}${t}Object.defineProperty(n,${_}k,${_}d.get${_}?${_}d${_}:${_}{${n}` +
4795
- `${i}${t}${t}enumerable:${_}true,${n}` +
4796
- `${i}${t}${t}get:${_}function${_}()${_}{${n}` +
4797
- `${i}${t}${t}${t}return e[k];${n}` +
4798
- `${i}${t}${t}}${n}` +
4799
- `${i}${t}});${n}` +
4800
- `${i}}${n}`);
4628
+ function errNoAssetSourceSet(assetName) {
4629
+ return {
4630
+ code: Errors.ASSET_SOURCE_MISSING,
4631
+ message: `Plugin error creating asset "${assetName}" - no asset source set.`
4632
+ };
4801
4633
  }
4802
- function copyPropertyStatic(_, n, _t, i) {
4803
- return `${i}n[k]${_}=${_}e[k];${n}`;
4634
+ function errBadLoader(id) {
4635
+ return {
4636
+ code: Errors.BAD_LOADER,
4637
+ message: `Error loading ${relativeId(id)}: plugin load hook should return a string, a { code, map } object, or nothing/null`
4638
+ };
4804
4639
  }
4805
- function getFrozen(fragment, freeze) {
4806
- return freeze ? `Object.freeze(${fragment})` : fragment;
4640
+ function errDeprecation(deprecation) {
4641
+ return {
4642
+ code: Errors.DEPRECATED_FEATURE,
4643
+ ...(typeof deprecation === 'string' ? { message: deprecation } : deprecation)
4644
+ };
4807
4645
  }
4808
- const HELPER_NAMES = Object.keys(HELPER_GENERATORS);
4809
-
4810
- function getExportBlock(exports, dependencies, namedExportsMode, interop, compact, t, externalLiveBindings, mechanism = 'return ') {
4811
- const _ = compact ? '' : ' ';
4812
- const n = compact ? '' : '\n';
4813
- if (!namedExportsMode) {
4814
- return `${n}${n}${mechanism}${getSingleDefaultExport(exports, dependencies, interop, externalLiveBindings)};`;
4815
- }
4816
- let exportBlock = '';
4817
- // star exports must always output first for precedence
4818
- for (const { name, reexports } of dependencies) {
4819
- if (reexports && namedExportsMode) {
4820
- for (const specifier of reexports) {
4821
- if (specifier.reexported === '*') {
4822
- if (exportBlock)
4823
- exportBlock += n;
4824
- if (specifier.needsLiveBinding) {
4825
- exportBlock +=
4826
- `Object.keys(${name}).forEach(function${_}(k)${_}{${n}` +
4827
- `${t}if${_}(k${_}!==${_}'default')${_}Object.defineProperty(exports,${_}k,${_}{${n}` +
4828
- `${t}${t}enumerable:${_}true,${n}` +
4829
- `${t}${t}get:${_}function${_}()${_}{${n}` +
4830
- `${t}${t}${t}return ${name}[k];${n}` +
4831
- `${t}${t}}${n}${t}});${n}});`;
4832
- }
4833
- else {
4834
- exportBlock +=
4835
- `Object.keys(${name}).forEach(function${_}(k)${_}{${n}` +
4836
- `${t}if${_}(k${_}!==${_}'default')${_}exports[k]${_}=${_}${name}[k];${n}});`;
4837
- }
4838
- }
4839
- }
4840
- }
4841
- }
4842
- for (const { defaultVariableName, id, isChunk, name, namedExportsMode: depNamedExportsMode, namespaceVariableName, reexports } of dependencies) {
4843
- if (reexports && namedExportsMode) {
4844
- for (const specifier of reexports) {
4845
- if (specifier.reexported !== '*') {
4846
- const importName = getReexportedImportName(name, specifier.imported, depNamedExportsMode, isChunk, defaultVariableName, namespaceVariableName, interop, id, externalLiveBindings);
4847
- if (exportBlock)
4848
- exportBlock += n;
4849
- exportBlock +=
4850
- specifier.imported !== '*' && specifier.needsLiveBinding
4851
- ? `Object.defineProperty(exports,${_}'${specifier.reexported}',${_}{${n}` +
4852
- `${t}enumerable:${_}true,${n}` +
4853
- `${t}get:${_}function${_}()${_}{${n}` +
4854
- `${t}${t}return ${importName};${n}${t}}${n}});`
4855
- : `exports.${specifier.reexported}${_}=${_}${importName};`;
4856
- }
4857
- }
4858
- }
4859
- }
4860
- for (const chunkExport of exports) {
4861
- const lhs = `exports.${chunkExport.exported}`;
4862
- const rhs = chunkExport.local;
4863
- if (lhs !== rhs) {
4864
- if (exportBlock)
4865
- exportBlock += n;
4866
- exportBlock += `${lhs}${_}=${_}${rhs};`;
4867
- }
4868
- }
4869
- if (exportBlock) {
4870
- return `${n}${n}${exportBlock}`;
4871
- }
4872
- return '';
4646
+ function errFileReferenceIdNotFoundForFilename(assetReferenceId) {
4647
+ return {
4648
+ code: Errors.FILE_NOT_FOUND,
4649
+ message: `Plugin error - Unable to get file name for unknown file "${assetReferenceId}".`
4650
+ };
4873
4651
  }
4874
- function getSingleDefaultExport(exports, dependencies, interop, externalLiveBindings) {
4875
- if (exports.length > 0) {
4876
- return exports[0].local;
4877
- }
4878
- else {
4879
- for (const { defaultVariableName, id, isChunk, name, namedExportsMode: depNamedExportsMode, namespaceVariableName, reexports } of dependencies) {
4880
- if (reexports) {
4881
- return getReexportedImportName(name, reexports[0].imported, depNamedExportsMode, isChunk, defaultVariableName, namespaceVariableName, interop, id, externalLiveBindings);
4882
- }
4883
- }
4884
- }
4652
+ function errFileNameConflict(fileName) {
4653
+ return {
4654
+ code: Errors.FILE_NAME_CONFLICT,
4655
+ message: `The emitted file "${fileName}" overwrites a previously emitted file of the same name.`
4656
+ };
4885
4657
  }
4886
- function getReexportedImportName(moduleVariableName, imported, depNamedExportsMode, isChunk, defaultVariableName, namespaceVariableName, interop, moduleId, externalLiveBindings) {
4887
- if (imported === 'default') {
4888
- if (!isChunk) {
4889
- const moduleInterop = String(interop(moduleId));
4890
- const variableName = defaultInteropHelpersByInteropType[moduleInterop]
4891
- ? defaultVariableName
4892
- : moduleVariableName;
4893
- return isDefaultAProperty(moduleInterop, externalLiveBindings)
4894
- ? `${variableName}['default']`
4895
- : variableName;
4896
- }
4897
- return depNamedExportsMode ? `${moduleVariableName}['default']` : moduleVariableName;
4898
- }
4899
- if (imported === '*') {
4900
- return (isChunk
4901
- ? !depNamedExportsMode
4902
- : namespaceInteropHelpersByInteropType[String(interop(moduleId))])
4903
- ? namespaceVariableName
4904
- : moduleVariableName;
4905
- }
4906
- return `${moduleVariableName}.${imported}`;
4658
+ function errInputHookInOutputPlugin(pluginName, hookName) {
4659
+ return {
4660
+ code: Errors.INPUT_HOOK_IN_OUTPUT_PLUGIN,
4661
+ message: `The "${hookName}" hook used by the output plugin ${pluginName} is a build time hook and will not be run for that plugin. Either this plugin cannot be used as an output plugin, or it should have an option to configure it as an output plugin.`
4662
+ };
4907
4663
  }
4908
- function getEsModuleExport(_) {
4909
- return `Object.defineProperty(exports,${_}'__esModule',${_}{${_}value:${_}true${_}});`;
4664
+ function errCannotAssignModuleToChunk(moduleId, assignToAlias, currentAlias) {
4665
+ return {
4666
+ code: Errors.INVALID_CHUNK,
4667
+ message: `Cannot assign ${relativeId(moduleId)} to the "${assignToAlias}" chunk as it is already in the "${currentAlias}" chunk.`
4668
+ };
4910
4669
  }
4911
- function getNamespaceToStringExport(_) {
4912
- return `exports[Symbol.toStringTag]${_}=${_}'Module';`;
4670
+ function errInvalidExportOptionValue(optionValue) {
4671
+ return {
4672
+ code: Errors.INVALID_EXPORT_OPTION,
4673
+ message: `"output.exports" must be "default", "named", "none", "auto", or left unspecified (defaults to "auto"), received "${optionValue}"`,
4674
+ url: `https://rollupjs.org/guide/en/#outputexports`
4675
+ };
4913
4676
  }
4914
- function getNamespaceMarkers(hasNamedExports, addEsModule, addNamespaceToStringTag, _, n) {
4915
- let namespaceMarkers = '';
4916
- if (hasNamedExports) {
4917
- if (addEsModule) {
4918
- namespaceMarkers += getEsModuleExport(_);
4919
- }
4920
- if (addNamespaceToStringTag) {
4921
- if (namespaceMarkers) {
4922
- namespaceMarkers += n;
4923
- }
4924
- namespaceMarkers += getNamespaceToStringExport(_);
4925
- }
4926
- }
4927
- return namespaceMarkers;
4677
+ function errIncompatibleExportOptionValue(optionValue, keys, entryModule) {
4678
+ return {
4679
+ code: 'INVALID_EXPORT_OPTION',
4680
+ message: `"${optionValue}" was specified for "output.exports", but entry module "${relativeId(entryModule)}" has the following exports: ${keys.join(', ')}`
4681
+ };
4928
4682
  }
4929
-
4930
- function getInteropBlock(dependencies, varOrConst, interop, externalLiveBindings, freeze, namespaceToStringTag, accessedGlobals, _, n, s, t) {
4931
- const neededInteropHelpers = new Set();
4932
- const interopStatements = [];
4933
- const addInteropStatement = (helperVariableName, helper, dependencyVariableName) => {
4934
- neededInteropHelpers.add(helper);
4935
- interopStatements.push(`${varOrConst} ${helperVariableName}${_}=${_}/*#__PURE__*/${helper}(${dependencyVariableName});`);
4683
+ function errInternalIdCannotBeExternal(source, importer) {
4684
+ return {
4685
+ code: Errors.INVALID_EXTERNAL_ID,
4686
+ message: `'${source}' is imported as an external by ${relativeId(importer)}, but is already an existing non-external module id.`
4936
4687
  };
4937
- for (const { defaultVariableName, imports, id, isChunk, name, namedExportsMode, namespaceVariableName, reexports } of dependencies) {
4938
- if (isChunk) {
4939
- for (const { imported, reexported } of [
4940
- ...(imports || []),
4941
- ...(reexports || [])
4942
- ]) {
4943
- if (imported === '*' && reexported !== '*') {
4944
- if (!namedExportsMode) {
4945
- addInteropStatement(namespaceVariableName, getDefaultOnlyHelper(), name);
4946
- }
4947
- break;
4948
- }
4949
- }
4950
- }
4951
- else {
4952
- const moduleInterop = String(interop(id));
4953
- let hasDefault = false;
4954
- let hasNamespace = false;
4955
- for (const { imported, reexported } of [
4956
- ...(imports || []),
4957
- ...(reexports || [])
4958
- ]) {
4959
- let helper;
4960
- let variableName;
4961
- if (imported === 'default') {
4962
- if (!hasDefault) {
4963
- hasDefault = true;
4964
- if (defaultVariableName !== namespaceVariableName) {
4965
- variableName = defaultVariableName;
4966
- helper = defaultInteropHelpersByInteropType[moduleInterop];
4967
- }
4968
- }
4969
- }
4970
- else if (imported === '*' && reexported !== '*') {
4971
- if (!hasNamespace) {
4972
- hasNamespace = true;
4973
- helper = namespaceInteropHelpersByInteropType[moduleInterop];
4974
- variableName = namespaceVariableName;
4975
- }
4976
- }
4977
- if (helper) {
4978
- addInteropStatement(variableName, helper, name);
4979
- }
4980
- }
4981
- }
4982
- }
4983
- return `${getHelpersBlock(neededInteropHelpers, accessedGlobals, _, n, s, t, externalLiveBindings, freeze, namespaceToStringTag)}${interopStatements.length > 0 ? `${interopStatements.join(n)}${n}${n}` : ''}`;
4984
4688
  }
4985
-
4986
- // AMD resolution will only respect the AMD baseUrl if the .js extension is omitted.
4987
- // The assumption is that this makes sense for all relative ids:
4988
- // https://requirejs.org/docs/api.html#jsfiles
4989
- function removeExtensionFromRelativeAmdId(id) {
4990
- return id[0] === '.' ? removeJsExtension(id) : id;
4689
+ function errInvalidOption(option, explanation) {
4690
+ return {
4691
+ code: Errors.INVALID_OPTION,
4692
+ message: `Invalid value for option "${option}" - ${explanation}.`
4693
+ };
4991
4694
  }
4992
-
4993
- const builtins$1 = {
4994
- assert: true,
4995
- buffer: true,
4996
- console: true,
4997
- constants: true,
4998
- domain: true,
4999
- events: true,
5000
- http: true,
5001
- https: true,
5002
- os: true,
5003
- path: true,
5004
- process: true,
5005
- punycode: true,
5006
- querystring: true,
5007
- stream: true,
5008
- string_decoder: true,
5009
- timers: true,
5010
- tty: true,
5011
- url: true,
5012
- util: true,
5013
- vm: true,
5014
- zlib: true
5015
- };
5016
- function warnOnBuiltins(warn, dependencies) {
5017
- const externalBuiltins = dependencies.map(({ id }) => id).filter(id => id in builtins$1);
5018
- if (!externalBuiltins.length)
5019
- return;
5020
- const detail = externalBuiltins.length === 1
5021
- ? `module ('${externalBuiltins[0]}')`
5022
- : `modules (${externalBuiltins
5023
- .slice(0, -1)
5024
- .map(name => `'${name}'`)
5025
- .join(', ')} and '${externalBuiltins.slice(-1)}')`;
5026
- warn({
5027
- code: 'MISSING_NODE_BUILTINS',
5028
- message: `Creating a browser bundle that depends on Node.js built-in ${detail}. You might need to include https://github.com/ionic-team/rollup-plugin-node-polyfills`,
5029
- modules: externalBuiltins
5030
- });
4695
+ function errInvalidRollupPhaseForAddWatchFile() {
4696
+ return {
4697
+ code: Errors.INVALID_ROLLUP_PHASE,
4698
+ message: `Cannot call addWatchFile after the build has finished.`
4699
+ };
5031
4700
  }
5032
-
5033
- function amd(magicString, { accessedGlobals, dependencies, exports, hasExports, id, indentString: t, intro, isEntryFacade, isModuleFacade, namedExportsMode, outro, varOrConst, warn }, { amd, compact, esModule, externalLiveBindings, freeze, interop, namespaceToStringTag, strict }) {
5034
- warnOnBuiltins(warn, dependencies);
5035
- const deps = dependencies.map(m => `'${removeExtensionFromRelativeAmdId(m.id)}'`);
5036
- const args = dependencies.map(m => m.name);
5037
- const n = compact ? '' : '\n';
5038
- const s = compact ? '' : ';';
5039
- const _ = compact ? '' : ' ';
5040
- if (namedExportsMode && hasExports) {
5041
- args.unshift(`exports`);
5042
- deps.unshift(`'exports'`);
5043
- }
5044
- if (accessedGlobals.has('require')) {
5045
- args.unshift('require');
5046
- deps.unshift(`'require'`);
5047
- }
5048
- if (accessedGlobals.has('module')) {
5049
- args.unshift('module');
5050
- deps.unshift(`'module'`);
5051
- }
5052
- const completeAmdId = getCompleteAmdId(amd, id);
5053
- const params = (completeAmdId ? `'${completeAmdId}',${_}` : ``) +
5054
- (deps.length ? `[${deps.join(`,${_}`)}],${_}` : ``);
5055
- const useStrict = strict ? `${_}'use strict';` : '';
5056
- magicString.prepend(`${intro}${getInteropBlock(dependencies, varOrConst, interop, externalLiveBindings, freeze, namespaceToStringTag, accessedGlobals, _, n, s, t)}`);
5057
- const exportBlock = getExportBlock(exports, dependencies, namedExportsMode, interop, compact, t, externalLiveBindings);
5058
- let namespaceMarkers = getNamespaceMarkers(namedExportsMode && hasExports, isEntryFacade && esModule, isModuleFacade && namespaceToStringTag, _, n);
5059
- if (namespaceMarkers) {
5060
- namespaceMarkers = n + n + namespaceMarkers;
4701
+ function errInvalidRollupPhaseForChunkEmission() {
4702
+ return {
4703
+ code: Errors.INVALID_ROLLUP_PHASE,
4704
+ message: `Cannot emit chunks after module loading has finished.`
4705
+ };
4706
+ }
4707
+ function errMissingExport(exportName, importingModule, importedModule) {
4708
+ return {
4709
+ code: Errors.MISSING_EXPORT,
4710
+ message: `'${exportName}' is not exported by ${relativeId(importedModule)}, imported by ${relativeId(importingModule)}`,
4711
+ url: `https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module`
4712
+ };
4713
+ }
4714
+ function errImplicitDependantCannotBeExternal(unresolvedId, implicitlyLoadedBefore) {
4715
+ return {
4716
+ code: Errors.MISSING_IMPLICIT_DEPENDANT,
4717
+ message: `Module "${relativeId(unresolvedId)}" that should be implicitly loaded before "${relativeId(implicitlyLoadedBefore)}" cannot be external.`
4718
+ };
4719
+ }
4720
+ function errUnresolvedImplicitDependant(unresolvedId, implicitlyLoadedBefore) {
4721
+ return {
4722
+ code: Errors.MISSING_IMPLICIT_DEPENDANT,
4723
+ message: `Module "${relativeId(unresolvedId)}" that should be implicitly loaded before "${relativeId(implicitlyLoadedBefore)}" could not be resolved.`
4724
+ };
4725
+ }
4726
+ function errImplicitDependantIsNotIncluded(module) {
4727
+ const implicitDependencies = Array.from(module.implicitlyLoadedBefore, dependency => relativeId(dependency.id)).sort();
4728
+ return {
4729
+ code: Errors.MISSING_IMPLICIT_DEPENDANT,
4730
+ message: `Module "${relativeId(module.id)}" that should be implicitly loaded before "${implicitDependencies.length === 1
4731
+ ? implicitDependencies[0]
4732
+ : `${implicitDependencies.slice(0, -1).join('", "')}" and "${implicitDependencies.slice(-1)[0]}`}" is not included in the module graph. Either it was not imported by an included module or only via a tree-shaken dynamic import, or no imported bindings were used and it had otherwise no side-effects.`
4733
+ };
4734
+ }
4735
+ function errMixedExport(facadeModuleId, name) {
4736
+ return {
4737
+ code: Errors.MIXED_EXPORTS,
4738
+ id: facadeModuleId,
4739
+ message: `Entry module "${relativeId(facadeModuleId)}" is using named and default exports together. Consumers of your bundle will have to use \`${name || 'chunk'}["default"]\` to access the default export, which may not be what you want. Use \`output.exports: "named"\` to disable this warning`,
4740
+ url: `https://rollupjs.org/guide/en/#outputexports`
4741
+ };
4742
+ }
4743
+ function errNamespaceConflict(name, reexportingModule, additionalExportAllModule) {
4744
+ return {
4745
+ code: Errors.NAMESPACE_CONFLICT,
4746
+ message: `Conflicting namespaces: ${relativeId(reexportingModule.id)} re-exports '${name}' from both ${relativeId(reexportingModule.exportsAll[name])} and ${relativeId(additionalExportAllModule.exportsAll[name])} (will be ignored)`,
4747
+ name,
4748
+ reexporter: reexportingModule.id,
4749
+ sources: [reexportingModule.exportsAll[name], additionalExportAllModule.exportsAll[name]]
4750
+ };
4751
+ }
4752
+ function errNoTransformMapOrAstWithoutCode(pluginName) {
4753
+ return {
4754
+ code: Errors.NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE,
4755
+ message: `The plugin "${pluginName}" returned a "map" or "ast" without returning ` +
4756
+ 'a "code". This will be ignored.'
4757
+ };
4758
+ }
4759
+ function errPreferNamedExports(facadeModuleId) {
4760
+ const file = relativeId(facadeModuleId);
4761
+ return {
4762
+ code: Errors.PREFER_NAMED_EXPORTS,
4763
+ id: facadeModuleId,
4764
+ message: `Entry module "${file}" is implicitly using "default" export mode, which means for CommonJS output that its default export is assigned to "module.exports". For many tools, such CommonJS output will not be interchangeable with the original ES module. If this is intended, explicitly set "output.exports" to either "auto" or "default", otherwise you might want to consider changing the signature of "${file}" to use named exports only.`,
4765
+ url: `https://rollupjs.org/guide/en/#outputexports`
4766
+ };
4767
+ }
4768
+ function errSyntheticNamedExportsNeedNamespaceExport(id, syntheticNamedExportsOption) {
4769
+ return {
4770
+ code: Errors.SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT,
4771
+ id,
4772
+ message: `Module "${relativeId(id)}" that is marked with 'syntheticNamedExports: ${JSON.stringify(syntheticNamedExportsOption)}' needs ${typeof syntheticNamedExportsOption === 'string' && syntheticNamedExportsOption !== 'default'
4773
+ ? `an export named "${syntheticNamedExportsOption}"`
4774
+ : 'a default export'} that does not reexport an unresolved named export of the same module.`
4775
+ };
4776
+ }
4777
+ function errUnexpectedNamedImport(id, imported, isReexport) {
4778
+ const importType = isReexport ? 'reexport' : 'import';
4779
+ return {
4780
+ code: Errors.UNEXPECTED_NAMED_IMPORT,
4781
+ id,
4782
+ message: `The named export "${imported}" was ${importType}ed from the external module ${relativeId(id)} even though its interop type is "defaultOnly". Either remove or change this ${importType} or change the value of the "output.interop" option.`,
4783
+ url: 'https://rollupjs.org/guide/en/#outputinterop'
4784
+ };
4785
+ }
4786
+ function errUnexpectedNamespaceReexport(id) {
4787
+ return {
4788
+ code: Errors.UNEXPECTED_NAMED_IMPORT,
4789
+ id,
4790
+ message: `There was a namespace "*" reexport from the external module ${relativeId(id)} even though its interop type is "defaultOnly". This will be ignored as namespace reexports only reexport named exports. If this is not intended, either remove or change this reexport or change the value of the "output.interop" option.`,
4791
+ url: 'https://rollupjs.org/guide/en/#outputinterop'
4792
+ };
4793
+ }
4794
+ function errEntryCannotBeExternal(unresolvedId) {
4795
+ return {
4796
+ code: Errors.UNRESOLVED_ENTRY,
4797
+ message: `Entry module cannot be external (${relativeId(unresolvedId)}).`
4798
+ };
4799
+ }
4800
+ function errUnresolvedEntry(unresolvedId) {
4801
+ return {
4802
+ code: Errors.UNRESOLVED_ENTRY,
4803
+ message: `Could not resolve entry module (${relativeId(unresolvedId)}).`
4804
+ };
4805
+ }
4806
+ function errUnresolvedImport(source, importer) {
4807
+ return {
4808
+ code: Errors.UNRESOLVED_IMPORT,
4809
+ message: `Could not resolve '${source}' from ${relativeId(importer)}`
4810
+ };
4811
+ }
4812
+ function errUnresolvedImportTreatedAsExternal(source, importer) {
4813
+ return {
4814
+ code: Errors.UNRESOLVED_IMPORT,
4815
+ importer: relativeId(importer),
4816
+ message: `'${source}' is imported by ${relativeId(importer)}, but could not be resolved – treating it as an external dependency`,
4817
+ source,
4818
+ url: 'https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency'
4819
+ };
4820
+ }
4821
+ function errExternalSyntheticExports(source, importer) {
4822
+ return {
4823
+ code: Errors.EXTERNAL_SYNTHETIC_EXPORTS,
4824
+ importer: relativeId(importer),
4825
+ message: `External '${source}' can not have 'syntheticNamedExports' enabled.`,
4826
+ source
4827
+ };
4828
+ }
4829
+ function errFailedValidation(message) {
4830
+ return {
4831
+ code: Errors.VALIDATION_ERROR,
4832
+ message
4833
+ };
4834
+ }
4835
+ function errAlreadyClosed() {
4836
+ return {
4837
+ code: Errors.ALREADY_CLOSED,
4838
+ message: 'Bundle is already closed, no more calls to "generate" or "write" are allowed.'
4839
+ };
4840
+ }
4841
+ function warnDeprecation(deprecation, activeDeprecation, options) {
4842
+ warnDeprecationWithOptions(deprecation, activeDeprecation, options.onwarn, options.strictDeprecations);
4843
+ }
4844
+ function warnDeprecationWithOptions(deprecation, activeDeprecation, warn, strictDeprecations) {
4845
+ if (activeDeprecation || strictDeprecations) {
4846
+ const warning = errDeprecation(deprecation);
4847
+ if (strictDeprecations) {
4848
+ return error(warning);
4849
+ }
4850
+ warn(warning);
5061
4851
  }
5062
- magicString.append(`${exportBlock}${namespaceMarkers}${outro}`);
5063
- return magicString
5064
- .indent(t)
5065
- .prepend(`${amd.define}(${params}function${_}(${args.join(`,${_}`)})${_}{${useStrict}${n}${n}`)
5066
- .append(`${n}${n}});`);
5067
4852
  }
5068
4853
 
5069
- function cjs(magicString, { accessedGlobals, dependencies, exports, hasExports, indentString: t, intro, isEntryFacade, isModuleFacade, namedExportsMode, outro, varOrConst }, { compact, esModule, externalLiveBindings, freeze, interop, namespaceToStringTag, strict }) {
5070
- const n = compact ? '' : '\n';
5071
- const s = compact ? '' : ';';
5072
- const _ = compact ? '' : ' ';
5073
- const useStrict = strict ? `'use strict';${n}${n}` : '';
5074
- let namespaceMarkers = getNamespaceMarkers(namedExportsMode && hasExports, isEntryFacade && esModule, isModuleFacade && namespaceToStringTag, _, n);
5075
- if (namespaceMarkers) {
5076
- namespaceMarkers += n + n;
4854
+ class SyntheticNamedExportVariable extends Variable {
4855
+ constructor(context, name, syntheticNamespace) {
4856
+ super(name);
4857
+ this.baseVariable = null;
4858
+ this.context = context;
4859
+ this.module = context.module;
4860
+ this.syntheticNamespace = syntheticNamespace;
5077
4861
  }
5078
- const importBlock = getImportBlock(dependencies, compact, varOrConst, n, _);
5079
- const interopBlock = getInteropBlock(dependencies, varOrConst, interop, externalLiveBindings, freeze, namespaceToStringTag, accessedGlobals, _, n, s, t);
5080
- magicString.prepend(`${useStrict}${intro}${namespaceMarkers}${importBlock}${interopBlock}`);
5081
- const exportBlock = getExportBlock(exports, dependencies, namedExportsMode, interop, compact, t, externalLiveBindings, `module.exports${_}=${_}`);
5082
- return magicString.append(`${exportBlock}${outro}`);
5083
- }
5084
- function getImportBlock(dependencies, compact, varOrConst, n, _) {
5085
- let importBlock = '';
5086
- let definingVariable = false;
5087
- for (const { id, name, reexports, imports } of dependencies) {
5088
- if (!reexports && !imports) {
5089
- if (importBlock) {
5090
- importBlock += !compact || definingVariable ? `;${n}` : ',';
4862
+ getBaseVariable() {
4863
+ if (this.baseVariable)
4864
+ return this.baseVariable;
4865
+ let baseVariable = this.syntheticNamespace;
4866
+ const checkedVariables = new Set();
4867
+ while (baseVariable instanceof ExportDefaultVariable ||
4868
+ baseVariable instanceof SyntheticNamedExportVariable) {
4869
+ checkedVariables.add(baseVariable);
4870
+ if (baseVariable instanceof ExportDefaultVariable) {
4871
+ const original = baseVariable.getOriginalVariable();
4872
+ if (original === baseVariable)
4873
+ break;
4874
+ baseVariable = original;
4875
+ }
4876
+ if (baseVariable instanceof SyntheticNamedExportVariable) {
4877
+ baseVariable = baseVariable.syntheticNamespace;
4878
+ }
4879
+ if (checkedVariables.has(baseVariable)) {
4880
+ return error(errSyntheticNamedExportsNeedNamespaceExport(this.module.id, this.module.info.syntheticNamedExports));
5091
4881
  }
5092
- definingVariable = false;
5093
- importBlock += `require('${id}')`;
5094
4882
  }
5095
- else {
5096
- importBlock +=
5097
- compact && definingVariable ? ',' : `${importBlock ? `;${n}` : ''}${varOrConst} `;
5098
- definingVariable = true;
5099
- importBlock += `${name}${_}=${_}require('${id}')`;
4883
+ return (this.baseVariable = baseVariable);
4884
+ }
4885
+ getBaseVariableName() {
4886
+ return this.syntheticNamespace.getBaseVariableName();
4887
+ }
4888
+ getName() {
4889
+ const name = this.name;
4890
+ return `${this.syntheticNamespace.getName()}${getPropertyAccess(name)}`;
4891
+ }
4892
+ include() {
4893
+ if (!this.included) {
4894
+ this.included = true;
4895
+ this.context.includeVariableInModule(this.syntheticNamespace);
5100
4896
  }
5101
4897
  }
5102
- if (importBlock) {
5103
- return `${importBlock};${n}${n}`;
4898
+ setRenderNames(baseName, name) {
4899
+ super.setRenderNames(baseName, name);
5104
4900
  }
5105
- return '';
5106
4901
  }
4902
+ const getPropertyAccess = (name) => {
4903
+ return !RESERVED_NAMES[name] && /^(?!\d)[\w$]+$/.test(name)
4904
+ ? `.${name}`
4905
+ : `[${JSON.stringify(name)}]`;
4906
+ };
5107
4907
 
5108
- function es(magicString, { intro, outro, dependencies, exports, varOrConst }, { compact }) {
5109
- const _ = compact ? '' : ' ';
5110
- const n = compact ? '' : '\n';
5111
- const importBlock = getImportBlock$1(dependencies, _);
5112
- if (importBlock.length > 0)
5113
- intro += importBlock.join(n) + n + n;
5114
- if (intro)
5115
- magicString.prepend(intro);
5116
- const exportBlock = getExportBlock$1(exports, _, varOrConst);
5117
- if (exportBlock.length)
5118
- magicString.append(n + n + exportBlock.join(n).trim());
5119
- if (outro)
5120
- magicString.append(outro);
5121
- return magicString.trim();
5122
- }
5123
- function getImportBlock$1(dependencies, _) {
5124
- const importBlock = [];
5125
- for (const { id, reexports, imports, name } of dependencies) {
5126
- if (!reexports && !imports) {
5127
- importBlock.push(`import${_}'${id}';`);
5128
- continue;
5129
- }
5130
- if (imports) {
5131
- let defaultImport = null;
5132
- let starImport = null;
5133
- const importedNames = [];
5134
- for (const specifier of imports) {
5135
- if (specifier.imported === 'default') {
5136
- defaultImport = specifier;
5137
- }
5138
- else if (specifier.imported === '*') {
5139
- starImport = specifier;
5140
- }
5141
- else {
5142
- importedNames.push(specifier);
5143
- }
5144
- }
5145
- if (starImport) {
5146
- importBlock.push(`import${_}*${_}as ${starImport.local} from${_}'${id}';`);
5147
- }
5148
- if (defaultImport && importedNames.length === 0) {
5149
- importBlock.push(`import ${defaultImport.local} from${_}'${id}';`);
5150
- }
5151
- else if (importedNames.length > 0) {
5152
- importBlock.push(`import ${defaultImport ? `${defaultImport.local},${_}` : ''}{${_}${importedNames
5153
- .map(specifier => {
5154
- if (specifier.imported === specifier.local) {
5155
- return specifier.imported;
5156
- }
5157
- else {
5158
- return `${specifier.imported} as ${specifier.local}`;
5159
- }
5160
- })
5161
- .join(`,${_}`)}${_}}${_}from${_}'${id}';`);
5162
- }
5163
- }
5164
- if (reexports) {
5165
- let starExport = null;
5166
- const namespaceReexports = [];
5167
- const namedReexports = [];
5168
- for (const specifier of reexports) {
5169
- if (specifier.reexported === '*') {
5170
- starExport = specifier;
5171
- }
5172
- else if (specifier.imported === '*') {
5173
- namespaceReexports.push(specifier);
5174
- }
5175
- else {
5176
- namedReexports.push(specifier);
5177
- }
5178
- }
5179
- if (starExport) {
5180
- importBlock.push(`export${_}*${_}from${_}'${id}';`);
5181
- }
5182
- if (namespaceReexports.length > 0) {
5183
- if (!imports ||
5184
- !imports.some(specifier => specifier.imported === '*' && specifier.local === name)) {
5185
- importBlock.push(`import${_}*${_}as ${name} from${_}'${id}';`);
5186
- }
5187
- for (const specifier of namespaceReexports) {
5188
- importBlock.push(`export${_}{${_}${name === specifier.reexported ? name : `${name} as ${specifier.reexported}`} };`);
5189
- }
5190
- }
5191
- if (namedReexports.length > 0) {
5192
- importBlock.push(`export${_}{${_}${namedReexports
5193
- .map(specifier => {
5194
- if (specifier.imported === specifier.reexported) {
5195
- return specifier.imported;
5196
- }
5197
- else {
5198
- return `${specifier.imported} as ${specifier.reexported}`;
5199
- }
5200
- })
5201
- .join(`,${_}`)}${_}}${_}from${_}'${id}';`);
5202
- }
4908
+ class ExternalVariable extends Variable {
4909
+ constructor(module, name) {
4910
+ super(name);
4911
+ this.module = module;
4912
+ this.isNamespace = name === '*';
4913
+ this.referenced = false;
4914
+ }
4915
+ addReference(identifier) {
4916
+ this.referenced = true;
4917
+ if (this.name === 'default' || this.name === '*') {
4918
+ this.module.suggestName(identifier.name);
5203
4919
  }
5204
4920
  }
5205
- return importBlock;
5206
- }
5207
- function getExportBlock$1(exports, _, varOrConst) {
5208
- const exportBlock = [];
5209
- const exportDeclaration = [];
5210
- for (const specifier of exports) {
5211
- if (specifier.exported === 'default') {
5212
- exportBlock.push(`export default ${specifier.local};`);
5213
- }
5214
- else {
5215
- if (specifier.expression) {
5216
- exportBlock.push(`${varOrConst} ${specifier.local}${_}=${_}${specifier.expression};`);
5217
- }
5218
- exportDeclaration.push(specifier.exported === specifier.local
5219
- ? specifier.local
5220
- : `${specifier.local} as ${specifier.exported}`);
4921
+ include() {
4922
+ if (!this.included) {
4923
+ this.included = true;
4924
+ this.module.used = true;
5221
4925
  }
5222
4926
  }
5223
- if (exportDeclaration.length) {
5224
- exportBlock.push(`export${_}{${_}${exportDeclaration.join(`,${_}`)}${_}};`);
5225
- }
5226
- return exportBlock;
5227
4927
  }
5228
4928
 
5229
- function spaces(i) {
5230
- let result = '';
5231
- while (i--)
5232
- result += ' ';
5233
- return result;
4929
+ const reservedWords = 'break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield enum await implements package protected static interface private public'.split(' ');
4930
+ const builtins = 'Infinity NaN undefined null true false eval uneval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Symbol Error EvalError InternalError RangeError ReferenceError SyntaxError TypeError URIError Number Math Date String RegExp Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array Map Set WeakMap WeakSet SIMD ArrayBuffer DataView JSON Promise Generator GeneratorFunction Reflect Proxy Intl'.split(' ');
4931
+ const blacklisted = new Set(reservedWords.concat(builtins));
4932
+ const illegalCharacters = /[^$_a-zA-Z0-9]/g;
4933
+ const startsWithDigit = (str) => /\d/.test(str[0]);
4934
+ function isLegal(str) {
4935
+ if (startsWithDigit(str) || blacklisted.has(str)) {
4936
+ return false;
4937
+ }
4938
+ return !illegalCharacters.test(str);
5234
4939
  }
5235
- function tabsToSpaces(str) {
5236
- return str.replace(/^\t+/, match => match.split('\t').join(' '));
4940
+ function makeLegal(str) {
4941
+ str = str.replace(/-(\w)/g, (_, letter) => letter.toUpperCase()).replace(illegalCharacters, '_');
4942
+ if (startsWithDigit(str) || blacklisted.has(str))
4943
+ str = `_${str}`;
4944
+ return str || '_';
5237
4945
  }
5238
- function getCodeFrame(source, line, column) {
5239
- let lines = source.split('\n');
5240
- const frameStart = Math.max(0, line - 3);
5241
- let frameEnd = Math.min(line + 2, lines.length);
5242
- lines = lines.slice(frameStart, frameEnd);
5243
- while (!/\S/.test(lines[lines.length - 1])) {
5244
- lines.pop();
5245
- frameEnd -= 1;
4946
+
4947
+ class ExternalModule {
4948
+ constructor(options, id, hasModuleSideEffects, meta) {
4949
+ this.options = options;
4950
+ this.id = id;
4951
+ this.defaultVariableName = '';
4952
+ this.dynamicImporters = [];
4953
+ this.importers = [];
4954
+ this.mostCommonSuggestion = 0;
4955
+ this.namespaceVariableName = '';
4956
+ this.reexported = false;
4957
+ this.renderPath = undefined;
4958
+ this.renormalizeRenderPath = false;
4959
+ this.used = false;
4960
+ this.variableName = '';
4961
+ this.execIndex = Infinity;
4962
+ this.suggestedVariableName = makeLegal(id.split(/[\\/]/).pop());
4963
+ this.nameSuggestions = Object.create(null);
4964
+ this.declarations = Object.create(null);
4965
+ this.exportedVariables = new Map();
4966
+ const module = this;
4967
+ this.info = {
4968
+ ast: null,
4969
+ code: null,
4970
+ dynamicallyImportedIds: EMPTY_ARRAY,
4971
+ get dynamicImporters() {
4972
+ return module.dynamicImporters.sort();
4973
+ },
4974
+ hasModuleSideEffects,
4975
+ id,
4976
+ implicitlyLoadedAfterOneOf: EMPTY_ARRAY,
4977
+ implicitlyLoadedBefore: EMPTY_ARRAY,
4978
+ importedIds: EMPTY_ARRAY,
4979
+ get importers() {
4980
+ return module.importers.sort();
4981
+ },
4982
+ isEntry: false,
4983
+ isExternal: true,
4984
+ meta,
4985
+ syntheticNamedExports: false
4986
+ };
5246
4987
  }
5247
- const digits = String(frameEnd).length;
5248
- return lines
5249
- .map((str, i) => {
5250
- const isErrorLine = frameStart + i + 1 === line;
5251
- let lineNum = String(i + frameStart + 1);
5252
- while (lineNum.length < digits)
5253
- lineNum = ` ${lineNum}`;
5254
- if (isErrorLine) {
5255
- const indicator = spaces(digits + 2 + tabsToSpaces(str.slice(0, column)).length) + '^';
5256
- return `${lineNum}: ${tabsToSpaces(str)}\n${indicator}`;
4988
+ getVariableForExportName(name) {
4989
+ let declaration = this.declarations[name];
4990
+ if (declaration)
4991
+ return declaration;
4992
+ this.declarations[name] = declaration = new ExternalVariable(this, name);
4993
+ this.exportedVariables.set(declaration, name);
4994
+ return declaration;
4995
+ }
4996
+ setRenderPath(options, inputBase) {
4997
+ this.renderPath =
4998
+ typeof options.paths === 'function' ? options.paths(this.id) : options.paths[this.id];
4999
+ if (!this.renderPath) {
5000
+ if (!isAbsolute(this.id)) {
5001
+ this.renderPath = this.id;
5002
+ }
5003
+ else {
5004
+ this.renderPath = normalize(sysPath.relative(inputBase, this.id));
5005
+ this.renormalizeRenderPath = true;
5006
+ }
5257
5007
  }
5258
- return `${lineNum}: ${tabsToSpaces(str)}`;
5259
- })
5260
- .join('\n');
5008
+ return this.renderPath;
5009
+ }
5010
+ suggestName(name) {
5011
+ if (!this.nameSuggestions[name])
5012
+ this.nameSuggestions[name] = 0;
5013
+ this.nameSuggestions[name] += 1;
5014
+ if (this.nameSuggestions[name] > this.mostCommonSuggestion) {
5015
+ this.mostCommonSuggestion = this.nameSuggestions[name];
5016
+ this.suggestedVariableName = name;
5017
+ }
5018
+ }
5019
+ warnUnusedImports() {
5020
+ const unused = Object.keys(this.declarations).filter(name => {
5021
+ if (name === '*')
5022
+ return false;
5023
+ const declaration = this.declarations[name];
5024
+ return !declaration.included && !this.reexported && !declaration.referenced;
5025
+ });
5026
+ if (unused.length === 0)
5027
+ return;
5028
+ const names = unused.length === 1
5029
+ ? `'${unused[0]}' is`
5030
+ : `${unused
5031
+ .slice(0, -1)
5032
+ .map(name => `'${name}'`)
5033
+ .join(', ')} and '${unused.slice(-1)}' are`;
5034
+ this.options.onwarn({
5035
+ code: 'UNUSED_EXTERNAL_IMPORT',
5036
+ message: `${names} imported from external module '${this.id}' but never used`,
5037
+ names: unused,
5038
+ source: this.id
5039
+ });
5040
+ }
5261
5041
  }
5262
5042
 
5263
- function error(base) {
5264
- if (!(base instanceof Error))
5265
- base = Object.assign(new Error(base.message), base);
5266
- throw base;
5043
+ function removeJsExtension(name) {
5044
+ return name.endsWith('.js') ? name.slice(0, -3) : name;
5267
5045
  }
5268
- function augmentCodeLocation(props, pos, source, id) {
5269
- if (typeof pos === 'object') {
5270
- const { line, column } = pos;
5271
- props.loc = { file: id, line, column };
5046
+
5047
+ function getCompleteAmdId(options, chunkId) {
5048
+ if (!options.autoId) {
5049
+ return options.id || '';
5272
5050
  }
5273
5051
  else {
5274
- props.pos = pos;
5275
- const { line, column } = locate(source, pos, { offsetLine: 1 });
5276
- props.loc = { file: id, line, column };
5277
- }
5278
- if (props.frame === undefined) {
5279
- const { line, column } = props.loc;
5280
- props.frame = getCodeFrame(source, line, column);
5052
+ return `${options.basePath ? options.basePath + '/' : ''}${removeJsExtension(chunkId)}`;
5281
5053
  }
5282
5054
  }
5283
- var Errors;
5284
- (function (Errors) {
5285
- Errors["ALREADY_CLOSED"] = "ALREADY_CLOSED";
5286
- Errors["ASSET_NOT_FINALISED"] = "ASSET_NOT_FINALISED";
5287
- Errors["ASSET_NOT_FOUND"] = "ASSET_NOT_FOUND";
5288
- Errors["ASSET_SOURCE_ALREADY_SET"] = "ASSET_SOURCE_ALREADY_SET";
5289
- Errors["ASSET_SOURCE_MISSING"] = "ASSET_SOURCE_MISSING";
5290
- Errors["BAD_LOADER"] = "BAD_LOADER";
5291
- Errors["CANNOT_EMIT_FROM_OPTIONS_HOOK"] = "CANNOT_EMIT_FROM_OPTIONS_HOOK";
5292
- Errors["CHUNK_NOT_GENERATED"] = "CHUNK_NOT_GENERATED";
5293
- Errors["DEPRECATED_FEATURE"] = "DEPRECATED_FEATURE";
5294
- Errors["EXTERNAL_SYNTHETIC_EXPORTS"] = "EXTERNAL_SYNTHETIC_EXPORTS";
5295
- Errors["FILE_NAME_CONFLICT"] = "FILE_NAME_CONFLICT";
5296
- Errors["FILE_NOT_FOUND"] = "FILE_NOT_FOUND";
5297
- Errors["INPUT_HOOK_IN_OUTPUT_PLUGIN"] = "INPUT_HOOK_IN_OUTPUT_PLUGIN";
5298
- Errors["INVALID_CHUNK"] = "INVALID_CHUNK";
5299
- Errors["INVALID_EXPORT_OPTION"] = "INVALID_EXPORT_OPTION";
5300
- Errors["INVALID_EXTERNAL_ID"] = "INVALID_EXTERNAL_ID";
5301
- Errors["INVALID_OPTION"] = "INVALID_OPTION";
5302
- Errors["INVALID_PLUGIN_HOOK"] = "INVALID_PLUGIN_HOOK";
5303
- Errors["INVALID_ROLLUP_PHASE"] = "INVALID_ROLLUP_PHASE";
5304
- Errors["MISSING_IMPLICIT_DEPENDANT"] = "MISSING_IMPLICIT_DEPENDANT";
5305
- Errors["MIXED_EXPORTS"] = "MIXED_EXPORTS";
5306
- Errors["NAMESPACE_CONFLICT"] = "NAMESPACE_CONFLICT";
5307
- Errors["NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE"] = "NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE";
5308
- Errors["PLUGIN_ERROR"] = "PLUGIN_ERROR";
5309
- Errors["PREFER_NAMED_EXPORTS"] = "PREFER_NAMED_EXPORTS";
5310
- Errors["SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT"] = "SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT";
5311
- Errors["UNEXPECTED_NAMED_IMPORT"] = "UNEXPECTED_NAMED_IMPORT";
5312
- Errors["UNRESOLVED_ENTRY"] = "UNRESOLVED_ENTRY";
5313
- Errors["UNRESOLVED_IMPORT"] = "UNRESOLVED_IMPORT";
5314
- Errors["VALIDATION_ERROR"] = "VALIDATION_ERROR";
5315
- })(Errors || (Errors = {}));
5316
- function errAssetNotFinalisedForFileName(name) {
5317
- return {
5318
- code: Errors.ASSET_NOT_FINALISED,
5319
- message: `Plugin error - Unable to get file name for asset "${name}". Ensure that the source is set and that generate is called first.`
5320
- };
5321
- }
5322
- function errCannotEmitFromOptionsHook() {
5323
- return {
5324
- code: Errors.CANNOT_EMIT_FROM_OPTIONS_HOOK,
5325
- message: `Cannot emit files or set asset sources in the "outputOptions" hook, use the "renderStart" hook instead.`
5326
- };
5327
- }
5328
- function errChunkNotGeneratedForFileName(name) {
5329
- return {
5330
- code: Errors.CHUNK_NOT_GENERATED,
5331
- message: `Plugin error - Unable to get file name for chunk "${name}". Ensure that generate is called first.`
5332
- };
5333
- }
5334
- function errAssetReferenceIdNotFoundForSetSource(assetReferenceId) {
5335
- return {
5336
- code: Errors.ASSET_NOT_FOUND,
5337
- message: `Plugin error - Unable to set the source for unknown asset "${assetReferenceId}".`
5338
- };
5339
- }
5340
- function errAssetSourceAlreadySet(name) {
5341
- return {
5342
- code: Errors.ASSET_SOURCE_ALREADY_SET,
5343
- message: `Unable to set the source for asset "${name}", source already set.`
5344
- };
5345
- }
5346
- function errNoAssetSourceSet(assetName) {
5347
- return {
5348
- code: Errors.ASSET_SOURCE_MISSING,
5349
- message: `Plugin error creating asset "${assetName}" - no asset source set.`
5350
- };
5351
- }
5352
- function errBadLoader(id) {
5353
- return {
5354
- code: Errors.BAD_LOADER,
5355
- message: `Error loading ${relativeId(id)}: plugin load hook should return a string, a { code, map } object, or nothing/null`
5356
- };
5357
- }
5358
- function errDeprecation(deprecation) {
5359
- return {
5360
- code: Errors.DEPRECATED_FEATURE,
5361
- ...(typeof deprecation === 'string' ? { message: deprecation } : deprecation)
5362
- };
5363
- }
5364
- function errFileReferenceIdNotFoundForFilename(assetReferenceId) {
5365
- return {
5366
- code: Errors.FILE_NOT_FOUND,
5367
- message: `Plugin error - Unable to get file name for unknown file "${assetReferenceId}".`
5368
- };
5369
- }
5370
- function errFileNameConflict(fileName) {
5371
- return {
5372
- code: Errors.FILE_NAME_CONFLICT,
5373
- message: `The emitted file "${fileName}" overwrites a previously emitted file of the same name.`
5374
- };
5375
- }
5376
- function errInputHookInOutputPlugin(pluginName, hookName) {
5377
- return {
5378
- code: Errors.INPUT_HOOK_IN_OUTPUT_PLUGIN,
5379
- message: `The "${hookName}" hook used by the output plugin ${pluginName} is a build time hook and will not be run for that plugin. Either this plugin cannot be used as an output plugin, or it should have an option to configure it as an output plugin.`
5380
- };
5381
- }
5382
- function errCannotAssignModuleToChunk(moduleId, assignToAlias, currentAlias) {
5383
- return {
5384
- code: Errors.INVALID_CHUNK,
5385
- message: `Cannot assign ${relativeId(moduleId)} to the "${assignToAlias}" chunk as it is already in the "${currentAlias}" chunk.`
5386
- };
5387
- }
5388
- function errInvalidExportOptionValue(optionValue) {
5389
- return {
5390
- code: Errors.INVALID_EXPORT_OPTION,
5391
- message: `"output.exports" must be "default", "named", "none", "auto", or left unspecified (defaults to "auto"), received "${optionValue}"`,
5392
- url: `https://rollupjs.org/guide/en/#outputexports`
5393
- };
5055
+
5056
+ const INTEROP_DEFAULT_VARIABLE = '_interopDefault';
5057
+ const INTEROP_DEFAULT_LEGACY_VARIABLE = '_interopDefaultLegacy';
5058
+ const INTEROP_NAMESPACE_VARIABLE = '_interopNamespace';
5059
+ const INTEROP_NAMESPACE_DEFAULT_VARIABLE = '_interopNamespaceDefault';
5060
+ const INTEROP_NAMESPACE_DEFAULT_ONLY_VARIABLE = '_interopNamespaceDefaultOnly';
5061
+ const defaultInteropHelpersByInteropType = {
5062
+ auto: INTEROP_DEFAULT_VARIABLE,
5063
+ default: null,
5064
+ defaultOnly: null,
5065
+ esModule: null,
5066
+ false: null,
5067
+ true: INTEROP_DEFAULT_LEGACY_VARIABLE
5068
+ };
5069
+ function isDefaultAProperty(interopType, externalLiveBindings) {
5070
+ return (interopType === 'esModule' ||
5071
+ (externalLiveBindings && (interopType === 'auto' || interopType === 'true')));
5394
5072
  }
5395
- function errIncompatibleExportOptionValue(optionValue, keys, entryModule) {
5396
- return {
5397
- code: 'INVALID_EXPORT_OPTION',
5398
- message: `"${optionValue}" was specified for "output.exports", but entry module "${relativeId(entryModule)}" has the following exports: ${keys.join(', ')}`
5399
- };
5073
+ const namespaceInteropHelpersByInteropType = {
5074
+ auto: INTEROP_NAMESPACE_VARIABLE,
5075
+ default: INTEROP_NAMESPACE_DEFAULT_VARIABLE,
5076
+ defaultOnly: INTEROP_NAMESPACE_DEFAULT_ONLY_VARIABLE,
5077
+ esModule: null,
5078
+ false: null,
5079
+ true: INTEROP_NAMESPACE_VARIABLE
5080
+ };
5081
+ function canDefaultBeTakenFromNamespace(interopType, externalLiveBindings) {
5082
+ return (isDefaultAProperty(interopType, externalLiveBindings) &&
5083
+ defaultInteropHelpersByInteropType[interopType] === INTEROP_DEFAULT_VARIABLE);
5400
5084
  }
5401
- function errInternalIdCannotBeExternal(source, importer) {
5402
- return {
5403
- code: Errors.INVALID_EXTERNAL_ID,
5404
- message: `'${source}' is imported as an external by ${relativeId(importer)}, but is already an existing non-external module id.`
5405
- };
5085
+ function getDefaultOnlyHelper() {
5086
+ return INTEROP_NAMESPACE_DEFAULT_ONLY_VARIABLE;
5406
5087
  }
5407
- function errInvalidOption(option, explanation) {
5408
- return {
5409
- code: Errors.INVALID_OPTION,
5410
- message: `Invalid value for option "${option}" - ${explanation}.`
5411
- };
5088
+ function getHelpersBlock(usedHelpers, accessedGlobals, _, n, s, t, liveBindings, freeze, namespaceToStringTag) {
5089
+ return HELPER_NAMES.map(variable => usedHelpers.has(variable) || accessedGlobals.has(variable)
5090
+ ? HELPER_GENERATORS[variable](_, n, s, t, liveBindings, freeze, namespaceToStringTag, usedHelpers)
5091
+ : '').join('');
5412
5092
  }
5413
- function errInvalidRollupPhaseForAddWatchFile() {
5414
- return {
5415
- code: Errors.INVALID_ROLLUP_PHASE,
5416
- message: `Cannot call addWatchFile after the build has finished.`
5417
- };
5093
+ const HELPER_GENERATORS = {
5094
+ [INTEROP_DEFAULT_VARIABLE]: (_, n, s, _t, liveBindings) => `function ${INTEROP_DEFAULT_VARIABLE}${_}(e)${_}{${_}return ` +
5095
+ `e${_}&&${_}e.__esModule${_}?${_}` +
5096
+ `${liveBindings ? getDefaultLiveBinding(_) : getDefaultStatic(_)}${s}${_}}${n}${n}`,
5097
+ [INTEROP_DEFAULT_LEGACY_VARIABLE]: (_, n, s, _t, liveBindings) => `function ${INTEROP_DEFAULT_LEGACY_VARIABLE}${_}(e)${_}{${_}return ` +
5098
+ `e${_}&&${_}typeof e${_}===${_}'object'${_}&&${_}'default'${_}in e${_}?${_}` +
5099
+ `${liveBindings ? getDefaultLiveBinding(_) : getDefaultStatic(_)}${s}${_}}${n}${n}`,
5100
+ [INTEROP_NAMESPACE_VARIABLE]: (_, n, s, t, liveBindings, freeze, namespaceToStringTag, usedHelpers) => `function ${INTEROP_NAMESPACE_VARIABLE}(e)${_}{${n}` +
5101
+ (usedHelpers.has(INTEROP_NAMESPACE_DEFAULT_VARIABLE)
5102
+ ? `${t}return e${_}&&${_}e.__esModule${_}?${_}e${_}:${_}${INTEROP_NAMESPACE_DEFAULT_VARIABLE}(e)${s}${n}`
5103
+ : `${t}if${_}(e${_}&&${_}e.__esModule)${_}return e;${n}` +
5104
+ createNamespaceObject(_, n, t, t, liveBindings, freeze, namespaceToStringTag)) +
5105
+ `}${n}${n}`,
5106
+ [INTEROP_NAMESPACE_DEFAULT_VARIABLE]: (_, n, _s, t, liveBindings, freeze, namespaceToStringTag) => `function ${INTEROP_NAMESPACE_DEFAULT_VARIABLE}(e)${_}{${n}` +
5107
+ createNamespaceObject(_, n, t, t, liveBindings, freeze, namespaceToStringTag) +
5108
+ `}${n}${n}`,
5109
+ [INTEROP_NAMESPACE_DEFAULT_ONLY_VARIABLE]: (_, n, _s, t, _liveBindings, freeze, namespaceToStringTag) => `function ${INTEROP_NAMESPACE_DEFAULT_ONLY_VARIABLE}(e)${_}{${n}` +
5110
+ `${t}return ${getFrozen(`{__proto__: null,${namespaceToStringTag ? `${_}[Symbol.toStringTag]:${_}'Module',` : ''}${_}'default':${_}e}`, freeze)};${n}` +
5111
+ `}${n}${n}`
5112
+ };
5113
+ function getDefaultLiveBinding(_) {
5114
+ return `e${_}:${_}{${_}'default':${_}e${_}}`;
5418
5115
  }
5419
- function errInvalidRollupPhaseForChunkEmission() {
5420
- return {
5421
- code: Errors.INVALID_ROLLUP_PHASE,
5422
- message: `Cannot emit chunks after module loading has finished.`
5423
- };
5116
+ function getDefaultStatic(_) {
5117
+ return `e['default']${_}:${_}e`;
5424
5118
  }
5425
- function errImplicitDependantCannotBeExternal(unresolvedId, implicitlyLoadedBefore) {
5426
- return {
5427
- code: Errors.MISSING_IMPLICIT_DEPENDANT,
5428
- message: `Module "${relativeId(unresolvedId)}" that should be implicitly loaded before "${relativeId(implicitlyLoadedBefore)}" cannot be external.`
5429
- };
5119
+ function createNamespaceObject(_, n, t, i, liveBindings, freeze, namespaceToStringTag) {
5120
+ return (`${i}var n${_}=${_}${namespaceToStringTag
5121
+ ? `{__proto__:${_}null,${_}[Symbol.toStringTag]:${_}'Module'}`
5122
+ : 'Object.create(null)'};${n}` +
5123
+ `${i}if${_}(e)${_}{${n}` +
5124
+ `${i}${t}Object.keys(e).forEach(function${_}(k)${_}{${n}` +
5125
+ (liveBindings ? copyPropertyLiveBinding : copyPropertyStatic)(_, n, t, i + t + t) +
5126
+ `${i}${t}});${n}` +
5127
+ `${i}}${n}` +
5128
+ `${i}n['default']${_}=${_}e;${n}` +
5129
+ `${i}return ${getFrozen('n', freeze)};${n}`);
5430
5130
  }
5431
- function errUnresolvedImplicitDependant(unresolvedId, implicitlyLoadedBefore) {
5432
- return {
5433
- code: Errors.MISSING_IMPLICIT_DEPENDANT,
5434
- message: `Module "${relativeId(unresolvedId)}" that should be implicitly loaded before "${relativeId(implicitlyLoadedBefore)}" could not be resolved.`
5435
- };
5131
+ function copyPropertyLiveBinding(_, n, t, i) {
5132
+ return (`${i}if${_}(k${_}!==${_}'default')${_}{${n}` +
5133
+ `${i}${t}var d${_}=${_}Object.getOwnPropertyDescriptor(e,${_}k);${n}` +
5134
+ `${i}${t}Object.defineProperty(n,${_}k,${_}d.get${_}?${_}d${_}:${_}{${n}` +
5135
+ `${i}${t}${t}enumerable:${_}true,${n}` +
5136
+ `${i}${t}${t}get:${_}function${_}()${_}{${n}` +
5137
+ `${i}${t}${t}${t}return e[k];${n}` +
5138
+ `${i}${t}${t}}${n}` +
5139
+ `${i}${t}});${n}` +
5140
+ `${i}}${n}`);
5436
5141
  }
5437
- function errImplicitDependantIsNotIncluded(module) {
5438
- const implicitDependencies = Array.from(module.implicitlyLoadedBefore, dependency => relativeId(dependency.id)).sort();
5439
- return {
5440
- code: Errors.MISSING_IMPLICIT_DEPENDANT,
5441
- message: `Module "${relativeId(module.id)}" that should be implicitly loaded before "${implicitDependencies.length === 1
5442
- ? implicitDependencies[0]
5443
- : `${implicitDependencies.slice(0, -1).join('", "')}" and "${implicitDependencies.slice(-1)[0]}`}" is not included in the module graph. Either it was not imported by an included module or only via a tree-shaken dynamic import, or no imported bindings were used and it had otherwise no side-effects.`
5444
- };
5142
+ function copyPropertyStatic(_, n, _t, i) {
5143
+ return `${i}n[k]${_}=${_}e[k];${n}`;
5445
5144
  }
5446
- function errMixedExport(facadeModuleId, name) {
5447
- return {
5448
- code: Errors.MIXED_EXPORTS,
5449
- id: facadeModuleId,
5450
- message: `Entry module "${relativeId(facadeModuleId)}" is using named and default exports together. Consumers of your bundle will have to use \`${name || 'chunk'}["default"]\` to access the default export, which may not be what you want. Use \`output.exports: "named"\` to disable this warning`,
5451
- url: `https://rollupjs.org/guide/en/#outputexports`
5452
- };
5145
+ function getFrozen(fragment, freeze) {
5146
+ return freeze ? `Object.freeze(${fragment})` : fragment;
5453
5147
  }
5454
- function errNamespaceConflict(name, reexportingModule, additionalExportAllModule) {
5455
- return {
5456
- code: Errors.NAMESPACE_CONFLICT,
5457
- message: `Conflicting namespaces: ${relativeId(reexportingModule.id)} re-exports '${name}' from both ${relativeId(reexportingModule.exportsAll[name])} and ${relativeId(additionalExportAllModule.exportsAll[name])} (will be ignored)`,
5458
- name,
5459
- reexporter: reexportingModule.id,
5460
- sources: [reexportingModule.exportsAll[name], additionalExportAllModule.exportsAll[name]]
5461
- };
5148
+ const HELPER_NAMES = Object.keys(HELPER_GENERATORS);
5149
+
5150
+ function getExportBlock(exports, dependencies, namedExportsMode, interop, compact, t, externalLiveBindings, mechanism = 'return ') {
5151
+ const _ = compact ? '' : ' ';
5152
+ const n = compact ? '' : '\n';
5153
+ if (!namedExportsMode) {
5154
+ return `${n}${n}${mechanism}${getSingleDefaultExport(exports, dependencies, interop, externalLiveBindings)};`;
5155
+ }
5156
+ let exportBlock = '';
5157
+ // star exports must always output first for precedence
5158
+ for (const { name, reexports } of dependencies) {
5159
+ if (reexports && namedExportsMode) {
5160
+ for (const specifier of reexports) {
5161
+ if (specifier.reexported === '*') {
5162
+ if (exportBlock)
5163
+ exportBlock += n;
5164
+ if (specifier.needsLiveBinding) {
5165
+ exportBlock +=
5166
+ `Object.keys(${name}).forEach(function${_}(k)${_}{${n}` +
5167
+ `${t}if${_}(k${_}!==${_}'default')${_}Object.defineProperty(exports,${_}k,${_}{${n}` +
5168
+ `${t}${t}enumerable:${_}true,${n}` +
5169
+ `${t}${t}get:${_}function${_}()${_}{${n}` +
5170
+ `${t}${t}${t}return ${name}[k];${n}` +
5171
+ `${t}${t}}${n}${t}});${n}});`;
5172
+ }
5173
+ else {
5174
+ exportBlock +=
5175
+ `Object.keys(${name}).forEach(function${_}(k)${_}{${n}` +
5176
+ `${t}if${_}(k${_}!==${_}'default')${_}exports[k]${_}=${_}${name}[k];${n}});`;
5177
+ }
5178
+ }
5179
+ }
5180
+ }
5181
+ }
5182
+ for (const { defaultVariableName, id, isChunk, name, namedExportsMode: depNamedExportsMode, namespaceVariableName, reexports } of dependencies) {
5183
+ if (reexports && namedExportsMode) {
5184
+ for (const specifier of reexports) {
5185
+ if (specifier.reexported !== '*') {
5186
+ const importName = getReexportedImportName(name, specifier.imported, depNamedExportsMode, isChunk, defaultVariableName, namespaceVariableName, interop, id, externalLiveBindings);
5187
+ if (exportBlock)
5188
+ exportBlock += n;
5189
+ exportBlock +=
5190
+ specifier.imported !== '*' && specifier.needsLiveBinding
5191
+ ? `Object.defineProperty(exports,${_}'${specifier.reexported}',${_}{${n}` +
5192
+ `${t}enumerable:${_}true,${n}` +
5193
+ `${t}get:${_}function${_}()${_}{${n}` +
5194
+ `${t}${t}return ${importName};${n}${t}}${n}});`
5195
+ : `exports.${specifier.reexported}${_}=${_}${importName};`;
5196
+ }
5197
+ }
5198
+ }
5199
+ }
5200
+ for (const chunkExport of exports) {
5201
+ const lhs = `exports.${chunkExport.exported}`;
5202
+ const rhs = chunkExport.local;
5203
+ if (lhs !== rhs) {
5204
+ if (exportBlock)
5205
+ exportBlock += n;
5206
+ exportBlock += `${lhs}${_}=${_}${rhs};`;
5207
+ }
5208
+ }
5209
+ if (exportBlock) {
5210
+ return `${n}${n}${exportBlock}`;
5211
+ }
5212
+ return '';
5462
5213
  }
5463
- function errNoTransformMapOrAstWithoutCode(pluginName) {
5464
- return {
5465
- code: Errors.NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE,
5466
- message: `The plugin "${pluginName}" returned a "map" or "ast" without returning ` +
5467
- 'a "code". This will be ignored.'
5468
- };
5214
+ function getSingleDefaultExport(exports, dependencies, interop, externalLiveBindings) {
5215
+ if (exports.length > 0) {
5216
+ return exports[0].local;
5217
+ }
5218
+ else {
5219
+ for (const { defaultVariableName, id, isChunk, name, namedExportsMode: depNamedExportsMode, namespaceVariableName, reexports } of dependencies) {
5220
+ if (reexports) {
5221
+ return getReexportedImportName(name, reexports[0].imported, depNamedExportsMode, isChunk, defaultVariableName, namespaceVariableName, interop, id, externalLiveBindings);
5222
+ }
5223
+ }
5224
+ }
5469
5225
  }
5470
- function errPreferNamedExports(facadeModuleId) {
5471
- const file = relativeId(facadeModuleId);
5472
- return {
5473
- code: Errors.PREFER_NAMED_EXPORTS,
5474
- id: facadeModuleId,
5475
- message: `Entry module "${file}" is implicitly using "default" export mode, which means for CommonJS output that its default export is assigned to "module.exports". For many tools, such CommonJS output will not be interchangeable with the original ES module. If this is intended, explicitly set "output.exports" to either "auto" or "default", otherwise you might want to consider changing the signature of "${file}" to use named exports only.`,
5476
- url: `https://rollupjs.org/guide/en/#outputexports`
5477
- };
5226
+ function getReexportedImportName(moduleVariableName, imported, depNamedExportsMode, isChunk, defaultVariableName, namespaceVariableName, interop, moduleId, externalLiveBindings) {
5227
+ if (imported === 'default') {
5228
+ if (!isChunk) {
5229
+ const moduleInterop = String(interop(moduleId));
5230
+ const variableName = defaultInteropHelpersByInteropType[moduleInterop]
5231
+ ? defaultVariableName
5232
+ : moduleVariableName;
5233
+ return isDefaultAProperty(moduleInterop, externalLiveBindings)
5234
+ ? `${variableName}['default']`
5235
+ : variableName;
5236
+ }
5237
+ return depNamedExportsMode ? `${moduleVariableName}['default']` : moduleVariableName;
5238
+ }
5239
+ if (imported === '*') {
5240
+ return (isChunk
5241
+ ? !depNamedExportsMode
5242
+ : namespaceInteropHelpersByInteropType[String(interop(moduleId))])
5243
+ ? namespaceVariableName
5244
+ : moduleVariableName;
5245
+ }
5246
+ return `${moduleVariableName}.${imported}`;
5478
5247
  }
5479
- function errUnexpectedNamedImport(id, imported, isReexport) {
5480
- const importType = isReexport ? 'reexport' : 'import';
5481
- return {
5482
- code: Errors.UNEXPECTED_NAMED_IMPORT,
5483
- id,
5484
- message: `The named export "${imported}" was ${importType}ed from the external module ${relativeId(id)} even though its interop type is "defaultOnly". Either remove or change this ${importType} or change the value of the "output.interop" option.`,
5485
- url: 'https://rollupjs.org/guide/en/#outputinterop'
5486
- };
5248
+ function getEsModuleExport(_) {
5249
+ return `Object.defineProperty(exports,${_}'__esModule',${_}{${_}value:${_}true${_}});`;
5487
5250
  }
5488
- function errUnexpectedNamespaceReexport(id) {
5489
- return {
5490
- code: Errors.UNEXPECTED_NAMED_IMPORT,
5491
- id,
5492
- message: `There was a namespace "*" reexport from the external module ${relativeId(id)} even though its interop type is "defaultOnly". This will be ignored as namespace reexports only reexport named exports. If this is not intended, either remove or change this reexport or change the value of the "output.interop" option.`,
5493
- url: 'https://rollupjs.org/guide/en/#outputinterop'
5494
- };
5251
+ function getNamespaceToStringExport(_) {
5252
+ return `exports[Symbol.toStringTag]${_}=${_}'Module';`;
5495
5253
  }
5496
- function errEntryCannotBeExternal(unresolvedId) {
5497
- return {
5498
- code: Errors.UNRESOLVED_ENTRY,
5499
- message: `Entry module cannot be external (${relativeId(unresolvedId)}).`
5500
- };
5254
+ function getNamespaceMarkers(hasNamedExports, addEsModule, addNamespaceToStringTag, _, n) {
5255
+ let namespaceMarkers = '';
5256
+ if (hasNamedExports) {
5257
+ if (addEsModule) {
5258
+ namespaceMarkers += getEsModuleExport(_);
5259
+ }
5260
+ if (addNamespaceToStringTag) {
5261
+ if (namespaceMarkers) {
5262
+ namespaceMarkers += n;
5263
+ }
5264
+ namespaceMarkers += getNamespaceToStringExport(_);
5265
+ }
5266
+ }
5267
+ return namespaceMarkers;
5501
5268
  }
5502
- function errUnresolvedEntry(unresolvedId) {
5503
- return {
5504
- code: Errors.UNRESOLVED_ENTRY,
5505
- message: `Could not resolve entry module (${relativeId(unresolvedId)}).`
5269
+
5270
+ function getInteropBlock(dependencies, varOrConst, interop, externalLiveBindings, freeze, namespaceToStringTag, accessedGlobals, _, n, s, t) {
5271
+ const neededInteropHelpers = new Set();
5272
+ const interopStatements = [];
5273
+ const addInteropStatement = (helperVariableName, helper, dependencyVariableName) => {
5274
+ neededInteropHelpers.add(helper);
5275
+ interopStatements.push(`${varOrConst} ${helperVariableName}${_}=${_}/*#__PURE__*/${helper}(${dependencyVariableName});`);
5506
5276
  };
5277
+ for (const { defaultVariableName, imports, id, isChunk, name, namedExportsMode, namespaceVariableName, reexports } of dependencies) {
5278
+ if (isChunk) {
5279
+ for (const { imported, reexported } of [
5280
+ ...(imports || []),
5281
+ ...(reexports || [])
5282
+ ]) {
5283
+ if (imported === '*' && reexported !== '*') {
5284
+ if (!namedExportsMode) {
5285
+ addInteropStatement(namespaceVariableName, getDefaultOnlyHelper(), name);
5286
+ }
5287
+ break;
5288
+ }
5289
+ }
5290
+ }
5291
+ else {
5292
+ const moduleInterop = String(interop(id));
5293
+ let hasDefault = false;
5294
+ let hasNamespace = false;
5295
+ for (const { imported, reexported } of [
5296
+ ...(imports || []),
5297
+ ...(reexports || [])
5298
+ ]) {
5299
+ let helper;
5300
+ let variableName;
5301
+ if (imported === 'default') {
5302
+ if (!hasDefault) {
5303
+ hasDefault = true;
5304
+ if (defaultVariableName !== namespaceVariableName) {
5305
+ variableName = defaultVariableName;
5306
+ helper = defaultInteropHelpersByInteropType[moduleInterop];
5307
+ }
5308
+ }
5309
+ }
5310
+ else if (imported === '*' && reexported !== '*') {
5311
+ if (!hasNamespace) {
5312
+ hasNamespace = true;
5313
+ helper = namespaceInteropHelpersByInteropType[moduleInterop];
5314
+ variableName = namespaceVariableName;
5315
+ }
5316
+ }
5317
+ if (helper) {
5318
+ addInteropStatement(variableName, helper, name);
5319
+ }
5320
+ }
5321
+ }
5322
+ }
5323
+ return `${getHelpersBlock(neededInteropHelpers, accessedGlobals, _, n, s, t, externalLiveBindings, freeze, namespaceToStringTag)}${interopStatements.length > 0 ? `${interopStatements.join(n)}${n}${n}` : ''}`;
5507
5324
  }
5508
- function errUnresolvedImport(source, importer) {
5509
- return {
5510
- code: Errors.UNRESOLVED_IMPORT,
5511
- message: `Could not resolve '${source}' from ${relativeId(importer)}`
5512
- };
5325
+
5326
+ // AMD resolution will only respect the AMD baseUrl if the .js extension is omitted.
5327
+ // The assumption is that this makes sense for all relative ids:
5328
+ // https://requirejs.org/docs/api.html#jsfiles
5329
+ function removeExtensionFromRelativeAmdId(id) {
5330
+ return id[0] === '.' ? removeJsExtension(id) : id;
5513
5331
  }
5514
- function errUnresolvedImportTreatedAsExternal(source, importer) {
5515
- return {
5516
- code: Errors.UNRESOLVED_IMPORT,
5517
- importer: relativeId(importer),
5518
- message: `'${source}' is imported by ${relativeId(importer)}, but could not be resolved – treating it as an external dependency`,
5519
- source,
5520
- url: 'https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency'
5521
- };
5332
+
5333
+ const builtins$1 = {
5334
+ assert: true,
5335
+ buffer: true,
5336
+ console: true,
5337
+ constants: true,
5338
+ domain: true,
5339
+ events: true,
5340
+ http: true,
5341
+ https: true,
5342
+ os: true,
5343
+ path: true,
5344
+ process: true,
5345
+ punycode: true,
5346
+ querystring: true,
5347
+ stream: true,
5348
+ string_decoder: true,
5349
+ timers: true,
5350
+ tty: true,
5351
+ url: true,
5352
+ util: true,
5353
+ vm: true,
5354
+ zlib: true
5355
+ };
5356
+ function warnOnBuiltins(warn, dependencies) {
5357
+ const externalBuiltins = dependencies.map(({ id }) => id).filter(id => id in builtins$1);
5358
+ if (!externalBuiltins.length)
5359
+ return;
5360
+ const detail = externalBuiltins.length === 1
5361
+ ? `module ('${externalBuiltins[0]}')`
5362
+ : `modules (${externalBuiltins
5363
+ .slice(0, -1)
5364
+ .map(name => `'${name}'`)
5365
+ .join(', ')} and '${externalBuiltins.slice(-1)}')`;
5366
+ warn({
5367
+ code: 'MISSING_NODE_BUILTINS',
5368
+ message: `Creating a browser bundle that depends on Node.js built-in ${detail}. You might need to include https://github.com/ionic-team/rollup-plugin-node-polyfills`,
5369
+ modules: externalBuiltins
5370
+ });
5522
5371
  }
5523
- function errExternalSyntheticExports(source, importer) {
5524
- return {
5525
- code: Errors.EXTERNAL_SYNTHETIC_EXPORTS,
5526
- importer: relativeId(importer),
5527
- message: `External '${source}' can not have 'syntheticNamedExports' enabled.`,
5528
- source
5529
- };
5372
+
5373
+ function amd(magicString, { accessedGlobals, dependencies, exports, hasExports, id, indentString: t, intro, isEntryFacade, isModuleFacade, namedExportsMode, outro, varOrConst, warn }, { amd, compact, esModule, externalLiveBindings, freeze, interop, namespaceToStringTag, strict }) {
5374
+ warnOnBuiltins(warn, dependencies);
5375
+ const deps = dependencies.map(m => `'${removeExtensionFromRelativeAmdId(m.id)}'`);
5376
+ const args = dependencies.map(m => m.name);
5377
+ const n = compact ? '' : '\n';
5378
+ const s = compact ? '' : ';';
5379
+ const _ = compact ? '' : ' ';
5380
+ if (namedExportsMode && hasExports) {
5381
+ args.unshift(`exports`);
5382
+ deps.unshift(`'exports'`);
5383
+ }
5384
+ if (accessedGlobals.has('require')) {
5385
+ args.unshift('require');
5386
+ deps.unshift(`'require'`);
5387
+ }
5388
+ if (accessedGlobals.has('module')) {
5389
+ args.unshift('module');
5390
+ deps.unshift(`'module'`);
5391
+ }
5392
+ const completeAmdId = getCompleteAmdId(amd, id);
5393
+ const params = (completeAmdId ? `'${completeAmdId}',${_}` : ``) +
5394
+ (deps.length ? `[${deps.join(`,${_}`)}],${_}` : ``);
5395
+ const useStrict = strict ? `${_}'use strict';` : '';
5396
+ magicString.prepend(`${intro}${getInteropBlock(dependencies, varOrConst, interop, externalLiveBindings, freeze, namespaceToStringTag, accessedGlobals, _, n, s, t)}`);
5397
+ const exportBlock = getExportBlock(exports, dependencies, namedExportsMode, interop, compact, t, externalLiveBindings);
5398
+ let namespaceMarkers = getNamespaceMarkers(namedExportsMode && hasExports, isEntryFacade && esModule, isModuleFacade && namespaceToStringTag, _, n);
5399
+ if (namespaceMarkers) {
5400
+ namespaceMarkers = n + n + namespaceMarkers;
5401
+ }
5402
+ magicString.append(`${exportBlock}${namespaceMarkers}${outro}`);
5403
+ return magicString
5404
+ .indent(t)
5405
+ .prepend(`${amd.define}(${params}function${_}(${args.join(`,${_}`)})${_}{${useStrict}${n}${n}`)
5406
+ .append(`${n}${n}});`);
5530
5407
  }
5531
- function errFailedValidation(message) {
5532
- return {
5533
- code: Errors.VALIDATION_ERROR,
5534
- message
5535
- };
5408
+
5409
+ function cjs(magicString, { accessedGlobals, dependencies, exports, hasExports, indentString: t, intro, isEntryFacade, isModuleFacade, namedExportsMode, outro, varOrConst }, { compact, esModule, externalLiveBindings, freeze, interop, namespaceToStringTag, strict }) {
5410
+ const n = compact ? '' : '\n';
5411
+ const s = compact ? '' : ';';
5412
+ const _ = compact ? '' : ' ';
5413
+ const useStrict = strict ? `'use strict';${n}${n}` : '';
5414
+ let namespaceMarkers = getNamespaceMarkers(namedExportsMode && hasExports, isEntryFacade && esModule, isModuleFacade && namespaceToStringTag, _, n);
5415
+ if (namespaceMarkers) {
5416
+ namespaceMarkers += n + n;
5417
+ }
5418
+ const importBlock = getImportBlock(dependencies, compact, varOrConst, n, _);
5419
+ const interopBlock = getInteropBlock(dependencies, varOrConst, interop, externalLiveBindings, freeze, namespaceToStringTag, accessedGlobals, _, n, s, t);
5420
+ magicString.prepend(`${useStrict}${intro}${namespaceMarkers}${importBlock}${interopBlock}`);
5421
+ const exportBlock = getExportBlock(exports, dependencies, namedExportsMode, interop, compact, t, externalLiveBindings, `module.exports${_}=${_}`);
5422
+ return magicString.append(`${exportBlock}${outro}`);
5536
5423
  }
5537
- function errAlreadyClosed() {
5538
- return {
5539
- code: Errors.ALREADY_CLOSED,
5540
- message: 'Bundle is already closed, no more calls to "generate" or "write" are allowed.'
5541
- };
5424
+ function getImportBlock(dependencies, compact, varOrConst, n, _) {
5425
+ let importBlock = '';
5426
+ let definingVariable = false;
5427
+ for (const { id, name, reexports, imports } of dependencies) {
5428
+ if (!reexports && !imports) {
5429
+ if (importBlock) {
5430
+ importBlock += !compact || definingVariable ? `;${n}` : ',';
5431
+ }
5432
+ definingVariable = false;
5433
+ importBlock += `require('${id}')`;
5434
+ }
5435
+ else {
5436
+ importBlock +=
5437
+ compact && definingVariable ? ',' : `${importBlock ? `;${n}` : ''}${varOrConst} `;
5438
+ definingVariable = true;
5439
+ importBlock += `${name}${_}=${_}require('${id}')`;
5440
+ }
5441
+ }
5442
+ if (importBlock) {
5443
+ return `${importBlock};${n}${n}`;
5444
+ }
5445
+ return '';
5542
5446
  }
5543
- function warnDeprecation(deprecation, activeDeprecation, options) {
5544
- warnDeprecationWithOptions(deprecation, activeDeprecation, options.onwarn, options.strictDeprecations);
5447
+
5448
+ function es(magicString, { intro, outro, dependencies, exports, varOrConst }, { compact }) {
5449
+ const _ = compact ? '' : ' ';
5450
+ const n = compact ? '' : '\n';
5451
+ const importBlock = getImportBlock$1(dependencies, _);
5452
+ if (importBlock.length > 0)
5453
+ intro += importBlock.join(n) + n + n;
5454
+ if (intro)
5455
+ magicString.prepend(intro);
5456
+ const exportBlock = getExportBlock$1(exports, _, varOrConst);
5457
+ if (exportBlock.length)
5458
+ magicString.append(n + n + exportBlock.join(n).trim());
5459
+ if (outro)
5460
+ magicString.append(outro);
5461
+ return magicString.trim();
5545
5462
  }
5546
- function warnDeprecationWithOptions(deprecation, activeDeprecation, warn, strictDeprecations) {
5547
- if (activeDeprecation || strictDeprecations) {
5548
- const warning = errDeprecation(deprecation);
5549
- if (strictDeprecations) {
5550
- return error(warning);
5463
+ function getImportBlock$1(dependencies, _) {
5464
+ const importBlock = [];
5465
+ for (const { id, reexports, imports, name } of dependencies) {
5466
+ if (!reexports && !imports) {
5467
+ importBlock.push(`import${_}'${id}';`);
5468
+ continue;
5551
5469
  }
5552
- warn(warning);
5470
+ if (imports) {
5471
+ let defaultImport = null;
5472
+ let starImport = null;
5473
+ const importedNames = [];
5474
+ for (const specifier of imports) {
5475
+ if (specifier.imported === 'default') {
5476
+ defaultImport = specifier;
5477
+ }
5478
+ else if (specifier.imported === '*') {
5479
+ starImport = specifier;
5480
+ }
5481
+ else {
5482
+ importedNames.push(specifier);
5483
+ }
5484
+ }
5485
+ if (starImport) {
5486
+ importBlock.push(`import${_}*${_}as ${starImport.local} from${_}'${id}';`);
5487
+ }
5488
+ if (defaultImport && importedNames.length === 0) {
5489
+ importBlock.push(`import ${defaultImport.local} from${_}'${id}';`);
5490
+ }
5491
+ else if (importedNames.length > 0) {
5492
+ importBlock.push(`import ${defaultImport ? `${defaultImport.local},${_}` : ''}{${_}${importedNames
5493
+ .map(specifier => {
5494
+ if (specifier.imported === specifier.local) {
5495
+ return specifier.imported;
5496
+ }
5497
+ else {
5498
+ return `${specifier.imported} as ${specifier.local}`;
5499
+ }
5500
+ })
5501
+ .join(`,${_}`)}${_}}${_}from${_}'${id}';`);
5502
+ }
5503
+ }
5504
+ if (reexports) {
5505
+ let starExport = null;
5506
+ const namespaceReexports = [];
5507
+ const namedReexports = [];
5508
+ for (const specifier of reexports) {
5509
+ if (specifier.reexported === '*') {
5510
+ starExport = specifier;
5511
+ }
5512
+ else if (specifier.imported === '*') {
5513
+ namespaceReexports.push(specifier);
5514
+ }
5515
+ else {
5516
+ namedReexports.push(specifier);
5517
+ }
5518
+ }
5519
+ if (starExport) {
5520
+ importBlock.push(`export${_}*${_}from${_}'${id}';`);
5521
+ }
5522
+ if (namespaceReexports.length > 0) {
5523
+ if (!imports ||
5524
+ !imports.some(specifier => specifier.imported === '*' && specifier.local === name)) {
5525
+ importBlock.push(`import${_}*${_}as ${name} from${_}'${id}';`);
5526
+ }
5527
+ for (const specifier of namespaceReexports) {
5528
+ importBlock.push(`export${_}{${_}${name === specifier.reexported ? name : `${name} as ${specifier.reexported}`} };`);
5529
+ }
5530
+ }
5531
+ if (namedReexports.length > 0) {
5532
+ importBlock.push(`export${_}{${_}${namedReexports
5533
+ .map(specifier => {
5534
+ if (specifier.imported === specifier.reexported) {
5535
+ return specifier.imported;
5536
+ }
5537
+ else {
5538
+ return `${specifier.imported} as ${specifier.reexported}`;
5539
+ }
5540
+ })
5541
+ .join(`,${_}`)}${_}}${_}from${_}'${id}';`);
5542
+ }
5543
+ }
5544
+ }
5545
+ return importBlock;
5546
+ }
5547
+ function getExportBlock$1(exports, _, varOrConst) {
5548
+ const exportBlock = [];
5549
+ const exportDeclaration = [];
5550
+ for (const specifier of exports) {
5551
+ if (specifier.exported === 'default') {
5552
+ exportBlock.push(`export default ${specifier.local};`);
5553
+ }
5554
+ else {
5555
+ if (specifier.expression) {
5556
+ exportBlock.push(`${varOrConst} ${specifier.local}${_}=${_}${specifier.expression};`);
5557
+ }
5558
+ exportDeclaration.push(specifier.exported === specifier.local
5559
+ ? specifier.local
5560
+ : `${specifier.local} as ${specifier.exported}`);
5561
+ }
5562
+ }
5563
+ if (exportDeclaration.length) {
5564
+ exportBlock.push(`export${_}{${_}${exportDeclaration.join(`,${_}`)}${_}};`);
5553
5565
  }
5566
+ return exportBlock;
5554
5567
  }
5555
5568
 
5556
5569
  // Generate strings which dereference dotted properties, but use array notation `['prop-deref']`
@@ -6221,7 +6234,8 @@ class AssignmentExpression extends NodeBase {
6221
6234
  this.right.render(code, options, {
6222
6235
  renderedParentType: renderedParentType || this.parent.type
6223
6236
  });
6224
- code.remove(this.start, this.right.start);
6237
+ const operatorPos = findFirstOccurrenceOutsideComment(code.original, '=', this.left.end);
6238
+ code.remove(this.start, findNonWhiteSpace(code.original, operatorPos + 1));
6225
6239
  }
6226
6240
  if (options.format === 'system') {
6227
6241
  const exportNames = this.left.variable && options.exportNamesByVariable.get(this.left.variable);
@@ -6465,7 +6479,6 @@ class MemberExpression extends NodeBase {
6465
6479
  this.replacement = null;
6466
6480
  this.wasPathDeoptimizedWhileOptimized = false;
6467
6481
  }
6468
- addExportedVariables() { }
6469
6482
  bind() {
6470
6483
  if (this.bound)
6471
6484
  return;
@@ -6572,7 +6585,7 @@ class MemberExpression extends NodeBase {
6572
6585
  if (!this.included) {
6573
6586
  this.included = true;
6574
6587
  if (this.variable !== null) {
6575
- this.context.includeVariable(this.variable);
6588
+ this.context.includeVariableInModule(this.variable);
6576
6589
  }
6577
6590
  }
6578
6591
  this.object.include(context, includeChildrenRecursively);
@@ -6612,7 +6625,7 @@ class MemberExpression extends NodeBase {
6612
6625
  const variable = this.scope.findVariable(this.object.name);
6613
6626
  if (variable.isNamespace) {
6614
6627
  if (this.variable) {
6615
- this.context.includeVariable(this.variable);
6628
+ this.context.includeVariableInModule(this.variable);
6616
6629
  }
6617
6630
  this.context.warn({
6618
6631
  code: 'ILLEGAL_NAMESPACE_REASSIGNMENT',
@@ -7240,7 +7253,7 @@ class ForInStatement extends NodeBase {
7240
7253
  }
7241
7254
  include(context, includeChildrenRecursively) {
7242
7255
  this.included = true;
7243
- this.left.includeWithAllDeclaredVariables(includeChildrenRecursively, context);
7256
+ this.left.includeAllDeclaredVariables(context, includeChildrenRecursively);
7244
7257
  this.left.deoptimizePath(EMPTY_PATH);
7245
7258
  this.right.include(context, includeChildrenRecursively);
7246
7259
  const { brokenFlow } = context;
@@ -7274,7 +7287,7 @@ class ForOfStatement extends NodeBase {
7274
7287
  }
7275
7288
  include(context, includeChildrenRecursively) {
7276
7289
  this.included = true;
7277
- this.left.includeWithAllDeclaredVariables(includeChildrenRecursively, context);
7290
+ this.left.includeAllDeclaredVariables(context, includeChildrenRecursively);
7278
7291
  this.left.deoptimizePath(EMPTY_PATH);
7279
7292
  this.right.include(context, includeChildrenRecursively);
7280
7293
  const { brokenFlow } = context;
@@ -8969,7 +8982,7 @@ function isReassignedExportsMember(variable, exportNamesByVariable) {
8969
8982
  }
8970
8983
  function areAllDeclarationsIncludedAndNotExported(declarations, exportNamesByVariable) {
8971
8984
  for (const declarator of declarations) {
8972
- if (!declarator.included)
8985
+ if (!declarator.id.included)
8973
8986
  return false;
8974
8987
  if (declarator.id.type === Identifier) {
8975
8988
  if (exportNamesByVariable.has(declarator.id.variable))
@@ -9000,10 +9013,11 @@ class VariableDeclaration extends NodeBase {
9000
9013
  declarator.include(context, includeChildrenRecursively);
9001
9014
  }
9002
9015
  }
9003
- includeWithAllDeclaredVariables(includeChildrenRecursively, context) {
9016
+ includeAllDeclaredVariables(context, includeChildrenRecursively) {
9004
9017
  this.included = true;
9005
9018
  for (const declarator of this.declarations) {
9006
- declarator.include(context, includeChildrenRecursively);
9019
+ declarator.id.included = true;
9020
+ declarator.includeAllDeclaredVariables(context, includeChildrenRecursively);
9007
9021
  }
9008
9022
  }
9009
9023
  initialise() {
@@ -9025,13 +9039,11 @@ class VariableDeclaration extends NodeBase {
9025
9039
  this.renderReplacedDeclarations(code, options, nodeRenderOptions);
9026
9040
  }
9027
9041
  }
9028
- renderDeclarationEnd(code, separatorString, lastSeparatorPos, actualContentEnd, renderedContentEnd, addSemicolon, systemPatternExports, options) {
9042
+ renderDeclarationEnd(code, separatorString, lastSeparatorPos, actualContentEnd, renderedContentEnd, systemPatternExports, options) {
9029
9043
  if (code.original.charCodeAt(this.end - 1) === 59 /*";"*/) {
9030
9044
  code.remove(this.end - 1, this.end);
9031
9045
  }
9032
- if (addSemicolon) {
9033
- separatorString += ';';
9034
- }
9046
+ separatorString += ';';
9035
9047
  if (lastSeparatorPos !== null) {
9036
9048
  if (code.original.charCodeAt(actualContentEnd - 1) === 10 /*"\n"*/ &&
9037
9049
  (code.original.charCodeAt(this.end) === 10 /*"\n"*/ ||
@@ -9056,15 +9068,10 @@ class VariableDeclaration extends NodeBase {
9056
9068
  code.appendLeft(renderedContentEnd, ` ${getSystemExportStatement(systemPatternExports, options)};`);
9057
9069
  }
9058
9070
  }
9059
- renderReplacedDeclarations(code, options, { start = this.start, end = this.end, isNoStatement }) {
9071
+ renderReplacedDeclarations(code, options, { start = this.start, end = this.end }) {
9060
9072
  const separatedNodes = getCommaSeparatedNodesWithBoundaries(this.declarations, code, this.start + this.kind.length, this.end - (code.original.charCodeAt(this.end - 1) === 59 /*";"*/ ? 1 : 0));
9061
9073
  let actualContentEnd, renderedContentEnd;
9062
- if (/\n\s*$/.test(code.slice(this.start, separatedNodes[0].start))) {
9063
- renderedContentEnd = this.start + this.kind.length;
9064
- }
9065
- else {
9066
- renderedContentEnd = separatedNodes[0].start;
9067
- }
9074
+ renderedContentEnd = findNonWhiteSpace(code.original, this.start + this.kind.length);
9068
9075
  let lastSeparatorPos = renderedContentEnd - 1;
9069
9076
  code.remove(this.start, lastSeparatorPos);
9070
9077
  let isInDeclaration = false;
@@ -9081,8 +9088,9 @@ class VariableDeclaration extends NodeBase {
9081
9088
  }
9082
9089
  leadingString = '';
9083
9090
  nextSeparatorString = '';
9084
- if (node.id instanceof Identifier$1 &&
9085
- isReassignedExportsMember(node.id.variable, options.exportNamesByVariable)) {
9091
+ if (!node.id.included ||
9092
+ (node.id instanceof Identifier$1 &&
9093
+ isReassignedExportsMember(node.id.variable, options.exportNamesByVariable))) {
9086
9094
  if (hasRenderedContent) {
9087
9095
  separatorString += ';';
9088
9096
  }
@@ -9131,7 +9139,7 @@ class VariableDeclaration extends NodeBase {
9131
9139
  separatorString = nextSeparatorString;
9132
9140
  }
9133
9141
  if (hasRenderedContent) {
9134
- this.renderDeclarationEnd(code, separatorString, lastSeparatorPos, actualContentEnd, renderedContentEnd, !isNoStatement, systemPatternExports, options);
9142
+ this.renderDeclarationEnd(code, separatorString, lastSeparatorPos, actualContentEnd, renderedContentEnd, systemPatternExports, options);
9135
9143
  }
9136
9144
  else {
9137
9145
  code.remove(start, end);
@@ -9146,6 +9154,35 @@ class VariableDeclarator extends NodeBase {
9146
9154
  deoptimizePath(path) {
9147
9155
  this.id.deoptimizePath(path);
9148
9156
  }
9157
+ hasEffects(context) {
9158
+ return this.id.hasEffects(context) || (this.init !== null && this.init.hasEffects(context));
9159
+ }
9160
+ include(context, includeChildrenRecursively) {
9161
+ this.included = true;
9162
+ if (includeChildrenRecursively || this.id.shouldBeIncluded(context)) {
9163
+ this.id.include(context, includeChildrenRecursively);
9164
+ }
9165
+ if (this.init) {
9166
+ this.init.include(context, includeChildrenRecursively);
9167
+ }
9168
+ }
9169
+ includeAllDeclaredVariables(context, includeChildrenRecursively) {
9170
+ this.included = true;
9171
+ this.id.include(context, includeChildrenRecursively);
9172
+ }
9173
+ render(code, options) {
9174
+ const renderId = this.id.included;
9175
+ if (renderId) {
9176
+ this.id.render(code, options);
9177
+ }
9178
+ else {
9179
+ const operatorPos = findFirstOccurrenceOutsideComment(code.original, '=', this.id.end);
9180
+ code.remove(this.start, findNonWhiteSpace(code.original, operatorPos + 1));
9181
+ }
9182
+ if (this.init) {
9183
+ this.init.render(code, options, renderId ? BLANK : { renderedParentType: ExpressionStatement });
9184
+ }
9185
+ }
9149
9186
  }
9150
9187
 
9151
9188
  class WhileStatement extends NodeBase {
@@ -9721,6 +9758,24 @@ function initialiseTimers(inputOptions) {
9721
9758
  }
9722
9759
  }
9723
9760
 
9761
+ function markModuleAndImpureDependenciesAsExecuted(baseModule) {
9762
+ baseModule.isExecuted = true;
9763
+ const modules = [baseModule];
9764
+ const visitedModules = new Set();
9765
+ for (const module of modules) {
9766
+ for (const dependency of [...module.dependencies, ...module.implicitlyLoadedBefore]) {
9767
+ if (!(dependency instanceof ExternalModule) &&
9768
+ !dependency.isExecuted &&
9769
+ (dependency.info.hasModuleSideEffects || module.implicitlyLoadedBefore.has(dependency)) &&
9770
+ !visitedModules.has(dependency.id)) {
9771
+ dependency.isExecuted = true;
9772
+ visitedModules.add(dependency.id);
9773
+ modules.push(dependency);
9774
+ }
9775
+ }
9776
+ }
9777
+ }
9778
+
9724
9779
  function tryParse(module, Parser, acornOptions) {
9725
9780
  try {
9726
9781
  return Parser.parse(module.info.code, {
@@ -9743,39 +9798,60 @@ function tryParse(module, Parser, acornOptions) {
9743
9798
  }, err.pos);
9744
9799
  }
9745
9800
  }
9746
- function handleMissingExport(exportName, importingModule, importedModule, importerStart) {
9747
- return importingModule.error({
9748
- code: 'MISSING_EXPORT',
9749
- message: `'${exportName}' is not exported by ${relativeId(importedModule)}, imported by ${relativeId(importingModule.id)}`,
9750
- url: `https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module`
9751
- }, importerStart);
9752
- }
9753
9801
  const MISSING_EXPORT_SHIM_DESCRIPTION = {
9754
9802
  identifier: null,
9755
9803
  localName: MISSING_EXPORT_SHIM_VARIABLE
9756
9804
  };
9757
- function getVariableForExportNameRecursive(target, name, isExportAllSearch, searchedNamesAndModules = new Map()) {
9805
+ function getVariableForExportNameRecursive(target, name, importerForSideEffects, isExportAllSearch, searchedNamesAndModules = new Map()) {
9758
9806
  const searchedModules = searchedNamesAndModules.get(name);
9759
9807
  if (searchedModules) {
9760
9808
  if (searchedModules.has(target)) {
9761
- return null;
9809
+ return isExportAllSearch ? null : error(errCircularReexport(name, target.id));
9762
9810
  }
9763
9811
  searchedModules.add(target);
9764
9812
  }
9765
9813
  else {
9766
9814
  searchedNamesAndModules.set(name, new Set([target]));
9767
9815
  }
9768
- return target.getVariableForExportName(name, isExportAllSearch, searchedNamesAndModules);
9816
+ return target.getVariableForExportName(name, importerForSideEffects, isExportAllSearch, searchedNamesAndModules);
9817
+ }
9818
+ function getAndExtendSideEffectModules(variable, module) {
9819
+ const sideEffectModules = getOrCreate(module.sideEffectDependenciesByVariable, variable, () => new Set());
9820
+ let currentVariable = variable;
9821
+ const referencedVariables = new Set([currentVariable]);
9822
+ while (true) {
9823
+ const importingModule = currentVariable.module;
9824
+ currentVariable =
9825
+ currentVariable instanceof ExportDefaultVariable
9826
+ ? currentVariable.getDirectOriginalVariable()
9827
+ : currentVariable instanceof SyntheticNamedExportVariable
9828
+ ? currentVariable.syntheticNamespace
9829
+ : null;
9830
+ if (!currentVariable || referencedVariables.has(currentVariable)) {
9831
+ break;
9832
+ }
9833
+ referencedVariables.add(variable);
9834
+ sideEffectModules.add(importingModule);
9835
+ const originalSideEffects = importingModule.sideEffectDependenciesByVariable.get(currentVariable);
9836
+ if (originalSideEffects) {
9837
+ for (const module of originalSideEffects) {
9838
+ sideEffectModules.add(module);
9839
+ }
9840
+ }
9841
+ }
9842
+ return sideEffectModules;
9769
9843
  }
9770
9844
  class Module {
9771
9845
  constructor(graph, id, options, isEntry, hasModuleSideEffects, syntheticNamedExports, meta) {
9772
9846
  this.graph = graph;
9773
9847
  this.id = id;
9774
9848
  this.options = options;
9849
+ this.alternativeReexportModules = new Map();
9775
9850
  this.ast = null;
9776
9851
  this.chunkFileNames = new Set();
9777
9852
  this.chunkName = null;
9778
9853
  this.comments = [];
9854
+ this.cycles = new Set();
9779
9855
  this.dependencies = new Set();
9780
9856
  this.dynamicDependencies = new Set();
9781
9857
  this.dynamicImporters = [];
@@ -9795,6 +9871,7 @@ class Module {
9795
9871
  this.isUserDefinedEntryPoint = false;
9796
9872
  this.preserveSignature = this.options.preserveEntrySignatures;
9797
9873
  this.reexportDescriptions = Object.create(null);
9874
+ this.sideEffectDependenciesByVariable = new Map();
9798
9875
  this.sources = new Set();
9799
9876
  this.userChunkNames = new Set();
9800
9877
  this.usesTopLevelAwait = false;
@@ -9884,9 +9961,9 @@ class Module {
9884
9961
  if (this.relevantDependencies)
9885
9962
  return this.relevantDependencies;
9886
9963
  const relevantDependencies = new Set();
9887
- const additionalSideEffectModules = new Set();
9888
- const possibleDependencies = new Set(this.dependencies);
9889
- let dependencyVariables = this.imports;
9964
+ const necessaryDependencies = new Set();
9965
+ const alwaysCheckedDependencies = new Set();
9966
+ let dependencyVariables = this.imports.keys();
9890
9967
  if (this.info.isEntry ||
9891
9968
  this.includedDynamicImporters.length > 0 ||
9892
9969
  this.namespace.included ||
@@ -9897,41 +9974,31 @@ class Module {
9897
9974
  }
9898
9975
  }
9899
9976
  for (let variable of dependencyVariables) {
9977
+ const sideEffectDependencies = this.sideEffectDependenciesByVariable.get(variable);
9978
+ if (sideEffectDependencies) {
9979
+ for (const module of sideEffectDependencies) {
9980
+ alwaysCheckedDependencies.add(module);
9981
+ }
9982
+ }
9900
9983
  if (variable instanceof SyntheticNamedExportVariable) {
9901
9984
  variable = variable.getBaseVariable();
9902
9985
  }
9903
9986
  else if (variable instanceof ExportDefaultVariable) {
9904
- const { modules, original } = variable.getOriginalVariableAndDeclarationModules();
9905
- variable = original;
9906
- for (const module of modules) {
9907
- additionalSideEffectModules.add(module);
9908
- possibleDependencies.add(module);
9909
- }
9987
+ variable = variable.getOriginalVariable();
9910
9988
  }
9911
- relevantDependencies.add(variable.module);
9989
+ necessaryDependencies.add(variable.module);
9912
9990
  }
9913
9991
  if (this.options.treeshake && this.info.hasModuleSideEffects !== 'no-treeshake') {
9914
- for (const dependency of possibleDependencies) {
9915
- if (!(dependency.info.hasModuleSideEffects ||
9916
- additionalSideEffectModules.has(dependency)) ||
9917
- relevantDependencies.has(dependency)) {
9918
- continue;
9919
- }
9920
- if (dependency instanceof ExternalModule || dependency.hasEffects()) {
9921
- relevantDependencies.add(dependency);
9922
- }
9923
- else {
9924
- for (const transitiveDependency of dependency.dependencies) {
9925
- possibleDependencies.add(transitiveDependency);
9926
- }
9927
- }
9928
- }
9992
+ this.addRelevantSideEffectDependencies(relevantDependencies, necessaryDependencies, alwaysCheckedDependencies);
9929
9993
  }
9930
9994
  else {
9931
9995
  for (const dependency of this.dependencies) {
9932
9996
  relevantDependencies.add(dependency);
9933
9997
  }
9934
9998
  }
9999
+ for (const dependency of necessaryDependencies) {
10000
+ relevantDependencies.add(dependency);
10001
+ }
9935
10002
  return (this.relevantDependencies = relevantDependencies);
9936
10003
  }
9937
10004
  getExportNamesByVariable() {
@@ -10004,20 +10071,14 @@ class Module {
10004
10071
  : 'default');
10005
10072
  }
10006
10073
  if (!this.syntheticNamespace) {
10007
- return error({
10008
- code: Errors.SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT,
10009
- id: this.id,
10010
- message: `Module "${relativeId(this.id)}" that is marked with 'syntheticNamedExports: ${JSON.stringify(this.info.syntheticNamedExports)}' needs ${typeof this.info.syntheticNamedExports === 'string' &&
10011
- this.info.syntheticNamedExports !== 'default'
10012
- ? `an export named "${this.info.syntheticNamedExports}"`
10013
- : 'a default export'}.`
10014
- });
10074
+ return error(errSyntheticNamedExportsNeedNamespaceExport(this.id, this.info.syntheticNamedExports));
10015
10075
  }
10016
10076
  return this.syntheticNamespace;
10017
10077
  }
10018
- getVariableForExportName(name, isExportAllSearch, searchedNamesAndModules) {
10078
+ getVariableForExportName(name, importerForSideEffects, isExportAllSearch, searchedNamesAndModules) {
10019
10079
  if (name[0] === '*') {
10020
10080
  if (name.length === 1) {
10081
+ // export * from './other'
10021
10082
  return this.namespace;
10022
10083
  }
10023
10084
  else {
@@ -10029,11 +10090,14 @@ class Module {
10029
10090
  // export { foo } from './other'
10030
10091
  const reexportDeclaration = this.reexportDescriptions[name];
10031
10092
  if (reexportDeclaration) {
10032
- const declaration = getVariableForExportNameRecursive(reexportDeclaration.module, reexportDeclaration.localName, false, searchedNamesAndModules);
10033
- if (!declaration) {
10034
- return handleMissingExport(reexportDeclaration.localName, this, reexportDeclaration.module.id, reexportDeclaration.start);
10093
+ const variable = getVariableForExportNameRecursive(reexportDeclaration.module, reexportDeclaration.localName, importerForSideEffects, false, searchedNamesAndModules);
10094
+ if (!variable) {
10095
+ return this.error(errMissingExport(reexportDeclaration.localName, this.id, reexportDeclaration.module.id), reexportDeclaration.start);
10035
10096
  }
10036
- return declaration;
10097
+ if (importerForSideEffects) {
10098
+ setAlternativeExporterIfCyclic(variable, importerForSideEffects, this);
10099
+ }
10100
+ return variable;
10037
10101
  }
10038
10102
  const exportDeclaration = this.exports[name];
10039
10103
  if (exportDeclaration) {
@@ -10041,28 +10105,43 @@ class Module {
10041
10105
  return this.exportShimVariable;
10042
10106
  }
10043
10107
  const name = exportDeclaration.localName;
10044
- return this.traceVariable(name);
10108
+ const variable = this.traceVariable(name, importerForSideEffects);
10109
+ if (importerForSideEffects) {
10110
+ getOrCreate(importerForSideEffects.sideEffectDependenciesByVariable, variable, () => new Set()).add(this);
10111
+ setAlternativeExporterIfCyclic(variable, importerForSideEffects, this);
10112
+ }
10113
+ return variable;
10045
10114
  }
10046
10115
  if (name !== 'default') {
10116
+ let foundSyntheticDeclaration = null;
10047
10117
  for (const module of this.exportAllModules) {
10048
- const declaration = getVariableForExportNameRecursive(module, name, true, searchedNamesAndModules);
10049
- if (declaration)
10050
- return declaration;
10118
+ const declaration = getVariableForExportNameRecursive(module, name, importerForSideEffects, true, searchedNamesAndModules);
10119
+ if (declaration) {
10120
+ if (!(declaration instanceof SyntheticNamedExportVariable)) {
10121
+ return declaration;
10122
+ }
10123
+ if (!foundSyntheticDeclaration) {
10124
+ foundSyntheticDeclaration = declaration;
10125
+ }
10126
+ }
10127
+ }
10128
+ if (foundSyntheticDeclaration) {
10129
+ return foundSyntheticDeclaration;
10130
+ }
10131
+ }
10132
+ if (this.info.syntheticNamedExports) {
10133
+ let syntheticExport = this.syntheticExports.get(name);
10134
+ if (!syntheticExport) {
10135
+ const syntheticNamespace = this.getSyntheticNamespace();
10136
+ syntheticExport = new SyntheticNamedExportVariable(this.astContext, name, syntheticNamespace);
10137
+ this.syntheticExports.set(name, syntheticExport);
10138
+ return syntheticExport;
10051
10139
  }
10140
+ return syntheticExport;
10052
10141
  }
10053
10142
  // we don't want to create shims when we are just
10054
10143
  // probing export * modules for exports
10055
10144
  if (!isExportAllSearch) {
10056
- if (this.info.syntheticNamedExports) {
10057
- let syntheticExport = this.syntheticExports.get(name);
10058
- if (!syntheticExport) {
10059
- const syntheticNamespace = this.getSyntheticNamespace();
10060
- syntheticExport = new SyntheticNamedExportVariable(this.astContext, name, syntheticNamespace);
10061
- this.syntheticExports.set(name, syntheticExport);
10062
- return syntheticExport;
10063
- }
10064
- return syntheticExport;
10065
- }
10066
10145
  if (this.options.shimMissingExports) {
10067
10146
  this.shimMissingExport(name);
10068
10147
  return this.exportShimVariable;
@@ -10089,8 +10168,7 @@ class Module {
10089
10168
  const variable = this.getVariableForExportName(exportName);
10090
10169
  variable.deoptimizePath(UNKNOWN_PATH);
10091
10170
  if (!variable.included) {
10092
- variable.include();
10093
- this.graph.needsTreeshakingPass = true;
10171
+ this.includeVariable(variable);
10094
10172
  }
10095
10173
  }
10096
10174
  }
@@ -10098,8 +10176,7 @@ class Module {
10098
10176
  const variable = this.getVariableForExportName(name);
10099
10177
  variable.deoptimizePath(UNKNOWN_PATH);
10100
10178
  if (!variable.included) {
10101
- variable.include();
10102
- this.graph.needsTreeshakingPass = true;
10179
+ this.includeVariable(variable);
10103
10180
  }
10104
10181
  if (variable instanceof ExternalVariable) {
10105
10182
  variable.module.reexported = true;
@@ -10119,7 +10196,7 @@ class Module {
10119
10196
  this.addModulesToImportDescriptions(this.importDescriptions);
10120
10197
  this.addModulesToImportDescriptions(this.reexportDescriptions);
10121
10198
  for (const name in this.exports) {
10122
- if (name !== 'default') {
10199
+ if (name !== 'default' && name !== this.info.syntheticNamedExports) {
10123
10200
  this.exportsAll[name] = this.id;
10124
10201
  }
10125
10202
  }
@@ -10199,7 +10276,7 @@ class Module {
10199
10276
  importDescriptions: this.importDescriptions,
10200
10277
  includeAllExports: () => this.includeAllExports(true),
10201
10278
  includeDynamicImport: this.includeDynamicImport.bind(this),
10202
- includeVariable: this.includeVariable.bind(this),
10279
+ includeVariableInModule: this.includeVariableInModule.bind(this),
10203
10280
  magicString: this.magicString,
10204
10281
  module: this,
10205
10282
  moduleContext: this.context,
@@ -10235,7 +10312,7 @@ class Module {
10235
10312
  transformFiles: this.transformFiles
10236
10313
  };
10237
10314
  }
10238
- traceVariable(name) {
10315
+ traceVariable(name, importerForSideEffects) {
10239
10316
  const localVariable = this.scope.variables.get(name);
10240
10317
  if (localVariable) {
10241
10318
  return localVariable;
@@ -10246,9 +10323,9 @@ class Module {
10246
10323
  if (otherModule instanceof Module && importDeclaration.name === '*') {
10247
10324
  return otherModule.namespace;
10248
10325
  }
10249
- const declaration = otherModule.getVariableForExportName(importDeclaration.name);
10326
+ const declaration = otherModule.getVariableForExportName(importDeclaration.name, importerForSideEffects || this);
10250
10327
  if (!declaration) {
10251
- return handleMissingExport(importDeclaration.name, this, otherModule.id, importDeclaration.start);
10328
+ return this.error(errMissingExport(importDeclaration.name, this.id, otherModule.id), importDeclaration.start);
10252
10329
  }
10253
10330
  return declaration;
10254
10331
  }
@@ -10400,6 +10477,31 @@ class Module {
10400
10477
  specifier.module = this.graph.modulesById.get(id);
10401
10478
  }
10402
10479
  }
10480
+ addRelevantSideEffectDependencies(relevantDependencies, necessaryDependencies, alwaysCheckedDependencies) {
10481
+ const handledDependencies = new Set();
10482
+ const addSideEffectDependencies = (possibleDependencies) => {
10483
+ for (const dependency of possibleDependencies) {
10484
+ if (handledDependencies.has(dependency)) {
10485
+ continue;
10486
+ }
10487
+ handledDependencies.add(dependency);
10488
+ if (necessaryDependencies.has(dependency)) {
10489
+ relevantDependencies.add(dependency);
10490
+ continue;
10491
+ }
10492
+ if (!(dependency.info.hasModuleSideEffects || alwaysCheckedDependencies.has(dependency))) {
10493
+ continue;
10494
+ }
10495
+ if (dependency instanceof ExternalModule || dependency.hasEffects()) {
10496
+ relevantDependencies.add(dependency);
10497
+ continue;
10498
+ }
10499
+ addSideEffectDependencies(dependency.dependencies);
10500
+ }
10501
+ };
10502
+ addSideEffectDependencies(this.dependencies);
10503
+ addSideEffectDependencies(alwaysCheckedDependencies);
10504
+ }
10403
10505
  includeAndGetAdditionalMergedNamespaces() {
10404
10506
  const mergedNamespaces = [];
10405
10507
  for (const module of this.exportAllModules) {
@@ -10426,11 +10528,26 @@ class Module {
10426
10528
  }
10427
10529
  }
10428
10530
  includeVariable(variable) {
10429
- const variableModule = variable.module;
10430
10531
  if (!variable.included) {
10431
10532
  variable.include();
10432
10533
  this.graph.needsTreeshakingPass = true;
10534
+ const variableModule = variable.module;
10535
+ if (variableModule && variableModule !== this && variableModule instanceof Module) {
10536
+ if (!variableModule.isExecuted) {
10537
+ markModuleAndImpureDependenciesAsExecuted(variableModule);
10538
+ }
10539
+ const sideEffectModules = getAndExtendSideEffectModules(variable, this);
10540
+ for (const module of sideEffectModules) {
10541
+ if (!module.isExecuted) {
10542
+ markModuleAndImpureDependenciesAsExecuted(module);
10543
+ }
10544
+ }
10545
+ }
10433
10546
  }
10547
+ }
10548
+ includeVariableInModule(variable) {
10549
+ this.includeVariable(variable);
10550
+ const variableModule = variable.module;
10434
10551
  if (variableModule && variableModule !== this) {
10435
10552
  this.imports.add(variable);
10436
10553
  }
@@ -10445,6 +10562,23 @@ class Module {
10445
10562
  this.exports[name] = MISSING_EXPORT_SHIM_DESCRIPTION;
10446
10563
  }
10447
10564
  }
10565
+ // if there is a cyclic import in the reexport chain, we should not
10566
+ // import from the original module but from the cyclic module to not
10567
+ // mess up execution order.
10568
+ function setAlternativeExporterIfCyclic(variable, importer, reexporter) {
10569
+ if (variable.module instanceof Module && variable.module !== reexporter) {
10570
+ const exporterCycles = variable.module.cycles;
10571
+ if (exporterCycles.size > 0) {
10572
+ const importerCycles = reexporter.cycles;
10573
+ for (const cycleSymbol of importerCycles) {
10574
+ if (exporterCycles.has(cycleSymbol)) {
10575
+ importer.alternativeReexportModules.set(variable, reexporter);
10576
+ break;
10577
+ }
10578
+ }
10579
+ }
10580
+ }
10581
+ }
10448
10582
 
10449
10583
  class Source {
10450
10584
  constructor(filename, content) {
@@ -10731,68 +10865,6 @@ function escapeId(id) {
10731
10865
  return id.replace(backSlashRegEx, '\\\\').replace(quoteNewlineRegEx, '\\$1');
10732
10866
  }
10733
10867
 
10734
- const compareExecIndex = (unitA, unitB) => unitA.execIndex > unitB.execIndex ? 1 : -1;
10735
- function sortByExecutionOrder(units) {
10736
- units.sort(compareExecIndex);
10737
- }
10738
- function analyseModuleExecution(entryModules) {
10739
- let nextExecIndex = 0;
10740
- const cyclePaths = [];
10741
- const analysedModules = new Set();
10742
- const dynamicImports = new Set();
10743
- const parents = new Map();
10744
- const orderedModules = [];
10745
- const analyseModule = (module) => {
10746
- if (module instanceof Module) {
10747
- for (const dependency of module.dependencies) {
10748
- if (parents.has(dependency)) {
10749
- if (!analysedModules.has(dependency)) {
10750
- cyclePaths.push(getCyclePath(dependency, module, parents));
10751
- }
10752
- continue;
10753
- }
10754
- parents.set(dependency, module);
10755
- analyseModule(dependency);
10756
- }
10757
- for (const dependency of module.implicitlyLoadedBefore) {
10758
- dynamicImports.add(dependency);
10759
- }
10760
- for (const { resolution } of module.dynamicImports) {
10761
- if (resolution instanceof Module) {
10762
- dynamicImports.add(resolution);
10763
- }
10764
- }
10765
- orderedModules.push(module);
10766
- }
10767
- module.execIndex = nextExecIndex++;
10768
- analysedModules.add(module);
10769
- };
10770
- for (const curEntry of entryModules) {
10771
- if (!parents.has(curEntry)) {
10772
- parents.set(curEntry, null);
10773
- analyseModule(curEntry);
10774
- }
10775
- }
10776
- for (const curEntry of dynamicImports) {
10777
- if (!parents.has(curEntry)) {
10778
- parents.set(curEntry, null);
10779
- analyseModule(curEntry);
10780
- }
10781
- }
10782
- return { orderedModules, cyclePaths };
10783
- }
10784
- function getCyclePath(module, parent, parents) {
10785
- const path = [relativeId(module.id)];
10786
- let nextModule = parent;
10787
- while (nextModule !== module) {
10788
- path.push(relativeId(nextModule.id));
10789
- nextModule = parents.get(nextModule);
10790
- }
10791
- path.push(path[0]);
10792
- path.reverse();
10793
- return path;
10794
- }
10795
-
10796
10868
  function assignExportsToMangledNames(exports, exportsByName, exportNamesByVariable) {
10797
10869
  let nameIndex = 0;
10798
10870
  for (const variable of exports) {
@@ -10884,6 +10956,44 @@ function getIndentString(modules, options) {
10884
10956
  return '\t';
10885
10957
  }
10886
10958
 
10959
+ function getStaticDependencies(chunk, orderedModules, chunkByModule) {
10960
+ const staticDependencyBlocks = [];
10961
+ const handledDependencies = new Set();
10962
+ for (let modulePos = orderedModules.length - 1; modulePos >= 0; modulePos--) {
10963
+ const module = orderedModules[modulePos];
10964
+ if (!handledDependencies.has(module)) {
10965
+ const staticDependencies = [];
10966
+ addStaticDependencies(module, staticDependencies, handledDependencies, chunk, chunkByModule);
10967
+ staticDependencyBlocks.unshift(staticDependencies);
10968
+ }
10969
+ }
10970
+ const dependencies = new Set();
10971
+ for (const block of staticDependencyBlocks) {
10972
+ for (const dependency of block) {
10973
+ dependencies.add(dependency);
10974
+ }
10975
+ }
10976
+ return dependencies;
10977
+ }
10978
+ function addStaticDependencies(module, staticDependencies, handledModules, chunk, chunkByModule) {
10979
+ const dependencies = module.getDependenciesToBeIncluded();
10980
+ for (const dependency of dependencies) {
10981
+ if (dependency instanceof ExternalModule) {
10982
+ staticDependencies.push(dependency);
10983
+ continue;
10984
+ }
10985
+ const dependencyChunk = chunkByModule.get(dependency);
10986
+ if (dependencyChunk !== chunk) {
10987
+ staticDependencies.push(dependencyChunk);
10988
+ continue;
10989
+ }
10990
+ if (!handledModules.has(dependency)) {
10991
+ handledModules.add(dependency);
10992
+ addStaticDependencies(dependency, staticDependencies, handledModules, chunk, chunkByModule);
10993
+ }
10994
+ }
10995
+ }
10996
+
10887
10997
  function decodedSourcemap(map) {
10888
10998
  if (!map)
10889
10999
  return null;
@@ -11139,7 +11249,6 @@ class Chunk$1 {
11139
11249
  this.facadeChunkByModule.set(module, this);
11140
11250
  if (module.preserveSignature) {
11141
11251
  this.strictFacade = needsStrictFacade;
11142
- this.ensureReexportsAreAvailableForModule(module);
11143
11252
  }
11144
11253
  this.assignFacadeName(requiredFacades.shift(), module);
11145
11254
  }
@@ -11277,8 +11386,8 @@ class Chunk$1 {
11277
11386
  return this.exportNamesByVariable.get(variable)[0];
11278
11387
  }
11279
11388
  link() {
11389
+ this.dependencies = getStaticDependencies(this, this.orderedModules, this.chunkByModule);
11280
11390
  for (const module of this.orderedModules) {
11281
- this.addDependenciesToChunk(module.getDependenciesToBeIncluded(), this.dependencies);
11282
11391
  this.addDependenciesToChunk(module.dynamicDependencies, this.dynamicDependencies);
11283
11392
  this.addDependenciesToChunk(module.implicitlyLoadedBefore, this.implicitlyLoadedBefore);
11284
11393
  this.setUpChunkImportsAndExportsForModule(module);
@@ -11311,9 +11420,6 @@ class Chunk$1 {
11311
11420
  this.inlineChunkDependencies(dep);
11312
11421
  }
11313
11422
  }
11314
- const sortedDependencies = [...this.dependencies];
11315
- sortByExecutionOrder(sortedDependencies);
11316
- this.dependencies = new Set(sortedDependencies);
11317
11423
  this.prepareDynamicImportsAndImportMetas();
11318
11424
  this.setIdentifierRenderResolutions(options);
11319
11425
  let hoistedSource = '';
@@ -11505,6 +11611,23 @@ class Chunk$1 {
11505
11611
  this.name = sanitizeFileName(name || facadedModule.chunkName || getAliasName(facadedModule.id));
11506
11612
  }
11507
11613
  }
11614
+ checkCircularDependencyImport(variable, importingModule) {
11615
+ const variableModule = variable.module;
11616
+ if (variableModule instanceof Module) {
11617
+ const exportChunk = this.chunkByModule.get(variableModule);
11618
+ let alternativeReexportModule;
11619
+ do {
11620
+ alternativeReexportModule = importingModule.alternativeReexportModules.get(variable);
11621
+ if (alternativeReexportModule) {
11622
+ const exportingChunk = this.chunkByModule.get(alternativeReexportModule);
11623
+ if (exportingChunk && exportingChunk !== exportChunk) {
11624
+ this.inputOptions.onwarn(errCyclicCrossChunkReexport(variableModule.getExportNamesByVariable().get(variable)[0], variableModule.id, alternativeReexportModule.id, importingModule.id));
11625
+ }
11626
+ importingModule = alternativeReexportModule;
11627
+ }
11628
+ } while (alternativeReexportModule);
11629
+ }
11630
+ }
11508
11631
  computeContentHashWithDependencies(addons, options, existingNames) {
11509
11632
  const hash = createHash();
11510
11633
  hash.update([addons.intro, addons.outro, addons.banner, addons.footer].map(addon => addon || '').join(':'));
@@ -11534,6 +11657,7 @@ class Chunk$1 {
11534
11657
  ? exportedVariable.getBaseVariable()
11535
11658
  : exportedVariable;
11536
11659
  if (!(importedVariable instanceof NamespaceVariable && this.outputOptions.preserveModules)) {
11660
+ this.checkCircularDependencyImport(importedVariable, module);
11537
11661
  const exportingModule = importedVariable.module;
11538
11662
  if (exportingModule instanceof Module) {
11539
11663
  const chunk = this.chunkByModule.get(exportingModule);
@@ -11929,6 +12053,7 @@ class Chunk$1 {
11929
12053
  if (!(variable instanceof NamespaceVariable && this.outputOptions.preserveModules) &&
11930
12054
  variable.module instanceof Module) {
11931
12055
  chunk.exports.add(variable);
12056
+ this.checkCircularDependencyImport(variable, module);
11932
12057
  }
11933
12058
  }
11934
12059
  }
@@ -12132,6 +12257,71 @@ function commondir(files) {
12132
12257
  return commonSegments.length > 1 ? commonSegments.join('/') : '/';
12133
12258
  }
12134
12259
 
12260
+ const compareExecIndex = (unitA, unitB) => unitA.execIndex > unitB.execIndex ? 1 : -1;
12261
+ function sortByExecutionOrder(units) {
12262
+ units.sort(compareExecIndex);
12263
+ }
12264
+ function analyseModuleExecution(entryModules) {
12265
+ let nextExecIndex = 0;
12266
+ const cyclePaths = [];
12267
+ const analysedModules = new Set();
12268
+ const dynamicImports = new Set();
12269
+ const parents = new Map();
12270
+ const orderedModules = [];
12271
+ const analyseModule = (module) => {
12272
+ if (module instanceof Module) {
12273
+ for (const dependency of module.dependencies) {
12274
+ if (parents.has(dependency)) {
12275
+ if (!analysedModules.has(dependency)) {
12276
+ cyclePaths.push(getCyclePath(dependency, module, parents));
12277
+ }
12278
+ continue;
12279
+ }
12280
+ parents.set(dependency, module);
12281
+ analyseModule(dependency);
12282
+ }
12283
+ for (const dependency of module.implicitlyLoadedBefore) {
12284
+ dynamicImports.add(dependency);
12285
+ }
12286
+ for (const { resolution } of module.dynamicImports) {
12287
+ if (resolution instanceof Module) {
12288
+ dynamicImports.add(resolution);
12289
+ }
12290
+ }
12291
+ orderedModules.push(module);
12292
+ }
12293
+ module.execIndex = nextExecIndex++;
12294
+ analysedModules.add(module);
12295
+ };
12296
+ for (const curEntry of entryModules) {
12297
+ if (!parents.has(curEntry)) {
12298
+ parents.set(curEntry, null);
12299
+ analyseModule(curEntry);
12300
+ }
12301
+ }
12302
+ for (const curEntry of dynamicImports) {
12303
+ if (!parents.has(curEntry)) {
12304
+ parents.set(curEntry, null);
12305
+ analyseModule(curEntry);
12306
+ }
12307
+ }
12308
+ return { orderedModules, cyclePaths };
12309
+ }
12310
+ function getCyclePath(module, parent, parents) {
12311
+ const cycleSymbol = Symbol(module.id);
12312
+ const path = [relativeId(module.id)];
12313
+ let nextModule = parent;
12314
+ module.cycles.add(cycleSymbol);
12315
+ while (nextModule !== module) {
12316
+ nextModule.cycles.add(cycleSymbol);
12317
+ path.push(relativeId(nextModule.id));
12318
+ nextModule = parents.get(nextModule);
12319
+ }
12320
+ path.push(path[0]);
12321
+ path.reverse();
12322
+ return path;
12323
+ }
12324
+
12135
12325
  var BuildPhase;
12136
12326
  (function (BuildPhase) {
12137
12327
  BuildPhase[BuildPhase["LOAD_AND_PARSE"] = 0] = "LOAD_AND_PARSE";
@@ -19258,160 +19448,6 @@ var acornClassFields = function(Parser) {
19258
19448
  }
19259
19449
  };
19260
19450
 
19261
- function withoutAcornBigInt(acorn, Parser) {
19262
- return class extends Parser {
19263
- readInt(radix, len) {
19264
- // Hack: len is only != null for unicode escape sequences,
19265
- // where numeric separators are not allowed
19266
- if (len != null) return super.readInt(radix, len)
19267
-
19268
- let start = this.pos, total = 0, acceptUnderscore = false;
19269
- for (;;) {
19270
- let code = this.input.charCodeAt(this.pos), val;
19271
- if (code >= 97) val = code - 97 + 10; // a
19272
- else if (code == 95) {
19273
- if (!acceptUnderscore) this.raise(this.pos, "Invalid numeric separator");
19274
- ++this.pos;
19275
- acceptUnderscore = false;
19276
- continue
19277
- } else if (code >= 65) val = code - 65 + 10; // A
19278
- else if (code >= 48 && code <= 57) val = code - 48; // 0-9
19279
- else val = Infinity;
19280
- if (val >= radix) break
19281
- ++this.pos;
19282
- total = total * radix + val;
19283
- acceptUnderscore = true;
19284
- }
19285
- if (this.pos === start) return null
19286
- if (!acceptUnderscore) this.raise(this.pos - 1, "Invalid numeric separator");
19287
-
19288
- return total
19289
- }
19290
-
19291
- readNumber(startsWithDot) {
19292
- const token = super.readNumber(startsWithDot);
19293
- let octal = this.end - this.start >= 2 && this.input.charCodeAt(this.start) === 48;
19294
- const stripped = this.getNumberInput(this.start, this.end);
19295
- if (stripped.length < this.end - this.start) {
19296
- if (octal) this.raise(this.start, "Invalid number");
19297
- this.value = parseFloat(stripped);
19298
- }
19299
- return token
19300
- }
19301
-
19302
- // This is used by acorn-bigint
19303
- getNumberInput(start, end) {
19304
- return this.input.slice(start, end).replace(/_/g, "")
19305
- }
19306
- }
19307
- }
19308
-
19309
- function withAcornBigInt(acorn, Parser) {
19310
- return class extends Parser {
19311
- readInt(radix, len) {
19312
- // Hack: len is only != null for unicode escape sequences,
19313
- // where numeric separators are not allowed
19314
- if (len != null) return super.readInt(radix, len)
19315
-
19316
- let start = this.pos, total = 0, acceptUnderscore = false;
19317
- for (;;) {
19318
- let code = this.input.charCodeAt(this.pos), val;
19319
- if (code >= 97) val = code - 97 + 10; // a
19320
- else if (code == 95) {
19321
- if (!acceptUnderscore) this.raise(this.pos, "Invalid numeric separator");
19322
- ++this.pos;
19323
- acceptUnderscore = false;
19324
- continue
19325
- } else if (code >= 65) val = code - 65 + 10; // A
19326
- else if (code >= 48 && code <= 57) val = code - 48; // 0-9
19327
- else val = Infinity;
19328
- if (val >= radix) break
19329
- ++this.pos;
19330
- total = total * radix + val;
19331
- acceptUnderscore = true;
19332
- }
19333
- if (this.pos === start) return null
19334
- if (!acceptUnderscore) this.raise(this.pos - 1, "Invalid numeric separator");
19335
-
19336
- return total
19337
- }
19338
-
19339
- readNumber(startsWithDot) {
19340
- let start = this.pos;
19341
- if (!startsWithDot && this.readInt(10) === null) this.raise(start, "Invalid number");
19342
- let octal = this.pos - start >= 2 && this.input.charCodeAt(start) === 48;
19343
- let octalLike = false;
19344
- if (octal && this.strict) this.raise(start, "Invalid number");
19345
- let next = this.input.charCodeAt(this.pos);
19346
- if (!octal && !startsWithDot && this.options.ecmaVersion >= 11 && next === 110) {
19347
- let str = this.getNumberInput(start, this.pos);
19348
- // eslint-disable-next-line node/no-unsupported-features/es-builtins
19349
- let val = typeof BigInt !== "undefined" ? BigInt(str) : null;
19350
- ++this.pos;
19351
- if (acorn.isIdentifierStart(this.fullCharCodeAtPos())) this.raise(this.pos, "Identifier directly after number");
19352
- return this.finishToken(acorn.tokTypes.num, val)
19353
- }
19354
- if (octal && /[89]/.test(this.input.slice(start, this.pos))) {
19355
- octal = false;
19356
- octalLike = true;
19357
- }
19358
- if (next === 46 && !octal) { // '.'
19359
- ++this.pos;
19360
- this.readInt(10);
19361
- next = this.input.charCodeAt(this.pos);
19362
- }
19363
- if ((next === 69 || next === 101) && !octal) { // 'eE'
19364
- next = this.input.charCodeAt(++this.pos);
19365
- if (next === 43 || next === 45) ++this.pos; // '+-'
19366
- if (this.readInt(10) === null) this.raise(start, "Invalid number");
19367
- }
19368
- if (acorn.isIdentifierStart(this.fullCharCodeAtPos())) this.raise(this.pos, "Identifier directly after number");
19369
- let str = this.getNumberInput(start, this.pos);
19370
- if ((octal || octalLike) && str.length < this.pos - start) {
19371
- this.raise(start, "Invalid number");
19372
- }
19373
-
19374
- let val = octal ? parseInt(str, 8) : parseFloat(str);
19375
- return this.finishToken(acorn.tokTypes.num, val)
19376
- }
19377
-
19378
- parseLiteral(value) {
19379
- const ret = super.parseLiteral(value);
19380
- if (ret.bigint) ret.bigint = ret.bigint.replace(/_/g, "");
19381
- return ret
19382
- }
19383
-
19384
- readRadixNumber(radix) {
19385
- let start = this.pos;
19386
- this.pos += 2; // 0x
19387
- let val = this.readInt(radix);
19388
- if (val == null) { this.raise(this.start + 2, `Expected number in radix ${radix}`); }
19389
- if (this.options.ecmaVersion >= 11 && this.input.charCodeAt(this.pos) === 110) {
19390
- let str = this.getNumberInput(start, this.pos);
19391
- // eslint-disable-next-line node/no-unsupported-features/es-builtins
19392
- val = typeof BigInt !== "undefined" ? BigInt(str) : null;
19393
- ++this.pos;
19394
- } else if (acorn.isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
19395
- return this.finishToken(acorn.tokTypes.num, val)
19396
- }
19397
-
19398
- // This is used by acorn-bigint, which theoretically could be used with acorn@6.2 || acorn@7
19399
- getNumberInput(start, end) {
19400
- return this.input.slice(start, end).replace(/_/g, "")
19401
- }
19402
- }
19403
- }
19404
-
19405
- // eslint-disable-next-line node/no-unsupported-features/es-syntax
19406
- function numericSeparator(Parser) {
19407
- const acorn = Parser.acorn || require$$0;
19408
- const withAcornBigIntSupport = (acorn.version.startsWith("6.") && !(acorn.version.startsWith("6.0.") || acorn.version.startsWith("6.1."))) || acorn.version.startsWith("7.");
19409
-
19410
- return withAcornBigIntSupport ? withAcornBigInt(acorn, Parser) : withoutAcornBigInt(acorn, Parser)
19411
- }
19412
-
19413
- var acornNumericSeparator = numericSeparator;
19414
-
19415
19451
  var acornStaticClassFeatures = function(Parser) {
19416
19452
  const ExtendedParser = acornPrivateClassElements(Parser);
19417
19453
 
@@ -19552,7 +19588,6 @@ const getAcorn$1 = (config) => ({
19552
19588
  const getAcornInjectPlugins = (config) => [
19553
19589
  acornClassFields,
19554
19590
  acornStaticClassFeatures,
19555
- acornNumericSeparator,
19556
19591
  ...ensureArray(config.acornInjectPlugins)
19557
19592
  ];
19558
19593
  const getCache = (config) => {