rollup 2.36.0 → 2.37.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v2.36.0
4
- Tue, 05 Jan 2021 13:34:51 GMT - commit 966bfa51915ae2bfa456d6f7f65dc23f18ea64e2
3
+ Rollup.js v2.37.1
4
+ Wed, 20 Jan 2021 11:53:42 GMT - commit e23bb354cca08dbe32e3f6a3ba5c63d015e91ff9
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.0";
22
+ var version = "2.37.1";
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)
@@ -3238,6 +3078,10 @@ function isReference(node, parent) {
3238
3078
  return false;
3239
3079
  }
3240
3080
 
3081
+ const BLANK = Object.freeze(Object.create(null));
3082
+ const EMPTY_OBJECT = Object.freeze({});
3083
+ const EMPTY_ARRAY = Object.freeze([]);
3084
+
3241
3085
  const ValueProperties = Symbol('Value Properties');
3242
3086
  const PURE = { pure: true };
3243
3087
  const IMPURE = { pure: false };
@@ -4205,7 +4049,7 @@ class Identifier$1 extends NodeBase {
4205
4049
  if (!this.included) {
4206
4050
  this.included = true;
4207
4051
  if (this.variable !== null) {
4208
- this.context.includeVariable(this.variable);
4052
+ this.context.includeVariableInModule(this.variable);
4209
4053
  }
4210
4054
  }
4211
4055
  }
@@ -4397,7 +4241,7 @@ class ExportDefaultDeclaration extends NodeBase {
4397
4241
  include(context, includeChildrenRecursively) {
4398
4242
  super.include(context, includeChildrenRecursively);
4399
4243
  if (includeChildrenRecursively) {
4400
- this.context.includeVariable(this.variable);
4244
+ this.context.includeVariableInModule(this.variable);
4401
4245
  }
4402
4246
  }
4403
4247
  initialise() {
@@ -4480,9 +4324,8 @@ class ExportDefaultVariable extends LocalVariable {
4480
4324
  constructor(name, exportDefaultDeclaration, context) {
4481
4325
  super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, context);
4482
4326
  this.hasId = false;
4483
- // Not initialised during construction
4484
4327
  this.originalId = null;
4485
- this.originalVariableAndDeclarationModules = null;
4328
+ this.originalVariable = null;
4486
4329
  const declaration = exportDefaultDeclaration.declaration;
4487
4330
  if ((declaration instanceof FunctionDeclaration || declaration instanceof ClassDeclaration) &&
4488
4331
  declaration.id) {
@@ -4510,6 +4353,14 @@ class ExportDefaultVariable extends LocalVariable {
4510
4353
  return original.getBaseVariableName();
4511
4354
  }
4512
4355
  }
4356
+ getDirectOriginalVariable() {
4357
+ return this.originalId &&
4358
+ (this.hasId ||
4359
+ !(this.originalId.variable.isReassigned ||
4360
+ this.originalId.variable instanceof UndefinedVariable))
4361
+ ? this.originalId.variable
4362
+ : null;
4363
+ }
4513
4364
  getName() {
4514
4365
  const original = this.getOriginalVariable();
4515
4366
  if (original === this) {
@@ -4520,34 +4371,17 @@ class ExportDefaultVariable extends LocalVariable {
4520
4371
  }
4521
4372
  }
4522
4373
  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;
4374
+ if (this.originalVariable)
4375
+ return this.originalVariable;
4376
+ let original = this;
4377
+ let currentVariable;
4378
+ const checkedVariables = new Set();
4379
+ do {
4380
+ checkedVariables.add(original);
4381
+ currentVariable = original;
4382
+ original = currentVariable.getDirectOriginalVariable();
4383
+ } while (original instanceof ExportDefaultVariable && !checkedVariables.has(original));
4384
+ return (this.originalVariable = original || currentVariable);
4551
4385
  }
4552
4386
  }
4553
4387
 
@@ -4660,897 +4494,1081 @@ class NamespaceVariable extends Variable {
4660
4494
  }
4661
4495
  NamespaceVariable.prototype.isNamespace = true;
4662
4496
 
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;
4497
+ function spaces(i) {
4498
+ let result = '';
4499
+ while (i--)
4500
+ result += ' ';
4501
+ return result;
4502
+ }
4503
+ function tabsToSpaces(str) {
4504
+ return str.replace(/^\t+/, match => match.split('\t').join(' '));
4505
+ }
4506
+ function getCodeFrame(source, line, column) {
4507
+ let lines = source.split('\n');
4508
+ const frameStart = Math.max(0, line - 3);
4509
+ let frameEnd = Math.min(line + 2, lines.length);
4510
+ lines = lines.slice(frameStart, frameEnd);
4511
+ while (!/\S/.test(lines[lines.length - 1])) {
4512
+ lines.pop();
4513
+ frameEnd -= 1;
4669
4514
  }
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)}`;
4686
- }
4687
- include() {
4688
- if (!this.included) {
4689
- this.included = true;
4690
- this.context.includeVariable(this.syntheticNamespace);
4515
+ const digits = String(frameEnd).length;
4516
+ return lines
4517
+ .map((str, i) => {
4518
+ const isErrorLine = frameStart + i + 1 === line;
4519
+ let lineNum = String(i + frameStart + 1);
4520
+ while (lineNum.length < digits)
4521
+ lineNum = ` ${lineNum}`;
4522
+ if (isErrorLine) {
4523
+ const indicator = spaces(digits + 2 + tabsToSpaces(str.slice(0, column)).length) + '^';
4524
+ return `${lineNum}: ${tabsToSpaces(str)}\n${indicator}`;
4691
4525
  }
4692
- }
4693
- setRenderNames(baseName, name) {
4694
- super.setRenderNames(baseName, name);
4695
- }
4526
+ return `${lineNum}: ${tabsToSpaces(str)}`;
4527
+ })
4528
+ .join('\n');
4696
4529
  }
4697
- const getPropertyAccess = (name) => {
4698
- return !RESERVED_NAMES[name] && /^(?!\d)[\w$]+$/.test(name)
4699
- ? `.${name}`
4700
- : `[${JSON.stringify(name)}]`;
4701
- };
4702
4530
 
4703
- function removeJsExtension(name) {
4704
- return name.endsWith('.js') ? name.slice(0, -3) : name;
4531
+ function error(base) {
4532
+ if (!(base instanceof Error))
4533
+ base = Object.assign(new Error(base.message), base);
4534
+ throw base;
4705
4535
  }
4706
-
4707
- function getCompleteAmdId(options, chunkId) {
4708
- if (!options.autoId) {
4709
- return options.id || '';
4536
+ function augmentCodeLocation(props, pos, source, id) {
4537
+ if (typeof pos === 'object') {
4538
+ const { line, column } = pos;
4539
+ props.loc = { file: id, line, column };
4710
4540
  }
4711
4541
  else {
4712
- return `${options.basePath ? options.basePath + '/' : ''}${removeJsExtension(chunkId)}`;
4542
+ props.pos = pos;
4543
+ const { line, column } = locate(source, pos, { offsetLine: 1 });
4544
+ props.loc = { file: id, line, column };
4545
+ }
4546
+ if (props.frame === undefined) {
4547
+ const { line, column } = props.loc;
4548
+ props.frame = getCodeFrame(source, line, column);
4713
4549
  }
4714
4550
  }
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')));
4551
+ var Errors;
4552
+ (function (Errors) {
4553
+ Errors["ALREADY_CLOSED"] = "ALREADY_CLOSED";
4554
+ Errors["ASSET_NOT_FINALISED"] = "ASSET_NOT_FINALISED";
4555
+ Errors["ASSET_NOT_FOUND"] = "ASSET_NOT_FOUND";
4556
+ Errors["ASSET_SOURCE_ALREADY_SET"] = "ASSET_SOURCE_ALREADY_SET";
4557
+ Errors["ASSET_SOURCE_MISSING"] = "ASSET_SOURCE_MISSING";
4558
+ Errors["BAD_LOADER"] = "BAD_LOADER";
4559
+ Errors["CANNOT_EMIT_FROM_OPTIONS_HOOK"] = "CANNOT_EMIT_FROM_OPTIONS_HOOK";
4560
+ Errors["CHUNK_NOT_GENERATED"] = "CHUNK_NOT_GENERATED";
4561
+ Errors["CIRCULAR_REEXPORT"] = "CIRCULAR_REEXPORT";
4562
+ Errors["CYCLIC_CROSS_CHUNK_REEXPORT"] = "CYCLIC_CROSS_CHUNK_REEXPORT";
4563
+ Errors["DEPRECATED_FEATURE"] = "DEPRECATED_FEATURE";
4564
+ Errors["EXTERNAL_SYNTHETIC_EXPORTS"] = "EXTERNAL_SYNTHETIC_EXPORTS";
4565
+ Errors["FILE_NAME_CONFLICT"] = "FILE_NAME_CONFLICT";
4566
+ Errors["FILE_NOT_FOUND"] = "FILE_NOT_FOUND";
4567
+ Errors["INPUT_HOOK_IN_OUTPUT_PLUGIN"] = "INPUT_HOOK_IN_OUTPUT_PLUGIN";
4568
+ Errors["INVALID_CHUNK"] = "INVALID_CHUNK";
4569
+ Errors["INVALID_EXPORT_OPTION"] = "INVALID_EXPORT_OPTION";
4570
+ Errors["INVALID_EXTERNAL_ID"] = "INVALID_EXTERNAL_ID";
4571
+ Errors["INVALID_OPTION"] = "INVALID_OPTION";
4572
+ Errors["INVALID_PLUGIN_HOOK"] = "INVALID_PLUGIN_HOOK";
4573
+ Errors["INVALID_ROLLUP_PHASE"] = "INVALID_ROLLUP_PHASE";
4574
+ Errors["MISSING_EXPORT"] = "MISSING_EXPORT";
4575
+ Errors["MISSING_IMPLICIT_DEPENDANT"] = "MISSING_IMPLICIT_DEPENDANT";
4576
+ Errors["MIXED_EXPORTS"] = "MIXED_EXPORTS";
4577
+ Errors["NAMESPACE_CONFLICT"] = "NAMESPACE_CONFLICT";
4578
+ Errors["NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE"] = "NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE";
4579
+ Errors["PLUGIN_ERROR"] = "PLUGIN_ERROR";
4580
+ Errors["PREFER_NAMED_EXPORTS"] = "PREFER_NAMED_EXPORTS";
4581
+ Errors["SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT"] = "SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT";
4582
+ Errors["UNEXPECTED_NAMED_IMPORT"] = "UNEXPECTED_NAMED_IMPORT";
4583
+ Errors["UNRESOLVED_ENTRY"] = "UNRESOLVED_ENTRY";
4584
+ Errors["UNRESOLVED_IMPORT"] = "UNRESOLVED_IMPORT";
4585
+ Errors["VALIDATION_ERROR"] = "VALIDATION_ERROR";
4586
+ })(Errors || (Errors = {}));
4587
+ function errAssetNotFinalisedForFileName(name) {
4588
+ return {
4589
+ code: Errors.ASSET_NOT_FINALISED,
4590
+ message: `Plugin error - Unable to get file name for asset "${name}". Ensure that the source is set and that generate is called first.`
4591
+ };
4732
4592
  }
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);
4593
+ function errCannotEmitFromOptionsHook() {
4594
+ return {
4595
+ code: Errors.CANNOT_EMIT_FROM_OPTIONS_HOOK,
4596
+ message: `Cannot emit files or set asset sources in the "outputOptions" hook, use the "renderStart" hook instead.`
4597
+ };
4744
4598
  }
4745
- function getDefaultOnlyHelper() {
4746
- return INTEROP_NAMESPACE_DEFAULT_ONLY_VARIABLE;
4599
+ function errChunkNotGeneratedForFileName(name) {
4600
+ return {
4601
+ code: Errors.CHUNK_NOT_GENERATED,
4602
+ message: `Plugin error - Unable to get file name for chunk "${name}". Ensure that generate is called first.`
4603
+ };
4747
4604
  }
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('');
4605
+ function errCircularReexport(exportName, importedModule) {
4606
+ return {
4607
+ code: Errors.CIRCULAR_REEXPORT,
4608
+ id: importedModule,
4609
+ message: `"${exportName}" cannot be exported from ${relativeId(importedModule)} as it is a reexport that references itself.`
4610
+ };
4752
4611
  }
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${_}}`;
4612
+ function errCyclicCrossChunkReexport(exportName, exporter, reexporter, importer) {
4613
+ return {
4614
+ code: Errors.CYCLIC_CROSS_CHUNK_REEXPORT,
4615
+ exporter,
4616
+ importer,
4617
+ 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.`,
4618
+ reexporter
4619
+ };
4775
4620
  }
4776
- function getDefaultStatic(_) {
4777
- return `e['default']${_}:${_}e`;
4621
+ function errAssetReferenceIdNotFoundForSetSource(assetReferenceId) {
4622
+ return {
4623
+ code: Errors.ASSET_NOT_FOUND,
4624
+ message: `Plugin error - Unable to set the source for unknown asset "${assetReferenceId}".`
4625
+ };
4778
4626
  }
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}`);
4627
+ function errAssetSourceAlreadySet(name) {
4628
+ return {
4629
+ code: Errors.ASSET_SOURCE_ALREADY_SET,
4630
+ message: `Unable to set the source for asset "${name}", source already set.`
4631
+ };
4790
4632
  }
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}`);
4633
+ function errNoAssetSourceSet(assetName) {
4634
+ return {
4635
+ code: Errors.ASSET_SOURCE_MISSING,
4636
+ message: `Plugin error creating asset "${assetName}" - no asset source set.`
4637
+ };
4801
4638
  }
4802
- function copyPropertyStatic(_, n, _t, i) {
4803
- return `${i}n[k]${_}=${_}e[k];${n}`;
4639
+ function errBadLoader(id) {
4640
+ return {
4641
+ code: Errors.BAD_LOADER,
4642
+ message: `Error loading ${relativeId(id)}: plugin load hook should return a string, a { code, map } object, or nothing/null`
4643
+ };
4804
4644
  }
4805
- function getFrozen(fragment, freeze) {
4806
- return freeze ? `Object.freeze(${fragment})` : fragment;
4645
+ function errDeprecation(deprecation) {
4646
+ return {
4647
+ code: Errors.DEPRECATED_FEATURE,
4648
+ ...(typeof deprecation === 'string' ? { message: deprecation } : deprecation)
4649
+ };
4807
4650
  }
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 '';
4651
+ function errFileReferenceIdNotFoundForFilename(assetReferenceId) {
4652
+ return {
4653
+ code: Errors.FILE_NOT_FOUND,
4654
+ message: `Plugin error - Unable to get file name for unknown file "${assetReferenceId}".`
4655
+ };
4873
4656
  }
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
- }
4657
+ function errFileNameConflict(fileName) {
4658
+ return {
4659
+ code: Errors.FILE_NAME_CONFLICT,
4660
+ message: `The emitted file "${fileName}" overwrites a previously emitted file of the same name.`
4661
+ };
4885
4662
  }
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}`;
4663
+ function errInputHookInOutputPlugin(pluginName, hookName) {
4664
+ return {
4665
+ code: Errors.INPUT_HOOK_IN_OUTPUT_PLUGIN,
4666
+ 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.`
4667
+ };
4907
4668
  }
4908
- function getEsModuleExport(_) {
4909
- return `Object.defineProperty(exports,${_}'__esModule',${_}{${_}value:${_}true${_}});`;
4669
+ function errCannotAssignModuleToChunk(moduleId, assignToAlias, currentAlias) {
4670
+ return {
4671
+ code: Errors.INVALID_CHUNK,
4672
+ message: `Cannot assign ${relativeId(moduleId)} to the "${assignToAlias}" chunk as it is already in the "${currentAlias}" chunk.`
4673
+ };
4910
4674
  }
4911
- function getNamespaceToStringExport(_) {
4912
- return `exports[Symbol.toStringTag]${_}=${_}'Module';`;
4675
+ function errInvalidExportOptionValue(optionValue) {
4676
+ return {
4677
+ code: Errors.INVALID_EXPORT_OPTION,
4678
+ message: `"output.exports" must be "default", "named", "none", "auto", or left unspecified (defaults to "auto"), received "${optionValue}"`,
4679
+ url: `https://rollupjs.org/guide/en/#outputexports`
4680
+ };
4913
4681
  }
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;
4682
+ function errIncompatibleExportOptionValue(optionValue, keys, entryModule) {
4683
+ return {
4684
+ code: 'INVALID_EXPORT_OPTION',
4685
+ message: `"${optionValue}" was specified for "output.exports", but entry module "${relativeId(entryModule)}" has the following exports: ${keys.join(', ')}`
4686
+ };
4928
4687
  }
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});`);
4688
+ function errInternalIdCannotBeExternal(source, importer) {
4689
+ return {
4690
+ code: Errors.INVALID_EXTERNAL_ID,
4691
+ message: `'${source}' is imported as an external by ${relativeId(importer)}, but is already an existing non-external module id.`
4936
4692
  };
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
4693
  }
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;
4694
+ function errInvalidOption(option, explanation) {
4695
+ return {
4696
+ code: Errors.INVALID_OPTION,
4697
+ message: `Invalid value for option "${option}" - ${explanation}.`
4698
+ };
4991
4699
  }
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
- });
4700
+ function errInvalidRollupPhaseForAddWatchFile() {
4701
+ return {
4702
+ code: Errors.INVALID_ROLLUP_PHASE,
4703
+ message: `Cannot call addWatchFile after the build has finished.`
4704
+ };
5031
4705
  }
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;
5061
- }
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}});`);
4706
+ function errInvalidRollupPhaseForChunkEmission() {
4707
+ return {
4708
+ code: Errors.INVALID_ROLLUP_PHASE,
4709
+ message: `Cannot emit chunks after module loading has finished.`
4710
+ };
5067
4711
  }
5068
-
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;
4712
+ function errMissingExport(exportName, importingModule, importedModule) {
4713
+ return {
4714
+ code: Errors.MISSING_EXPORT,
4715
+ message: `'${exportName}' is not exported by ${relativeId(importedModule)}, imported by ${relativeId(importingModule)}`,
4716
+ url: `https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module`
4717
+ };
4718
+ }
4719
+ function errImplicitDependantCannotBeExternal(unresolvedId, implicitlyLoadedBefore) {
4720
+ return {
4721
+ code: Errors.MISSING_IMPLICIT_DEPENDANT,
4722
+ message: `Module "${relativeId(unresolvedId)}" that should be implicitly loaded before "${relativeId(implicitlyLoadedBefore)}" cannot be external.`
4723
+ };
4724
+ }
4725
+ function errUnresolvedImplicitDependant(unresolvedId, implicitlyLoadedBefore) {
4726
+ return {
4727
+ code: Errors.MISSING_IMPLICIT_DEPENDANT,
4728
+ message: `Module "${relativeId(unresolvedId)}" that should be implicitly loaded before "${relativeId(implicitlyLoadedBefore)}" could not be resolved.`
4729
+ };
4730
+ }
4731
+ function errImplicitDependantIsNotIncluded(module) {
4732
+ const implicitDependencies = Array.from(module.implicitlyLoadedBefore, dependency => relativeId(dependency.id)).sort();
4733
+ return {
4734
+ code: Errors.MISSING_IMPLICIT_DEPENDANT,
4735
+ message: `Module "${relativeId(module.id)}" that should be implicitly loaded before "${implicitDependencies.length === 1
4736
+ ? implicitDependencies[0]
4737
+ : `${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.`
4738
+ };
4739
+ }
4740
+ function errMixedExport(facadeModuleId, name) {
4741
+ return {
4742
+ code: Errors.MIXED_EXPORTS,
4743
+ id: facadeModuleId,
4744
+ 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`,
4745
+ url: `https://rollupjs.org/guide/en/#outputexports`
4746
+ };
4747
+ }
4748
+ function errNamespaceConflict(name, reexportingModule, additionalExportAllModule) {
4749
+ return {
4750
+ code: Errors.NAMESPACE_CONFLICT,
4751
+ message: `Conflicting namespaces: ${relativeId(reexportingModule.id)} re-exports '${name}' from both ${relativeId(reexportingModule.exportsAll[name])} and ${relativeId(additionalExportAllModule.exportsAll[name])} (will be ignored)`,
4752
+ name,
4753
+ reexporter: reexportingModule.id,
4754
+ sources: [reexportingModule.exportsAll[name], additionalExportAllModule.exportsAll[name]]
4755
+ };
4756
+ }
4757
+ function errNoTransformMapOrAstWithoutCode(pluginName) {
4758
+ return {
4759
+ code: Errors.NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE,
4760
+ message: `The plugin "${pluginName}" returned a "map" or "ast" without returning ` +
4761
+ 'a "code". This will be ignored.'
4762
+ };
4763
+ }
4764
+ function errPreferNamedExports(facadeModuleId) {
4765
+ const file = relativeId(facadeModuleId);
4766
+ return {
4767
+ code: Errors.PREFER_NAMED_EXPORTS,
4768
+ id: facadeModuleId,
4769
+ 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.`,
4770
+ url: `https://rollupjs.org/guide/en/#outputexports`
4771
+ };
4772
+ }
4773
+ function errSyntheticNamedExportsNeedNamespaceExport(id, syntheticNamedExportsOption) {
4774
+ return {
4775
+ code: Errors.SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT,
4776
+ id,
4777
+ message: `Module "${relativeId(id)}" that is marked with 'syntheticNamedExports: ${JSON.stringify(syntheticNamedExportsOption)}' needs ${typeof syntheticNamedExportsOption === 'string' && syntheticNamedExportsOption !== 'default'
4778
+ ? `an export named "${syntheticNamedExportsOption}"`
4779
+ : 'a default export'} that does not reexport an unresolved named export of the same module.`
4780
+ };
4781
+ }
4782
+ function errUnexpectedNamedImport(id, imported, isReexport) {
4783
+ const importType = isReexport ? 'reexport' : 'import';
4784
+ return {
4785
+ code: Errors.UNEXPECTED_NAMED_IMPORT,
4786
+ id,
4787
+ 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.`,
4788
+ url: 'https://rollupjs.org/guide/en/#outputinterop'
4789
+ };
4790
+ }
4791
+ function errUnexpectedNamespaceReexport(id) {
4792
+ return {
4793
+ code: Errors.UNEXPECTED_NAMED_IMPORT,
4794
+ id,
4795
+ 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.`,
4796
+ url: 'https://rollupjs.org/guide/en/#outputinterop'
4797
+ };
4798
+ }
4799
+ function errEntryCannotBeExternal(unresolvedId) {
4800
+ return {
4801
+ code: Errors.UNRESOLVED_ENTRY,
4802
+ message: `Entry module cannot be external (${relativeId(unresolvedId)}).`
4803
+ };
4804
+ }
4805
+ function errUnresolvedEntry(unresolvedId) {
4806
+ return {
4807
+ code: Errors.UNRESOLVED_ENTRY,
4808
+ message: `Could not resolve entry module (${relativeId(unresolvedId)}).`
4809
+ };
4810
+ }
4811
+ function errUnresolvedImport(source, importer) {
4812
+ return {
4813
+ code: Errors.UNRESOLVED_IMPORT,
4814
+ message: `Could not resolve '${source}' from ${relativeId(importer)}`
4815
+ };
4816
+ }
4817
+ function errUnresolvedImportTreatedAsExternal(source, importer) {
4818
+ return {
4819
+ code: Errors.UNRESOLVED_IMPORT,
4820
+ importer: relativeId(importer),
4821
+ message: `'${source}' is imported by ${relativeId(importer)}, but could not be resolved – treating it as an external dependency`,
4822
+ source,
4823
+ url: 'https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency'
4824
+ };
4825
+ }
4826
+ function errExternalSyntheticExports(source, importer) {
4827
+ return {
4828
+ code: Errors.EXTERNAL_SYNTHETIC_EXPORTS,
4829
+ importer: relativeId(importer),
4830
+ message: `External '${source}' can not have 'syntheticNamedExports' enabled.`,
4831
+ source
4832
+ };
4833
+ }
4834
+ function errFailedValidation(message) {
4835
+ return {
4836
+ code: Errors.VALIDATION_ERROR,
4837
+ message
4838
+ };
4839
+ }
4840
+ function errAlreadyClosed() {
4841
+ return {
4842
+ code: Errors.ALREADY_CLOSED,
4843
+ message: 'Bundle is already closed, no more calls to "generate" or "write" are allowed.'
4844
+ };
4845
+ }
4846
+ function warnDeprecation(deprecation, activeDeprecation, options) {
4847
+ warnDeprecationWithOptions(deprecation, activeDeprecation, options.onwarn, options.strictDeprecations);
4848
+ }
4849
+ function warnDeprecationWithOptions(deprecation, activeDeprecation, warn, strictDeprecations) {
4850
+ if (activeDeprecation || strictDeprecations) {
4851
+ const warning = errDeprecation(deprecation);
4852
+ if (strictDeprecations) {
4853
+ return error(warning);
4854
+ }
4855
+ warn(warning);
5077
4856
  }
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
4857
  }
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}` : ',';
4858
+
4859
+ class SyntheticNamedExportVariable extends Variable {
4860
+ constructor(context, name, syntheticNamespace) {
4861
+ super(name);
4862
+ this.baseVariable = null;
4863
+ this.context = context;
4864
+ this.module = context.module;
4865
+ this.syntheticNamespace = syntheticNamespace;
4866
+ }
4867
+ getBaseVariable() {
4868
+ if (this.baseVariable)
4869
+ return this.baseVariable;
4870
+ let baseVariable = this.syntheticNamespace;
4871
+ const checkedVariables = new Set();
4872
+ while (baseVariable instanceof ExportDefaultVariable ||
4873
+ baseVariable instanceof SyntheticNamedExportVariable) {
4874
+ checkedVariables.add(baseVariable);
4875
+ if (baseVariable instanceof ExportDefaultVariable) {
4876
+ const original = baseVariable.getOriginalVariable();
4877
+ if (original === baseVariable)
4878
+ break;
4879
+ baseVariable = original;
4880
+ }
4881
+ if (baseVariable instanceof SyntheticNamedExportVariable) {
4882
+ baseVariable = baseVariable.syntheticNamespace;
4883
+ }
4884
+ if (checkedVariables.has(baseVariable)) {
4885
+ return error(errSyntheticNamedExportsNeedNamespaceExport(this.module.id, this.module.info.syntheticNamedExports));
5091
4886
  }
5092
- definingVariable = false;
5093
- importBlock += `require('${id}')`;
5094
4887
  }
5095
- else {
5096
- importBlock +=
5097
- compact && definingVariable ? ',' : `${importBlock ? `;${n}` : ''}${varOrConst} `;
5098
- definingVariable = true;
5099
- importBlock += `${name}${_}=${_}require('${id}')`;
4888
+ return (this.baseVariable = baseVariable);
4889
+ }
4890
+ getBaseVariableName() {
4891
+ return this.syntheticNamespace.getBaseVariableName();
4892
+ }
4893
+ getName() {
4894
+ const name = this.name;
4895
+ return `${this.syntheticNamespace.getName()}${getPropertyAccess(name)}`;
4896
+ }
4897
+ include() {
4898
+ if (!this.included) {
4899
+ this.included = true;
4900
+ this.context.includeVariableInModule(this.syntheticNamespace);
5100
4901
  }
5101
4902
  }
5102
- if (importBlock) {
5103
- return `${importBlock};${n}${n}`;
4903
+ setRenderNames(baseName, name) {
4904
+ super.setRenderNames(baseName, name);
5104
4905
  }
5105
- return '';
5106
4906
  }
4907
+ const getPropertyAccess = (name) => {
4908
+ return !RESERVED_NAMES[name] && /^(?!\d)[\w$]+$/.test(name)
4909
+ ? `.${name}`
4910
+ : `[${JSON.stringify(name)}]`;
4911
+ };
5107
4912
 
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
- }
4913
+ class ExternalVariable extends Variable {
4914
+ constructor(module, name) {
4915
+ super(name);
4916
+ this.module = module;
4917
+ this.isNamespace = name === '*';
4918
+ this.referenced = false;
4919
+ }
4920
+ addReference(identifier) {
4921
+ this.referenced = true;
4922
+ if (this.name === 'default' || this.name === '*') {
4923
+ this.module.suggestName(identifier.name);
5203
4924
  }
5204
4925
  }
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}`);
4926
+ include() {
4927
+ if (!this.included) {
4928
+ this.included = true;
4929
+ this.module.used = true;
5221
4930
  }
5222
4931
  }
5223
- if (exportDeclaration.length) {
5224
- exportBlock.push(`export${_}{${_}${exportDeclaration.join(`,${_}`)}${_}};`);
5225
- }
5226
- return exportBlock;
5227
4932
  }
5228
4933
 
5229
- function spaces(i) {
5230
- let result = '';
5231
- while (i--)
5232
- result += ' ';
5233
- return result;
4934
+ 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(' ');
4935
+ 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(' ');
4936
+ const blacklisted = new Set(reservedWords.concat(builtins));
4937
+ const illegalCharacters = /[^$_a-zA-Z0-9]/g;
4938
+ const startsWithDigit = (str) => /\d/.test(str[0]);
4939
+ function isLegal(str) {
4940
+ if (startsWithDigit(str) || blacklisted.has(str)) {
4941
+ return false;
4942
+ }
4943
+ return !illegalCharacters.test(str);
5234
4944
  }
5235
- function tabsToSpaces(str) {
5236
- return str.replace(/^\t+/, match => match.split('\t').join(' '));
4945
+ function makeLegal(str) {
4946
+ str = str.replace(/-(\w)/g, (_, letter) => letter.toUpperCase()).replace(illegalCharacters, '_');
4947
+ if (startsWithDigit(str) || blacklisted.has(str))
4948
+ str = `_${str}`;
4949
+ return str || '_';
5237
4950
  }
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;
4951
+
4952
+ class ExternalModule {
4953
+ constructor(options, id, hasModuleSideEffects, meta) {
4954
+ this.options = options;
4955
+ this.id = id;
4956
+ this.defaultVariableName = '';
4957
+ this.dynamicImporters = [];
4958
+ this.importers = [];
4959
+ this.mostCommonSuggestion = 0;
4960
+ this.namespaceVariableName = '';
4961
+ this.reexported = false;
4962
+ this.renderPath = undefined;
4963
+ this.renormalizeRenderPath = false;
4964
+ this.used = false;
4965
+ this.variableName = '';
4966
+ this.execIndex = Infinity;
4967
+ this.suggestedVariableName = makeLegal(id.split(/[\\/]/).pop());
4968
+ this.nameSuggestions = Object.create(null);
4969
+ this.declarations = Object.create(null);
4970
+ this.exportedVariables = new Map();
4971
+ const module = this;
4972
+ this.info = {
4973
+ ast: null,
4974
+ code: null,
4975
+ dynamicallyImportedIds: EMPTY_ARRAY,
4976
+ get dynamicImporters() {
4977
+ return module.dynamicImporters.sort();
4978
+ },
4979
+ hasModuleSideEffects,
4980
+ id,
4981
+ implicitlyLoadedAfterOneOf: EMPTY_ARRAY,
4982
+ implicitlyLoadedBefore: EMPTY_ARRAY,
4983
+ importedIds: EMPTY_ARRAY,
4984
+ get importers() {
4985
+ return module.importers.sort();
4986
+ },
4987
+ isEntry: false,
4988
+ isExternal: true,
4989
+ meta,
4990
+ syntheticNamedExports: false
4991
+ };
5246
4992
  }
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}`;
4993
+ getVariableForExportName(name) {
4994
+ let declaration = this.declarations[name];
4995
+ if (declaration)
4996
+ return declaration;
4997
+ this.declarations[name] = declaration = new ExternalVariable(this, name);
4998
+ this.exportedVariables.set(declaration, name);
4999
+ return declaration;
5000
+ }
5001
+ setRenderPath(options, inputBase) {
5002
+ this.renderPath =
5003
+ typeof options.paths === 'function' ? options.paths(this.id) : options.paths[this.id];
5004
+ if (!this.renderPath) {
5005
+ if (!isAbsolute(this.id)) {
5006
+ this.renderPath = this.id;
5007
+ }
5008
+ else {
5009
+ this.renderPath = normalize(sysPath.relative(inputBase, this.id));
5010
+ this.renormalizeRenderPath = true;
5011
+ }
5257
5012
  }
5258
- return `${lineNum}: ${tabsToSpaces(str)}`;
5259
- })
5260
- .join('\n');
5013
+ return this.renderPath;
5014
+ }
5015
+ suggestName(name) {
5016
+ if (!this.nameSuggestions[name])
5017
+ this.nameSuggestions[name] = 0;
5018
+ this.nameSuggestions[name] += 1;
5019
+ if (this.nameSuggestions[name] > this.mostCommonSuggestion) {
5020
+ this.mostCommonSuggestion = this.nameSuggestions[name];
5021
+ this.suggestedVariableName = name;
5022
+ }
5023
+ }
5024
+ warnUnusedImports() {
5025
+ const unused = Object.keys(this.declarations).filter(name => {
5026
+ if (name === '*')
5027
+ return false;
5028
+ const declaration = this.declarations[name];
5029
+ return !declaration.included && !this.reexported && !declaration.referenced;
5030
+ });
5031
+ if (unused.length === 0)
5032
+ return;
5033
+ const names = unused.length === 1
5034
+ ? `'${unused[0]}' is`
5035
+ : `${unused
5036
+ .slice(0, -1)
5037
+ .map(name => `'${name}'`)
5038
+ .join(', ')} and '${unused.slice(-1)}' are`;
5039
+ this.options.onwarn({
5040
+ code: 'UNUSED_EXTERNAL_IMPORT',
5041
+ message: `${names} imported from external module '${this.id}' but never used`,
5042
+ names: unused,
5043
+ source: this.id
5044
+ });
5045
+ }
5261
5046
  }
5262
5047
 
5263
- function error(base) {
5264
- if (!(base instanceof Error))
5265
- base = Object.assign(new Error(base.message), base);
5266
- throw base;
5048
+ function removeJsExtension(name) {
5049
+ return name.endsWith('.js') ? name.slice(0, -3) : name;
5267
5050
  }
5268
- function augmentCodeLocation(props, pos, source, id) {
5269
- if (typeof pos === 'object') {
5270
- const { line, column } = pos;
5271
- props.loc = { file: id, line, column };
5051
+
5052
+ function getCompleteAmdId(options, chunkId) {
5053
+ if (!options.autoId) {
5054
+ return options.id || '';
5272
5055
  }
5273
5056
  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);
5057
+ return `${options.basePath ? options.basePath + '/' : ''}${removeJsExtension(chunkId)}`;
5281
5058
  }
5282
5059
  }
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
- };
5060
+
5061
+ const INTEROP_DEFAULT_VARIABLE = '_interopDefault';
5062
+ const INTEROP_DEFAULT_LEGACY_VARIABLE = '_interopDefaultLegacy';
5063
+ const INTEROP_NAMESPACE_VARIABLE = '_interopNamespace';
5064
+ const INTEROP_NAMESPACE_DEFAULT_VARIABLE = '_interopNamespaceDefault';
5065
+ const INTEROP_NAMESPACE_DEFAULT_ONLY_VARIABLE = '_interopNamespaceDefaultOnly';
5066
+ const defaultInteropHelpersByInteropType = {
5067
+ auto: INTEROP_DEFAULT_VARIABLE,
5068
+ default: null,
5069
+ defaultOnly: null,
5070
+ esModule: null,
5071
+ false: null,
5072
+ true: INTEROP_DEFAULT_LEGACY_VARIABLE
5073
+ };
5074
+ function isDefaultAProperty(interopType, externalLiveBindings) {
5075
+ return (interopType === 'esModule' ||
5076
+ (externalLiveBindings && (interopType === 'auto' || interopType === 'true')));
5387
5077
  }
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
- };
5078
+ const namespaceInteropHelpersByInteropType = {
5079
+ auto: INTEROP_NAMESPACE_VARIABLE,
5080
+ default: INTEROP_NAMESPACE_DEFAULT_VARIABLE,
5081
+ defaultOnly: INTEROP_NAMESPACE_DEFAULT_ONLY_VARIABLE,
5082
+ esModule: null,
5083
+ false: null,
5084
+ true: INTEROP_NAMESPACE_VARIABLE
5085
+ };
5086
+ function canDefaultBeTakenFromNamespace(interopType, externalLiveBindings) {
5087
+ return (isDefaultAProperty(interopType, externalLiveBindings) &&
5088
+ defaultInteropHelpersByInteropType[interopType] === INTEROP_DEFAULT_VARIABLE);
5394
5089
  }
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
- };
5090
+ function getDefaultOnlyHelper() {
5091
+ return INTEROP_NAMESPACE_DEFAULT_ONLY_VARIABLE;
5400
5092
  }
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
- };
5093
+ function getHelpersBlock(usedHelpers, accessedGlobals, _, n, s, t, liveBindings, freeze, namespaceToStringTag) {
5094
+ return HELPER_NAMES.map(variable => usedHelpers.has(variable) || accessedGlobals.has(variable)
5095
+ ? HELPER_GENERATORS[variable](_, n, s, t, liveBindings, freeze, namespaceToStringTag, usedHelpers)
5096
+ : '').join('');
5406
5097
  }
5407
- function errInvalidOption(option, explanation) {
5408
- return {
5409
- code: Errors.INVALID_OPTION,
5410
- message: `Invalid value for option "${option}" - ${explanation}.`
5411
- };
5098
+ const HELPER_GENERATORS = {
5099
+ [INTEROP_DEFAULT_VARIABLE]: (_, n, s, _t, liveBindings) => `function ${INTEROP_DEFAULT_VARIABLE}${_}(e)${_}{${_}return ` +
5100
+ `e${_}&&${_}e.__esModule${_}?${_}` +
5101
+ `${liveBindings ? getDefaultLiveBinding(_) : getDefaultStatic(_)}${s}${_}}${n}${n}`,
5102
+ [INTEROP_DEFAULT_LEGACY_VARIABLE]: (_, n, s, _t, liveBindings) => `function ${INTEROP_DEFAULT_LEGACY_VARIABLE}${_}(e)${_}{${_}return ` +
5103
+ `e${_}&&${_}typeof e${_}===${_}'object'${_}&&${_}'default'${_}in e${_}?${_}` +
5104
+ `${liveBindings ? getDefaultLiveBinding(_) : getDefaultStatic(_)}${s}${_}}${n}${n}`,
5105
+ [INTEROP_NAMESPACE_VARIABLE]: (_, n, s, t, liveBindings, freeze, namespaceToStringTag, usedHelpers) => `function ${INTEROP_NAMESPACE_VARIABLE}(e)${_}{${n}` +
5106
+ (usedHelpers.has(INTEROP_NAMESPACE_DEFAULT_VARIABLE)
5107
+ ? `${t}return e${_}&&${_}e.__esModule${_}?${_}e${_}:${_}${INTEROP_NAMESPACE_DEFAULT_VARIABLE}(e)${s}${n}`
5108
+ : `${t}if${_}(e${_}&&${_}e.__esModule)${_}return e;${n}` +
5109
+ createNamespaceObject(_, n, t, t, liveBindings, freeze, namespaceToStringTag)) +
5110
+ `}${n}${n}`,
5111
+ [INTEROP_NAMESPACE_DEFAULT_VARIABLE]: (_, n, _s, t, liveBindings, freeze, namespaceToStringTag) => `function ${INTEROP_NAMESPACE_DEFAULT_VARIABLE}(e)${_}{${n}` +
5112
+ createNamespaceObject(_, n, t, t, liveBindings, freeze, namespaceToStringTag) +
5113
+ `}${n}${n}`,
5114
+ [INTEROP_NAMESPACE_DEFAULT_ONLY_VARIABLE]: (_, n, _s, t, _liveBindings, freeze, namespaceToStringTag) => `function ${INTEROP_NAMESPACE_DEFAULT_ONLY_VARIABLE}(e)${_}{${n}` +
5115
+ `${t}return ${getFrozen(`{__proto__: null,${namespaceToStringTag ? `${_}[Symbol.toStringTag]:${_}'Module',` : ''}${_}'default':${_}e}`, freeze)};${n}` +
5116
+ `}${n}${n}`
5117
+ };
5118
+ function getDefaultLiveBinding(_) {
5119
+ return `e${_}:${_}{${_}'default':${_}e${_}}`;
5412
5120
  }
5413
- function errInvalidRollupPhaseForAddWatchFile() {
5414
- return {
5415
- code: Errors.INVALID_ROLLUP_PHASE,
5416
- message: `Cannot call addWatchFile after the build has finished.`
5417
- };
5121
+ function getDefaultStatic(_) {
5122
+ return `e['default']${_}:${_}e`;
5418
5123
  }
5419
- function errInvalidRollupPhaseForChunkEmission() {
5420
- return {
5421
- code: Errors.INVALID_ROLLUP_PHASE,
5422
- message: `Cannot emit chunks after module loading has finished.`
5423
- };
5124
+ function createNamespaceObject(_, n, t, i, liveBindings, freeze, namespaceToStringTag) {
5125
+ return (`${i}var n${_}=${_}${namespaceToStringTag
5126
+ ? `{__proto__:${_}null,${_}[Symbol.toStringTag]:${_}'Module'}`
5127
+ : 'Object.create(null)'};${n}` +
5128
+ `${i}if${_}(e)${_}{${n}` +
5129
+ `${i}${t}Object.keys(e).forEach(function${_}(k)${_}{${n}` +
5130
+ (liveBindings ? copyPropertyLiveBinding : copyPropertyStatic)(_, n, t, i + t + t) +
5131
+ `${i}${t}});${n}` +
5132
+ `${i}}${n}` +
5133
+ `${i}n['default']${_}=${_}e;${n}` +
5134
+ `${i}return ${getFrozen('n', freeze)};${n}`);
5424
5135
  }
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
- };
5136
+ function copyPropertyLiveBinding(_, n, t, i) {
5137
+ return (`${i}if${_}(k${_}!==${_}'default')${_}{${n}` +
5138
+ `${i}${t}var d${_}=${_}Object.getOwnPropertyDescriptor(e,${_}k);${n}` +
5139
+ `${i}${t}Object.defineProperty(n,${_}k,${_}d.get${_}?${_}d${_}:${_}{${n}` +
5140
+ `${i}${t}${t}enumerable:${_}true,${n}` +
5141
+ `${i}${t}${t}get:${_}function${_}()${_}{${n}` +
5142
+ `${i}${t}${t}${t}return e[k];${n}` +
5143
+ `${i}${t}${t}}${n}` +
5144
+ `${i}${t}});${n}` +
5145
+ `${i}}${n}`);
5430
5146
  }
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
- };
5147
+ function copyPropertyStatic(_, n, _t, i) {
5148
+ return `${i}n[k]${_}=${_}e[k];${n}`;
5436
5149
  }
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
- };
5150
+ function getFrozen(fragment, freeze) {
5151
+ return freeze ? `Object.freeze(${fragment})` : fragment;
5445
5152
  }
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
- };
5153
+ const HELPER_NAMES = Object.keys(HELPER_GENERATORS);
5154
+
5155
+ function getExportBlock(exports, dependencies, namedExportsMode, interop, compact, t, externalLiveBindings, mechanism = 'return ') {
5156
+ const _ = compact ? '' : ' ';
5157
+ const n = compact ? '' : '\n';
5158
+ if (!namedExportsMode) {
5159
+ return `${n}${n}${mechanism}${getSingleDefaultExport(exports, dependencies, interop, externalLiveBindings)};`;
5160
+ }
5161
+ let exportBlock = '';
5162
+ // star exports must always output first for precedence
5163
+ for (const { name, reexports } of dependencies) {
5164
+ if (reexports && namedExportsMode) {
5165
+ for (const specifier of reexports) {
5166
+ if (specifier.reexported === '*') {
5167
+ if (exportBlock)
5168
+ exportBlock += n;
5169
+ if (specifier.needsLiveBinding) {
5170
+ exportBlock +=
5171
+ `Object.keys(${name}).forEach(function${_}(k)${_}{${n}` +
5172
+ `${t}if${_}(k${_}!==${_}'default')${_}Object.defineProperty(exports,${_}k,${_}{${n}` +
5173
+ `${t}${t}enumerable:${_}true,${n}` +
5174
+ `${t}${t}get:${_}function${_}()${_}{${n}` +
5175
+ `${t}${t}${t}return ${name}[k];${n}` +
5176
+ `${t}${t}}${n}${t}});${n}});`;
5177
+ }
5178
+ else {
5179
+ exportBlock +=
5180
+ `Object.keys(${name}).forEach(function${_}(k)${_}{${n}` +
5181
+ `${t}if${_}(k${_}!==${_}'default')${_}exports[k]${_}=${_}${name}[k];${n}});`;
5182
+ }
5183
+ }
5184
+ }
5185
+ }
5186
+ }
5187
+ for (const { defaultVariableName, id, isChunk, name, namedExportsMode: depNamedExportsMode, namespaceVariableName, reexports } of dependencies) {
5188
+ if (reexports && namedExportsMode) {
5189
+ for (const specifier of reexports) {
5190
+ if (specifier.reexported !== '*') {
5191
+ const importName = getReexportedImportName(name, specifier.imported, depNamedExportsMode, isChunk, defaultVariableName, namespaceVariableName, interop, id, externalLiveBindings);
5192
+ if (exportBlock)
5193
+ exportBlock += n;
5194
+ exportBlock +=
5195
+ specifier.imported !== '*' && specifier.needsLiveBinding
5196
+ ? `Object.defineProperty(exports,${_}'${specifier.reexported}',${_}{${n}` +
5197
+ `${t}enumerable:${_}true,${n}` +
5198
+ `${t}get:${_}function${_}()${_}{${n}` +
5199
+ `${t}${t}return ${importName};${n}${t}}${n}});`
5200
+ : `exports.${specifier.reexported}${_}=${_}${importName};`;
5201
+ }
5202
+ }
5203
+ }
5204
+ }
5205
+ for (const chunkExport of exports) {
5206
+ const lhs = `exports.${chunkExport.exported}`;
5207
+ const rhs = chunkExport.local;
5208
+ if (lhs !== rhs) {
5209
+ if (exportBlock)
5210
+ exportBlock += n;
5211
+ exportBlock += `${lhs}${_}=${_}${rhs};`;
5212
+ }
5213
+ }
5214
+ if (exportBlock) {
5215
+ return `${n}${n}${exportBlock}`;
5216
+ }
5217
+ return '';
5453
5218
  }
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
- };
5219
+ function getSingleDefaultExport(exports, dependencies, interop, externalLiveBindings) {
5220
+ if (exports.length > 0) {
5221
+ return exports[0].local;
5222
+ }
5223
+ else {
5224
+ for (const { defaultVariableName, id, isChunk, name, namedExportsMode: depNamedExportsMode, namespaceVariableName, reexports } of dependencies) {
5225
+ if (reexports) {
5226
+ return getReexportedImportName(name, reexports[0].imported, depNamedExportsMode, isChunk, defaultVariableName, namespaceVariableName, interop, id, externalLiveBindings);
5227
+ }
5228
+ }
5229
+ }
5462
5230
  }
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
- };
5231
+ function getReexportedImportName(moduleVariableName, imported, depNamedExportsMode, isChunk, defaultVariableName, namespaceVariableName, interop, moduleId, externalLiveBindings) {
5232
+ if (imported === 'default') {
5233
+ if (!isChunk) {
5234
+ const moduleInterop = String(interop(moduleId));
5235
+ const variableName = defaultInteropHelpersByInteropType[moduleInterop]
5236
+ ? defaultVariableName
5237
+ : moduleVariableName;
5238
+ return isDefaultAProperty(moduleInterop, externalLiveBindings)
5239
+ ? `${variableName}['default']`
5240
+ : variableName;
5241
+ }
5242
+ return depNamedExportsMode ? `${moduleVariableName}['default']` : moduleVariableName;
5243
+ }
5244
+ if (imported === '*') {
5245
+ return (isChunk
5246
+ ? !depNamedExportsMode
5247
+ : namespaceInteropHelpersByInteropType[String(interop(moduleId))])
5248
+ ? namespaceVariableName
5249
+ : moduleVariableName;
5250
+ }
5251
+ return `${moduleVariableName}.${imported}`;
5469
5252
  }
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
- };
5253
+ function getEsModuleExport(_) {
5254
+ return `Object.defineProperty(exports,${_}'__esModule',${_}{${_}value:${_}true${_}});`;
5478
5255
  }
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
- };
5256
+ function getNamespaceToStringExport(_) {
5257
+ return `exports[Symbol.toStringTag]${_}=${_}'Module';`;
5487
5258
  }
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
- };
5259
+ function getNamespaceMarkers(hasNamedExports, addEsModule, addNamespaceToStringTag, _, n) {
5260
+ let namespaceMarkers = '';
5261
+ if (hasNamedExports) {
5262
+ if (addEsModule) {
5263
+ namespaceMarkers += getEsModuleExport(_);
5264
+ }
5265
+ if (addNamespaceToStringTag) {
5266
+ if (namespaceMarkers) {
5267
+ namespaceMarkers += n;
5268
+ }
5269
+ namespaceMarkers += getNamespaceToStringExport(_);
5270
+ }
5271
+ }
5272
+ return namespaceMarkers;
5495
5273
  }
5496
- function errEntryCannotBeExternal(unresolvedId) {
5497
- return {
5498
- code: Errors.UNRESOLVED_ENTRY,
5499
- message: `Entry module cannot be external (${relativeId(unresolvedId)}).`
5274
+
5275
+ function getInteropBlock(dependencies, varOrConst, interop, externalLiveBindings, freeze, namespaceToStringTag, accessedGlobals, _, n, s, t) {
5276
+ const neededInteropHelpers = new Set();
5277
+ const interopStatements = [];
5278
+ const addInteropStatement = (helperVariableName, helper, dependencyVariableName) => {
5279
+ neededInteropHelpers.add(helper);
5280
+ interopStatements.push(`${varOrConst} ${helperVariableName}${_}=${_}/*#__PURE__*/${helper}(${dependencyVariableName});`);
5500
5281
  };
5282
+ for (const { defaultVariableName, imports, id, isChunk, name, namedExportsMode, namespaceVariableName, reexports } of dependencies) {
5283
+ if (isChunk) {
5284
+ for (const { imported, reexported } of [
5285
+ ...(imports || []),
5286
+ ...(reexports || [])
5287
+ ]) {
5288
+ if (imported === '*' && reexported !== '*') {
5289
+ if (!namedExportsMode) {
5290
+ addInteropStatement(namespaceVariableName, getDefaultOnlyHelper(), name);
5291
+ }
5292
+ break;
5293
+ }
5294
+ }
5295
+ }
5296
+ else {
5297
+ const moduleInterop = String(interop(id));
5298
+ let hasDefault = false;
5299
+ let hasNamespace = false;
5300
+ for (const { imported, reexported } of [
5301
+ ...(imports || []),
5302
+ ...(reexports || [])
5303
+ ]) {
5304
+ let helper;
5305
+ let variableName;
5306
+ if (imported === 'default') {
5307
+ if (!hasDefault) {
5308
+ hasDefault = true;
5309
+ if (defaultVariableName !== namespaceVariableName) {
5310
+ variableName = defaultVariableName;
5311
+ helper = defaultInteropHelpersByInteropType[moduleInterop];
5312
+ }
5313
+ }
5314
+ }
5315
+ else if (imported === '*' && reexported !== '*') {
5316
+ if (!hasNamespace) {
5317
+ hasNamespace = true;
5318
+ helper = namespaceInteropHelpersByInteropType[moduleInterop];
5319
+ variableName = namespaceVariableName;
5320
+ }
5321
+ }
5322
+ if (helper) {
5323
+ addInteropStatement(variableName, helper, name);
5324
+ }
5325
+ }
5326
+ }
5327
+ }
5328
+ return `${getHelpersBlock(neededInteropHelpers, accessedGlobals, _, n, s, t, externalLiveBindings, freeze, namespaceToStringTag)}${interopStatements.length > 0 ? `${interopStatements.join(n)}${n}${n}` : ''}`;
5501
5329
  }
5502
- function errUnresolvedEntry(unresolvedId) {
5503
- return {
5504
- code: Errors.UNRESOLVED_ENTRY,
5505
- message: `Could not resolve entry module (${relativeId(unresolvedId)}).`
5506
- };
5330
+
5331
+ // AMD resolution will only respect the AMD baseUrl if the .js extension is omitted.
5332
+ // The assumption is that this makes sense for all relative ids:
5333
+ // https://requirejs.org/docs/api.html#jsfiles
5334
+ function removeExtensionFromRelativeAmdId(id) {
5335
+ return id[0] === '.' ? removeJsExtension(id) : id;
5507
5336
  }
5508
- function errUnresolvedImport(source, importer) {
5509
- return {
5510
- code: Errors.UNRESOLVED_IMPORT,
5511
- message: `Could not resolve '${source}' from ${relativeId(importer)}`
5512
- };
5337
+
5338
+ const builtins$1 = {
5339
+ assert: true,
5340
+ buffer: true,
5341
+ console: true,
5342
+ constants: true,
5343
+ domain: true,
5344
+ events: true,
5345
+ http: true,
5346
+ https: true,
5347
+ os: true,
5348
+ path: true,
5349
+ process: true,
5350
+ punycode: true,
5351
+ querystring: true,
5352
+ stream: true,
5353
+ string_decoder: true,
5354
+ timers: true,
5355
+ tty: true,
5356
+ url: true,
5357
+ util: true,
5358
+ vm: true,
5359
+ zlib: true
5360
+ };
5361
+ function warnOnBuiltins(warn, dependencies) {
5362
+ const externalBuiltins = dependencies.map(({ id }) => id).filter(id => id in builtins$1);
5363
+ if (!externalBuiltins.length)
5364
+ return;
5365
+ const detail = externalBuiltins.length === 1
5366
+ ? `module ('${externalBuiltins[0]}')`
5367
+ : `modules (${externalBuiltins
5368
+ .slice(0, -1)
5369
+ .map(name => `'${name}'`)
5370
+ .join(', ')} and '${externalBuiltins.slice(-1)}')`;
5371
+ warn({
5372
+ code: 'MISSING_NODE_BUILTINS',
5373
+ 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`,
5374
+ modules: externalBuiltins
5375
+ });
5513
5376
  }
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
- };
5377
+
5378
+ 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 }) {
5379
+ warnOnBuiltins(warn, dependencies);
5380
+ const deps = dependencies.map(m => `'${removeExtensionFromRelativeAmdId(m.id)}'`);
5381
+ const args = dependencies.map(m => m.name);
5382
+ const n = compact ? '' : '\n';
5383
+ const s = compact ? '' : ';';
5384
+ const _ = compact ? '' : ' ';
5385
+ if (namedExportsMode && hasExports) {
5386
+ args.unshift(`exports`);
5387
+ deps.unshift(`'exports'`);
5388
+ }
5389
+ if (accessedGlobals.has('require')) {
5390
+ args.unshift('require');
5391
+ deps.unshift(`'require'`);
5392
+ }
5393
+ if (accessedGlobals.has('module')) {
5394
+ args.unshift('module');
5395
+ deps.unshift(`'module'`);
5396
+ }
5397
+ const completeAmdId = getCompleteAmdId(amd, id);
5398
+ const params = (completeAmdId ? `'${completeAmdId}',${_}` : ``) +
5399
+ (deps.length ? `[${deps.join(`,${_}`)}],${_}` : ``);
5400
+ const useStrict = strict ? `${_}'use strict';` : '';
5401
+ magicString.prepend(`${intro}${getInteropBlock(dependencies, varOrConst, interop, externalLiveBindings, freeze, namespaceToStringTag, accessedGlobals, _, n, s, t)}`);
5402
+ const exportBlock = getExportBlock(exports, dependencies, namedExportsMode, interop, compact, t, externalLiveBindings);
5403
+ let namespaceMarkers = getNamespaceMarkers(namedExportsMode && hasExports, isEntryFacade && esModule, isModuleFacade && namespaceToStringTag, _, n);
5404
+ if (namespaceMarkers) {
5405
+ namespaceMarkers = n + n + namespaceMarkers;
5406
+ }
5407
+ magicString.append(`${exportBlock}${namespaceMarkers}${outro}`);
5408
+ return magicString
5409
+ .indent(t)
5410
+ .prepend(`${amd.define}(${params}function${_}(${args.join(`,${_}`)})${_}{${useStrict}${n}${n}`)
5411
+ .append(`${n}${n}});`);
5522
5412
  }
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
- };
5413
+
5414
+ function cjs(magicString, { accessedGlobals, dependencies, exports, hasExports, indentString: t, intro, isEntryFacade, isModuleFacade, namedExportsMode, outro, varOrConst }, { compact, esModule, externalLiveBindings, freeze, interop, namespaceToStringTag, strict }) {
5415
+ const n = compact ? '' : '\n';
5416
+ const s = compact ? '' : ';';
5417
+ const _ = compact ? '' : ' ';
5418
+ const useStrict = strict ? `'use strict';${n}${n}` : '';
5419
+ let namespaceMarkers = getNamespaceMarkers(namedExportsMode && hasExports, isEntryFacade && esModule, isModuleFacade && namespaceToStringTag, _, n);
5420
+ if (namespaceMarkers) {
5421
+ namespaceMarkers += n + n;
5422
+ }
5423
+ const importBlock = getImportBlock(dependencies, compact, varOrConst, n, _);
5424
+ const interopBlock = getInteropBlock(dependencies, varOrConst, interop, externalLiveBindings, freeze, namespaceToStringTag, accessedGlobals, _, n, s, t);
5425
+ magicString.prepend(`${useStrict}${intro}${namespaceMarkers}${importBlock}${interopBlock}`);
5426
+ const exportBlock = getExportBlock(exports, dependencies, namedExportsMode, interop, compact, t, externalLiveBindings, `module.exports${_}=${_}`);
5427
+ return magicString.append(`${exportBlock}${outro}`);
5530
5428
  }
5531
- function errFailedValidation(message) {
5532
- return {
5533
- code: Errors.VALIDATION_ERROR,
5534
- message
5535
- };
5429
+ function getImportBlock(dependencies, compact, varOrConst, n, _) {
5430
+ let importBlock = '';
5431
+ let definingVariable = false;
5432
+ for (const { id, name, reexports, imports } of dependencies) {
5433
+ if (!reexports && !imports) {
5434
+ if (importBlock) {
5435
+ importBlock += !compact || definingVariable ? `;${n}` : ',';
5436
+ }
5437
+ definingVariable = false;
5438
+ importBlock += `require('${id}')`;
5439
+ }
5440
+ else {
5441
+ importBlock +=
5442
+ compact && definingVariable ? ',' : `${importBlock ? `;${n}` : ''}${varOrConst} `;
5443
+ definingVariable = true;
5444
+ importBlock += `${name}${_}=${_}require('${id}')`;
5445
+ }
5446
+ }
5447
+ if (importBlock) {
5448
+ return `${importBlock};${n}${n}`;
5449
+ }
5450
+ return '';
5536
5451
  }
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
- };
5452
+
5453
+ function es(magicString, { intro, outro, dependencies, exports, varOrConst }, { compact }) {
5454
+ const _ = compact ? '' : ' ';
5455
+ const n = compact ? '' : '\n';
5456
+ const importBlock = getImportBlock$1(dependencies, _);
5457
+ if (importBlock.length > 0)
5458
+ intro += importBlock.join(n) + n + n;
5459
+ if (intro)
5460
+ magicString.prepend(intro);
5461
+ const exportBlock = getExportBlock$1(exports, _, varOrConst);
5462
+ if (exportBlock.length)
5463
+ magicString.append(n + n + exportBlock.join(n).trim());
5464
+ if (outro)
5465
+ magicString.append(outro);
5466
+ return magicString.trim();
5542
5467
  }
5543
- function warnDeprecation(deprecation, activeDeprecation, options) {
5544
- warnDeprecationWithOptions(deprecation, activeDeprecation, options.onwarn, options.strictDeprecations);
5468
+ function getImportBlock$1(dependencies, _) {
5469
+ const importBlock = [];
5470
+ for (const { id, reexports, imports, name } of dependencies) {
5471
+ if (!reexports && !imports) {
5472
+ importBlock.push(`import${_}'${id}';`);
5473
+ continue;
5474
+ }
5475
+ if (imports) {
5476
+ let defaultImport = null;
5477
+ let starImport = null;
5478
+ const importedNames = [];
5479
+ for (const specifier of imports) {
5480
+ if (specifier.imported === 'default') {
5481
+ defaultImport = specifier;
5482
+ }
5483
+ else if (specifier.imported === '*') {
5484
+ starImport = specifier;
5485
+ }
5486
+ else {
5487
+ importedNames.push(specifier);
5488
+ }
5489
+ }
5490
+ if (starImport) {
5491
+ importBlock.push(`import${_}*${_}as ${starImport.local} from${_}'${id}';`);
5492
+ }
5493
+ if (defaultImport && importedNames.length === 0) {
5494
+ importBlock.push(`import ${defaultImport.local} from${_}'${id}';`);
5495
+ }
5496
+ else if (importedNames.length > 0) {
5497
+ importBlock.push(`import ${defaultImport ? `${defaultImport.local},${_}` : ''}{${_}${importedNames
5498
+ .map(specifier => {
5499
+ if (specifier.imported === specifier.local) {
5500
+ return specifier.imported;
5501
+ }
5502
+ else {
5503
+ return `${specifier.imported} as ${specifier.local}`;
5504
+ }
5505
+ })
5506
+ .join(`,${_}`)}${_}}${_}from${_}'${id}';`);
5507
+ }
5508
+ }
5509
+ if (reexports) {
5510
+ let starExport = null;
5511
+ const namespaceReexports = [];
5512
+ const namedReexports = [];
5513
+ for (const specifier of reexports) {
5514
+ if (specifier.reexported === '*') {
5515
+ starExport = specifier;
5516
+ }
5517
+ else if (specifier.imported === '*') {
5518
+ namespaceReexports.push(specifier);
5519
+ }
5520
+ else {
5521
+ namedReexports.push(specifier);
5522
+ }
5523
+ }
5524
+ if (starExport) {
5525
+ importBlock.push(`export${_}*${_}from${_}'${id}';`);
5526
+ }
5527
+ if (namespaceReexports.length > 0) {
5528
+ if (!imports ||
5529
+ !imports.some(specifier => specifier.imported === '*' && specifier.local === name)) {
5530
+ importBlock.push(`import${_}*${_}as ${name} from${_}'${id}';`);
5531
+ }
5532
+ for (const specifier of namespaceReexports) {
5533
+ importBlock.push(`export${_}{${_}${name === specifier.reexported ? name : `${name} as ${specifier.reexported}`} };`);
5534
+ }
5535
+ }
5536
+ if (namedReexports.length > 0) {
5537
+ importBlock.push(`export${_}{${_}${namedReexports
5538
+ .map(specifier => {
5539
+ if (specifier.imported === specifier.reexported) {
5540
+ return specifier.imported;
5541
+ }
5542
+ else {
5543
+ return `${specifier.imported} as ${specifier.reexported}`;
5544
+ }
5545
+ })
5546
+ .join(`,${_}`)}${_}}${_}from${_}'${id}';`);
5547
+ }
5548
+ }
5549
+ }
5550
+ return importBlock;
5545
5551
  }
5546
- function warnDeprecationWithOptions(deprecation, activeDeprecation, warn, strictDeprecations) {
5547
- if (activeDeprecation || strictDeprecations) {
5548
- const warning = errDeprecation(deprecation);
5549
- if (strictDeprecations) {
5550
- return error(warning);
5552
+ function getExportBlock$1(exports, _, varOrConst) {
5553
+ const exportBlock = [];
5554
+ const exportDeclaration = [];
5555
+ for (const specifier of exports) {
5556
+ if (specifier.exported === 'default') {
5557
+ exportBlock.push(`export default ${specifier.local};`);
5558
+ }
5559
+ else {
5560
+ if (specifier.expression) {
5561
+ exportBlock.push(`${varOrConst} ${specifier.local}${_}=${_}${specifier.expression};`);
5562
+ }
5563
+ exportDeclaration.push(specifier.exported === specifier.local
5564
+ ? specifier.local
5565
+ : `${specifier.local} as ${specifier.exported}`);
5551
5566
  }
5552
- warn(warning);
5553
5567
  }
5568
+ if (exportDeclaration.length) {
5569
+ exportBlock.push(`export${_}{${_}${exportDeclaration.join(`,${_}`)}${_}};`);
5570
+ }
5571
+ return exportBlock;
5554
5572
  }
5555
5573
 
5556
5574
  // Generate strings which dereference dotted properties, but use array notation `['prop-deref']`
@@ -6212,13 +6230,17 @@ class AssignmentExpression extends NodeBase {
6212
6230
  }
6213
6231
  this.right.include(context, includeChildrenRecursively);
6214
6232
  }
6215
- render(code, options) {
6216
- this.right.render(code, options);
6233
+ render(code, options, { renderedParentType } = BLANK) {
6217
6234
  if (this.left.included) {
6218
6235
  this.left.render(code, options);
6236
+ this.right.render(code, options);
6219
6237
  }
6220
6238
  else {
6221
- code.remove(this.start, this.right.start);
6239
+ this.right.render(code, options, {
6240
+ renderedParentType: renderedParentType || this.parent.type
6241
+ });
6242
+ const operatorPos = findFirstOccurrenceOutsideComment(code.original, '=', this.left.end);
6243
+ code.remove(this.start, findNonWhiteSpace(code.original, operatorPos + 1));
6222
6244
  }
6223
6245
  if (options.format === 'system') {
6224
6246
  const exportNames = this.left.variable && options.exportNamesByVariable.get(this.left.variable);
@@ -6569,7 +6591,7 @@ class MemberExpression extends NodeBase {
6569
6591
  if (!this.included) {
6570
6592
  this.included = true;
6571
6593
  if (this.variable !== null) {
6572
- this.context.includeVariable(this.variable);
6594
+ this.context.includeVariableInModule(this.variable);
6573
6595
  }
6574
6596
  }
6575
6597
  this.object.include(context, includeChildrenRecursively);
@@ -6609,7 +6631,7 @@ class MemberExpression extends NodeBase {
6609
6631
  const variable = this.scope.findVariable(this.object.name);
6610
6632
  if (variable.isNamespace) {
6611
6633
  if (this.variable) {
6612
- this.context.includeVariable(this.variable);
6634
+ this.context.includeVariableInModule(this.variable);
6613
6635
  }
6614
6636
  this.context.warn({
6615
6637
  code: 'ILLEGAL_NAMESPACE_REASSIGNMENT',
@@ -9718,6 +9740,24 @@ function initialiseTimers(inputOptions) {
9718
9740
  }
9719
9741
  }
9720
9742
 
9743
+ function markModuleAndImpureDependenciesAsExecuted(baseModule) {
9744
+ baseModule.isExecuted = true;
9745
+ const modules = [baseModule];
9746
+ const visitedModules = new Set();
9747
+ for (const module of modules) {
9748
+ for (const dependency of [...module.dependencies, ...module.implicitlyLoadedBefore]) {
9749
+ if (!(dependency instanceof ExternalModule) &&
9750
+ !dependency.isExecuted &&
9751
+ (dependency.info.hasModuleSideEffects || module.implicitlyLoadedBefore.has(dependency)) &&
9752
+ !visitedModules.has(dependency.id)) {
9753
+ dependency.isExecuted = true;
9754
+ visitedModules.add(dependency.id);
9755
+ modules.push(dependency);
9756
+ }
9757
+ }
9758
+ }
9759
+ }
9760
+
9721
9761
  function tryParse(module, Parser, acornOptions) {
9722
9762
  try {
9723
9763
  return Parser.parse(module.info.code, {
@@ -9740,39 +9780,60 @@ function tryParse(module, Parser, acornOptions) {
9740
9780
  }, err.pos);
9741
9781
  }
9742
9782
  }
9743
- function handleMissingExport(exportName, importingModule, importedModule, importerStart) {
9744
- return importingModule.error({
9745
- code: 'MISSING_EXPORT',
9746
- message: `'${exportName}' is not exported by ${relativeId(importedModule)}, imported by ${relativeId(importingModule.id)}`,
9747
- url: `https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module`
9748
- }, importerStart);
9749
- }
9750
9783
  const MISSING_EXPORT_SHIM_DESCRIPTION = {
9751
9784
  identifier: null,
9752
9785
  localName: MISSING_EXPORT_SHIM_VARIABLE
9753
9786
  };
9754
- function getVariableForExportNameRecursive(target, name, isExportAllSearch, searchedNamesAndModules = new Map()) {
9787
+ function getVariableForExportNameRecursive(target, name, importerForSideEffects, isExportAllSearch, searchedNamesAndModules = new Map()) {
9755
9788
  const searchedModules = searchedNamesAndModules.get(name);
9756
9789
  if (searchedModules) {
9757
9790
  if (searchedModules.has(target)) {
9758
- return null;
9791
+ return isExportAllSearch ? null : error(errCircularReexport(name, target.id));
9759
9792
  }
9760
9793
  searchedModules.add(target);
9761
9794
  }
9762
9795
  else {
9763
9796
  searchedNamesAndModules.set(name, new Set([target]));
9764
9797
  }
9765
- return target.getVariableForExportName(name, isExportAllSearch, searchedNamesAndModules);
9798
+ return target.getVariableForExportName(name, importerForSideEffects, isExportAllSearch, searchedNamesAndModules);
9799
+ }
9800
+ function getAndExtendSideEffectModules(variable, module) {
9801
+ const sideEffectModules = getOrCreate(module.sideEffectDependenciesByVariable, variable, () => new Set());
9802
+ let currentVariable = variable;
9803
+ const referencedVariables = new Set([currentVariable]);
9804
+ while (true) {
9805
+ const importingModule = currentVariable.module;
9806
+ currentVariable =
9807
+ currentVariable instanceof ExportDefaultVariable
9808
+ ? currentVariable.getDirectOriginalVariable()
9809
+ : currentVariable instanceof SyntheticNamedExportVariable
9810
+ ? currentVariable.syntheticNamespace
9811
+ : null;
9812
+ if (!currentVariable || referencedVariables.has(currentVariable)) {
9813
+ break;
9814
+ }
9815
+ referencedVariables.add(variable);
9816
+ sideEffectModules.add(importingModule);
9817
+ const originalSideEffects = importingModule.sideEffectDependenciesByVariable.get(currentVariable);
9818
+ if (originalSideEffects) {
9819
+ for (const module of originalSideEffects) {
9820
+ sideEffectModules.add(module);
9821
+ }
9822
+ }
9823
+ }
9824
+ return sideEffectModules;
9766
9825
  }
9767
9826
  class Module {
9768
9827
  constructor(graph, id, options, isEntry, hasModuleSideEffects, syntheticNamedExports, meta) {
9769
9828
  this.graph = graph;
9770
9829
  this.id = id;
9771
9830
  this.options = options;
9831
+ this.alternativeReexportModules = new Map();
9772
9832
  this.ast = null;
9773
9833
  this.chunkFileNames = new Set();
9774
9834
  this.chunkName = null;
9775
9835
  this.comments = [];
9836
+ this.cycles = new Set();
9776
9837
  this.dependencies = new Set();
9777
9838
  this.dynamicDependencies = new Set();
9778
9839
  this.dynamicImporters = [];
@@ -9792,6 +9853,7 @@ class Module {
9792
9853
  this.isUserDefinedEntryPoint = false;
9793
9854
  this.preserveSignature = this.options.preserveEntrySignatures;
9794
9855
  this.reexportDescriptions = Object.create(null);
9856
+ this.sideEffectDependenciesByVariable = new Map();
9795
9857
  this.sources = new Set();
9796
9858
  this.userChunkNames = new Set();
9797
9859
  this.usesTopLevelAwait = false;
@@ -9881,9 +9943,9 @@ class Module {
9881
9943
  if (this.relevantDependencies)
9882
9944
  return this.relevantDependencies;
9883
9945
  const relevantDependencies = new Set();
9884
- const additionalSideEffectModules = new Set();
9885
- const possibleDependencies = new Set(this.dependencies);
9886
- let dependencyVariables = this.imports;
9946
+ const necessaryDependencies = new Set();
9947
+ const alwaysCheckedDependencies = new Set();
9948
+ let dependencyVariables = this.imports.keys();
9887
9949
  if (this.info.isEntry ||
9888
9950
  this.includedDynamicImporters.length > 0 ||
9889
9951
  this.namespace.included ||
@@ -9894,41 +9956,31 @@ class Module {
9894
9956
  }
9895
9957
  }
9896
9958
  for (let variable of dependencyVariables) {
9959
+ const sideEffectDependencies = this.sideEffectDependenciesByVariable.get(variable);
9960
+ if (sideEffectDependencies) {
9961
+ for (const module of sideEffectDependencies) {
9962
+ alwaysCheckedDependencies.add(module);
9963
+ }
9964
+ }
9897
9965
  if (variable instanceof SyntheticNamedExportVariable) {
9898
9966
  variable = variable.getBaseVariable();
9899
9967
  }
9900
9968
  else if (variable instanceof ExportDefaultVariable) {
9901
- const { modules, original } = variable.getOriginalVariableAndDeclarationModules();
9902
- variable = original;
9903
- for (const module of modules) {
9904
- additionalSideEffectModules.add(module);
9905
- possibleDependencies.add(module);
9906
- }
9969
+ variable = variable.getOriginalVariable();
9907
9970
  }
9908
- relevantDependencies.add(variable.module);
9971
+ necessaryDependencies.add(variable.module);
9909
9972
  }
9910
9973
  if (this.options.treeshake && this.info.hasModuleSideEffects !== 'no-treeshake') {
9911
- for (const dependency of possibleDependencies) {
9912
- if (!(dependency.info.hasModuleSideEffects ||
9913
- additionalSideEffectModules.has(dependency)) ||
9914
- relevantDependencies.has(dependency)) {
9915
- continue;
9916
- }
9917
- if (dependency instanceof ExternalModule || dependency.hasEffects()) {
9918
- relevantDependencies.add(dependency);
9919
- }
9920
- else {
9921
- for (const transitiveDependency of dependency.dependencies) {
9922
- possibleDependencies.add(transitiveDependency);
9923
- }
9924
- }
9925
- }
9974
+ this.addRelevantSideEffectDependencies(relevantDependencies, necessaryDependencies, alwaysCheckedDependencies);
9926
9975
  }
9927
9976
  else {
9928
9977
  for (const dependency of this.dependencies) {
9929
9978
  relevantDependencies.add(dependency);
9930
9979
  }
9931
9980
  }
9981
+ for (const dependency of necessaryDependencies) {
9982
+ relevantDependencies.add(dependency);
9983
+ }
9932
9984
  return (this.relevantDependencies = relevantDependencies);
9933
9985
  }
9934
9986
  getExportNamesByVariable() {
@@ -10001,20 +10053,14 @@ class Module {
10001
10053
  : 'default');
10002
10054
  }
10003
10055
  if (!this.syntheticNamespace) {
10004
- return error({
10005
- code: Errors.SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT,
10006
- id: this.id,
10007
- message: `Module "${relativeId(this.id)}" that is marked with 'syntheticNamedExports: ${JSON.stringify(this.info.syntheticNamedExports)}' needs ${typeof this.info.syntheticNamedExports === 'string' &&
10008
- this.info.syntheticNamedExports !== 'default'
10009
- ? `an export named "${this.info.syntheticNamedExports}"`
10010
- : 'a default export'}.`
10011
- });
10056
+ return error(errSyntheticNamedExportsNeedNamespaceExport(this.id, this.info.syntheticNamedExports));
10012
10057
  }
10013
10058
  return this.syntheticNamespace;
10014
10059
  }
10015
- getVariableForExportName(name, isExportAllSearch, searchedNamesAndModules) {
10060
+ getVariableForExportName(name, importerForSideEffects, isExportAllSearch, searchedNamesAndModules) {
10016
10061
  if (name[0] === '*') {
10017
10062
  if (name.length === 1) {
10063
+ // export * from './other'
10018
10064
  return this.namespace;
10019
10065
  }
10020
10066
  else {
@@ -10026,11 +10072,14 @@ class Module {
10026
10072
  // export { foo } from './other'
10027
10073
  const reexportDeclaration = this.reexportDescriptions[name];
10028
10074
  if (reexportDeclaration) {
10029
- const declaration = getVariableForExportNameRecursive(reexportDeclaration.module, reexportDeclaration.localName, false, searchedNamesAndModules);
10030
- if (!declaration) {
10031
- return handleMissingExport(reexportDeclaration.localName, this, reexportDeclaration.module.id, reexportDeclaration.start);
10075
+ const variable = getVariableForExportNameRecursive(reexportDeclaration.module, reexportDeclaration.localName, importerForSideEffects, false, searchedNamesAndModules);
10076
+ if (!variable) {
10077
+ return this.error(errMissingExport(reexportDeclaration.localName, this.id, reexportDeclaration.module.id), reexportDeclaration.start);
10032
10078
  }
10033
- return declaration;
10079
+ if (importerForSideEffects) {
10080
+ setAlternativeExporterIfCyclic(variable, importerForSideEffects, this);
10081
+ }
10082
+ return variable;
10034
10083
  }
10035
10084
  const exportDeclaration = this.exports[name];
10036
10085
  if (exportDeclaration) {
@@ -10038,28 +10087,43 @@ class Module {
10038
10087
  return this.exportShimVariable;
10039
10088
  }
10040
10089
  const name = exportDeclaration.localName;
10041
- return this.traceVariable(name);
10090
+ const variable = this.traceVariable(name, importerForSideEffects);
10091
+ if (importerForSideEffects) {
10092
+ getOrCreate(importerForSideEffects.sideEffectDependenciesByVariable, variable, () => new Set()).add(this);
10093
+ setAlternativeExporterIfCyclic(variable, importerForSideEffects, this);
10094
+ }
10095
+ return variable;
10042
10096
  }
10043
10097
  if (name !== 'default') {
10098
+ let foundSyntheticDeclaration = null;
10044
10099
  for (const module of this.exportAllModules) {
10045
- const declaration = getVariableForExportNameRecursive(module, name, true, searchedNamesAndModules);
10046
- if (declaration)
10047
- return declaration;
10100
+ const declaration = getVariableForExportNameRecursive(module, name, importerForSideEffects, true, searchedNamesAndModules);
10101
+ if (declaration) {
10102
+ if (!(declaration instanceof SyntheticNamedExportVariable)) {
10103
+ return declaration;
10104
+ }
10105
+ if (!foundSyntheticDeclaration) {
10106
+ foundSyntheticDeclaration = declaration;
10107
+ }
10108
+ }
10109
+ }
10110
+ if (foundSyntheticDeclaration) {
10111
+ return foundSyntheticDeclaration;
10112
+ }
10113
+ }
10114
+ if (this.info.syntheticNamedExports) {
10115
+ let syntheticExport = this.syntheticExports.get(name);
10116
+ if (!syntheticExport) {
10117
+ const syntheticNamespace = this.getSyntheticNamespace();
10118
+ syntheticExport = new SyntheticNamedExportVariable(this.astContext, name, syntheticNamespace);
10119
+ this.syntheticExports.set(name, syntheticExport);
10120
+ return syntheticExport;
10048
10121
  }
10122
+ return syntheticExport;
10049
10123
  }
10050
10124
  // we don't want to create shims when we are just
10051
10125
  // probing export * modules for exports
10052
10126
  if (!isExportAllSearch) {
10053
- if (this.info.syntheticNamedExports) {
10054
- let syntheticExport = this.syntheticExports.get(name);
10055
- if (!syntheticExport) {
10056
- const syntheticNamespace = this.getSyntheticNamespace();
10057
- syntheticExport = new SyntheticNamedExportVariable(this.astContext, name, syntheticNamespace);
10058
- this.syntheticExports.set(name, syntheticExport);
10059
- return syntheticExport;
10060
- }
10061
- return syntheticExport;
10062
- }
10063
10127
  if (this.options.shimMissingExports) {
10064
10128
  this.shimMissingExport(name);
10065
10129
  return this.exportShimVariable;
@@ -10086,8 +10150,7 @@ class Module {
10086
10150
  const variable = this.getVariableForExportName(exportName);
10087
10151
  variable.deoptimizePath(UNKNOWN_PATH);
10088
10152
  if (!variable.included) {
10089
- variable.include();
10090
- this.graph.needsTreeshakingPass = true;
10153
+ this.includeVariable(variable);
10091
10154
  }
10092
10155
  }
10093
10156
  }
@@ -10095,8 +10158,7 @@ class Module {
10095
10158
  const variable = this.getVariableForExportName(name);
10096
10159
  variable.deoptimizePath(UNKNOWN_PATH);
10097
10160
  if (!variable.included) {
10098
- variable.include();
10099
- this.graph.needsTreeshakingPass = true;
10161
+ this.includeVariable(variable);
10100
10162
  }
10101
10163
  if (variable instanceof ExternalVariable) {
10102
10164
  variable.module.reexported = true;
@@ -10116,7 +10178,7 @@ class Module {
10116
10178
  this.addModulesToImportDescriptions(this.importDescriptions);
10117
10179
  this.addModulesToImportDescriptions(this.reexportDescriptions);
10118
10180
  for (const name in this.exports) {
10119
- if (name !== 'default') {
10181
+ if (name !== 'default' && name !== this.info.syntheticNamedExports) {
10120
10182
  this.exportsAll[name] = this.id;
10121
10183
  }
10122
10184
  }
@@ -10196,7 +10258,7 @@ class Module {
10196
10258
  importDescriptions: this.importDescriptions,
10197
10259
  includeAllExports: () => this.includeAllExports(true),
10198
10260
  includeDynamicImport: this.includeDynamicImport.bind(this),
10199
- includeVariable: this.includeVariable.bind(this),
10261
+ includeVariableInModule: this.includeVariableInModule.bind(this),
10200
10262
  magicString: this.magicString,
10201
10263
  module: this,
10202
10264
  moduleContext: this.context,
@@ -10232,7 +10294,7 @@ class Module {
10232
10294
  transformFiles: this.transformFiles
10233
10295
  };
10234
10296
  }
10235
- traceVariable(name) {
10297
+ traceVariable(name, importerForSideEffects) {
10236
10298
  const localVariable = this.scope.variables.get(name);
10237
10299
  if (localVariable) {
10238
10300
  return localVariable;
@@ -10243,9 +10305,9 @@ class Module {
10243
10305
  if (otherModule instanceof Module && importDeclaration.name === '*') {
10244
10306
  return otherModule.namespace;
10245
10307
  }
10246
- const declaration = otherModule.getVariableForExportName(importDeclaration.name);
10308
+ const declaration = otherModule.getVariableForExportName(importDeclaration.name, importerForSideEffects || this);
10247
10309
  if (!declaration) {
10248
- return handleMissingExport(importDeclaration.name, this, otherModule.id, importDeclaration.start);
10310
+ return this.error(errMissingExport(importDeclaration.name, this.id, otherModule.id), importDeclaration.start);
10249
10311
  }
10250
10312
  return declaration;
10251
10313
  }
@@ -10397,6 +10459,31 @@ class Module {
10397
10459
  specifier.module = this.graph.modulesById.get(id);
10398
10460
  }
10399
10461
  }
10462
+ addRelevantSideEffectDependencies(relevantDependencies, necessaryDependencies, alwaysCheckedDependencies) {
10463
+ const handledDependencies = new Set();
10464
+ const addSideEffectDependencies = (possibleDependencies) => {
10465
+ for (const dependency of possibleDependencies) {
10466
+ if (handledDependencies.has(dependency)) {
10467
+ continue;
10468
+ }
10469
+ handledDependencies.add(dependency);
10470
+ if (necessaryDependencies.has(dependency)) {
10471
+ relevantDependencies.add(dependency);
10472
+ continue;
10473
+ }
10474
+ if (!(dependency.info.hasModuleSideEffects || alwaysCheckedDependencies.has(dependency))) {
10475
+ continue;
10476
+ }
10477
+ if (dependency instanceof ExternalModule || dependency.hasEffects()) {
10478
+ relevantDependencies.add(dependency);
10479
+ continue;
10480
+ }
10481
+ addSideEffectDependencies(dependency.dependencies);
10482
+ }
10483
+ };
10484
+ addSideEffectDependencies(this.dependencies);
10485
+ addSideEffectDependencies(alwaysCheckedDependencies);
10486
+ }
10400
10487
  includeAndGetAdditionalMergedNamespaces() {
10401
10488
  const mergedNamespaces = [];
10402
10489
  for (const module of this.exportAllModules) {
@@ -10423,11 +10510,26 @@ class Module {
10423
10510
  }
10424
10511
  }
10425
10512
  includeVariable(variable) {
10426
- const variableModule = variable.module;
10427
10513
  if (!variable.included) {
10428
10514
  variable.include();
10429
10515
  this.graph.needsTreeshakingPass = true;
10516
+ const variableModule = variable.module;
10517
+ if (variableModule && variableModule !== this && variableModule instanceof Module) {
10518
+ if (!variableModule.isExecuted) {
10519
+ markModuleAndImpureDependenciesAsExecuted(variableModule);
10520
+ }
10521
+ const sideEffectModules = getAndExtendSideEffectModules(variable, this);
10522
+ for (const module of sideEffectModules) {
10523
+ if (!module.isExecuted) {
10524
+ markModuleAndImpureDependenciesAsExecuted(module);
10525
+ }
10526
+ }
10527
+ }
10430
10528
  }
10529
+ }
10530
+ includeVariableInModule(variable) {
10531
+ this.includeVariable(variable);
10532
+ const variableModule = variable.module;
10431
10533
  if (variableModule && variableModule !== this) {
10432
10534
  this.imports.add(variable);
10433
10535
  }
@@ -10442,6 +10544,23 @@ class Module {
10442
10544
  this.exports[name] = MISSING_EXPORT_SHIM_DESCRIPTION;
10443
10545
  }
10444
10546
  }
10547
+ // if there is a cyclic import in the reexport chain, we should not
10548
+ // import from the original module but from the cyclic module to not
10549
+ // mess up execution order.
10550
+ function setAlternativeExporterIfCyclic(variable, importer, reexporter) {
10551
+ if (variable.module instanceof Module && variable.module !== reexporter) {
10552
+ const exporterCycles = variable.module.cycles;
10553
+ if (exporterCycles.size > 0) {
10554
+ const importerCycles = reexporter.cycles;
10555
+ for (const cycleSymbol of importerCycles) {
10556
+ if (exporterCycles.has(cycleSymbol)) {
10557
+ importer.alternativeReexportModules.set(variable, reexporter);
10558
+ break;
10559
+ }
10560
+ }
10561
+ }
10562
+ }
10563
+ }
10445
10564
 
10446
10565
  class Source {
10447
10566
  constructor(filename, content) {
@@ -10728,68 +10847,6 @@ function escapeId(id) {
10728
10847
  return id.replace(backSlashRegEx, '\\\\').replace(quoteNewlineRegEx, '\\$1');
10729
10848
  }
10730
10849
 
10731
- const compareExecIndex = (unitA, unitB) => unitA.execIndex > unitB.execIndex ? 1 : -1;
10732
- function sortByExecutionOrder(units) {
10733
- units.sort(compareExecIndex);
10734
- }
10735
- function analyseModuleExecution(entryModules) {
10736
- let nextExecIndex = 0;
10737
- const cyclePaths = [];
10738
- const analysedModules = new Set();
10739
- const dynamicImports = new Set();
10740
- const parents = new Map();
10741
- const orderedModules = [];
10742
- const analyseModule = (module) => {
10743
- if (module instanceof Module) {
10744
- for (const dependency of module.dependencies) {
10745
- if (parents.has(dependency)) {
10746
- if (!analysedModules.has(dependency)) {
10747
- cyclePaths.push(getCyclePath(dependency, module, parents));
10748
- }
10749
- continue;
10750
- }
10751
- parents.set(dependency, module);
10752
- analyseModule(dependency);
10753
- }
10754
- for (const dependency of module.implicitlyLoadedBefore) {
10755
- dynamicImports.add(dependency);
10756
- }
10757
- for (const { resolution } of module.dynamicImports) {
10758
- if (resolution instanceof Module) {
10759
- dynamicImports.add(resolution);
10760
- }
10761
- }
10762
- orderedModules.push(module);
10763
- }
10764
- module.execIndex = nextExecIndex++;
10765
- analysedModules.add(module);
10766
- };
10767
- for (const curEntry of entryModules) {
10768
- if (!parents.has(curEntry)) {
10769
- parents.set(curEntry, null);
10770
- analyseModule(curEntry);
10771
- }
10772
- }
10773
- for (const curEntry of dynamicImports) {
10774
- if (!parents.has(curEntry)) {
10775
- parents.set(curEntry, null);
10776
- analyseModule(curEntry);
10777
- }
10778
- }
10779
- return { orderedModules, cyclePaths };
10780
- }
10781
- function getCyclePath(module, parent, parents) {
10782
- const path = [relativeId(module.id)];
10783
- let nextModule = parent;
10784
- while (nextModule !== module) {
10785
- path.push(relativeId(nextModule.id));
10786
- nextModule = parents.get(nextModule);
10787
- }
10788
- path.push(path[0]);
10789
- path.reverse();
10790
- return path;
10791
- }
10792
-
10793
10850
  function assignExportsToMangledNames(exports, exportsByName, exportNamesByVariable) {
10794
10851
  let nameIndex = 0;
10795
10852
  for (const variable of exports) {
@@ -10881,6 +10938,44 @@ function getIndentString(modules, options) {
10881
10938
  return '\t';
10882
10939
  }
10883
10940
 
10941
+ function getStaticDependencies(chunk, orderedModules, chunkByModule) {
10942
+ const staticDependencyBlocks = [];
10943
+ const handledDependencies = new Set();
10944
+ for (let modulePos = orderedModules.length - 1; modulePos >= 0; modulePos--) {
10945
+ const module = orderedModules[modulePos];
10946
+ if (!handledDependencies.has(module)) {
10947
+ const staticDependencies = [];
10948
+ addStaticDependencies(module, staticDependencies, handledDependencies, chunk, chunkByModule);
10949
+ staticDependencyBlocks.unshift(staticDependencies);
10950
+ }
10951
+ }
10952
+ const dependencies = new Set();
10953
+ for (const block of staticDependencyBlocks) {
10954
+ for (const dependency of block) {
10955
+ dependencies.add(dependency);
10956
+ }
10957
+ }
10958
+ return dependencies;
10959
+ }
10960
+ function addStaticDependencies(module, staticDependencies, handledModules, chunk, chunkByModule) {
10961
+ const dependencies = module.getDependenciesToBeIncluded();
10962
+ for (const dependency of dependencies) {
10963
+ if (dependency instanceof ExternalModule) {
10964
+ staticDependencies.push(dependency);
10965
+ continue;
10966
+ }
10967
+ const dependencyChunk = chunkByModule.get(dependency);
10968
+ if (dependencyChunk !== chunk) {
10969
+ staticDependencies.push(dependencyChunk);
10970
+ continue;
10971
+ }
10972
+ if (!handledModules.has(dependency)) {
10973
+ handledModules.add(dependency);
10974
+ addStaticDependencies(dependency, staticDependencies, handledModules, chunk, chunkByModule);
10975
+ }
10976
+ }
10977
+ }
10978
+
10884
10979
  function decodedSourcemap(map) {
10885
10980
  if (!map)
10886
10981
  return null;
@@ -11136,7 +11231,6 @@ class Chunk$1 {
11136
11231
  this.facadeChunkByModule.set(module, this);
11137
11232
  if (module.preserveSignature) {
11138
11233
  this.strictFacade = needsStrictFacade;
11139
- this.ensureReexportsAreAvailableForModule(module);
11140
11234
  }
11141
11235
  this.assignFacadeName(requiredFacades.shift(), module);
11142
11236
  }
@@ -11274,8 +11368,8 @@ class Chunk$1 {
11274
11368
  return this.exportNamesByVariable.get(variable)[0];
11275
11369
  }
11276
11370
  link() {
11371
+ this.dependencies = getStaticDependencies(this, this.orderedModules, this.chunkByModule);
11277
11372
  for (const module of this.orderedModules) {
11278
- this.addDependenciesToChunk(module.getDependenciesToBeIncluded(), this.dependencies);
11279
11373
  this.addDependenciesToChunk(module.dynamicDependencies, this.dynamicDependencies);
11280
11374
  this.addDependenciesToChunk(module.implicitlyLoadedBefore, this.implicitlyLoadedBefore);
11281
11375
  this.setUpChunkImportsAndExportsForModule(module);
@@ -11308,9 +11402,6 @@ class Chunk$1 {
11308
11402
  this.inlineChunkDependencies(dep);
11309
11403
  }
11310
11404
  }
11311
- const sortedDependencies = [...this.dependencies];
11312
- sortByExecutionOrder(sortedDependencies);
11313
- this.dependencies = new Set(sortedDependencies);
11314
11405
  this.prepareDynamicImportsAndImportMetas();
11315
11406
  this.setIdentifierRenderResolutions(options);
11316
11407
  let hoistedSource = '';
@@ -11502,6 +11593,23 @@ class Chunk$1 {
11502
11593
  this.name = sanitizeFileName(name || facadedModule.chunkName || getAliasName(facadedModule.id));
11503
11594
  }
11504
11595
  }
11596
+ checkCircularDependencyImport(variable, importingModule) {
11597
+ const variableModule = variable.module;
11598
+ if (variableModule instanceof Module) {
11599
+ const exportChunk = this.chunkByModule.get(variableModule);
11600
+ let alternativeReexportModule;
11601
+ do {
11602
+ alternativeReexportModule = importingModule.alternativeReexportModules.get(variable);
11603
+ if (alternativeReexportModule) {
11604
+ const exportingChunk = this.chunkByModule.get(alternativeReexportModule);
11605
+ if (exportingChunk && exportingChunk !== exportChunk) {
11606
+ this.inputOptions.onwarn(errCyclicCrossChunkReexport(variableModule.getExportNamesByVariable().get(variable)[0], variableModule.id, alternativeReexportModule.id, importingModule.id));
11607
+ }
11608
+ importingModule = alternativeReexportModule;
11609
+ }
11610
+ } while (alternativeReexportModule);
11611
+ }
11612
+ }
11505
11613
  computeContentHashWithDependencies(addons, options, existingNames) {
11506
11614
  const hash = createHash();
11507
11615
  hash.update([addons.intro, addons.outro, addons.banner, addons.footer].map(addon => addon || '').join(':'));
@@ -11531,6 +11639,7 @@ class Chunk$1 {
11531
11639
  ? exportedVariable.getBaseVariable()
11532
11640
  : exportedVariable;
11533
11641
  if (!(importedVariable instanceof NamespaceVariable && this.outputOptions.preserveModules)) {
11642
+ this.checkCircularDependencyImport(importedVariable, module);
11534
11643
  const exportingModule = importedVariable.module;
11535
11644
  if (exportingModule instanceof Module) {
11536
11645
  const chunk = this.chunkByModule.get(exportingModule);
@@ -11926,6 +12035,7 @@ class Chunk$1 {
11926
12035
  if (!(variable instanceof NamespaceVariable && this.outputOptions.preserveModules) &&
11927
12036
  variable.module instanceof Module) {
11928
12037
  chunk.exports.add(variable);
12038
+ this.checkCircularDependencyImport(variable, module);
11929
12039
  }
11930
12040
  }
11931
12041
  }
@@ -12129,6 +12239,71 @@ function commondir(files) {
12129
12239
  return commonSegments.length > 1 ? commonSegments.join('/') : '/';
12130
12240
  }
12131
12241
 
12242
+ const compareExecIndex = (unitA, unitB) => unitA.execIndex > unitB.execIndex ? 1 : -1;
12243
+ function sortByExecutionOrder(units) {
12244
+ units.sort(compareExecIndex);
12245
+ }
12246
+ function analyseModuleExecution(entryModules) {
12247
+ let nextExecIndex = 0;
12248
+ const cyclePaths = [];
12249
+ const analysedModules = new Set();
12250
+ const dynamicImports = new Set();
12251
+ const parents = new Map();
12252
+ const orderedModules = [];
12253
+ const analyseModule = (module) => {
12254
+ if (module instanceof Module) {
12255
+ for (const dependency of module.dependencies) {
12256
+ if (parents.has(dependency)) {
12257
+ if (!analysedModules.has(dependency)) {
12258
+ cyclePaths.push(getCyclePath(dependency, module, parents));
12259
+ }
12260
+ continue;
12261
+ }
12262
+ parents.set(dependency, module);
12263
+ analyseModule(dependency);
12264
+ }
12265
+ for (const dependency of module.implicitlyLoadedBefore) {
12266
+ dynamicImports.add(dependency);
12267
+ }
12268
+ for (const { resolution } of module.dynamicImports) {
12269
+ if (resolution instanceof Module) {
12270
+ dynamicImports.add(resolution);
12271
+ }
12272
+ }
12273
+ orderedModules.push(module);
12274
+ }
12275
+ module.execIndex = nextExecIndex++;
12276
+ analysedModules.add(module);
12277
+ };
12278
+ for (const curEntry of entryModules) {
12279
+ if (!parents.has(curEntry)) {
12280
+ parents.set(curEntry, null);
12281
+ analyseModule(curEntry);
12282
+ }
12283
+ }
12284
+ for (const curEntry of dynamicImports) {
12285
+ if (!parents.has(curEntry)) {
12286
+ parents.set(curEntry, null);
12287
+ analyseModule(curEntry);
12288
+ }
12289
+ }
12290
+ return { orderedModules, cyclePaths };
12291
+ }
12292
+ function getCyclePath(module, parent, parents) {
12293
+ const cycleSymbol = Symbol(module.id);
12294
+ const path = [relativeId(module.id)];
12295
+ let nextModule = parent;
12296
+ module.cycles.add(cycleSymbol);
12297
+ while (nextModule !== module) {
12298
+ nextModule.cycles.add(cycleSymbol);
12299
+ path.push(relativeId(nextModule.id));
12300
+ nextModule = parents.get(nextModule);
12301
+ }
12302
+ path.push(path[0]);
12303
+ path.reverse();
12304
+ return path;
12305
+ }
12306
+
12132
12307
  var BuildPhase;
12133
12308
  (function (BuildPhase) {
12134
12309
  BuildPhase[BuildPhase["LOAD_AND_PARSE"] = 0] = "LOAD_AND_PARSE";
@@ -19255,160 +19430,6 @@ var acornClassFields = function(Parser) {
19255
19430
  }
19256
19431
  };
19257
19432
 
19258
- function withoutAcornBigInt(acorn, Parser) {
19259
- return class extends Parser {
19260
- readInt(radix, len) {
19261
- // Hack: len is only != null for unicode escape sequences,
19262
- // where numeric separators are not allowed
19263
- if (len != null) return super.readInt(radix, len)
19264
-
19265
- let start = this.pos, total = 0, acceptUnderscore = false;
19266
- for (;;) {
19267
- let code = this.input.charCodeAt(this.pos), val;
19268
- if (code >= 97) val = code - 97 + 10; // a
19269
- else if (code == 95) {
19270
- if (!acceptUnderscore) this.raise(this.pos, "Invalid numeric separator");
19271
- ++this.pos;
19272
- acceptUnderscore = false;
19273
- continue
19274
- } else if (code >= 65) val = code - 65 + 10; // A
19275
- else if (code >= 48 && code <= 57) val = code - 48; // 0-9
19276
- else val = Infinity;
19277
- if (val >= radix) break
19278
- ++this.pos;
19279
- total = total * radix + val;
19280
- acceptUnderscore = true;
19281
- }
19282
- if (this.pos === start) return null
19283
- if (!acceptUnderscore) this.raise(this.pos - 1, "Invalid numeric separator");
19284
-
19285
- return total
19286
- }
19287
-
19288
- readNumber(startsWithDot) {
19289
- const token = super.readNumber(startsWithDot);
19290
- let octal = this.end - this.start >= 2 && this.input.charCodeAt(this.start) === 48;
19291
- const stripped = this.getNumberInput(this.start, this.end);
19292
- if (stripped.length < this.end - this.start) {
19293
- if (octal) this.raise(this.start, "Invalid number");
19294
- this.value = parseFloat(stripped);
19295
- }
19296
- return token
19297
- }
19298
-
19299
- // This is used by acorn-bigint
19300
- getNumberInput(start, end) {
19301
- return this.input.slice(start, end).replace(/_/g, "")
19302
- }
19303
- }
19304
- }
19305
-
19306
- function withAcornBigInt(acorn, Parser) {
19307
- return class extends Parser {
19308
- readInt(radix, len) {
19309
- // Hack: len is only != null for unicode escape sequences,
19310
- // where numeric separators are not allowed
19311
- if (len != null) return super.readInt(radix, len)
19312
-
19313
- let start = this.pos, total = 0, acceptUnderscore = false;
19314
- for (;;) {
19315
- let code = this.input.charCodeAt(this.pos), val;
19316
- if (code >= 97) val = code - 97 + 10; // a
19317
- else if (code == 95) {
19318
- if (!acceptUnderscore) this.raise(this.pos, "Invalid numeric separator");
19319
- ++this.pos;
19320
- acceptUnderscore = false;
19321
- continue
19322
- } else if (code >= 65) val = code - 65 + 10; // A
19323
- else if (code >= 48 && code <= 57) val = code - 48; // 0-9
19324
- else val = Infinity;
19325
- if (val >= radix) break
19326
- ++this.pos;
19327
- total = total * radix + val;
19328
- acceptUnderscore = true;
19329
- }
19330
- if (this.pos === start) return null
19331
- if (!acceptUnderscore) this.raise(this.pos - 1, "Invalid numeric separator");
19332
-
19333
- return total
19334
- }
19335
-
19336
- readNumber(startsWithDot) {
19337
- let start = this.pos;
19338
- if (!startsWithDot && this.readInt(10) === null) this.raise(start, "Invalid number");
19339
- let octal = this.pos - start >= 2 && this.input.charCodeAt(start) === 48;
19340
- let octalLike = false;
19341
- if (octal && this.strict) this.raise(start, "Invalid number");
19342
- let next = this.input.charCodeAt(this.pos);
19343
- if (!octal && !startsWithDot && this.options.ecmaVersion >= 11 && next === 110) {
19344
- let str = this.getNumberInput(start, this.pos);
19345
- // eslint-disable-next-line node/no-unsupported-features/es-builtins
19346
- let val = typeof BigInt !== "undefined" ? BigInt(str) : null;
19347
- ++this.pos;
19348
- if (acorn.isIdentifierStart(this.fullCharCodeAtPos())) this.raise(this.pos, "Identifier directly after number");
19349
- return this.finishToken(acorn.tokTypes.num, val)
19350
- }
19351
- if (octal && /[89]/.test(this.input.slice(start, this.pos))) {
19352
- octal = false;
19353
- octalLike = true;
19354
- }
19355
- if (next === 46 && !octal) { // '.'
19356
- ++this.pos;
19357
- this.readInt(10);
19358
- next = this.input.charCodeAt(this.pos);
19359
- }
19360
- if ((next === 69 || next === 101) && !octal) { // 'eE'
19361
- next = this.input.charCodeAt(++this.pos);
19362
- if (next === 43 || next === 45) ++this.pos; // '+-'
19363
- if (this.readInt(10) === null) this.raise(start, "Invalid number");
19364
- }
19365
- if (acorn.isIdentifierStart(this.fullCharCodeAtPos())) this.raise(this.pos, "Identifier directly after number");
19366
- let str = this.getNumberInput(start, this.pos);
19367
- if ((octal || octalLike) && str.length < this.pos - start) {
19368
- this.raise(start, "Invalid number");
19369
- }
19370
-
19371
- let val = octal ? parseInt(str, 8) : parseFloat(str);
19372
- return this.finishToken(acorn.tokTypes.num, val)
19373
- }
19374
-
19375
- parseLiteral(value) {
19376
- const ret = super.parseLiteral(value);
19377
- if (ret.bigint) ret.bigint = ret.bigint.replace(/_/g, "");
19378
- return ret
19379
- }
19380
-
19381
- readRadixNumber(radix) {
19382
- let start = this.pos;
19383
- this.pos += 2; // 0x
19384
- let val = this.readInt(radix);
19385
- if (val == null) { this.raise(this.start + 2, `Expected number in radix ${radix}`); }
19386
- if (this.options.ecmaVersion >= 11 && this.input.charCodeAt(this.pos) === 110) {
19387
- let str = this.getNumberInput(start, this.pos);
19388
- // eslint-disable-next-line node/no-unsupported-features/es-builtins
19389
- val = typeof BigInt !== "undefined" ? BigInt(str) : null;
19390
- ++this.pos;
19391
- } else if (acorn.isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
19392
- return this.finishToken(acorn.tokTypes.num, val)
19393
- }
19394
-
19395
- // This is used by acorn-bigint, which theoretically could be used with acorn@6.2 || acorn@7
19396
- getNumberInput(start, end) {
19397
- return this.input.slice(start, end).replace(/_/g, "")
19398
- }
19399
- }
19400
- }
19401
-
19402
- // eslint-disable-next-line node/no-unsupported-features/es-syntax
19403
- function numericSeparator(Parser) {
19404
- const acorn = Parser.acorn || require$$0;
19405
- const withAcornBigIntSupport = (acorn.version.startsWith("6.") && !(acorn.version.startsWith("6.0.") || acorn.version.startsWith("6.1."))) || acorn.version.startsWith("7.");
19406
-
19407
- return withAcornBigIntSupport ? withAcornBigInt(acorn, Parser) : withoutAcornBigInt(acorn, Parser)
19408
- }
19409
-
19410
- var acornNumericSeparator = numericSeparator;
19411
-
19412
19433
  var acornStaticClassFeatures = function(Parser) {
19413
19434
  const ExtendedParser = acornPrivateClassElements(Parser);
19414
19435
 
@@ -19549,7 +19570,6 @@ const getAcorn$1 = (config) => ({
19549
19570
  const getAcornInjectPlugins = (config) => [
19550
19571
  acornClassFields,
19551
19572
  acornStaticClassFeatures,
19552
- acornNumericSeparator,
19553
19573
  ...ensureArray(config.acornInjectPlugins)
19554
19574
  ];
19555
19575
  const getCache = (config) => {