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
@@ -13,7 +13,7 @@ import { createHash as createHash$1 } from 'crypto';
13
13
  import { writeFile as writeFile$1, readdirSync, mkdirSync, readFile as readFile$1, lstatSync, realpathSync } from 'fs';
14
14
  import { EventEmitter } from 'events';
15
15
 
16
- var version = "2.36.0";
16
+ var version = "2.37.1";
17
17
 
18
18
  var charToInteger = {};
19
19
  var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
@@ -1518,11 +1518,11 @@ function findFirstOccurrenceOutsideComment(code, searchString, start = 0) {
1518
1518
  }
1519
1519
  }
1520
1520
  }
1521
- const WHITESPACE = /\s/;
1521
+ const NON_WHITESPACE = /\S/g;
1522
1522
  function findNonWhiteSpace(code, index) {
1523
- while (index < code.length && WHITESPACE.test(code[index]))
1524
- index++;
1525
- return index;
1523
+ NON_WHITESPACE.lastIndex = index;
1524
+ const result = NON_WHITESPACE.exec(code);
1525
+ return result.index;
1526
1526
  }
1527
1527
  // This assumes "code" only contains white-space and comments
1528
1528
  // Returns position of line-comment if applicable
@@ -2183,6 +2183,34 @@ function getMemberReturnExpressionWhenCalled(members, memberName) {
2183
2183
  : new members[memberName].returns();
2184
2184
  }
2185
2185
 
2186
+ const BROKEN_FLOW_NONE = 0;
2187
+ const BROKEN_FLOW_BREAK_CONTINUE = 1;
2188
+ const BROKEN_FLOW_ERROR_RETURN_LABEL = 2;
2189
+ function createInclusionContext() {
2190
+ return {
2191
+ brokenFlow: BROKEN_FLOW_NONE,
2192
+ includedCallArguments: new Set(),
2193
+ includedLabels: new Set()
2194
+ };
2195
+ }
2196
+ function createHasEffectsContext() {
2197
+ return {
2198
+ accessed: new PathTracker(),
2199
+ assigned: new PathTracker(),
2200
+ brokenFlow: BROKEN_FLOW_NONE,
2201
+ called: new DiscriminatedPathTracker(),
2202
+ ignore: {
2203
+ breaks: false,
2204
+ continues: false,
2205
+ labels: new Set(),
2206
+ returnAwaitYield: false
2207
+ },
2208
+ includedLabels: new Set(),
2209
+ instantiated: new DiscriminatedPathTracker(),
2210
+ replacedVariableInits: new Map()
2211
+ };
2212
+ }
2213
+
2186
2214
  class Variable {
2187
2215
  constructor(name) {
2188
2216
  this.alwaysRendered = false;
@@ -2244,205 +2272,6 @@ class Variable {
2244
2272
  }
2245
2273
  }
2246
2274
 
2247
- class ExternalVariable extends Variable {
2248
- constructor(module, name) {
2249
- super(name);
2250
- this.module = module;
2251
- this.isNamespace = name === '*';
2252
- this.referenced = false;
2253
- }
2254
- addReference(identifier) {
2255
- this.referenced = true;
2256
- if (this.name === 'default' || this.name === '*') {
2257
- this.module.suggestName(identifier.name);
2258
- }
2259
- }
2260
- include() {
2261
- if (!this.included) {
2262
- this.included = true;
2263
- this.module.used = true;
2264
- }
2265
- }
2266
- }
2267
-
2268
- const BLANK = Object.freeze(Object.create(null));
2269
- const EMPTY_OBJECT = Object.freeze({});
2270
- const EMPTY_ARRAY = Object.freeze([]);
2271
-
2272
- 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(' ');
2273
- 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(' ');
2274
- const blacklisted = new Set(reservedWords.concat(builtins));
2275
- const illegalCharacters = /[^$_a-zA-Z0-9]/g;
2276
- const startsWithDigit = (str) => /\d/.test(str[0]);
2277
- function isLegal(str) {
2278
- if (startsWithDigit(str) || blacklisted.has(str)) {
2279
- return false;
2280
- }
2281
- return !illegalCharacters.test(str);
2282
- }
2283
- function makeLegal(str) {
2284
- str = str.replace(/-(\w)/g, (_, letter) => letter.toUpperCase()).replace(illegalCharacters, '_');
2285
- if (startsWithDigit(str) || blacklisted.has(str))
2286
- str = `_${str}`;
2287
- return str || '_';
2288
- }
2289
-
2290
- const absolutePath = /^(?:\/|(?:[A-Za-z]:)?[\\|/])/;
2291
- const relativePath = /^\.?\.\//;
2292
- function isAbsolute(path) {
2293
- return absolutePath.test(path);
2294
- }
2295
- function isRelative(path) {
2296
- return relativePath.test(path);
2297
- }
2298
- function normalize(path) {
2299
- if (path.indexOf('\\') == -1)
2300
- return path;
2301
- return path.replace(/\\/g, '/');
2302
- }
2303
-
2304
- class ExternalModule {
2305
- constructor(options, id, hasModuleSideEffects, meta) {
2306
- this.options = options;
2307
- this.id = id;
2308
- this.defaultVariableName = '';
2309
- this.dynamicImporters = [];
2310
- this.importers = [];
2311
- this.mostCommonSuggestion = 0;
2312
- this.namespaceVariableName = '';
2313
- this.reexported = false;
2314
- this.renderPath = undefined;
2315
- this.renormalizeRenderPath = false;
2316
- this.used = false;
2317
- this.variableName = '';
2318
- this.execIndex = Infinity;
2319
- this.suggestedVariableName = makeLegal(id.split(/[\\/]/).pop());
2320
- this.nameSuggestions = Object.create(null);
2321
- this.declarations = Object.create(null);
2322
- this.exportedVariables = new Map();
2323
- const module = this;
2324
- this.info = {
2325
- ast: null,
2326
- code: null,
2327
- dynamicallyImportedIds: EMPTY_ARRAY,
2328
- get dynamicImporters() {
2329
- return module.dynamicImporters.sort();
2330
- },
2331
- hasModuleSideEffects,
2332
- id,
2333
- implicitlyLoadedAfterOneOf: EMPTY_ARRAY,
2334
- implicitlyLoadedBefore: EMPTY_ARRAY,
2335
- importedIds: EMPTY_ARRAY,
2336
- get importers() {
2337
- return module.importers.sort();
2338
- },
2339
- isEntry: false,
2340
- isExternal: true,
2341
- meta,
2342
- syntheticNamedExports: false
2343
- };
2344
- }
2345
- getVariableForExportName(name) {
2346
- let declaration = this.declarations[name];
2347
- if (declaration)
2348
- return declaration;
2349
- this.declarations[name] = declaration = new ExternalVariable(this, name);
2350
- this.exportedVariables.set(declaration, name);
2351
- return declaration;
2352
- }
2353
- setRenderPath(options, inputBase) {
2354
- this.renderPath =
2355
- typeof options.paths === 'function' ? options.paths(this.id) : options.paths[this.id];
2356
- if (!this.renderPath) {
2357
- if (!isAbsolute(this.id)) {
2358
- this.renderPath = this.id;
2359
- }
2360
- else {
2361
- this.renderPath = normalize(relative$1(inputBase, this.id));
2362
- this.renormalizeRenderPath = true;
2363
- }
2364
- }
2365
- return this.renderPath;
2366
- }
2367
- suggestName(name) {
2368
- if (!this.nameSuggestions[name])
2369
- this.nameSuggestions[name] = 0;
2370
- this.nameSuggestions[name] += 1;
2371
- if (this.nameSuggestions[name] > this.mostCommonSuggestion) {
2372
- this.mostCommonSuggestion = this.nameSuggestions[name];
2373
- this.suggestedVariableName = name;
2374
- }
2375
- }
2376
- warnUnusedImports() {
2377
- const unused = Object.keys(this.declarations).filter(name => {
2378
- if (name === '*')
2379
- return false;
2380
- const declaration = this.declarations[name];
2381
- return !declaration.included && !this.reexported && !declaration.referenced;
2382
- });
2383
- if (unused.length === 0)
2384
- return;
2385
- const names = unused.length === 1
2386
- ? `'${unused[0]}' is`
2387
- : `${unused
2388
- .slice(0, -1)
2389
- .map(name => `'${name}'`)
2390
- .join(', ')} and '${unused.slice(-1)}' are`;
2391
- this.options.onwarn({
2392
- code: 'UNUSED_EXTERNAL_IMPORT',
2393
- message: `${names} imported from external module '${this.id}' but never used`,
2394
- names: unused,
2395
- source: this.id
2396
- });
2397
- }
2398
- }
2399
-
2400
- function markModuleAndImpureDependenciesAsExecuted(baseModule) {
2401
- baseModule.isExecuted = true;
2402
- const modules = [baseModule];
2403
- const visitedModules = new Set();
2404
- for (const module of modules) {
2405
- for (const dependency of [...module.dependencies, ...module.implicitlyLoadedBefore]) {
2406
- if (!(dependency instanceof ExternalModule) &&
2407
- !dependency.isExecuted &&
2408
- (dependency.info.hasModuleSideEffects || module.implicitlyLoadedBefore.has(dependency)) &&
2409
- !visitedModules.has(dependency.id)) {
2410
- dependency.isExecuted = true;
2411
- visitedModules.add(dependency.id);
2412
- modules.push(dependency);
2413
- }
2414
- }
2415
- }
2416
- }
2417
-
2418
- const BROKEN_FLOW_NONE = 0;
2419
- const BROKEN_FLOW_BREAK_CONTINUE = 1;
2420
- const BROKEN_FLOW_ERROR_RETURN_LABEL = 2;
2421
- function createInclusionContext() {
2422
- return {
2423
- brokenFlow: BROKEN_FLOW_NONE,
2424
- includedCallArguments: new Set(),
2425
- includedLabels: new Set()
2426
- };
2427
- }
2428
- function createHasEffectsContext() {
2429
- return {
2430
- accessed: new PathTracker(),
2431
- assigned: new PathTracker(),
2432
- brokenFlow: BROKEN_FLOW_NONE,
2433
- called: new DiscriminatedPathTracker(),
2434
- ignore: {
2435
- breaks: false,
2436
- continues: false,
2437
- labels: new Set(),
2438
- returnAwaitYield: false
2439
- },
2440
- includedLabels: new Set(),
2441
- instantiated: new DiscriminatedPathTracker(),
2442
- replacedVariableInits: new Map()
2443
- };
2444
- }
2445
-
2446
2275
  // To avoid infinite recursions
2447
2276
  const MAX_PATH_DEPTH = 7;
2448
2277
  class LocalVariable extends Variable {
@@ -2565,9 +2394,6 @@ class LocalVariable extends Variable {
2565
2394
  include() {
2566
2395
  if (!this.included) {
2567
2396
  this.included = true;
2568
- if (!this.module.isExecuted) {
2569
- markModuleAndImpureDependenciesAsExecuted(this.module);
2570
- }
2571
2397
  for (const declaration of this.declarations) {
2572
2398
  // If node is a default export, it can save a tree-shaking run to include the full declaration now
2573
2399
  if (!declaration.included)
@@ -3161,6 +2987,10 @@ function isReference(node, parent) {
3161
2987
  return false;
3162
2988
  }
3163
2989
 
2990
+ const BLANK = Object.freeze(Object.create(null));
2991
+ const EMPTY_OBJECT = Object.freeze({});
2992
+ const EMPTY_ARRAY = Object.freeze([]);
2993
+
3164
2994
  const ValueProperties = Symbol('Value Properties');
3165
2995
  const PURE = { pure: true };
3166
2996
  const IMPURE = { pure: false };
@@ -4128,7 +3958,7 @@ class Identifier$1 extends NodeBase {
4128
3958
  if (!this.included) {
4129
3959
  this.included = true;
4130
3960
  if (this.variable !== null) {
4131
- this.context.includeVariable(this.variable);
3961
+ this.context.includeVariableInModule(this.variable);
4132
3962
  }
4133
3963
  }
4134
3964
  }
@@ -4320,7 +4150,7 @@ class ExportDefaultDeclaration extends NodeBase {
4320
4150
  include(context, includeChildrenRecursively) {
4321
4151
  super.include(context, includeChildrenRecursively);
4322
4152
  if (includeChildrenRecursively) {
4323
- this.context.includeVariable(this.variable);
4153
+ this.context.includeVariableInModule(this.variable);
4324
4154
  }
4325
4155
  }
4326
4156
  initialise() {
@@ -4403,9 +4233,8 @@ class ExportDefaultVariable extends LocalVariable {
4403
4233
  constructor(name, exportDefaultDeclaration, context) {
4404
4234
  super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, context);
4405
4235
  this.hasId = false;
4406
- // Not initialised during construction
4407
4236
  this.originalId = null;
4408
- this.originalVariableAndDeclarationModules = null;
4237
+ this.originalVariable = null;
4409
4238
  const declaration = exportDefaultDeclaration.declaration;
4410
4239
  if ((declaration instanceof FunctionDeclaration || declaration instanceof ClassDeclaration) &&
4411
4240
  declaration.id) {
@@ -4433,6 +4262,14 @@ class ExportDefaultVariable extends LocalVariable {
4433
4262
  return original.getBaseVariableName();
4434
4263
  }
4435
4264
  }
4265
+ getDirectOriginalVariable() {
4266
+ return this.originalId &&
4267
+ (this.hasId ||
4268
+ !(this.originalId.variable.isReassigned ||
4269
+ this.originalId.variable instanceof UndefinedVariable))
4270
+ ? this.originalId.variable
4271
+ : null;
4272
+ }
4436
4273
  getName() {
4437
4274
  const original = this.getOriginalVariable();
4438
4275
  if (original === this) {
@@ -4443,34 +4280,17 @@ class ExportDefaultVariable extends LocalVariable {
4443
4280
  }
4444
4281
  }
4445
4282
  getOriginalVariable() {
4446
- return this.getOriginalVariableAndDeclarationModules().original;
4447
- }
4448
- getOriginalVariableAndDeclarationModules() {
4449
- if (this.originalVariableAndDeclarationModules === null) {
4450
- if (!this.originalId ||
4451
- (!this.hasId &&
4452
- (this.originalId.variable.isReassigned ||
4453
- this.originalId.variable instanceof UndefinedVariable))) {
4454
- this.originalVariableAndDeclarationModules = { modules: [], original: this };
4455
- }
4456
- else {
4457
- const assignedOriginal = this.originalId.variable;
4458
- if (assignedOriginal instanceof ExportDefaultVariable) {
4459
- const { modules, original } = assignedOriginal.getOriginalVariableAndDeclarationModules();
4460
- this.originalVariableAndDeclarationModules = {
4461
- modules: modules.concat(this.module),
4462
- original
4463
- };
4464
- }
4465
- else {
4466
- this.originalVariableAndDeclarationModules = {
4467
- modules: [this.module],
4468
- original: assignedOriginal
4469
- };
4470
- }
4471
- }
4472
- }
4473
- return this.originalVariableAndDeclarationModules;
4283
+ if (this.originalVariable)
4284
+ return this.originalVariable;
4285
+ let original = this;
4286
+ let currentVariable;
4287
+ const checkedVariables = new Set();
4288
+ do {
4289
+ checkedVariables.add(original);
4290
+ currentVariable = original;
4291
+ original = currentVariable.getDirectOriginalVariable();
4292
+ } while (original instanceof ExportDefaultVariable && !checkedVariables.has(original));
4293
+ return (this.originalVariable = original || currentVariable);
4474
4294
  }
4475
4295
  }
4476
4296
 
@@ -4583,918 +4403,1116 @@ class NamespaceVariable extends Variable {
4583
4403
  }
4584
4404
  NamespaceVariable.prototype.isNamespace = true;
4585
4405
 
4586
- class SyntheticNamedExportVariable extends Variable {
4587
- constructor(context, name, syntheticNamespace) {
4588
- super(name);
4589
- this.context = context;
4590
- this.module = context.module;
4591
- this.syntheticNamespace = syntheticNamespace;
4592
- }
4593
- getBaseVariable() {
4594
- let baseVariable = this.syntheticNamespace;
4595
- if (baseVariable instanceof ExportDefaultVariable) {
4596
- baseVariable = baseVariable.getOriginalVariable();
4597
- }
4598
- if (baseVariable instanceof SyntheticNamedExportVariable) {
4599
- baseVariable = baseVariable.getBaseVariable();
4600
- }
4601
- return baseVariable;
4602
- }
4603
- getBaseVariableName() {
4604
- return this.syntheticNamespace.getBaseVariableName();
4605
- }
4606
- getName() {
4607
- const name = this.name;
4608
- return `${this.syntheticNamespace.getName()}${getPropertyAccess(name)}`;
4406
+ function spaces(i) {
4407
+ let result = '';
4408
+ while (i--)
4409
+ result += ' ';
4410
+ return result;
4411
+ }
4412
+ function tabsToSpaces(str) {
4413
+ return str.replace(/^\t+/, match => match.split('\t').join(' '));
4414
+ }
4415
+ function getCodeFrame(source, line, column) {
4416
+ let lines = source.split('\n');
4417
+ const frameStart = Math.max(0, line - 3);
4418
+ let frameEnd = Math.min(line + 2, lines.length);
4419
+ lines = lines.slice(frameStart, frameEnd);
4420
+ while (!/\S/.test(lines[lines.length - 1])) {
4421
+ lines.pop();
4422
+ frameEnd -= 1;
4609
4423
  }
4610
- include() {
4611
- if (!this.included) {
4612
- this.included = true;
4613
- this.context.includeVariable(this.syntheticNamespace);
4424
+ const digits = String(frameEnd).length;
4425
+ return lines
4426
+ .map((str, i) => {
4427
+ const isErrorLine = frameStart + i + 1 === line;
4428
+ let lineNum = String(i + frameStart + 1);
4429
+ while (lineNum.length < digits)
4430
+ lineNum = ` ${lineNum}`;
4431
+ if (isErrorLine) {
4432
+ const indicator = spaces(digits + 2 + tabsToSpaces(str.slice(0, column)).length) + '^';
4433
+ return `${lineNum}: ${tabsToSpaces(str)}\n${indicator}`;
4614
4434
  }
4615
- }
4616
- setRenderNames(baseName, name) {
4617
- super.setRenderNames(baseName, name);
4618
- }
4435
+ return `${lineNum}: ${tabsToSpaces(str)}`;
4436
+ })
4437
+ .join('\n');
4619
4438
  }
4620
- const getPropertyAccess = (name) => {
4621
- return !RESERVED_NAMES[name] && /^(?!\d)[\w$]+$/.test(name)
4622
- ? `.${name}`
4623
- : `[${JSON.stringify(name)}]`;
4624
- };
4625
4439
 
4626
- function removeJsExtension(name) {
4627
- return name.endsWith('.js') ? name.slice(0, -3) : name;
4440
+ const absolutePath = /^(?:\/|(?:[A-Za-z]:)?[\\|/])/;
4441
+ const relativePath = /^\.?\.\//;
4442
+ function isAbsolute(path) {
4443
+ return absolutePath.test(path);
4444
+ }
4445
+ function isRelative(path) {
4446
+ return relativePath.test(path);
4447
+ }
4448
+ function normalize(path) {
4449
+ if (path.indexOf('\\') == -1)
4450
+ return path;
4451
+ return path.replace(/\\/g, '/');
4628
4452
  }
4629
4453
 
4630
- function getCompleteAmdId(options, chunkId) {
4631
- if (!options.autoId) {
4632
- return options.id || '';
4454
+ function sanitizeFileName(name) {
4455
+ return name.replace(/[\0?*]/g, '_');
4456
+ }
4457
+
4458
+ function getAliasName(id) {
4459
+ const base = basename(id);
4460
+ return base.substr(0, base.length - extname(id).length);
4461
+ }
4462
+ function relativeId(id) {
4463
+ if (typeof process === 'undefined' || !isAbsolute(id))
4464
+ return id;
4465
+ return relative$1(process.cwd(), id);
4466
+ }
4467
+ function isPlainPathFragment(name) {
4468
+ // not starting with "/", "./", "../"
4469
+ return (name[0] !== '/' &&
4470
+ !(name[0] === '.' && (name[1] === '/' || name[1] === '.')) &&
4471
+ sanitizeFileName(name) === name &&
4472
+ !isAbsolute(name));
4473
+ }
4474
+
4475
+ function error(base) {
4476
+ if (!(base instanceof Error))
4477
+ base = Object.assign(new Error(base.message), base);
4478
+ throw base;
4479
+ }
4480
+ function augmentCodeLocation(props, pos, source, id) {
4481
+ if (typeof pos === 'object') {
4482
+ const { line, column } = pos;
4483
+ props.loc = { file: id, line, column };
4633
4484
  }
4634
4485
  else {
4635
- return `${options.basePath ? options.basePath + '/' : ''}${removeJsExtension(chunkId)}`;
4486
+ props.pos = pos;
4487
+ const { line, column } = locate(source, pos, { offsetLine: 1 });
4488
+ props.loc = { file: id, line, column };
4489
+ }
4490
+ if (props.frame === undefined) {
4491
+ const { line, column } = props.loc;
4492
+ props.frame = getCodeFrame(source, line, column);
4636
4493
  }
4637
4494
  }
4638
-
4639
- const INTEROP_DEFAULT_VARIABLE = '_interopDefault';
4640
- const INTEROP_DEFAULT_LEGACY_VARIABLE = '_interopDefaultLegacy';
4641
- const INTEROP_NAMESPACE_VARIABLE = '_interopNamespace';
4642
- const INTEROP_NAMESPACE_DEFAULT_VARIABLE = '_interopNamespaceDefault';
4643
- const INTEROP_NAMESPACE_DEFAULT_ONLY_VARIABLE = '_interopNamespaceDefaultOnly';
4644
- const defaultInteropHelpersByInteropType = {
4645
- auto: INTEROP_DEFAULT_VARIABLE,
4646
- default: null,
4647
- defaultOnly: null,
4648
- esModule: null,
4649
- false: null,
4650
- true: INTEROP_DEFAULT_LEGACY_VARIABLE
4651
- };
4652
- function isDefaultAProperty(interopType, externalLiveBindings) {
4653
- return (interopType === 'esModule' ||
4654
- (externalLiveBindings && (interopType === 'auto' || interopType === 'true')));
4495
+ var Errors;
4496
+ (function (Errors) {
4497
+ Errors["ALREADY_CLOSED"] = "ALREADY_CLOSED";
4498
+ Errors["ASSET_NOT_FINALISED"] = "ASSET_NOT_FINALISED";
4499
+ Errors["ASSET_NOT_FOUND"] = "ASSET_NOT_FOUND";
4500
+ Errors["ASSET_SOURCE_ALREADY_SET"] = "ASSET_SOURCE_ALREADY_SET";
4501
+ Errors["ASSET_SOURCE_MISSING"] = "ASSET_SOURCE_MISSING";
4502
+ Errors["BAD_LOADER"] = "BAD_LOADER";
4503
+ Errors["CANNOT_EMIT_FROM_OPTIONS_HOOK"] = "CANNOT_EMIT_FROM_OPTIONS_HOOK";
4504
+ Errors["CHUNK_NOT_GENERATED"] = "CHUNK_NOT_GENERATED";
4505
+ Errors["CIRCULAR_REEXPORT"] = "CIRCULAR_REEXPORT";
4506
+ Errors["CYCLIC_CROSS_CHUNK_REEXPORT"] = "CYCLIC_CROSS_CHUNK_REEXPORT";
4507
+ Errors["DEPRECATED_FEATURE"] = "DEPRECATED_FEATURE";
4508
+ Errors["EXTERNAL_SYNTHETIC_EXPORTS"] = "EXTERNAL_SYNTHETIC_EXPORTS";
4509
+ Errors["FILE_NAME_CONFLICT"] = "FILE_NAME_CONFLICT";
4510
+ Errors["FILE_NOT_FOUND"] = "FILE_NOT_FOUND";
4511
+ Errors["INPUT_HOOK_IN_OUTPUT_PLUGIN"] = "INPUT_HOOK_IN_OUTPUT_PLUGIN";
4512
+ Errors["INVALID_CHUNK"] = "INVALID_CHUNK";
4513
+ Errors["INVALID_EXPORT_OPTION"] = "INVALID_EXPORT_OPTION";
4514
+ Errors["INVALID_EXTERNAL_ID"] = "INVALID_EXTERNAL_ID";
4515
+ Errors["INVALID_OPTION"] = "INVALID_OPTION";
4516
+ Errors["INVALID_PLUGIN_HOOK"] = "INVALID_PLUGIN_HOOK";
4517
+ Errors["INVALID_ROLLUP_PHASE"] = "INVALID_ROLLUP_PHASE";
4518
+ Errors["MISSING_EXPORT"] = "MISSING_EXPORT";
4519
+ Errors["MISSING_IMPLICIT_DEPENDANT"] = "MISSING_IMPLICIT_DEPENDANT";
4520
+ Errors["MIXED_EXPORTS"] = "MIXED_EXPORTS";
4521
+ Errors["NAMESPACE_CONFLICT"] = "NAMESPACE_CONFLICT";
4522
+ Errors["NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE"] = "NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE";
4523
+ Errors["PLUGIN_ERROR"] = "PLUGIN_ERROR";
4524
+ Errors["PREFER_NAMED_EXPORTS"] = "PREFER_NAMED_EXPORTS";
4525
+ Errors["SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT"] = "SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT";
4526
+ Errors["UNEXPECTED_NAMED_IMPORT"] = "UNEXPECTED_NAMED_IMPORT";
4527
+ Errors["UNRESOLVED_ENTRY"] = "UNRESOLVED_ENTRY";
4528
+ Errors["UNRESOLVED_IMPORT"] = "UNRESOLVED_IMPORT";
4529
+ Errors["VALIDATION_ERROR"] = "VALIDATION_ERROR";
4530
+ })(Errors || (Errors = {}));
4531
+ function errAssetNotFinalisedForFileName(name) {
4532
+ return {
4533
+ code: Errors.ASSET_NOT_FINALISED,
4534
+ message: `Plugin error - Unable to get file name for asset "${name}". Ensure that the source is set and that generate is called first.`
4535
+ };
4655
4536
  }
4656
- const namespaceInteropHelpersByInteropType = {
4657
- auto: INTEROP_NAMESPACE_VARIABLE,
4658
- default: INTEROP_NAMESPACE_DEFAULT_VARIABLE,
4659
- defaultOnly: INTEROP_NAMESPACE_DEFAULT_ONLY_VARIABLE,
4660
- esModule: null,
4661
- false: null,
4662
- true: INTEROP_NAMESPACE_VARIABLE
4663
- };
4664
- function canDefaultBeTakenFromNamespace(interopType, externalLiveBindings) {
4665
- return (isDefaultAProperty(interopType, externalLiveBindings) &&
4666
- defaultInteropHelpersByInteropType[interopType] === INTEROP_DEFAULT_VARIABLE);
4537
+ function errCannotEmitFromOptionsHook() {
4538
+ return {
4539
+ code: Errors.CANNOT_EMIT_FROM_OPTIONS_HOOK,
4540
+ message: `Cannot emit files or set asset sources in the "outputOptions" hook, use the "renderStart" hook instead.`
4541
+ };
4667
4542
  }
4668
- function getDefaultOnlyHelper() {
4669
- return INTEROP_NAMESPACE_DEFAULT_ONLY_VARIABLE;
4543
+ function errChunkNotGeneratedForFileName(name) {
4544
+ return {
4545
+ code: Errors.CHUNK_NOT_GENERATED,
4546
+ message: `Plugin error - Unable to get file name for chunk "${name}". Ensure that generate is called first.`
4547
+ };
4670
4548
  }
4671
- function getHelpersBlock(usedHelpers, accessedGlobals, _, n, s, t, liveBindings, freeze, namespaceToStringTag) {
4672
- return HELPER_NAMES.map(variable => usedHelpers.has(variable) || accessedGlobals.has(variable)
4673
- ? HELPER_GENERATORS[variable](_, n, s, t, liveBindings, freeze, namespaceToStringTag, usedHelpers)
4674
- : '').join('');
4549
+ function errCircularReexport(exportName, importedModule) {
4550
+ return {
4551
+ code: Errors.CIRCULAR_REEXPORT,
4552
+ id: importedModule,
4553
+ message: `"${exportName}" cannot be exported from ${relativeId(importedModule)} as it is a reexport that references itself.`
4554
+ };
4675
4555
  }
4676
- const HELPER_GENERATORS = {
4677
- [INTEROP_DEFAULT_VARIABLE]: (_, n, s, _t, liveBindings) => `function ${INTEROP_DEFAULT_VARIABLE}${_}(e)${_}{${_}return ` +
4678
- `e${_}&&${_}e.__esModule${_}?${_}` +
4679
- `${liveBindings ? getDefaultLiveBinding(_) : getDefaultStatic(_)}${s}${_}}${n}${n}`,
4680
- [INTEROP_DEFAULT_LEGACY_VARIABLE]: (_, n, s, _t, liveBindings) => `function ${INTEROP_DEFAULT_LEGACY_VARIABLE}${_}(e)${_}{${_}return ` +
4681
- `e${_}&&${_}typeof e${_}===${_}'object'${_}&&${_}'default'${_}in e${_}?${_}` +
4682
- `${liveBindings ? getDefaultLiveBinding(_) : getDefaultStatic(_)}${s}${_}}${n}${n}`,
4683
- [INTEROP_NAMESPACE_VARIABLE]: (_, n, s, t, liveBindings, freeze, namespaceToStringTag, usedHelpers) => `function ${INTEROP_NAMESPACE_VARIABLE}(e)${_}{${n}` +
4684
- (usedHelpers.has(INTEROP_NAMESPACE_DEFAULT_VARIABLE)
4685
- ? `${t}return e${_}&&${_}e.__esModule${_}?${_}e${_}:${_}${INTEROP_NAMESPACE_DEFAULT_VARIABLE}(e)${s}${n}`
4686
- : `${t}if${_}(e${_}&&${_}e.__esModule)${_}return e;${n}` +
4687
- createNamespaceObject(_, n, t, t, liveBindings, freeze, namespaceToStringTag)) +
4688
- `}${n}${n}`,
4689
- [INTEROP_NAMESPACE_DEFAULT_VARIABLE]: (_, n, _s, t, liveBindings, freeze, namespaceToStringTag) => `function ${INTEROP_NAMESPACE_DEFAULT_VARIABLE}(e)${_}{${n}` +
4690
- createNamespaceObject(_, n, t, t, liveBindings, freeze, namespaceToStringTag) +
4691
- `}${n}${n}`,
4692
- [INTEROP_NAMESPACE_DEFAULT_ONLY_VARIABLE]: (_, n, _s, t, _liveBindings, freeze, namespaceToStringTag) => `function ${INTEROP_NAMESPACE_DEFAULT_ONLY_VARIABLE}(e)${_}{${n}` +
4693
- `${t}return ${getFrozen(`{__proto__: null,${namespaceToStringTag ? `${_}[Symbol.toStringTag]:${_}'Module',` : ''}${_}'default':${_}e}`, freeze)};${n}` +
4694
- `}${n}${n}`
4695
- };
4696
- function getDefaultLiveBinding(_) {
4697
- return `e${_}:${_}{${_}'default':${_}e${_}}`;
4556
+ function errCyclicCrossChunkReexport(exportName, exporter, reexporter, importer) {
4557
+ return {
4558
+ code: Errors.CYCLIC_CROSS_CHUNK_REEXPORT,
4559
+ exporter,
4560
+ importer,
4561
+ 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.`,
4562
+ reexporter
4563
+ };
4698
4564
  }
4699
- function getDefaultStatic(_) {
4700
- return `e['default']${_}:${_}e`;
4565
+ function errAssetReferenceIdNotFoundForSetSource(assetReferenceId) {
4566
+ return {
4567
+ code: Errors.ASSET_NOT_FOUND,
4568
+ message: `Plugin error - Unable to set the source for unknown asset "${assetReferenceId}".`
4569
+ };
4701
4570
  }
4702
- function createNamespaceObject(_, n, t, i, liveBindings, freeze, namespaceToStringTag) {
4703
- return (`${i}var n${_}=${_}${namespaceToStringTag
4704
- ? `{__proto__:${_}null,${_}[Symbol.toStringTag]:${_}'Module'}`
4705
- : 'Object.create(null)'};${n}` +
4706
- `${i}if${_}(e)${_}{${n}` +
4707
- `${i}${t}Object.keys(e).forEach(function${_}(k)${_}{${n}` +
4708
- (liveBindings ? copyPropertyLiveBinding : copyPropertyStatic)(_, n, t, i + t + t) +
4709
- `${i}${t}});${n}` +
4710
- `${i}}${n}` +
4711
- `${i}n['default']${_}=${_}e;${n}` +
4712
- `${i}return ${getFrozen('n', freeze)};${n}`);
4571
+ function errAssetSourceAlreadySet(name) {
4572
+ return {
4573
+ code: Errors.ASSET_SOURCE_ALREADY_SET,
4574
+ message: `Unable to set the source for asset "${name}", source already set.`
4575
+ };
4713
4576
  }
4714
- function copyPropertyLiveBinding(_, n, t, i) {
4715
- return (`${i}if${_}(k${_}!==${_}'default')${_}{${n}` +
4716
- `${i}${t}var d${_}=${_}Object.getOwnPropertyDescriptor(e,${_}k);${n}` +
4717
- `${i}${t}Object.defineProperty(n,${_}k,${_}d.get${_}?${_}d${_}:${_}{${n}` +
4718
- `${i}${t}${t}enumerable:${_}true,${n}` +
4719
- `${i}${t}${t}get:${_}function${_}()${_}{${n}` +
4720
- `${i}${t}${t}${t}return e[k];${n}` +
4721
- `${i}${t}${t}}${n}` +
4722
- `${i}${t}});${n}` +
4723
- `${i}}${n}`);
4577
+ function errNoAssetSourceSet(assetName) {
4578
+ return {
4579
+ code: Errors.ASSET_SOURCE_MISSING,
4580
+ message: `Plugin error creating asset "${assetName}" - no asset source set.`
4581
+ };
4724
4582
  }
4725
- function copyPropertyStatic(_, n, _t, i) {
4726
- return `${i}n[k]${_}=${_}e[k];${n}`;
4583
+ function errBadLoader(id) {
4584
+ return {
4585
+ code: Errors.BAD_LOADER,
4586
+ message: `Error loading ${relativeId(id)}: plugin load hook should return a string, a { code, map } object, or nothing/null`
4587
+ };
4727
4588
  }
4728
- function getFrozen(fragment, freeze) {
4729
- return freeze ? `Object.freeze(${fragment})` : fragment;
4589
+ function errDeprecation(deprecation) {
4590
+ return {
4591
+ code: Errors.DEPRECATED_FEATURE,
4592
+ ...(typeof deprecation === 'string' ? { message: deprecation } : deprecation)
4593
+ };
4730
4594
  }
4731
- const HELPER_NAMES = Object.keys(HELPER_GENERATORS);
4732
-
4733
- function getExportBlock(exports, dependencies, namedExportsMode, interop, compact, t, externalLiveBindings, mechanism = 'return ') {
4734
- const _ = compact ? '' : ' ';
4735
- const n = compact ? '' : '\n';
4736
- if (!namedExportsMode) {
4737
- return `${n}${n}${mechanism}${getSingleDefaultExport(exports, dependencies, interop, externalLiveBindings)};`;
4738
- }
4739
- let exportBlock = '';
4740
- // star exports must always output first for precedence
4741
- for (const { name, reexports } of dependencies) {
4742
- if (reexports && namedExportsMode) {
4743
- for (const specifier of reexports) {
4744
- if (specifier.reexported === '*') {
4745
- if (exportBlock)
4746
- exportBlock += n;
4747
- if (specifier.needsLiveBinding) {
4748
- exportBlock +=
4749
- `Object.keys(${name}).forEach(function${_}(k)${_}{${n}` +
4750
- `${t}if${_}(k${_}!==${_}'default')${_}Object.defineProperty(exports,${_}k,${_}{${n}` +
4751
- `${t}${t}enumerable:${_}true,${n}` +
4752
- `${t}${t}get:${_}function${_}()${_}{${n}` +
4753
- `${t}${t}${t}return ${name}[k];${n}` +
4754
- `${t}${t}}${n}${t}});${n}});`;
4755
- }
4756
- else {
4757
- exportBlock +=
4758
- `Object.keys(${name}).forEach(function${_}(k)${_}{${n}` +
4759
- `${t}if${_}(k${_}!==${_}'default')${_}exports[k]${_}=${_}${name}[k];${n}});`;
4760
- }
4761
- }
4762
- }
4763
- }
4764
- }
4765
- for (const { defaultVariableName, id, isChunk, name, namedExportsMode: depNamedExportsMode, namespaceVariableName, reexports } of dependencies) {
4766
- if (reexports && namedExportsMode) {
4767
- for (const specifier of reexports) {
4768
- if (specifier.reexported !== '*') {
4769
- const importName = getReexportedImportName(name, specifier.imported, depNamedExportsMode, isChunk, defaultVariableName, namespaceVariableName, interop, id, externalLiveBindings);
4770
- if (exportBlock)
4771
- exportBlock += n;
4772
- exportBlock +=
4773
- specifier.imported !== '*' && specifier.needsLiveBinding
4774
- ? `Object.defineProperty(exports,${_}'${specifier.reexported}',${_}{${n}` +
4775
- `${t}enumerable:${_}true,${n}` +
4776
- `${t}get:${_}function${_}()${_}{${n}` +
4777
- `${t}${t}return ${importName};${n}${t}}${n}});`
4778
- : `exports.${specifier.reexported}${_}=${_}${importName};`;
4779
- }
4780
- }
4781
- }
4782
- }
4783
- for (const chunkExport of exports) {
4784
- const lhs = `exports.${chunkExport.exported}`;
4785
- const rhs = chunkExport.local;
4786
- if (lhs !== rhs) {
4787
- if (exportBlock)
4788
- exportBlock += n;
4789
- exportBlock += `${lhs}${_}=${_}${rhs};`;
4790
- }
4791
- }
4792
- if (exportBlock) {
4793
- return `${n}${n}${exportBlock}`;
4794
- }
4795
- return '';
4595
+ function errFileReferenceIdNotFoundForFilename(assetReferenceId) {
4596
+ return {
4597
+ code: Errors.FILE_NOT_FOUND,
4598
+ message: `Plugin error - Unable to get file name for unknown file "${assetReferenceId}".`
4599
+ };
4796
4600
  }
4797
- function getSingleDefaultExport(exports, dependencies, interop, externalLiveBindings) {
4798
- if (exports.length > 0) {
4799
- return exports[0].local;
4800
- }
4801
- else {
4802
- for (const { defaultVariableName, id, isChunk, name, namedExportsMode: depNamedExportsMode, namespaceVariableName, reexports } of dependencies) {
4803
- if (reexports) {
4804
- return getReexportedImportName(name, reexports[0].imported, depNamedExportsMode, isChunk, defaultVariableName, namespaceVariableName, interop, id, externalLiveBindings);
4805
- }
4806
- }
4807
- }
4601
+ function errFileNameConflict(fileName) {
4602
+ return {
4603
+ code: Errors.FILE_NAME_CONFLICT,
4604
+ message: `The emitted file "${fileName}" overwrites a previously emitted file of the same name.`
4605
+ };
4808
4606
  }
4809
- function getReexportedImportName(moduleVariableName, imported, depNamedExportsMode, isChunk, defaultVariableName, namespaceVariableName, interop, moduleId, externalLiveBindings) {
4810
- if (imported === 'default') {
4811
- if (!isChunk) {
4812
- const moduleInterop = String(interop(moduleId));
4813
- const variableName = defaultInteropHelpersByInteropType[moduleInterop]
4814
- ? defaultVariableName
4815
- : moduleVariableName;
4816
- return isDefaultAProperty(moduleInterop, externalLiveBindings)
4817
- ? `${variableName}['default']`
4818
- : variableName;
4819
- }
4820
- return depNamedExportsMode ? `${moduleVariableName}['default']` : moduleVariableName;
4821
- }
4822
- if (imported === '*') {
4823
- return (isChunk
4824
- ? !depNamedExportsMode
4825
- : namespaceInteropHelpersByInteropType[String(interop(moduleId))])
4826
- ? namespaceVariableName
4827
- : moduleVariableName;
4828
- }
4829
- return `${moduleVariableName}.${imported}`;
4607
+ function errInputHookInOutputPlugin(pluginName, hookName) {
4608
+ return {
4609
+ code: Errors.INPUT_HOOK_IN_OUTPUT_PLUGIN,
4610
+ 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.`
4611
+ };
4830
4612
  }
4831
- function getEsModuleExport(_) {
4832
- return `Object.defineProperty(exports,${_}'__esModule',${_}{${_}value:${_}true${_}});`;
4613
+ function errCannotAssignModuleToChunk(moduleId, assignToAlias, currentAlias) {
4614
+ return {
4615
+ code: Errors.INVALID_CHUNK,
4616
+ message: `Cannot assign ${relativeId(moduleId)} to the "${assignToAlias}" chunk as it is already in the "${currentAlias}" chunk.`
4617
+ };
4833
4618
  }
4834
- function getNamespaceToStringExport(_) {
4835
- return `exports[Symbol.toStringTag]${_}=${_}'Module';`;
4619
+ function errInvalidExportOptionValue(optionValue) {
4620
+ return {
4621
+ code: Errors.INVALID_EXPORT_OPTION,
4622
+ message: `"output.exports" must be "default", "named", "none", "auto", or left unspecified (defaults to "auto"), received "${optionValue}"`,
4623
+ url: `https://rollupjs.org/guide/en/#outputexports`
4624
+ };
4836
4625
  }
4837
- function getNamespaceMarkers(hasNamedExports, addEsModule, addNamespaceToStringTag, _, n) {
4838
- let namespaceMarkers = '';
4839
- if (hasNamedExports) {
4840
- if (addEsModule) {
4841
- namespaceMarkers += getEsModuleExport(_);
4842
- }
4843
- if (addNamespaceToStringTag) {
4844
- if (namespaceMarkers) {
4845
- namespaceMarkers += n;
4846
- }
4847
- namespaceMarkers += getNamespaceToStringExport(_);
4848
- }
4849
- }
4850
- return namespaceMarkers;
4626
+ function errIncompatibleExportOptionValue(optionValue, keys, entryModule) {
4627
+ return {
4628
+ code: 'INVALID_EXPORT_OPTION',
4629
+ message: `"${optionValue}" was specified for "output.exports", but entry module "${relativeId(entryModule)}" has the following exports: ${keys.join(', ')}`
4630
+ };
4851
4631
  }
4852
-
4853
- function getInteropBlock(dependencies, varOrConst, interop, externalLiveBindings, freeze, namespaceToStringTag, accessedGlobals, _, n, s, t) {
4854
- const neededInteropHelpers = new Set();
4855
- const interopStatements = [];
4856
- const addInteropStatement = (helperVariableName, helper, dependencyVariableName) => {
4857
- neededInteropHelpers.add(helper);
4858
- interopStatements.push(`${varOrConst} ${helperVariableName}${_}=${_}/*#__PURE__*/${helper}(${dependencyVariableName});`);
4632
+ function errInternalIdCannotBeExternal(source, importer) {
4633
+ return {
4634
+ code: Errors.INVALID_EXTERNAL_ID,
4635
+ message: `'${source}' is imported as an external by ${relativeId(importer)}, but is already an existing non-external module id.`
4859
4636
  };
4860
- for (const { defaultVariableName, imports, id, isChunk, name, namedExportsMode, namespaceVariableName, reexports } of dependencies) {
4861
- if (isChunk) {
4862
- for (const { imported, reexported } of [
4863
- ...(imports || []),
4864
- ...(reexports || [])
4865
- ]) {
4866
- if (imported === '*' && reexported !== '*') {
4867
- if (!namedExportsMode) {
4868
- addInteropStatement(namespaceVariableName, getDefaultOnlyHelper(), name);
4869
- }
4870
- break;
4871
- }
4872
- }
4873
- }
4874
- else {
4875
- const moduleInterop = String(interop(id));
4876
- let hasDefault = false;
4877
- let hasNamespace = false;
4878
- for (const { imported, reexported } of [
4879
- ...(imports || []),
4880
- ...(reexports || [])
4881
- ]) {
4882
- let helper;
4883
- let variableName;
4884
- if (imported === 'default') {
4885
- if (!hasDefault) {
4886
- hasDefault = true;
4887
- if (defaultVariableName !== namespaceVariableName) {
4888
- variableName = defaultVariableName;
4889
- helper = defaultInteropHelpersByInteropType[moduleInterop];
4890
- }
4891
- }
4892
- }
4893
- else if (imported === '*' && reexported !== '*') {
4894
- if (!hasNamespace) {
4895
- hasNamespace = true;
4896
- helper = namespaceInteropHelpersByInteropType[moduleInterop];
4897
- variableName = namespaceVariableName;
4898
- }
4899
- }
4900
- if (helper) {
4901
- addInteropStatement(variableName, helper, name);
4902
- }
4903
- }
4904
- }
4905
- }
4906
- return `${getHelpersBlock(neededInteropHelpers, accessedGlobals, _, n, s, t, externalLiveBindings, freeze, namespaceToStringTag)}${interopStatements.length > 0 ? `${interopStatements.join(n)}${n}${n}` : ''}`;
4907
4637
  }
4908
-
4909
- // AMD resolution will only respect the AMD baseUrl if the .js extension is omitted.
4910
- // The assumption is that this makes sense for all relative ids:
4911
- // https://requirejs.org/docs/api.html#jsfiles
4912
- function removeExtensionFromRelativeAmdId(id) {
4913
- return id[0] === '.' ? removeJsExtension(id) : id;
4638
+ function errInvalidOption(option, explanation) {
4639
+ return {
4640
+ code: Errors.INVALID_OPTION,
4641
+ message: `Invalid value for option "${option}" - ${explanation}.`
4642
+ };
4914
4643
  }
4915
-
4916
- const builtins$1 = {
4917
- assert: true,
4918
- buffer: true,
4919
- console: true,
4920
- constants: true,
4921
- domain: true,
4922
- events: true,
4923
- http: true,
4924
- https: true,
4925
- os: true,
4926
- path: true,
4927
- process: true,
4928
- punycode: true,
4929
- querystring: true,
4930
- stream: true,
4931
- string_decoder: true,
4932
- timers: true,
4933
- tty: true,
4934
- url: true,
4935
- util: true,
4936
- vm: true,
4937
- zlib: true
4938
- };
4939
- function warnOnBuiltins(warn, dependencies) {
4940
- const externalBuiltins = dependencies.map(({ id }) => id).filter(id => id in builtins$1);
4941
- if (!externalBuiltins.length)
4942
- return;
4943
- const detail = externalBuiltins.length === 1
4944
- ? `module ('${externalBuiltins[0]}')`
4945
- : `modules (${externalBuiltins
4946
- .slice(0, -1)
4947
- .map(name => `'${name}'`)
4948
- .join(', ')} and '${externalBuiltins.slice(-1)}')`;
4949
- warn({
4950
- code: 'MISSING_NODE_BUILTINS',
4951
- 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`,
4952
- modules: externalBuiltins
4953
- });
4644
+ function errInvalidRollupPhaseForAddWatchFile() {
4645
+ return {
4646
+ code: Errors.INVALID_ROLLUP_PHASE,
4647
+ message: `Cannot call addWatchFile after the build has finished.`
4648
+ };
4954
4649
  }
4955
-
4956
- 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 }) {
4957
- warnOnBuiltins(warn, dependencies);
4958
- const deps = dependencies.map(m => `'${removeExtensionFromRelativeAmdId(m.id)}'`);
4959
- const args = dependencies.map(m => m.name);
4960
- const n = compact ? '' : '\n';
4961
- const s = compact ? '' : ';';
4962
- const _ = compact ? '' : ' ';
4963
- if (namedExportsMode && hasExports) {
4964
- args.unshift(`exports`);
4965
- deps.unshift(`'exports'`);
4966
- }
4967
- if (accessedGlobals.has('require')) {
4968
- args.unshift('require');
4969
- deps.unshift(`'require'`);
4970
- }
4971
- if (accessedGlobals.has('module')) {
4972
- args.unshift('module');
4973
- deps.unshift(`'module'`);
4974
- }
4975
- const completeAmdId = getCompleteAmdId(amd, id);
4976
- const params = (completeAmdId ? `'${completeAmdId}',${_}` : ``) +
4977
- (deps.length ? `[${deps.join(`,${_}`)}],${_}` : ``);
4978
- const useStrict = strict ? `${_}'use strict';` : '';
4979
- magicString.prepend(`${intro}${getInteropBlock(dependencies, varOrConst, interop, externalLiveBindings, freeze, namespaceToStringTag, accessedGlobals, _, n, s, t)}`);
4980
- const exportBlock = getExportBlock(exports, dependencies, namedExportsMode, interop, compact, t, externalLiveBindings);
4981
- let namespaceMarkers = getNamespaceMarkers(namedExportsMode && hasExports, isEntryFacade && esModule, isModuleFacade && namespaceToStringTag, _, n);
4982
- if (namespaceMarkers) {
4983
- namespaceMarkers = n + n + namespaceMarkers;
4650
+ function errInvalidRollupPhaseForChunkEmission() {
4651
+ return {
4652
+ code: Errors.INVALID_ROLLUP_PHASE,
4653
+ message: `Cannot emit chunks after module loading has finished.`
4654
+ };
4655
+ }
4656
+ function errMissingExport(exportName, importingModule, importedModule) {
4657
+ return {
4658
+ code: Errors.MISSING_EXPORT,
4659
+ message: `'${exportName}' is not exported by ${relativeId(importedModule)}, imported by ${relativeId(importingModule)}`,
4660
+ url: `https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module`
4661
+ };
4662
+ }
4663
+ function errImplicitDependantCannotBeExternal(unresolvedId, implicitlyLoadedBefore) {
4664
+ return {
4665
+ code: Errors.MISSING_IMPLICIT_DEPENDANT,
4666
+ message: `Module "${relativeId(unresolvedId)}" that should be implicitly loaded before "${relativeId(implicitlyLoadedBefore)}" cannot be external.`
4667
+ };
4668
+ }
4669
+ function errUnresolvedImplicitDependant(unresolvedId, implicitlyLoadedBefore) {
4670
+ return {
4671
+ code: Errors.MISSING_IMPLICIT_DEPENDANT,
4672
+ message: `Module "${relativeId(unresolvedId)}" that should be implicitly loaded before "${relativeId(implicitlyLoadedBefore)}" could not be resolved.`
4673
+ };
4674
+ }
4675
+ function errImplicitDependantIsNotIncluded(module) {
4676
+ const implicitDependencies = Array.from(module.implicitlyLoadedBefore, dependency => relativeId(dependency.id)).sort();
4677
+ return {
4678
+ code: Errors.MISSING_IMPLICIT_DEPENDANT,
4679
+ message: `Module "${relativeId(module.id)}" that should be implicitly loaded before "${implicitDependencies.length === 1
4680
+ ? implicitDependencies[0]
4681
+ : `${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.`
4682
+ };
4683
+ }
4684
+ function errMixedExport(facadeModuleId, name) {
4685
+ return {
4686
+ code: Errors.MIXED_EXPORTS,
4687
+ id: facadeModuleId,
4688
+ 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`,
4689
+ url: `https://rollupjs.org/guide/en/#outputexports`
4690
+ };
4691
+ }
4692
+ function errNamespaceConflict(name, reexportingModule, additionalExportAllModule) {
4693
+ return {
4694
+ code: Errors.NAMESPACE_CONFLICT,
4695
+ message: `Conflicting namespaces: ${relativeId(reexportingModule.id)} re-exports '${name}' from both ${relativeId(reexportingModule.exportsAll[name])} and ${relativeId(additionalExportAllModule.exportsAll[name])} (will be ignored)`,
4696
+ name,
4697
+ reexporter: reexportingModule.id,
4698
+ sources: [reexportingModule.exportsAll[name], additionalExportAllModule.exportsAll[name]]
4699
+ };
4700
+ }
4701
+ function errNoTransformMapOrAstWithoutCode(pluginName) {
4702
+ return {
4703
+ code: Errors.NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE,
4704
+ message: `The plugin "${pluginName}" returned a "map" or "ast" without returning ` +
4705
+ 'a "code". This will be ignored.'
4706
+ };
4707
+ }
4708
+ function errPreferNamedExports(facadeModuleId) {
4709
+ const file = relativeId(facadeModuleId);
4710
+ return {
4711
+ code: Errors.PREFER_NAMED_EXPORTS,
4712
+ id: facadeModuleId,
4713
+ 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.`,
4714
+ url: `https://rollupjs.org/guide/en/#outputexports`
4715
+ };
4716
+ }
4717
+ function errSyntheticNamedExportsNeedNamespaceExport(id, syntheticNamedExportsOption) {
4718
+ return {
4719
+ code: Errors.SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT,
4720
+ id,
4721
+ message: `Module "${relativeId(id)}" that is marked with 'syntheticNamedExports: ${JSON.stringify(syntheticNamedExportsOption)}' needs ${typeof syntheticNamedExportsOption === 'string' && syntheticNamedExportsOption !== 'default'
4722
+ ? `an export named "${syntheticNamedExportsOption}"`
4723
+ : 'a default export'} that does not reexport an unresolved named export of the same module.`
4724
+ };
4725
+ }
4726
+ function errUnexpectedNamedImport(id, imported, isReexport) {
4727
+ const importType = isReexport ? 'reexport' : 'import';
4728
+ return {
4729
+ code: Errors.UNEXPECTED_NAMED_IMPORT,
4730
+ id,
4731
+ 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.`,
4732
+ url: 'https://rollupjs.org/guide/en/#outputinterop'
4733
+ };
4734
+ }
4735
+ function errUnexpectedNamespaceReexport(id) {
4736
+ return {
4737
+ code: Errors.UNEXPECTED_NAMED_IMPORT,
4738
+ id,
4739
+ 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.`,
4740
+ url: 'https://rollupjs.org/guide/en/#outputinterop'
4741
+ };
4742
+ }
4743
+ function errEntryCannotBeExternal(unresolvedId) {
4744
+ return {
4745
+ code: Errors.UNRESOLVED_ENTRY,
4746
+ message: `Entry module cannot be external (${relativeId(unresolvedId)}).`
4747
+ };
4748
+ }
4749
+ function errUnresolvedEntry(unresolvedId) {
4750
+ return {
4751
+ code: Errors.UNRESOLVED_ENTRY,
4752
+ message: `Could not resolve entry module (${relativeId(unresolvedId)}).`
4753
+ };
4754
+ }
4755
+ function errUnresolvedImport(source, importer) {
4756
+ return {
4757
+ code: Errors.UNRESOLVED_IMPORT,
4758
+ message: `Could not resolve '${source}' from ${relativeId(importer)}`
4759
+ };
4760
+ }
4761
+ function errUnresolvedImportTreatedAsExternal(source, importer) {
4762
+ return {
4763
+ code: Errors.UNRESOLVED_IMPORT,
4764
+ importer: relativeId(importer),
4765
+ message: `'${source}' is imported by ${relativeId(importer)}, but could not be resolved – treating it as an external dependency`,
4766
+ source,
4767
+ url: 'https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency'
4768
+ };
4769
+ }
4770
+ function errExternalSyntheticExports(source, importer) {
4771
+ return {
4772
+ code: Errors.EXTERNAL_SYNTHETIC_EXPORTS,
4773
+ importer: relativeId(importer),
4774
+ message: `External '${source}' can not have 'syntheticNamedExports' enabled.`,
4775
+ source
4776
+ };
4777
+ }
4778
+ function errFailedValidation(message) {
4779
+ return {
4780
+ code: Errors.VALIDATION_ERROR,
4781
+ message
4782
+ };
4783
+ }
4784
+ function errAlreadyClosed() {
4785
+ return {
4786
+ code: Errors.ALREADY_CLOSED,
4787
+ message: 'Bundle is already closed, no more calls to "generate" or "write" are allowed.'
4788
+ };
4789
+ }
4790
+ function warnDeprecation(deprecation, activeDeprecation, options) {
4791
+ warnDeprecationWithOptions(deprecation, activeDeprecation, options.onwarn, options.strictDeprecations);
4792
+ }
4793
+ function warnDeprecationWithOptions(deprecation, activeDeprecation, warn, strictDeprecations) {
4794
+ if (activeDeprecation || strictDeprecations) {
4795
+ const warning = errDeprecation(deprecation);
4796
+ if (strictDeprecations) {
4797
+ return error(warning);
4798
+ }
4799
+ warn(warning);
4984
4800
  }
4985
- magicString.append(`${exportBlock}${namespaceMarkers}${outro}`);
4986
- return magicString
4987
- .indent(t)
4988
- .prepend(`${amd.define}(${params}function${_}(${args.join(`,${_}`)})${_}{${useStrict}${n}${n}`)
4989
- .append(`${n}${n}});`);
4990
4801
  }
4991
4802
 
4992
- function cjs(magicString, { accessedGlobals, dependencies, exports, hasExports, indentString: t, intro, isEntryFacade, isModuleFacade, namedExportsMode, outro, varOrConst }, { compact, esModule, externalLiveBindings, freeze, interop, namespaceToStringTag, strict }) {
4993
- const n = compact ? '' : '\n';
4994
- const s = compact ? '' : ';';
4995
- const _ = compact ? '' : ' ';
4996
- const useStrict = strict ? `'use strict';${n}${n}` : '';
4997
- let namespaceMarkers = getNamespaceMarkers(namedExportsMode && hasExports, isEntryFacade && esModule, isModuleFacade && namespaceToStringTag, _, n);
4998
- if (namespaceMarkers) {
4999
- namespaceMarkers += n + n;
4803
+ class SyntheticNamedExportVariable extends Variable {
4804
+ constructor(context, name, syntheticNamespace) {
4805
+ super(name);
4806
+ this.baseVariable = null;
4807
+ this.context = context;
4808
+ this.module = context.module;
4809
+ this.syntheticNamespace = syntheticNamespace;
5000
4810
  }
5001
- const importBlock = getImportBlock(dependencies, compact, varOrConst, n, _);
5002
- const interopBlock = getInteropBlock(dependencies, varOrConst, interop, externalLiveBindings, freeze, namespaceToStringTag, accessedGlobals, _, n, s, t);
5003
- magicString.prepend(`${useStrict}${intro}${namespaceMarkers}${importBlock}${interopBlock}`);
5004
- const exportBlock = getExportBlock(exports, dependencies, namedExportsMode, interop, compact, t, externalLiveBindings, `module.exports${_}=${_}`);
5005
- return magicString.append(`${exportBlock}${outro}`);
5006
- }
5007
- function getImportBlock(dependencies, compact, varOrConst, n, _) {
5008
- let importBlock = '';
5009
- let definingVariable = false;
5010
- for (const { id, name, reexports, imports } of dependencies) {
5011
- if (!reexports && !imports) {
5012
- if (importBlock) {
5013
- importBlock += !compact || definingVariable ? `;${n}` : ',';
4811
+ getBaseVariable() {
4812
+ if (this.baseVariable)
4813
+ return this.baseVariable;
4814
+ let baseVariable = this.syntheticNamespace;
4815
+ const checkedVariables = new Set();
4816
+ while (baseVariable instanceof ExportDefaultVariable ||
4817
+ baseVariable instanceof SyntheticNamedExportVariable) {
4818
+ checkedVariables.add(baseVariable);
4819
+ if (baseVariable instanceof ExportDefaultVariable) {
4820
+ const original = baseVariable.getOriginalVariable();
4821
+ if (original === baseVariable)
4822
+ break;
4823
+ baseVariable = original;
4824
+ }
4825
+ if (baseVariable instanceof SyntheticNamedExportVariable) {
4826
+ baseVariable = baseVariable.syntheticNamespace;
4827
+ }
4828
+ if (checkedVariables.has(baseVariable)) {
4829
+ return error(errSyntheticNamedExportsNeedNamespaceExport(this.module.id, this.module.info.syntheticNamedExports));
5014
4830
  }
5015
- definingVariable = false;
5016
- importBlock += `require('${id}')`;
5017
4831
  }
5018
- else {
5019
- importBlock +=
5020
- compact && definingVariable ? ',' : `${importBlock ? `;${n}` : ''}${varOrConst} `;
5021
- definingVariable = true;
5022
- importBlock += `${name}${_}=${_}require('${id}')`;
4832
+ return (this.baseVariable = baseVariable);
4833
+ }
4834
+ getBaseVariableName() {
4835
+ return this.syntheticNamespace.getBaseVariableName();
4836
+ }
4837
+ getName() {
4838
+ const name = this.name;
4839
+ return `${this.syntheticNamespace.getName()}${getPropertyAccess(name)}`;
4840
+ }
4841
+ include() {
4842
+ if (!this.included) {
4843
+ this.included = true;
4844
+ this.context.includeVariableInModule(this.syntheticNamespace);
5023
4845
  }
5024
4846
  }
5025
- if (importBlock) {
5026
- return `${importBlock};${n}${n}`;
4847
+ setRenderNames(baseName, name) {
4848
+ super.setRenderNames(baseName, name);
5027
4849
  }
5028
- return '';
5029
4850
  }
4851
+ const getPropertyAccess = (name) => {
4852
+ return !RESERVED_NAMES[name] && /^(?!\d)[\w$]+$/.test(name)
4853
+ ? `.${name}`
4854
+ : `[${JSON.stringify(name)}]`;
4855
+ };
5030
4856
 
5031
- function es(magicString, { intro, outro, dependencies, exports, varOrConst }, { compact }) {
5032
- const _ = compact ? '' : ' ';
5033
- const n = compact ? '' : '\n';
5034
- const importBlock = getImportBlock$1(dependencies, _);
5035
- if (importBlock.length > 0)
5036
- intro += importBlock.join(n) + n + n;
5037
- if (intro)
5038
- magicString.prepend(intro);
5039
- const exportBlock = getExportBlock$1(exports, _, varOrConst);
5040
- if (exportBlock.length)
5041
- magicString.append(n + n + exportBlock.join(n).trim());
5042
- if (outro)
5043
- magicString.append(outro);
5044
- return magicString.trim();
5045
- }
5046
- function getImportBlock$1(dependencies, _) {
5047
- const importBlock = [];
5048
- for (const { id, reexports, imports, name } of dependencies) {
5049
- if (!reexports && !imports) {
5050
- importBlock.push(`import${_}'${id}';`);
5051
- continue;
4857
+ class ExternalVariable extends Variable {
4858
+ constructor(module, name) {
4859
+ super(name);
4860
+ this.module = module;
4861
+ this.isNamespace = name === '*';
4862
+ this.referenced = false;
4863
+ }
4864
+ addReference(identifier) {
4865
+ this.referenced = true;
4866
+ if (this.name === 'default' || this.name === '*') {
4867
+ this.module.suggestName(identifier.name);
5052
4868
  }
5053
- if (imports) {
5054
- let defaultImport = null;
5055
- let starImport = null;
5056
- const importedNames = [];
5057
- for (const specifier of imports) {
5058
- if (specifier.imported === 'default') {
5059
- defaultImport = specifier;
5060
- }
5061
- else if (specifier.imported === '*') {
5062
- starImport = specifier;
5063
- }
5064
- else {
5065
- importedNames.push(specifier);
5066
- }
5067
- }
5068
- if (starImport) {
5069
- importBlock.push(`import${_}*${_}as ${starImport.local} from${_}'${id}';`);
5070
- }
5071
- if (defaultImport && importedNames.length === 0) {
5072
- importBlock.push(`import ${defaultImport.local} from${_}'${id}';`);
5073
- }
5074
- else if (importedNames.length > 0) {
5075
- importBlock.push(`import ${defaultImport ? `${defaultImport.local},${_}` : ''}{${_}${importedNames
5076
- .map(specifier => {
5077
- if (specifier.imported === specifier.local) {
5078
- return specifier.imported;
5079
- }
5080
- else {
5081
- return `${specifier.imported} as ${specifier.local}`;
5082
- }
5083
- })
5084
- .join(`,${_}`)}${_}}${_}from${_}'${id}';`);
5085
- }
4869
+ }
4870
+ include() {
4871
+ if (!this.included) {
4872
+ this.included = true;
4873
+ this.module.used = true;
5086
4874
  }
5087
- if (reexports) {
5088
- let starExport = null;
5089
- const namespaceReexports = [];
5090
- const namedReexports = [];
5091
- for (const specifier of reexports) {
5092
- if (specifier.reexported === '*') {
5093
- starExport = specifier;
5094
- }
5095
- else if (specifier.imported === '*') {
5096
- namespaceReexports.push(specifier);
5097
- }
5098
- else {
5099
- namedReexports.push(specifier);
5100
- }
5101
- }
5102
- if (starExport) {
5103
- importBlock.push(`export${_}*${_}from${_}'${id}';`);
5104
- }
5105
- if (namespaceReexports.length > 0) {
5106
- if (!imports ||
5107
- !imports.some(specifier => specifier.imported === '*' && specifier.local === name)) {
5108
- importBlock.push(`import${_}*${_}as ${name} from${_}'${id}';`);
5109
- }
5110
- for (const specifier of namespaceReexports) {
5111
- importBlock.push(`export${_}{${_}${name === specifier.reexported ? name : `${name} as ${specifier.reexported}`} };`);
5112
- }
4875
+ }
4876
+ }
4877
+
4878
+ 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(' ');
4879
+ 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(' ');
4880
+ const blacklisted = new Set(reservedWords.concat(builtins));
4881
+ const illegalCharacters = /[^$_a-zA-Z0-9]/g;
4882
+ const startsWithDigit = (str) => /\d/.test(str[0]);
4883
+ function isLegal(str) {
4884
+ if (startsWithDigit(str) || blacklisted.has(str)) {
4885
+ return false;
4886
+ }
4887
+ return !illegalCharacters.test(str);
4888
+ }
4889
+ function makeLegal(str) {
4890
+ str = str.replace(/-(\w)/g, (_, letter) => letter.toUpperCase()).replace(illegalCharacters, '_');
4891
+ if (startsWithDigit(str) || blacklisted.has(str))
4892
+ str = `_${str}`;
4893
+ return str || '_';
4894
+ }
4895
+
4896
+ class ExternalModule {
4897
+ constructor(options, id, hasModuleSideEffects, meta) {
4898
+ this.options = options;
4899
+ this.id = id;
4900
+ this.defaultVariableName = '';
4901
+ this.dynamicImporters = [];
4902
+ this.importers = [];
4903
+ this.mostCommonSuggestion = 0;
4904
+ this.namespaceVariableName = '';
4905
+ this.reexported = false;
4906
+ this.renderPath = undefined;
4907
+ this.renormalizeRenderPath = false;
4908
+ this.used = false;
4909
+ this.variableName = '';
4910
+ this.execIndex = Infinity;
4911
+ this.suggestedVariableName = makeLegal(id.split(/[\\/]/).pop());
4912
+ this.nameSuggestions = Object.create(null);
4913
+ this.declarations = Object.create(null);
4914
+ this.exportedVariables = new Map();
4915
+ const module = this;
4916
+ this.info = {
4917
+ ast: null,
4918
+ code: null,
4919
+ dynamicallyImportedIds: EMPTY_ARRAY,
4920
+ get dynamicImporters() {
4921
+ return module.dynamicImporters.sort();
4922
+ },
4923
+ hasModuleSideEffects,
4924
+ id,
4925
+ implicitlyLoadedAfterOneOf: EMPTY_ARRAY,
4926
+ implicitlyLoadedBefore: EMPTY_ARRAY,
4927
+ importedIds: EMPTY_ARRAY,
4928
+ get importers() {
4929
+ return module.importers.sort();
4930
+ },
4931
+ isEntry: false,
4932
+ isExternal: true,
4933
+ meta,
4934
+ syntheticNamedExports: false
4935
+ };
4936
+ }
4937
+ getVariableForExportName(name) {
4938
+ let declaration = this.declarations[name];
4939
+ if (declaration)
4940
+ return declaration;
4941
+ this.declarations[name] = declaration = new ExternalVariable(this, name);
4942
+ this.exportedVariables.set(declaration, name);
4943
+ return declaration;
4944
+ }
4945
+ setRenderPath(options, inputBase) {
4946
+ this.renderPath =
4947
+ typeof options.paths === 'function' ? options.paths(this.id) : options.paths[this.id];
4948
+ if (!this.renderPath) {
4949
+ if (!isAbsolute(this.id)) {
4950
+ this.renderPath = this.id;
5113
4951
  }
5114
- if (namedReexports.length > 0) {
5115
- importBlock.push(`export${_}{${_}${namedReexports
5116
- .map(specifier => {
5117
- if (specifier.imported === specifier.reexported) {
5118
- return specifier.imported;
5119
- }
5120
- else {
5121
- return `${specifier.imported} as ${specifier.reexported}`;
5122
- }
5123
- })
5124
- .join(`,${_}`)}${_}}${_}from${_}'${id}';`);
4952
+ else {
4953
+ this.renderPath = normalize(relative$1(inputBase, this.id));
4954
+ this.renormalizeRenderPath = true;
5125
4955
  }
5126
4956
  }
4957
+ return this.renderPath;
5127
4958
  }
5128
- return importBlock;
5129
- }
5130
- function getExportBlock$1(exports, _, varOrConst) {
5131
- const exportBlock = [];
5132
- const exportDeclaration = [];
5133
- for (const specifier of exports) {
5134
- if (specifier.exported === 'default') {
5135
- exportBlock.push(`export default ${specifier.local};`);
5136
- }
5137
- else {
5138
- if (specifier.expression) {
5139
- exportBlock.push(`${varOrConst} ${specifier.local}${_}=${_}${specifier.expression};`);
5140
- }
5141
- exportDeclaration.push(specifier.exported === specifier.local
5142
- ? specifier.local
5143
- : `${specifier.local} as ${specifier.exported}`);
4959
+ suggestName(name) {
4960
+ if (!this.nameSuggestions[name])
4961
+ this.nameSuggestions[name] = 0;
4962
+ this.nameSuggestions[name] += 1;
4963
+ if (this.nameSuggestions[name] > this.mostCommonSuggestion) {
4964
+ this.mostCommonSuggestion = this.nameSuggestions[name];
4965
+ this.suggestedVariableName = name;
5144
4966
  }
5145
4967
  }
5146
- if (exportDeclaration.length) {
5147
- exportBlock.push(`export${_}{${_}${exportDeclaration.join(`,${_}`)}${_}};`);
4968
+ warnUnusedImports() {
4969
+ const unused = Object.keys(this.declarations).filter(name => {
4970
+ if (name === '*')
4971
+ return false;
4972
+ const declaration = this.declarations[name];
4973
+ return !declaration.included && !this.reexported && !declaration.referenced;
4974
+ });
4975
+ if (unused.length === 0)
4976
+ return;
4977
+ const names = unused.length === 1
4978
+ ? `'${unused[0]}' is`
4979
+ : `${unused
4980
+ .slice(0, -1)
4981
+ .map(name => `'${name}'`)
4982
+ .join(', ')} and '${unused.slice(-1)}' are`;
4983
+ this.options.onwarn({
4984
+ code: 'UNUSED_EXTERNAL_IMPORT',
4985
+ message: `${names} imported from external module '${this.id}' but never used`,
4986
+ names: unused,
4987
+ source: this.id
4988
+ });
5148
4989
  }
5149
- return exportBlock;
5150
4990
  }
5151
4991
 
5152
- function spaces(i) {
5153
- let result = '';
5154
- while (i--)
5155
- result += ' ';
5156
- return result;
5157
- }
5158
- function tabsToSpaces(str) {
5159
- return str.replace(/^\t+/, match => match.split('\t').join(' '));
4992
+ function removeJsExtension(name) {
4993
+ return name.endsWith('.js') ? name.slice(0, -3) : name;
5160
4994
  }
5161
- function getCodeFrame(source, line, column) {
5162
- let lines = source.split('\n');
5163
- const frameStart = Math.max(0, line - 3);
5164
- let frameEnd = Math.min(line + 2, lines.length);
5165
- lines = lines.slice(frameStart, frameEnd);
5166
- while (!/\S/.test(lines[lines.length - 1])) {
5167
- lines.pop();
5168
- frameEnd -= 1;
5169
- }
5170
- const digits = String(frameEnd).length;
5171
- return lines
5172
- .map((str, i) => {
5173
- const isErrorLine = frameStart + i + 1 === line;
5174
- let lineNum = String(i + frameStart + 1);
5175
- while (lineNum.length < digits)
5176
- lineNum = ` ${lineNum}`;
5177
- if (isErrorLine) {
5178
- const indicator = spaces(digits + 2 + tabsToSpaces(str.slice(0, column)).length) + '^';
5179
- return `${lineNum}: ${tabsToSpaces(str)}\n${indicator}`;
5180
- }
5181
- return `${lineNum}: ${tabsToSpaces(str)}`;
5182
- })
5183
- .join('\n');
5184
- }
5185
-
5186
- function sanitizeFileName(name) {
5187
- return name.replace(/[\0?*]/g, '_');
5188
- }
5189
-
5190
- function getAliasName(id) {
5191
- const base = basename(id);
5192
- return base.substr(0, base.length - extname(id).length);
5193
- }
5194
- function relativeId(id) {
5195
- if (typeof process === 'undefined' || !isAbsolute(id))
5196
- return id;
5197
- return relative$1(process.cwd(), id);
5198
- }
5199
- function isPlainPathFragment(name) {
5200
- // not starting with "/", "./", "../"
5201
- return (name[0] !== '/' &&
5202
- !(name[0] === '.' && (name[1] === '/' || name[1] === '.')) &&
5203
- sanitizeFileName(name) === name &&
5204
- !isAbsolute(name));
5205
- }
5206
-
5207
- function error(base) {
5208
- if (!(base instanceof Error))
5209
- base = Object.assign(new Error(base.message), base);
5210
- throw base;
5211
- }
5212
- function augmentCodeLocation(props, pos, source, id) {
5213
- if (typeof pos === 'object') {
5214
- const { line, column } = pos;
5215
- props.loc = { file: id, line, column };
4995
+
4996
+ function getCompleteAmdId(options, chunkId) {
4997
+ if (!options.autoId) {
4998
+ return options.id || '';
5216
4999
  }
5217
5000
  else {
5218
- props.pos = pos;
5219
- const { line, column } = locate(source, pos, { offsetLine: 1 });
5220
- props.loc = { file: id, line, column };
5221
- }
5222
- if (props.frame === undefined) {
5223
- const { line, column } = props.loc;
5224
- props.frame = getCodeFrame(source, line, column);
5001
+ return `${options.basePath ? options.basePath + '/' : ''}${removeJsExtension(chunkId)}`;
5225
5002
  }
5226
5003
  }
5227
- var Errors;
5228
- (function (Errors) {
5229
- Errors["ALREADY_CLOSED"] = "ALREADY_CLOSED";
5230
- Errors["ASSET_NOT_FINALISED"] = "ASSET_NOT_FINALISED";
5231
- Errors["ASSET_NOT_FOUND"] = "ASSET_NOT_FOUND";
5232
- Errors["ASSET_SOURCE_ALREADY_SET"] = "ASSET_SOURCE_ALREADY_SET";
5233
- Errors["ASSET_SOURCE_MISSING"] = "ASSET_SOURCE_MISSING";
5234
- Errors["BAD_LOADER"] = "BAD_LOADER";
5235
- Errors["CANNOT_EMIT_FROM_OPTIONS_HOOK"] = "CANNOT_EMIT_FROM_OPTIONS_HOOK";
5236
- Errors["CHUNK_NOT_GENERATED"] = "CHUNK_NOT_GENERATED";
5237
- Errors["DEPRECATED_FEATURE"] = "DEPRECATED_FEATURE";
5238
- Errors["EXTERNAL_SYNTHETIC_EXPORTS"] = "EXTERNAL_SYNTHETIC_EXPORTS";
5239
- Errors["FILE_NAME_CONFLICT"] = "FILE_NAME_CONFLICT";
5240
- Errors["FILE_NOT_FOUND"] = "FILE_NOT_FOUND";
5241
- Errors["INPUT_HOOK_IN_OUTPUT_PLUGIN"] = "INPUT_HOOK_IN_OUTPUT_PLUGIN";
5242
- Errors["INVALID_CHUNK"] = "INVALID_CHUNK";
5243
- Errors["INVALID_EXPORT_OPTION"] = "INVALID_EXPORT_OPTION";
5244
- Errors["INVALID_EXTERNAL_ID"] = "INVALID_EXTERNAL_ID";
5245
- Errors["INVALID_OPTION"] = "INVALID_OPTION";
5246
- Errors["INVALID_PLUGIN_HOOK"] = "INVALID_PLUGIN_HOOK";
5247
- Errors["INVALID_ROLLUP_PHASE"] = "INVALID_ROLLUP_PHASE";
5248
- Errors["MISSING_IMPLICIT_DEPENDANT"] = "MISSING_IMPLICIT_DEPENDANT";
5249
- Errors["MIXED_EXPORTS"] = "MIXED_EXPORTS";
5250
- Errors["NAMESPACE_CONFLICT"] = "NAMESPACE_CONFLICT";
5251
- Errors["NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE"] = "NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE";
5252
- Errors["PLUGIN_ERROR"] = "PLUGIN_ERROR";
5253
- Errors["PREFER_NAMED_EXPORTS"] = "PREFER_NAMED_EXPORTS";
5254
- Errors["SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT"] = "SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT";
5255
- Errors["UNEXPECTED_NAMED_IMPORT"] = "UNEXPECTED_NAMED_IMPORT";
5256
- Errors["UNRESOLVED_ENTRY"] = "UNRESOLVED_ENTRY";
5257
- Errors["UNRESOLVED_IMPORT"] = "UNRESOLVED_IMPORT";
5258
- Errors["VALIDATION_ERROR"] = "VALIDATION_ERROR";
5259
- })(Errors || (Errors = {}));
5260
- function errAssetNotFinalisedForFileName(name) {
5261
- return {
5262
- code: Errors.ASSET_NOT_FINALISED,
5263
- message: `Plugin error - Unable to get file name for asset "${name}". Ensure that the source is set and that generate is called first.`
5264
- };
5265
- }
5266
- function errCannotEmitFromOptionsHook() {
5267
- return {
5268
- code: Errors.CANNOT_EMIT_FROM_OPTIONS_HOOK,
5269
- message: `Cannot emit files or set asset sources in the "outputOptions" hook, use the "renderStart" hook instead.`
5270
- };
5271
- }
5272
- function errChunkNotGeneratedForFileName(name) {
5273
- return {
5274
- code: Errors.CHUNK_NOT_GENERATED,
5275
- message: `Plugin error - Unable to get file name for chunk "${name}". Ensure that generate is called first.`
5276
- };
5277
- }
5278
- function errAssetReferenceIdNotFoundForSetSource(assetReferenceId) {
5279
- return {
5280
- code: Errors.ASSET_NOT_FOUND,
5281
- message: `Plugin error - Unable to set the source for unknown asset "${assetReferenceId}".`
5282
- };
5283
- }
5284
- function errAssetSourceAlreadySet(name) {
5285
- return {
5286
- code: Errors.ASSET_SOURCE_ALREADY_SET,
5287
- message: `Unable to set the source for asset "${name}", source already set.`
5288
- };
5289
- }
5290
- function errNoAssetSourceSet(assetName) {
5291
- return {
5292
- code: Errors.ASSET_SOURCE_MISSING,
5293
- message: `Plugin error creating asset "${assetName}" - no asset source set.`
5294
- };
5295
- }
5296
- function errBadLoader(id) {
5297
- return {
5298
- code: Errors.BAD_LOADER,
5299
- message: `Error loading ${relativeId(id)}: plugin load hook should return a string, a { code, map } object, or nothing/null`
5300
- };
5301
- }
5302
- function errDeprecation(deprecation) {
5303
- return {
5304
- code: Errors.DEPRECATED_FEATURE,
5305
- ...(typeof deprecation === 'string' ? { message: deprecation } : deprecation)
5306
- };
5004
+
5005
+ const INTEROP_DEFAULT_VARIABLE = '_interopDefault';
5006
+ const INTEROP_DEFAULT_LEGACY_VARIABLE = '_interopDefaultLegacy';
5007
+ const INTEROP_NAMESPACE_VARIABLE = '_interopNamespace';
5008
+ const INTEROP_NAMESPACE_DEFAULT_VARIABLE = '_interopNamespaceDefault';
5009
+ const INTEROP_NAMESPACE_DEFAULT_ONLY_VARIABLE = '_interopNamespaceDefaultOnly';
5010
+ const defaultInteropHelpersByInteropType = {
5011
+ auto: INTEROP_DEFAULT_VARIABLE,
5012
+ default: null,
5013
+ defaultOnly: null,
5014
+ esModule: null,
5015
+ false: null,
5016
+ true: INTEROP_DEFAULT_LEGACY_VARIABLE
5017
+ };
5018
+ function isDefaultAProperty(interopType, externalLiveBindings) {
5019
+ return (interopType === 'esModule' ||
5020
+ (externalLiveBindings && (interopType === 'auto' || interopType === 'true')));
5307
5021
  }
5308
- function errFileReferenceIdNotFoundForFilename(assetReferenceId) {
5309
- return {
5310
- code: Errors.FILE_NOT_FOUND,
5311
- message: `Plugin error - Unable to get file name for unknown file "${assetReferenceId}".`
5312
- };
5022
+ const namespaceInteropHelpersByInteropType = {
5023
+ auto: INTEROP_NAMESPACE_VARIABLE,
5024
+ default: INTEROP_NAMESPACE_DEFAULT_VARIABLE,
5025
+ defaultOnly: INTEROP_NAMESPACE_DEFAULT_ONLY_VARIABLE,
5026
+ esModule: null,
5027
+ false: null,
5028
+ true: INTEROP_NAMESPACE_VARIABLE
5029
+ };
5030
+ function canDefaultBeTakenFromNamespace(interopType, externalLiveBindings) {
5031
+ return (isDefaultAProperty(interopType, externalLiveBindings) &&
5032
+ defaultInteropHelpersByInteropType[interopType] === INTEROP_DEFAULT_VARIABLE);
5313
5033
  }
5314
- function errFileNameConflict(fileName) {
5315
- return {
5316
- code: Errors.FILE_NAME_CONFLICT,
5317
- message: `The emitted file "${fileName}" overwrites a previously emitted file of the same name.`
5318
- };
5034
+ function getDefaultOnlyHelper() {
5035
+ return INTEROP_NAMESPACE_DEFAULT_ONLY_VARIABLE;
5319
5036
  }
5320
- function errInputHookInOutputPlugin(pluginName, hookName) {
5321
- return {
5322
- code: Errors.INPUT_HOOK_IN_OUTPUT_PLUGIN,
5323
- 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.`
5324
- };
5037
+ function getHelpersBlock(usedHelpers, accessedGlobals, _, n, s, t, liveBindings, freeze, namespaceToStringTag) {
5038
+ return HELPER_NAMES.map(variable => usedHelpers.has(variable) || accessedGlobals.has(variable)
5039
+ ? HELPER_GENERATORS[variable](_, n, s, t, liveBindings, freeze, namespaceToStringTag, usedHelpers)
5040
+ : '').join('');
5325
5041
  }
5326
- function errCannotAssignModuleToChunk(moduleId, assignToAlias, currentAlias) {
5327
- return {
5328
- code: Errors.INVALID_CHUNK,
5329
- message: `Cannot assign ${relativeId(moduleId)} to the "${assignToAlias}" chunk as it is already in the "${currentAlias}" chunk.`
5330
- };
5042
+ const HELPER_GENERATORS = {
5043
+ [INTEROP_DEFAULT_VARIABLE]: (_, n, s, _t, liveBindings) => `function ${INTEROP_DEFAULT_VARIABLE}${_}(e)${_}{${_}return ` +
5044
+ `e${_}&&${_}e.__esModule${_}?${_}` +
5045
+ `${liveBindings ? getDefaultLiveBinding(_) : getDefaultStatic(_)}${s}${_}}${n}${n}`,
5046
+ [INTEROP_DEFAULT_LEGACY_VARIABLE]: (_, n, s, _t, liveBindings) => `function ${INTEROP_DEFAULT_LEGACY_VARIABLE}${_}(e)${_}{${_}return ` +
5047
+ `e${_}&&${_}typeof e${_}===${_}'object'${_}&&${_}'default'${_}in e${_}?${_}` +
5048
+ `${liveBindings ? getDefaultLiveBinding(_) : getDefaultStatic(_)}${s}${_}}${n}${n}`,
5049
+ [INTEROP_NAMESPACE_VARIABLE]: (_, n, s, t, liveBindings, freeze, namespaceToStringTag, usedHelpers) => `function ${INTEROP_NAMESPACE_VARIABLE}(e)${_}{${n}` +
5050
+ (usedHelpers.has(INTEROP_NAMESPACE_DEFAULT_VARIABLE)
5051
+ ? `${t}return e${_}&&${_}e.__esModule${_}?${_}e${_}:${_}${INTEROP_NAMESPACE_DEFAULT_VARIABLE}(e)${s}${n}`
5052
+ : `${t}if${_}(e${_}&&${_}e.__esModule)${_}return e;${n}` +
5053
+ createNamespaceObject(_, n, t, t, liveBindings, freeze, namespaceToStringTag)) +
5054
+ `}${n}${n}`,
5055
+ [INTEROP_NAMESPACE_DEFAULT_VARIABLE]: (_, n, _s, t, liveBindings, freeze, namespaceToStringTag) => `function ${INTEROP_NAMESPACE_DEFAULT_VARIABLE}(e)${_}{${n}` +
5056
+ createNamespaceObject(_, n, t, t, liveBindings, freeze, namespaceToStringTag) +
5057
+ `}${n}${n}`,
5058
+ [INTEROP_NAMESPACE_DEFAULT_ONLY_VARIABLE]: (_, n, _s, t, _liveBindings, freeze, namespaceToStringTag) => `function ${INTEROP_NAMESPACE_DEFAULT_ONLY_VARIABLE}(e)${_}{${n}` +
5059
+ `${t}return ${getFrozen(`{__proto__: null,${namespaceToStringTag ? `${_}[Symbol.toStringTag]:${_}'Module',` : ''}${_}'default':${_}e}`, freeze)};${n}` +
5060
+ `}${n}${n}`
5061
+ };
5062
+ function getDefaultLiveBinding(_) {
5063
+ return `e${_}:${_}{${_}'default':${_}e${_}}`;
5331
5064
  }
5332
- function errInvalidExportOptionValue(optionValue) {
5333
- return {
5334
- code: Errors.INVALID_EXPORT_OPTION,
5335
- message: `"output.exports" must be "default", "named", "none", "auto", or left unspecified (defaults to "auto"), received "${optionValue}"`,
5336
- url: `https://rollupjs.org/guide/en/#outputexports`
5337
- };
5065
+ function getDefaultStatic(_) {
5066
+ return `e['default']${_}:${_}e`;
5338
5067
  }
5339
- function errIncompatibleExportOptionValue(optionValue, keys, entryModule) {
5340
- return {
5341
- code: 'INVALID_EXPORT_OPTION',
5342
- message: `"${optionValue}" was specified for "output.exports", but entry module "${relativeId(entryModule)}" has the following exports: ${keys.join(', ')}`
5343
- };
5068
+ function createNamespaceObject(_, n, t, i, liveBindings, freeze, namespaceToStringTag) {
5069
+ return (`${i}var n${_}=${_}${namespaceToStringTag
5070
+ ? `{__proto__:${_}null,${_}[Symbol.toStringTag]:${_}'Module'}`
5071
+ : 'Object.create(null)'};${n}` +
5072
+ `${i}if${_}(e)${_}{${n}` +
5073
+ `${i}${t}Object.keys(e).forEach(function${_}(k)${_}{${n}` +
5074
+ (liveBindings ? copyPropertyLiveBinding : copyPropertyStatic)(_, n, t, i + t + t) +
5075
+ `${i}${t}});${n}` +
5076
+ `${i}}${n}` +
5077
+ `${i}n['default']${_}=${_}e;${n}` +
5078
+ `${i}return ${getFrozen('n', freeze)};${n}`);
5344
5079
  }
5345
- function errInternalIdCannotBeExternal(source, importer) {
5346
- return {
5347
- code: Errors.INVALID_EXTERNAL_ID,
5348
- message: `'${source}' is imported as an external by ${relativeId(importer)}, but is already an existing non-external module id.`
5349
- };
5080
+ function copyPropertyLiveBinding(_, n, t, i) {
5081
+ return (`${i}if${_}(k${_}!==${_}'default')${_}{${n}` +
5082
+ `${i}${t}var d${_}=${_}Object.getOwnPropertyDescriptor(e,${_}k);${n}` +
5083
+ `${i}${t}Object.defineProperty(n,${_}k,${_}d.get${_}?${_}d${_}:${_}{${n}` +
5084
+ `${i}${t}${t}enumerable:${_}true,${n}` +
5085
+ `${i}${t}${t}get:${_}function${_}()${_}{${n}` +
5086
+ `${i}${t}${t}${t}return e[k];${n}` +
5087
+ `${i}${t}${t}}${n}` +
5088
+ `${i}${t}});${n}` +
5089
+ `${i}}${n}`);
5350
5090
  }
5351
- function errInvalidOption(option, explanation) {
5352
- return {
5353
- code: Errors.INVALID_OPTION,
5354
- message: `Invalid value for option "${option}" - ${explanation}.`
5355
- };
5091
+ function copyPropertyStatic(_, n, _t, i) {
5092
+ return `${i}n[k]${_}=${_}e[k];${n}`;
5356
5093
  }
5357
- function errInvalidRollupPhaseForAddWatchFile() {
5358
- return {
5359
- code: Errors.INVALID_ROLLUP_PHASE,
5360
- message: `Cannot call addWatchFile after the build has finished.`
5361
- };
5094
+ function getFrozen(fragment, freeze) {
5095
+ return freeze ? `Object.freeze(${fragment})` : fragment;
5362
5096
  }
5363
- function errInvalidRollupPhaseForChunkEmission() {
5364
- return {
5365
- code: Errors.INVALID_ROLLUP_PHASE,
5366
- message: `Cannot emit chunks after module loading has finished.`
5367
- };
5368
- }
5369
- function errImplicitDependantCannotBeExternal(unresolvedId, implicitlyLoadedBefore) {
5370
- return {
5371
- code: Errors.MISSING_IMPLICIT_DEPENDANT,
5372
- message: `Module "${relativeId(unresolvedId)}" that should be implicitly loaded before "${relativeId(implicitlyLoadedBefore)}" cannot be external.`
5373
- };
5374
- }
5375
- function errUnresolvedImplicitDependant(unresolvedId, implicitlyLoadedBefore) {
5376
- return {
5377
- code: Errors.MISSING_IMPLICIT_DEPENDANT,
5378
- message: `Module "${relativeId(unresolvedId)}" that should be implicitly loaded before "${relativeId(implicitlyLoadedBefore)}" could not be resolved.`
5379
- };
5380
- }
5381
- function errImplicitDependantIsNotIncluded(module) {
5382
- const implicitDependencies = Array.from(module.implicitlyLoadedBefore, dependency => relativeId(dependency.id)).sort();
5383
- return {
5384
- code: Errors.MISSING_IMPLICIT_DEPENDANT,
5385
- message: `Module "${relativeId(module.id)}" that should be implicitly loaded before "${implicitDependencies.length === 1
5386
- ? implicitDependencies[0]
5387
- : `${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.`
5388
- };
5389
- }
5390
- function errMixedExport(facadeModuleId, name) {
5391
- return {
5392
- code: Errors.MIXED_EXPORTS,
5393
- id: facadeModuleId,
5394
- 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`,
5395
- url: `https://rollupjs.org/guide/en/#outputexports`
5396
- };
5097
+ const HELPER_NAMES = Object.keys(HELPER_GENERATORS);
5098
+
5099
+ function getExportBlock(exports, dependencies, namedExportsMode, interop, compact, t, externalLiveBindings, mechanism = 'return ') {
5100
+ const _ = compact ? '' : ' ';
5101
+ const n = compact ? '' : '\n';
5102
+ if (!namedExportsMode) {
5103
+ return `${n}${n}${mechanism}${getSingleDefaultExport(exports, dependencies, interop, externalLiveBindings)};`;
5104
+ }
5105
+ let exportBlock = '';
5106
+ // star exports must always output first for precedence
5107
+ for (const { name, reexports } of dependencies) {
5108
+ if (reexports && namedExportsMode) {
5109
+ for (const specifier of reexports) {
5110
+ if (specifier.reexported === '*') {
5111
+ if (exportBlock)
5112
+ exportBlock += n;
5113
+ if (specifier.needsLiveBinding) {
5114
+ exportBlock +=
5115
+ `Object.keys(${name}).forEach(function${_}(k)${_}{${n}` +
5116
+ `${t}if${_}(k${_}!==${_}'default')${_}Object.defineProperty(exports,${_}k,${_}{${n}` +
5117
+ `${t}${t}enumerable:${_}true,${n}` +
5118
+ `${t}${t}get:${_}function${_}()${_}{${n}` +
5119
+ `${t}${t}${t}return ${name}[k];${n}` +
5120
+ `${t}${t}}${n}${t}});${n}});`;
5121
+ }
5122
+ else {
5123
+ exportBlock +=
5124
+ `Object.keys(${name}).forEach(function${_}(k)${_}{${n}` +
5125
+ `${t}if${_}(k${_}!==${_}'default')${_}exports[k]${_}=${_}${name}[k];${n}});`;
5126
+ }
5127
+ }
5128
+ }
5129
+ }
5130
+ }
5131
+ for (const { defaultVariableName, id, isChunk, name, namedExportsMode: depNamedExportsMode, namespaceVariableName, reexports } of dependencies) {
5132
+ if (reexports && namedExportsMode) {
5133
+ for (const specifier of reexports) {
5134
+ if (specifier.reexported !== '*') {
5135
+ const importName = getReexportedImportName(name, specifier.imported, depNamedExportsMode, isChunk, defaultVariableName, namespaceVariableName, interop, id, externalLiveBindings);
5136
+ if (exportBlock)
5137
+ exportBlock += n;
5138
+ exportBlock +=
5139
+ specifier.imported !== '*' && specifier.needsLiveBinding
5140
+ ? `Object.defineProperty(exports,${_}'${specifier.reexported}',${_}{${n}` +
5141
+ `${t}enumerable:${_}true,${n}` +
5142
+ `${t}get:${_}function${_}()${_}{${n}` +
5143
+ `${t}${t}return ${importName};${n}${t}}${n}});`
5144
+ : `exports.${specifier.reexported}${_}=${_}${importName};`;
5145
+ }
5146
+ }
5147
+ }
5148
+ }
5149
+ for (const chunkExport of exports) {
5150
+ const lhs = `exports.${chunkExport.exported}`;
5151
+ const rhs = chunkExport.local;
5152
+ if (lhs !== rhs) {
5153
+ if (exportBlock)
5154
+ exportBlock += n;
5155
+ exportBlock += `${lhs}${_}=${_}${rhs};`;
5156
+ }
5157
+ }
5158
+ if (exportBlock) {
5159
+ return `${n}${n}${exportBlock}`;
5160
+ }
5161
+ return '';
5397
5162
  }
5398
- function errNamespaceConflict(name, reexportingModule, additionalExportAllModule) {
5399
- return {
5400
- code: Errors.NAMESPACE_CONFLICT,
5401
- message: `Conflicting namespaces: ${relativeId(reexportingModule.id)} re-exports '${name}' from both ${relativeId(reexportingModule.exportsAll[name])} and ${relativeId(additionalExportAllModule.exportsAll[name])} (will be ignored)`,
5402
- name,
5403
- reexporter: reexportingModule.id,
5404
- sources: [reexportingModule.exportsAll[name], additionalExportAllModule.exportsAll[name]]
5405
- };
5163
+ function getSingleDefaultExport(exports, dependencies, interop, externalLiveBindings) {
5164
+ if (exports.length > 0) {
5165
+ return exports[0].local;
5166
+ }
5167
+ else {
5168
+ for (const { defaultVariableName, id, isChunk, name, namedExportsMode: depNamedExportsMode, namespaceVariableName, reexports } of dependencies) {
5169
+ if (reexports) {
5170
+ return getReexportedImportName(name, reexports[0].imported, depNamedExportsMode, isChunk, defaultVariableName, namespaceVariableName, interop, id, externalLiveBindings);
5171
+ }
5172
+ }
5173
+ }
5406
5174
  }
5407
- function errNoTransformMapOrAstWithoutCode(pluginName) {
5408
- return {
5409
- code: Errors.NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE,
5410
- message: `The plugin "${pluginName}" returned a "map" or "ast" without returning ` +
5411
- 'a "code". This will be ignored.'
5412
- };
5175
+ function getReexportedImportName(moduleVariableName, imported, depNamedExportsMode, isChunk, defaultVariableName, namespaceVariableName, interop, moduleId, externalLiveBindings) {
5176
+ if (imported === 'default') {
5177
+ if (!isChunk) {
5178
+ const moduleInterop = String(interop(moduleId));
5179
+ const variableName = defaultInteropHelpersByInteropType[moduleInterop]
5180
+ ? defaultVariableName
5181
+ : moduleVariableName;
5182
+ return isDefaultAProperty(moduleInterop, externalLiveBindings)
5183
+ ? `${variableName}['default']`
5184
+ : variableName;
5185
+ }
5186
+ return depNamedExportsMode ? `${moduleVariableName}['default']` : moduleVariableName;
5187
+ }
5188
+ if (imported === '*') {
5189
+ return (isChunk
5190
+ ? !depNamedExportsMode
5191
+ : namespaceInteropHelpersByInteropType[String(interop(moduleId))])
5192
+ ? namespaceVariableName
5193
+ : moduleVariableName;
5194
+ }
5195
+ return `${moduleVariableName}.${imported}`;
5413
5196
  }
5414
- function errPreferNamedExports(facadeModuleId) {
5415
- const file = relativeId(facadeModuleId);
5416
- return {
5417
- code: Errors.PREFER_NAMED_EXPORTS,
5418
- id: facadeModuleId,
5419
- 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.`,
5420
- url: `https://rollupjs.org/guide/en/#outputexports`
5421
- };
5197
+ function getEsModuleExport(_) {
5198
+ return `Object.defineProperty(exports,${_}'__esModule',${_}{${_}value:${_}true${_}});`;
5422
5199
  }
5423
- function errUnexpectedNamedImport(id, imported, isReexport) {
5424
- const importType = isReexport ? 'reexport' : 'import';
5425
- return {
5426
- code: Errors.UNEXPECTED_NAMED_IMPORT,
5427
- id,
5428
- 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.`,
5429
- url: 'https://rollupjs.org/guide/en/#outputinterop'
5430
- };
5200
+ function getNamespaceToStringExport(_) {
5201
+ return `exports[Symbol.toStringTag]${_}=${_}'Module';`;
5431
5202
  }
5432
- function errUnexpectedNamespaceReexport(id) {
5433
- return {
5434
- code: Errors.UNEXPECTED_NAMED_IMPORT,
5435
- id,
5436
- 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.`,
5437
- url: 'https://rollupjs.org/guide/en/#outputinterop'
5438
- };
5203
+ function getNamespaceMarkers(hasNamedExports, addEsModule, addNamespaceToStringTag, _, n) {
5204
+ let namespaceMarkers = '';
5205
+ if (hasNamedExports) {
5206
+ if (addEsModule) {
5207
+ namespaceMarkers += getEsModuleExport(_);
5208
+ }
5209
+ if (addNamespaceToStringTag) {
5210
+ if (namespaceMarkers) {
5211
+ namespaceMarkers += n;
5212
+ }
5213
+ namespaceMarkers += getNamespaceToStringExport(_);
5214
+ }
5215
+ }
5216
+ return namespaceMarkers;
5439
5217
  }
5440
- function errEntryCannotBeExternal(unresolvedId) {
5441
- return {
5442
- code: Errors.UNRESOLVED_ENTRY,
5443
- message: `Entry module cannot be external (${relativeId(unresolvedId)}).`
5218
+
5219
+ function getInteropBlock(dependencies, varOrConst, interop, externalLiveBindings, freeze, namespaceToStringTag, accessedGlobals, _, n, s, t) {
5220
+ const neededInteropHelpers = new Set();
5221
+ const interopStatements = [];
5222
+ const addInteropStatement = (helperVariableName, helper, dependencyVariableName) => {
5223
+ neededInteropHelpers.add(helper);
5224
+ interopStatements.push(`${varOrConst} ${helperVariableName}${_}=${_}/*#__PURE__*/${helper}(${dependencyVariableName});`);
5444
5225
  };
5226
+ for (const { defaultVariableName, imports, id, isChunk, name, namedExportsMode, namespaceVariableName, reexports } of dependencies) {
5227
+ if (isChunk) {
5228
+ for (const { imported, reexported } of [
5229
+ ...(imports || []),
5230
+ ...(reexports || [])
5231
+ ]) {
5232
+ if (imported === '*' && reexported !== '*') {
5233
+ if (!namedExportsMode) {
5234
+ addInteropStatement(namespaceVariableName, getDefaultOnlyHelper(), name);
5235
+ }
5236
+ break;
5237
+ }
5238
+ }
5239
+ }
5240
+ else {
5241
+ const moduleInterop = String(interop(id));
5242
+ let hasDefault = false;
5243
+ let hasNamespace = false;
5244
+ for (const { imported, reexported } of [
5245
+ ...(imports || []),
5246
+ ...(reexports || [])
5247
+ ]) {
5248
+ let helper;
5249
+ let variableName;
5250
+ if (imported === 'default') {
5251
+ if (!hasDefault) {
5252
+ hasDefault = true;
5253
+ if (defaultVariableName !== namespaceVariableName) {
5254
+ variableName = defaultVariableName;
5255
+ helper = defaultInteropHelpersByInteropType[moduleInterop];
5256
+ }
5257
+ }
5258
+ }
5259
+ else if (imported === '*' && reexported !== '*') {
5260
+ if (!hasNamespace) {
5261
+ hasNamespace = true;
5262
+ helper = namespaceInteropHelpersByInteropType[moduleInterop];
5263
+ variableName = namespaceVariableName;
5264
+ }
5265
+ }
5266
+ if (helper) {
5267
+ addInteropStatement(variableName, helper, name);
5268
+ }
5269
+ }
5270
+ }
5271
+ }
5272
+ return `${getHelpersBlock(neededInteropHelpers, accessedGlobals, _, n, s, t, externalLiveBindings, freeze, namespaceToStringTag)}${interopStatements.length > 0 ? `${interopStatements.join(n)}${n}${n}` : ''}`;
5445
5273
  }
5446
- function errUnresolvedEntry(unresolvedId) {
5447
- return {
5448
- code: Errors.UNRESOLVED_ENTRY,
5449
- message: `Could not resolve entry module (${relativeId(unresolvedId)}).`
5450
- };
5274
+
5275
+ // AMD resolution will only respect the AMD baseUrl if the .js extension is omitted.
5276
+ // The assumption is that this makes sense for all relative ids:
5277
+ // https://requirejs.org/docs/api.html#jsfiles
5278
+ function removeExtensionFromRelativeAmdId(id) {
5279
+ return id[0] === '.' ? removeJsExtension(id) : id;
5451
5280
  }
5452
- function errUnresolvedImport(source, importer) {
5453
- return {
5454
- code: Errors.UNRESOLVED_IMPORT,
5455
- message: `Could not resolve '${source}' from ${relativeId(importer)}`
5456
- };
5281
+
5282
+ const builtins$1 = {
5283
+ assert: true,
5284
+ buffer: true,
5285
+ console: true,
5286
+ constants: true,
5287
+ domain: true,
5288
+ events: true,
5289
+ http: true,
5290
+ https: true,
5291
+ os: true,
5292
+ path: true,
5293
+ process: true,
5294
+ punycode: true,
5295
+ querystring: true,
5296
+ stream: true,
5297
+ string_decoder: true,
5298
+ timers: true,
5299
+ tty: true,
5300
+ url: true,
5301
+ util: true,
5302
+ vm: true,
5303
+ zlib: true
5304
+ };
5305
+ function warnOnBuiltins(warn, dependencies) {
5306
+ const externalBuiltins = dependencies.map(({ id }) => id).filter(id => id in builtins$1);
5307
+ if (!externalBuiltins.length)
5308
+ return;
5309
+ const detail = externalBuiltins.length === 1
5310
+ ? `module ('${externalBuiltins[0]}')`
5311
+ : `modules (${externalBuiltins
5312
+ .slice(0, -1)
5313
+ .map(name => `'${name}'`)
5314
+ .join(', ')} and '${externalBuiltins.slice(-1)}')`;
5315
+ warn({
5316
+ code: 'MISSING_NODE_BUILTINS',
5317
+ 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`,
5318
+ modules: externalBuiltins
5319
+ });
5457
5320
  }
5458
- function errUnresolvedImportTreatedAsExternal(source, importer) {
5459
- return {
5460
- code: Errors.UNRESOLVED_IMPORT,
5461
- importer: relativeId(importer),
5462
- message: `'${source}' is imported by ${relativeId(importer)}, but could not be resolved – treating it as an external dependency`,
5463
- source,
5464
- url: 'https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency'
5465
- };
5321
+
5322
+ 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 }) {
5323
+ warnOnBuiltins(warn, dependencies);
5324
+ const deps = dependencies.map(m => `'${removeExtensionFromRelativeAmdId(m.id)}'`);
5325
+ const args = dependencies.map(m => m.name);
5326
+ const n = compact ? '' : '\n';
5327
+ const s = compact ? '' : ';';
5328
+ const _ = compact ? '' : ' ';
5329
+ if (namedExportsMode && hasExports) {
5330
+ args.unshift(`exports`);
5331
+ deps.unshift(`'exports'`);
5332
+ }
5333
+ if (accessedGlobals.has('require')) {
5334
+ args.unshift('require');
5335
+ deps.unshift(`'require'`);
5336
+ }
5337
+ if (accessedGlobals.has('module')) {
5338
+ args.unshift('module');
5339
+ deps.unshift(`'module'`);
5340
+ }
5341
+ const completeAmdId = getCompleteAmdId(amd, id);
5342
+ const params = (completeAmdId ? `'${completeAmdId}',${_}` : ``) +
5343
+ (deps.length ? `[${deps.join(`,${_}`)}],${_}` : ``);
5344
+ const useStrict = strict ? `${_}'use strict';` : '';
5345
+ magicString.prepend(`${intro}${getInteropBlock(dependencies, varOrConst, interop, externalLiveBindings, freeze, namespaceToStringTag, accessedGlobals, _, n, s, t)}`);
5346
+ const exportBlock = getExportBlock(exports, dependencies, namedExportsMode, interop, compact, t, externalLiveBindings);
5347
+ let namespaceMarkers = getNamespaceMarkers(namedExportsMode && hasExports, isEntryFacade && esModule, isModuleFacade && namespaceToStringTag, _, n);
5348
+ if (namespaceMarkers) {
5349
+ namespaceMarkers = n + n + namespaceMarkers;
5350
+ }
5351
+ magicString.append(`${exportBlock}${namespaceMarkers}${outro}`);
5352
+ return magicString
5353
+ .indent(t)
5354
+ .prepend(`${amd.define}(${params}function${_}(${args.join(`,${_}`)})${_}{${useStrict}${n}${n}`)
5355
+ .append(`${n}${n}});`);
5466
5356
  }
5467
- function errExternalSyntheticExports(source, importer) {
5468
- return {
5469
- code: Errors.EXTERNAL_SYNTHETIC_EXPORTS,
5470
- importer: relativeId(importer),
5471
- message: `External '${source}' can not have 'syntheticNamedExports' enabled.`,
5472
- source
5473
- };
5357
+
5358
+ function cjs(magicString, { accessedGlobals, dependencies, exports, hasExports, indentString: t, intro, isEntryFacade, isModuleFacade, namedExportsMode, outro, varOrConst }, { compact, esModule, externalLiveBindings, freeze, interop, namespaceToStringTag, strict }) {
5359
+ const n = compact ? '' : '\n';
5360
+ const s = compact ? '' : ';';
5361
+ const _ = compact ? '' : ' ';
5362
+ const useStrict = strict ? `'use strict';${n}${n}` : '';
5363
+ let namespaceMarkers = getNamespaceMarkers(namedExportsMode && hasExports, isEntryFacade && esModule, isModuleFacade && namespaceToStringTag, _, n);
5364
+ if (namespaceMarkers) {
5365
+ namespaceMarkers += n + n;
5366
+ }
5367
+ const importBlock = getImportBlock(dependencies, compact, varOrConst, n, _);
5368
+ const interopBlock = getInteropBlock(dependencies, varOrConst, interop, externalLiveBindings, freeze, namespaceToStringTag, accessedGlobals, _, n, s, t);
5369
+ magicString.prepend(`${useStrict}${intro}${namespaceMarkers}${importBlock}${interopBlock}`);
5370
+ const exportBlock = getExportBlock(exports, dependencies, namedExportsMode, interop, compact, t, externalLiveBindings, `module.exports${_}=${_}`);
5371
+ return magicString.append(`${exportBlock}${outro}`);
5474
5372
  }
5475
- function errFailedValidation(message) {
5476
- return {
5477
- code: Errors.VALIDATION_ERROR,
5478
- message
5479
- };
5373
+ function getImportBlock(dependencies, compact, varOrConst, n, _) {
5374
+ let importBlock = '';
5375
+ let definingVariable = false;
5376
+ for (const { id, name, reexports, imports } of dependencies) {
5377
+ if (!reexports && !imports) {
5378
+ if (importBlock) {
5379
+ importBlock += !compact || definingVariable ? `;${n}` : ',';
5380
+ }
5381
+ definingVariable = false;
5382
+ importBlock += `require('${id}')`;
5383
+ }
5384
+ else {
5385
+ importBlock +=
5386
+ compact && definingVariable ? ',' : `${importBlock ? `;${n}` : ''}${varOrConst} `;
5387
+ definingVariable = true;
5388
+ importBlock += `${name}${_}=${_}require('${id}')`;
5389
+ }
5390
+ }
5391
+ if (importBlock) {
5392
+ return `${importBlock};${n}${n}`;
5393
+ }
5394
+ return '';
5480
5395
  }
5481
- function errAlreadyClosed() {
5482
- return {
5483
- code: Errors.ALREADY_CLOSED,
5484
- message: 'Bundle is already closed, no more calls to "generate" or "write" are allowed.'
5485
- };
5396
+
5397
+ function es(magicString, { intro, outro, dependencies, exports, varOrConst }, { compact }) {
5398
+ const _ = compact ? '' : ' ';
5399
+ const n = compact ? '' : '\n';
5400
+ const importBlock = getImportBlock$1(dependencies, _);
5401
+ if (importBlock.length > 0)
5402
+ intro += importBlock.join(n) + n + n;
5403
+ if (intro)
5404
+ magicString.prepend(intro);
5405
+ const exportBlock = getExportBlock$1(exports, _, varOrConst);
5406
+ if (exportBlock.length)
5407
+ magicString.append(n + n + exportBlock.join(n).trim());
5408
+ if (outro)
5409
+ magicString.append(outro);
5410
+ return magicString.trim();
5486
5411
  }
5487
- function warnDeprecation(deprecation, activeDeprecation, options) {
5488
- warnDeprecationWithOptions(deprecation, activeDeprecation, options.onwarn, options.strictDeprecations);
5412
+ function getImportBlock$1(dependencies, _) {
5413
+ const importBlock = [];
5414
+ for (const { id, reexports, imports, name } of dependencies) {
5415
+ if (!reexports && !imports) {
5416
+ importBlock.push(`import${_}'${id}';`);
5417
+ continue;
5418
+ }
5419
+ if (imports) {
5420
+ let defaultImport = null;
5421
+ let starImport = null;
5422
+ const importedNames = [];
5423
+ for (const specifier of imports) {
5424
+ if (specifier.imported === 'default') {
5425
+ defaultImport = specifier;
5426
+ }
5427
+ else if (specifier.imported === '*') {
5428
+ starImport = specifier;
5429
+ }
5430
+ else {
5431
+ importedNames.push(specifier);
5432
+ }
5433
+ }
5434
+ if (starImport) {
5435
+ importBlock.push(`import${_}*${_}as ${starImport.local} from${_}'${id}';`);
5436
+ }
5437
+ if (defaultImport && importedNames.length === 0) {
5438
+ importBlock.push(`import ${defaultImport.local} from${_}'${id}';`);
5439
+ }
5440
+ else if (importedNames.length > 0) {
5441
+ importBlock.push(`import ${defaultImport ? `${defaultImport.local},${_}` : ''}{${_}${importedNames
5442
+ .map(specifier => {
5443
+ if (specifier.imported === specifier.local) {
5444
+ return specifier.imported;
5445
+ }
5446
+ else {
5447
+ return `${specifier.imported} as ${specifier.local}`;
5448
+ }
5449
+ })
5450
+ .join(`,${_}`)}${_}}${_}from${_}'${id}';`);
5451
+ }
5452
+ }
5453
+ if (reexports) {
5454
+ let starExport = null;
5455
+ const namespaceReexports = [];
5456
+ const namedReexports = [];
5457
+ for (const specifier of reexports) {
5458
+ if (specifier.reexported === '*') {
5459
+ starExport = specifier;
5460
+ }
5461
+ else if (specifier.imported === '*') {
5462
+ namespaceReexports.push(specifier);
5463
+ }
5464
+ else {
5465
+ namedReexports.push(specifier);
5466
+ }
5467
+ }
5468
+ if (starExport) {
5469
+ importBlock.push(`export${_}*${_}from${_}'${id}';`);
5470
+ }
5471
+ if (namespaceReexports.length > 0) {
5472
+ if (!imports ||
5473
+ !imports.some(specifier => specifier.imported === '*' && specifier.local === name)) {
5474
+ importBlock.push(`import${_}*${_}as ${name} from${_}'${id}';`);
5475
+ }
5476
+ for (const specifier of namespaceReexports) {
5477
+ importBlock.push(`export${_}{${_}${name === specifier.reexported ? name : `${name} as ${specifier.reexported}`} };`);
5478
+ }
5479
+ }
5480
+ if (namedReexports.length > 0) {
5481
+ importBlock.push(`export${_}{${_}${namedReexports
5482
+ .map(specifier => {
5483
+ if (specifier.imported === specifier.reexported) {
5484
+ return specifier.imported;
5485
+ }
5486
+ else {
5487
+ return `${specifier.imported} as ${specifier.reexported}`;
5488
+ }
5489
+ })
5490
+ .join(`,${_}`)}${_}}${_}from${_}'${id}';`);
5491
+ }
5492
+ }
5493
+ }
5494
+ return importBlock;
5489
5495
  }
5490
- function warnDeprecationWithOptions(deprecation, activeDeprecation, warn, strictDeprecations) {
5491
- if (activeDeprecation || strictDeprecations) {
5492
- const warning = errDeprecation(deprecation);
5493
- if (strictDeprecations) {
5494
- return error(warning);
5496
+ function getExportBlock$1(exports, _, varOrConst) {
5497
+ const exportBlock = [];
5498
+ const exportDeclaration = [];
5499
+ for (const specifier of exports) {
5500
+ if (specifier.exported === 'default') {
5501
+ exportBlock.push(`export default ${specifier.local};`);
5502
+ }
5503
+ else {
5504
+ if (specifier.expression) {
5505
+ exportBlock.push(`${varOrConst} ${specifier.local}${_}=${_}${specifier.expression};`);
5506
+ }
5507
+ exportDeclaration.push(specifier.exported === specifier.local
5508
+ ? specifier.local
5509
+ : `${specifier.local} as ${specifier.exported}`);
5495
5510
  }
5496
- warn(warning);
5497
5511
  }
5512
+ if (exportDeclaration.length) {
5513
+ exportBlock.push(`export${_}{${_}${exportDeclaration.join(`,${_}`)}${_}};`);
5514
+ }
5515
+ return exportBlock;
5498
5516
  }
5499
5517
 
5500
5518
  // Generate strings which dereference dotted properties, but use array notation `['prop-deref']`
@@ -6156,13 +6174,17 @@ class AssignmentExpression extends NodeBase {
6156
6174
  }
6157
6175
  this.right.include(context, includeChildrenRecursively);
6158
6176
  }
6159
- render(code, options) {
6160
- this.right.render(code, options);
6177
+ render(code, options, { renderedParentType } = BLANK) {
6161
6178
  if (this.left.included) {
6162
6179
  this.left.render(code, options);
6180
+ this.right.render(code, options);
6163
6181
  }
6164
6182
  else {
6165
- code.remove(this.start, this.right.start);
6183
+ this.right.render(code, options, {
6184
+ renderedParentType: renderedParentType || this.parent.type
6185
+ });
6186
+ const operatorPos = findFirstOccurrenceOutsideComment(code.original, '=', this.left.end);
6187
+ code.remove(this.start, findNonWhiteSpace(code.original, operatorPos + 1));
6166
6188
  }
6167
6189
  if (options.format === 'system') {
6168
6190
  const exportNames = this.left.variable && options.exportNamesByVariable.get(this.left.variable);
@@ -6513,7 +6535,7 @@ class MemberExpression extends NodeBase {
6513
6535
  if (!this.included) {
6514
6536
  this.included = true;
6515
6537
  if (this.variable !== null) {
6516
- this.context.includeVariable(this.variable);
6538
+ this.context.includeVariableInModule(this.variable);
6517
6539
  }
6518
6540
  }
6519
6541
  this.object.include(context, includeChildrenRecursively);
@@ -6553,7 +6575,7 @@ class MemberExpression extends NodeBase {
6553
6575
  const variable = this.scope.findVariable(this.object.name);
6554
6576
  if (variable.isNamespace) {
6555
6577
  if (this.variable) {
6556
- this.context.includeVariable(this.variable);
6578
+ this.context.includeVariableInModule(this.variable);
6557
6579
  }
6558
6580
  this.context.warn({
6559
6581
  code: 'ILLEGAL_NAMESPACE_REASSIGNMENT',
@@ -9662,6 +9684,24 @@ function initialiseTimers(inputOptions) {
9662
9684
  }
9663
9685
  }
9664
9686
 
9687
+ function markModuleAndImpureDependenciesAsExecuted(baseModule) {
9688
+ baseModule.isExecuted = true;
9689
+ const modules = [baseModule];
9690
+ const visitedModules = new Set();
9691
+ for (const module of modules) {
9692
+ for (const dependency of [...module.dependencies, ...module.implicitlyLoadedBefore]) {
9693
+ if (!(dependency instanceof ExternalModule) &&
9694
+ !dependency.isExecuted &&
9695
+ (dependency.info.hasModuleSideEffects || module.implicitlyLoadedBefore.has(dependency)) &&
9696
+ !visitedModules.has(dependency.id)) {
9697
+ dependency.isExecuted = true;
9698
+ visitedModules.add(dependency.id);
9699
+ modules.push(dependency);
9700
+ }
9701
+ }
9702
+ }
9703
+ }
9704
+
9665
9705
  function tryParse(module, Parser, acornOptions) {
9666
9706
  try {
9667
9707
  return Parser.parse(module.info.code, {
@@ -9684,39 +9724,60 @@ function tryParse(module, Parser, acornOptions) {
9684
9724
  }, err.pos);
9685
9725
  }
9686
9726
  }
9687
- function handleMissingExport(exportName, importingModule, importedModule, importerStart) {
9688
- return importingModule.error({
9689
- code: 'MISSING_EXPORT',
9690
- message: `'${exportName}' is not exported by ${relativeId(importedModule)}, imported by ${relativeId(importingModule.id)}`,
9691
- url: `https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module`
9692
- }, importerStart);
9693
- }
9694
9727
  const MISSING_EXPORT_SHIM_DESCRIPTION = {
9695
9728
  identifier: null,
9696
9729
  localName: MISSING_EXPORT_SHIM_VARIABLE
9697
9730
  };
9698
- function getVariableForExportNameRecursive(target, name, isExportAllSearch, searchedNamesAndModules = new Map()) {
9731
+ function getVariableForExportNameRecursive(target, name, importerForSideEffects, isExportAllSearch, searchedNamesAndModules = new Map()) {
9699
9732
  const searchedModules = searchedNamesAndModules.get(name);
9700
9733
  if (searchedModules) {
9701
9734
  if (searchedModules.has(target)) {
9702
- return null;
9735
+ return isExportAllSearch ? null : error(errCircularReexport(name, target.id));
9703
9736
  }
9704
9737
  searchedModules.add(target);
9705
9738
  }
9706
9739
  else {
9707
9740
  searchedNamesAndModules.set(name, new Set([target]));
9708
9741
  }
9709
- return target.getVariableForExportName(name, isExportAllSearch, searchedNamesAndModules);
9742
+ return target.getVariableForExportName(name, importerForSideEffects, isExportAllSearch, searchedNamesAndModules);
9743
+ }
9744
+ function getAndExtendSideEffectModules(variable, module) {
9745
+ const sideEffectModules = getOrCreate(module.sideEffectDependenciesByVariable, variable, () => new Set());
9746
+ let currentVariable = variable;
9747
+ const referencedVariables = new Set([currentVariable]);
9748
+ while (true) {
9749
+ const importingModule = currentVariable.module;
9750
+ currentVariable =
9751
+ currentVariable instanceof ExportDefaultVariable
9752
+ ? currentVariable.getDirectOriginalVariable()
9753
+ : currentVariable instanceof SyntheticNamedExportVariable
9754
+ ? currentVariable.syntheticNamespace
9755
+ : null;
9756
+ if (!currentVariable || referencedVariables.has(currentVariable)) {
9757
+ break;
9758
+ }
9759
+ referencedVariables.add(variable);
9760
+ sideEffectModules.add(importingModule);
9761
+ const originalSideEffects = importingModule.sideEffectDependenciesByVariable.get(currentVariable);
9762
+ if (originalSideEffects) {
9763
+ for (const module of originalSideEffects) {
9764
+ sideEffectModules.add(module);
9765
+ }
9766
+ }
9767
+ }
9768
+ return sideEffectModules;
9710
9769
  }
9711
9770
  class Module {
9712
9771
  constructor(graph, id, options, isEntry, hasModuleSideEffects, syntheticNamedExports, meta) {
9713
9772
  this.graph = graph;
9714
9773
  this.id = id;
9715
9774
  this.options = options;
9775
+ this.alternativeReexportModules = new Map();
9716
9776
  this.ast = null;
9717
9777
  this.chunkFileNames = new Set();
9718
9778
  this.chunkName = null;
9719
9779
  this.comments = [];
9780
+ this.cycles = new Set();
9720
9781
  this.dependencies = new Set();
9721
9782
  this.dynamicDependencies = new Set();
9722
9783
  this.dynamicImporters = [];
@@ -9736,6 +9797,7 @@ class Module {
9736
9797
  this.isUserDefinedEntryPoint = false;
9737
9798
  this.preserveSignature = this.options.preserveEntrySignatures;
9738
9799
  this.reexportDescriptions = Object.create(null);
9800
+ this.sideEffectDependenciesByVariable = new Map();
9739
9801
  this.sources = new Set();
9740
9802
  this.userChunkNames = new Set();
9741
9803
  this.usesTopLevelAwait = false;
@@ -9825,9 +9887,9 @@ class Module {
9825
9887
  if (this.relevantDependencies)
9826
9888
  return this.relevantDependencies;
9827
9889
  const relevantDependencies = new Set();
9828
- const additionalSideEffectModules = new Set();
9829
- const possibleDependencies = new Set(this.dependencies);
9830
- let dependencyVariables = this.imports;
9890
+ const necessaryDependencies = new Set();
9891
+ const alwaysCheckedDependencies = new Set();
9892
+ let dependencyVariables = this.imports.keys();
9831
9893
  if (this.info.isEntry ||
9832
9894
  this.includedDynamicImporters.length > 0 ||
9833
9895
  this.namespace.included ||
@@ -9838,41 +9900,31 @@ class Module {
9838
9900
  }
9839
9901
  }
9840
9902
  for (let variable of dependencyVariables) {
9903
+ const sideEffectDependencies = this.sideEffectDependenciesByVariable.get(variable);
9904
+ if (sideEffectDependencies) {
9905
+ for (const module of sideEffectDependencies) {
9906
+ alwaysCheckedDependencies.add(module);
9907
+ }
9908
+ }
9841
9909
  if (variable instanceof SyntheticNamedExportVariable) {
9842
9910
  variable = variable.getBaseVariable();
9843
9911
  }
9844
9912
  else if (variable instanceof ExportDefaultVariable) {
9845
- const { modules, original } = variable.getOriginalVariableAndDeclarationModules();
9846
- variable = original;
9847
- for (const module of modules) {
9848
- additionalSideEffectModules.add(module);
9849
- possibleDependencies.add(module);
9850
- }
9913
+ variable = variable.getOriginalVariable();
9851
9914
  }
9852
- relevantDependencies.add(variable.module);
9915
+ necessaryDependencies.add(variable.module);
9853
9916
  }
9854
9917
  if (this.options.treeshake && this.info.hasModuleSideEffects !== 'no-treeshake') {
9855
- for (const dependency of possibleDependencies) {
9856
- if (!(dependency.info.hasModuleSideEffects ||
9857
- additionalSideEffectModules.has(dependency)) ||
9858
- relevantDependencies.has(dependency)) {
9859
- continue;
9860
- }
9861
- if (dependency instanceof ExternalModule || dependency.hasEffects()) {
9862
- relevantDependencies.add(dependency);
9863
- }
9864
- else {
9865
- for (const transitiveDependency of dependency.dependencies) {
9866
- possibleDependencies.add(transitiveDependency);
9867
- }
9868
- }
9869
- }
9918
+ this.addRelevantSideEffectDependencies(relevantDependencies, necessaryDependencies, alwaysCheckedDependencies);
9870
9919
  }
9871
9920
  else {
9872
9921
  for (const dependency of this.dependencies) {
9873
9922
  relevantDependencies.add(dependency);
9874
9923
  }
9875
9924
  }
9925
+ for (const dependency of necessaryDependencies) {
9926
+ relevantDependencies.add(dependency);
9927
+ }
9876
9928
  return (this.relevantDependencies = relevantDependencies);
9877
9929
  }
9878
9930
  getExportNamesByVariable() {
@@ -9945,20 +9997,14 @@ class Module {
9945
9997
  : 'default');
9946
9998
  }
9947
9999
  if (!this.syntheticNamespace) {
9948
- return error({
9949
- code: Errors.SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT,
9950
- id: this.id,
9951
- message: `Module "${relativeId(this.id)}" that is marked with 'syntheticNamedExports: ${JSON.stringify(this.info.syntheticNamedExports)}' needs ${typeof this.info.syntheticNamedExports === 'string' &&
9952
- this.info.syntheticNamedExports !== 'default'
9953
- ? `an export named "${this.info.syntheticNamedExports}"`
9954
- : 'a default export'}.`
9955
- });
10000
+ return error(errSyntheticNamedExportsNeedNamespaceExport(this.id, this.info.syntheticNamedExports));
9956
10001
  }
9957
10002
  return this.syntheticNamespace;
9958
10003
  }
9959
- getVariableForExportName(name, isExportAllSearch, searchedNamesAndModules) {
10004
+ getVariableForExportName(name, importerForSideEffects, isExportAllSearch, searchedNamesAndModules) {
9960
10005
  if (name[0] === '*') {
9961
10006
  if (name.length === 1) {
10007
+ // export * from './other'
9962
10008
  return this.namespace;
9963
10009
  }
9964
10010
  else {
@@ -9970,11 +10016,14 @@ class Module {
9970
10016
  // export { foo } from './other'
9971
10017
  const reexportDeclaration = this.reexportDescriptions[name];
9972
10018
  if (reexportDeclaration) {
9973
- const declaration = getVariableForExportNameRecursive(reexportDeclaration.module, reexportDeclaration.localName, false, searchedNamesAndModules);
9974
- if (!declaration) {
9975
- return handleMissingExport(reexportDeclaration.localName, this, reexportDeclaration.module.id, reexportDeclaration.start);
10019
+ const variable = getVariableForExportNameRecursive(reexportDeclaration.module, reexportDeclaration.localName, importerForSideEffects, false, searchedNamesAndModules);
10020
+ if (!variable) {
10021
+ return this.error(errMissingExport(reexportDeclaration.localName, this.id, reexportDeclaration.module.id), reexportDeclaration.start);
9976
10022
  }
9977
- return declaration;
10023
+ if (importerForSideEffects) {
10024
+ setAlternativeExporterIfCyclic(variable, importerForSideEffects, this);
10025
+ }
10026
+ return variable;
9978
10027
  }
9979
10028
  const exportDeclaration = this.exports[name];
9980
10029
  if (exportDeclaration) {
@@ -9982,28 +10031,43 @@ class Module {
9982
10031
  return this.exportShimVariable;
9983
10032
  }
9984
10033
  const name = exportDeclaration.localName;
9985
- return this.traceVariable(name);
10034
+ const variable = this.traceVariable(name, importerForSideEffects);
10035
+ if (importerForSideEffects) {
10036
+ getOrCreate(importerForSideEffects.sideEffectDependenciesByVariable, variable, () => new Set()).add(this);
10037
+ setAlternativeExporterIfCyclic(variable, importerForSideEffects, this);
10038
+ }
10039
+ return variable;
9986
10040
  }
9987
10041
  if (name !== 'default') {
10042
+ let foundSyntheticDeclaration = null;
9988
10043
  for (const module of this.exportAllModules) {
9989
- const declaration = getVariableForExportNameRecursive(module, name, true, searchedNamesAndModules);
9990
- if (declaration)
9991
- return declaration;
10044
+ const declaration = getVariableForExportNameRecursive(module, name, importerForSideEffects, true, searchedNamesAndModules);
10045
+ if (declaration) {
10046
+ if (!(declaration instanceof SyntheticNamedExportVariable)) {
10047
+ return declaration;
10048
+ }
10049
+ if (!foundSyntheticDeclaration) {
10050
+ foundSyntheticDeclaration = declaration;
10051
+ }
10052
+ }
10053
+ }
10054
+ if (foundSyntheticDeclaration) {
10055
+ return foundSyntheticDeclaration;
10056
+ }
10057
+ }
10058
+ if (this.info.syntheticNamedExports) {
10059
+ let syntheticExport = this.syntheticExports.get(name);
10060
+ if (!syntheticExport) {
10061
+ const syntheticNamespace = this.getSyntheticNamespace();
10062
+ syntheticExport = new SyntheticNamedExportVariable(this.astContext, name, syntheticNamespace);
10063
+ this.syntheticExports.set(name, syntheticExport);
10064
+ return syntheticExport;
9992
10065
  }
10066
+ return syntheticExport;
9993
10067
  }
9994
10068
  // we don't want to create shims when we are just
9995
10069
  // probing export * modules for exports
9996
10070
  if (!isExportAllSearch) {
9997
- if (this.info.syntheticNamedExports) {
9998
- let syntheticExport = this.syntheticExports.get(name);
9999
- if (!syntheticExport) {
10000
- const syntheticNamespace = this.getSyntheticNamespace();
10001
- syntheticExport = new SyntheticNamedExportVariable(this.astContext, name, syntheticNamespace);
10002
- this.syntheticExports.set(name, syntheticExport);
10003
- return syntheticExport;
10004
- }
10005
- return syntheticExport;
10006
- }
10007
10071
  if (this.options.shimMissingExports) {
10008
10072
  this.shimMissingExport(name);
10009
10073
  return this.exportShimVariable;
@@ -10030,8 +10094,7 @@ class Module {
10030
10094
  const variable = this.getVariableForExportName(exportName);
10031
10095
  variable.deoptimizePath(UNKNOWN_PATH);
10032
10096
  if (!variable.included) {
10033
- variable.include();
10034
- this.graph.needsTreeshakingPass = true;
10097
+ this.includeVariable(variable);
10035
10098
  }
10036
10099
  }
10037
10100
  }
@@ -10039,8 +10102,7 @@ class Module {
10039
10102
  const variable = this.getVariableForExportName(name);
10040
10103
  variable.deoptimizePath(UNKNOWN_PATH);
10041
10104
  if (!variable.included) {
10042
- variable.include();
10043
- this.graph.needsTreeshakingPass = true;
10105
+ this.includeVariable(variable);
10044
10106
  }
10045
10107
  if (variable instanceof ExternalVariable) {
10046
10108
  variable.module.reexported = true;
@@ -10060,7 +10122,7 @@ class Module {
10060
10122
  this.addModulesToImportDescriptions(this.importDescriptions);
10061
10123
  this.addModulesToImportDescriptions(this.reexportDescriptions);
10062
10124
  for (const name in this.exports) {
10063
- if (name !== 'default') {
10125
+ if (name !== 'default' && name !== this.info.syntheticNamedExports) {
10064
10126
  this.exportsAll[name] = this.id;
10065
10127
  }
10066
10128
  }
@@ -10140,7 +10202,7 @@ class Module {
10140
10202
  importDescriptions: this.importDescriptions,
10141
10203
  includeAllExports: () => this.includeAllExports(true),
10142
10204
  includeDynamicImport: this.includeDynamicImport.bind(this),
10143
- includeVariable: this.includeVariable.bind(this),
10205
+ includeVariableInModule: this.includeVariableInModule.bind(this),
10144
10206
  magicString: this.magicString,
10145
10207
  module: this,
10146
10208
  moduleContext: this.context,
@@ -10176,7 +10238,7 @@ class Module {
10176
10238
  transformFiles: this.transformFiles
10177
10239
  };
10178
10240
  }
10179
- traceVariable(name) {
10241
+ traceVariable(name, importerForSideEffects) {
10180
10242
  const localVariable = this.scope.variables.get(name);
10181
10243
  if (localVariable) {
10182
10244
  return localVariable;
@@ -10187,9 +10249,9 @@ class Module {
10187
10249
  if (otherModule instanceof Module && importDeclaration.name === '*') {
10188
10250
  return otherModule.namespace;
10189
10251
  }
10190
- const declaration = otherModule.getVariableForExportName(importDeclaration.name);
10252
+ const declaration = otherModule.getVariableForExportName(importDeclaration.name, importerForSideEffects || this);
10191
10253
  if (!declaration) {
10192
- return handleMissingExport(importDeclaration.name, this, otherModule.id, importDeclaration.start);
10254
+ return this.error(errMissingExport(importDeclaration.name, this.id, otherModule.id), importDeclaration.start);
10193
10255
  }
10194
10256
  return declaration;
10195
10257
  }
@@ -10341,6 +10403,31 @@ class Module {
10341
10403
  specifier.module = this.graph.modulesById.get(id);
10342
10404
  }
10343
10405
  }
10406
+ addRelevantSideEffectDependencies(relevantDependencies, necessaryDependencies, alwaysCheckedDependencies) {
10407
+ const handledDependencies = new Set();
10408
+ const addSideEffectDependencies = (possibleDependencies) => {
10409
+ for (const dependency of possibleDependencies) {
10410
+ if (handledDependencies.has(dependency)) {
10411
+ continue;
10412
+ }
10413
+ handledDependencies.add(dependency);
10414
+ if (necessaryDependencies.has(dependency)) {
10415
+ relevantDependencies.add(dependency);
10416
+ continue;
10417
+ }
10418
+ if (!(dependency.info.hasModuleSideEffects || alwaysCheckedDependencies.has(dependency))) {
10419
+ continue;
10420
+ }
10421
+ if (dependency instanceof ExternalModule || dependency.hasEffects()) {
10422
+ relevantDependencies.add(dependency);
10423
+ continue;
10424
+ }
10425
+ addSideEffectDependencies(dependency.dependencies);
10426
+ }
10427
+ };
10428
+ addSideEffectDependencies(this.dependencies);
10429
+ addSideEffectDependencies(alwaysCheckedDependencies);
10430
+ }
10344
10431
  includeAndGetAdditionalMergedNamespaces() {
10345
10432
  const mergedNamespaces = [];
10346
10433
  for (const module of this.exportAllModules) {
@@ -10367,11 +10454,26 @@ class Module {
10367
10454
  }
10368
10455
  }
10369
10456
  includeVariable(variable) {
10370
- const variableModule = variable.module;
10371
10457
  if (!variable.included) {
10372
10458
  variable.include();
10373
10459
  this.graph.needsTreeshakingPass = true;
10460
+ const variableModule = variable.module;
10461
+ if (variableModule && variableModule !== this && variableModule instanceof Module) {
10462
+ if (!variableModule.isExecuted) {
10463
+ markModuleAndImpureDependenciesAsExecuted(variableModule);
10464
+ }
10465
+ const sideEffectModules = getAndExtendSideEffectModules(variable, this);
10466
+ for (const module of sideEffectModules) {
10467
+ if (!module.isExecuted) {
10468
+ markModuleAndImpureDependenciesAsExecuted(module);
10469
+ }
10470
+ }
10471
+ }
10374
10472
  }
10473
+ }
10474
+ includeVariableInModule(variable) {
10475
+ this.includeVariable(variable);
10476
+ const variableModule = variable.module;
10375
10477
  if (variableModule && variableModule !== this) {
10376
10478
  this.imports.add(variable);
10377
10479
  }
@@ -10386,6 +10488,23 @@ class Module {
10386
10488
  this.exports[name] = MISSING_EXPORT_SHIM_DESCRIPTION;
10387
10489
  }
10388
10490
  }
10491
+ // if there is a cyclic import in the reexport chain, we should not
10492
+ // import from the original module but from the cyclic module to not
10493
+ // mess up execution order.
10494
+ function setAlternativeExporterIfCyclic(variable, importer, reexporter) {
10495
+ if (variable.module instanceof Module && variable.module !== reexporter) {
10496
+ const exporterCycles = variable.module.cycles;
10497
+ if (exporterCycles.size > 0) {
10498
+ const importerCycles = reexporter.cycles;
10499
+ for (const cycleSymbol of importerCycles) {
10500
+ if (exporterCycles.has(cycleSymbol)) {
10501
+ importer.alternativeReexportModules.set(variable, reexporter);
10502
+ break;
10503
+ }
10504
+ }
10505
+ }
10506
+ }
10507
+ }
10389
10508
 
10390
10509
  class Source {
10391
10510
  constructor(filename, content) {
@@ -10672,68 +10791,6 @@ function escapeId(id) {
10672
10791
  return id.replace(backSlashRegEx, '\\\\').replace(quoteNewlineRegEx, '\\$1');
10673
10792
  }
10674
10793
 
10675
- const compareExecIndex = (unitA, unitB) => unitA.execIndex > unitB.execIndex ? 1 : -1;
10676
- function sortByExecutionOrder(units) {
10677
- units.sort(compareExecIndex);
10678
- }
10679
- function analyseModuleExecution(entryModules) {
10680
- let nextExecIndex = 0;
10681
- const cyclePaths = [];
10682
- const analysedModules = new Set();
10683
- const dynamicImports = new Set();
10684
- const parents = new Map();
10685
- const orderedModules = [];
10686
- const analyseModule = (module) => {
10687
- if (module instanceof Module) {
10688
- for (const dependency of module.dependencies) {
10689
- if (parents.has(dependency)) {
10690
- if (!analysedModules.has(dependency)) {
10691
- cyclePaths.push(getCyclePath(dependency, module, parents));
10692
- }
10693
- continue;
10694
- }
10695
- parents.set(dependency, module);
10696
- analyseModule(dependency);
10697
- }
10698
- for (const dependency of module.implicitlyLoadedBefore) {
10699
- dynamicImports.add(dependency);
10700
- }
10701
- for (const { resolution } of module.dynamicImports) {
10702
- if (resolution instanceof Module) {
10703
- dynamicImports.add(resolution);
10704
- }
10705
- }
10706
- orderedModules.push(module);
10707
- }
10708
- module.execIndex = nextExecIndex++;
10709
- analysedModules.add(module);
10710
- };
10711
- for (const curEntry of entryModules) {
10712
- if (!parents.has(curEntry)) {
10713
- parents.set(curEntry, null);
10714
- analyseModule(curEntry);
10715
- }
10716
- }
10717
- for (const curEntry of dynamicImports) {
10718
- if (!parents.has(curEntry)) {
10719
- parents.set(curEntry, null);
10720
- analyseModule(curEntry);
10721
- }
10722
- }
10723
- return { orderedModules, cyclePaths };
10724
- }
10725
- function getCyclePath(module, parent, parents) {
10726
- const path = [relativeId(module.id)];
10727
- let nextModule = parent;
10728
- while (nextModule !== module) {
10729
- path.push(relativeId(nextModule.id));
10730
- nextModule = parents.get(nextModule);
10731
- }
10732
- path.push(path[0]);
10733
- path.reverse();
10734
- return path;
10735
- }
10736
-
10737
10794
  function assignExportsToMangledNames(exports, exportsByName, exportNamesByVariable) {
10738
10795
  let nameIndex = 0;
10739
10796
  for (const variable of exports) {
@@ -10825,6 +10882,44 @@ function getIndentString(modules, options) {
10825
10882
  return '\t';
10826
10883
  }
10827
10884
 
10885
+ function getStaticDependencies(chunk, orderedModules, chunkByModule) {
10886
+ const staticDependencyBlocks = [];
10887
+ const handledDependencies = new Set();
10888
+ for (let modulePos = orderedModules.length - 1; modulePos >= 0; modulePos--) {
10889
+ const module = orderedModules[modulePos];
10890
+ if (!handledDependencies.has(module)) {
10891
+ const staticDependencies = [];
10892
+ addStaticDependencies(module, staticDependencies, handledDependencies, chunk, chunkByModule);
10893
+ staticDependencyBlocks.unshift(staticDependencies);
10894
+ }
10895
+ }
10896
+ const dependencies = new Set();
10897
+ for (const block of staticDependencyBlocks) {
10898
+ for (const dependency of block) {
10899
+ dependencies.add(dependency);
10900
+ }
10901
+ }
10902
+ return dependencies;
10903
+ }
10904
+ function addStaticDependencies(module, staticDependencies, handledModules, chunk, chunkByModule) {
10905
+ const dependencies = module.getDependenciesToBeIncluded();
10906
+ for (const dependency of dependencies) {
10907
+ if (dependency instanceof ExternalModule) {
10908
+ staticDependencies.push(dependency);
10909
+ continue;
10910
+ }
10911
+ const dependencyChunk = chunkByModule.get(dependency);
10912
+ if (dependencyChunk !== chunk) {
10913
+ staticDependencies.push(dependencyChunk);
10914
+ continue;
10915
+ }
10916
+ if (!handledModules.has(dependency)) {
10917
+ handledModules.add(dependency);
10918
+ addStaticDependencies(dependency, staticDependencies, handledModules, chunk, chunkByModule);
10919
+ }
10920
+ }
10921
+ }
10922
+
10828
10923
  function decodedSourcemap(map) {
10829
10924
  if (!map)
10830
10925
  return null;
@@ -11080,7 +11175,6 @@ class Chunk$1 {
11080
11175
  this.facadeChunkByModule.set(module, this);
11081
11176
  if (module.preserveSignature) {
11082
11177
  this.strictFacade = needsStrictFacade;
11083
- this.ensureReexportsAreAvailableForModule(module);
11084
11178
  }
11085
11179
  this.assignFacadeName(requiredFacades.shift(), module);
11086
11180
  }
@@ -11218,8 +11312,8 @@ class Chunk$1 {
11218
11312
  return this.exportNamesByVariable.get(variable)[0];
11219
11313
  }
11220
11314
  link() {
11315
+ this.dependencies = getStaticDependencies(this, this.orderedModules, this.chunkByModule);
11221
11316
  for (const module of this.orderedModules) {
11222
- this.addDependenciesToChunk(module.getDependenciesToBeIncluded(), this.dependencies);
11223
11317
  this.addDependenciesToChunk(module.dynamicDependencies, this.dynamicDependencies);
11224
11318
  this.addDependenciesToChunk(module.implicitlyLoadedBefore, this.implicitlyLoadedBefore);
11225
11319
  this.setUpChunkImportsAndExportsForModule(module);
@@ -11252,9 +11346,6 @@ class Chunk$1 {
11252
11346
  this.inlineChunkDependencies(dep);
11253
11347
  }
11254
11348
  }
11255
- const sortedDependencies = [...this.dependencies];
11256
- sortByExecutionOrder(sortedDependencies);
11257
- this.dependencies = new Set(sortedDependencies);
11258
11349
  this.prepareDynamicImportsAndImportMetas();
11259
11350
  this.setIdentifierRenderResolutions(options);
11260
11351
  let hoistedSource = '';
@@ -11446,6 +11537,23 @@ class Chunk$1 {
11446
11537
  this.name = sanitizeFileName(name || facadedModule.chunkName || getAliasName(facadedModule.id));
11447
11538
  }
11448
11539
  }
11540
+ checkCircularDependencyImport(variable, importingModule) {
11541
+ const variableModule = variable.module;
11542
+ if (variableModule instanceof Module) {
11543
+ const exportChunk = this.chunkByModule.get(variableModule);
11544
+ let alternativeReexportModule;
11545
+ do {
11546
+ alternativeReexportModule = importingModule.alternativeReexportModules.get(variable);
11547
+ if (alternativeReexportModule) {
11548
+ const exportingChunk = this.chunkByModule.get(alternativeReexportModule);
11549
+ if (exportingChunk && exportingChunk !== exportChunk) {
11550
+ this.inputOptions.onwarn(errCyclicCrossChunkReexport(variableModule.getExportNamesByVariable().get(variable)[0], variableModule.id, alternativeReexportModule.id, importingModule.id));
11551
+ }
11552
+ importingModule = alternativeReexportModule;
11553
+ }
11554
+ } while (alternativeReexportModule);
11555
+ }
11556
+ }
11449
11557
  computeContentHashWithDependencies(addons, options, existingNames) {
11450
11558
  const hash = createHash();
11451
11559
  hash.update([addons.intro, addons.outro, addons.banner, addons.footer].map(addon => addon || '').join(':'));
@@ -11475,6 +11583,7 @@ class Chunk$1 {
11475
11583
  ? exportedVariable.getBaseVariable()
11476
11584
  : exportedVariable;
11477
11585
  if (!(importedVariable instanceof NamespaceVariable && this.outputOptions.preserveModules)) {
11586
+ this.checkCircularDependencyImport(importedVariable, module);
11478
11587
  const exportingModule = importedVariable.module;
11479
11588
  if (exportingModule instanceof Module) {
11480
11589
  const chunk = this.chunkByModule.get(exportingModule);
@@ -11870,6 +11979,7 @@ class Chunk$1 {
11870
11979
  if (!(variable instanceof NamespaceVariable && this.outputOptions.preserveModules) &&
11871
11980
  variable.module instanceof Module) {
11872
11981
  chunk.exports.add(variable);
11982
+ this.checkCircularDependencyImport(variable, module);
11873
11983
  }
11874
11984
  }
11875
11985
  }
@@ -12073,6 +12183,71 @@ function commondir(files) {
12073
12183
  return commonSegments.length > 1 ? commonSegments.join('/') : '/';
12074
12184
  }
12075
12185
 
12186
+ const compareExecIndex = (unitA, unitB) => unitA.execIndex > unitB.execIndex ? 1 : -1;
12187
+ function sortByExecutionOrder(units) {
12188
+ units.sort(compareExecIndex);
12189
+ }
12190
+ function analyseModuleExecution(entryModules) {
12191
+ let nextExecIndex = 0;
12192
+ const cyclePaths = [];
12193
+ const analysedModules = new Set();
12194
+ const dynamicImports = new Set();
12195
+ const parents = new Map();
12196
+ const orderedModules = [];
12197
+ const analyseModule = (module) => {
12198
+ if (module instanceof Module) {
12199
+ for (const dependency of module.dependencies) {
12200
+ if (parents.has(dependency)) {
12201
+ if (!analysedModules.has(dependency)) {
12202
+ cyclePaths.push(getCyclePath(dependency, module, parents));
12203
+ }
12204
+ continue;
12205
+ }
12206
+ parents.set(dependency, module);
12207
+ analyseModule(dependency);
12208
+ }
12209
+ for (const dependency of module.implicitlyLoadedBefore) {
12210
+ dynamicImports.add(dependency);
12211
+ }
12212
+ for (const { resolution } of module.dynamicImports) {
12213
+ if (resolution instanceof Module) {
12214
+ dynamicImports.add(resolution);
12215
+ }
12216
+ }
12217
+ orderedModules.push(module);
12218
+ }
12219
+ module.execIndex = nextExecIndex++;
12220
+ analysedModules.add(module);
12221
+ };
12222
+ for (const curEntry of entryModules) {
12223
+ if (!parents.has(curEntry)) {
12224
+ parents.set(curEntry, null);
12225
+ analyseModule(curEntry);
12226
+ }
12227
+ }
12228
+ for (const curEntry of dynamicImports) {
12229
+ if (!parents.has(curEntry)) {
12230
+ parents.set(curEntry, null);
12231
+ analyseModule(curEntry);
12232
+ }
12233
+ }
12234
+ return { orderedModules, cyclePaths };
12235
+ }
12236
+ function getCyclePath(module, parent, parents) {
12237
+ const cycleSymbol = Symbol(module.id);
12238
+ const path = [relativeId(module.id)];
12239
+ let nextModule = parent;
12240
+ module.cycles.add(cycleSymbol);
12241
+ while (nextModule !== module) {
12242
+ nextModule.cycles.add(cycleSymbol);
12243
+ path.push(relativeId(nextModule.id));
12244
+ nextModule = parents.get(nextModule);
12245
+ }
12246
+ path.push(path[0]);
12247
+ path.reverse();
12248
+ return path;
12249
+ }
12250
+
12076
12251
  var BuildPhase;
12077
12252
  (function (BuildPhase) {
12078
12253
  BuildPhase[BuildPhase["LOAD_AND_PARSE"] = 0] = "LOAD_AND_PARSE";
@@ -19209,160 +19384,6 @@ var acornClassFields = function(Parser) {
19209
19384
  }
19210
19385
  };
19211
19386
 
19212
- function withoutAcornBigInt(acorn, Parser) {
19213
- return class extends Parser {
19214
- readInt(radix, len) {
19215
- // Hack: len is only != null for unicode escape sequences,
19216
- // where numeric separators are not allowed
19217
- if (len != null) return super.readInt(radix, len)
19218
-
19219
- let start = this.pos, total = 0, acceptUnderscore = false;
19220
- for (;;) {
19221
- let code = this.input.charCodeAt(this.pos), val;
19222
- if (code >= 97) val = code - 97 + 10; // a
19223
- else if (code == 95) {
19224
- if (!acceptUnderscore) this.raise(this.pos, "Invalid numeric separator");
19225
- ++this.pos;
19226
- acceptUnderscore = false;
19227
- continue
19228
- } else if (code >= 65) val = code - 65 + 10; // A
19229
- else if (code >= 48 && code <= 57) val = code - 48; // 0-9
19230
- else val = Infinity;
19231
- if (val >= radix) break
19232
- ++this.pos;
19233
- total = total * radix + val;
19234
- acceptUnderscore = true;
19235
- }
19236
- if (this.pos === start) return null
19237
- if (!acceptUnderscore) this.raise(this.pos - 1, "Invalid numeric separator");
19238
-
19239
- return total
19240
- }
19241
-
19242
- readNumber(startsWithDot) {
19243
- const token = super.readNumber(startsWithDot);
19244
- let octal = this.end - this.start >= 2 && this.input.charCodeAt(this.start) === 48;
19245
- const stripped = this.getNumberInput(this.start, this.end);
19246
- if (stripped.length < this.end - this.start) {
19247
- if (octal) this.raise(this.start, "Invalid number");
19248
- this.value = parseFloat(stripped);
19249
- }
19250
- return token
19251
- }
19252
-
19253
- // This is used by acorn-bigint
19254
- getNumberInput(start, end) {
19255
- return this.input.slice(start, end).replace(/_/g, "")
19256
- }
19257
- }
19258
- }
19259
-
19260
- function withAcornBigInt(acorn, Parser) {
19261
- return class extends Parser {
19262
- readInt(radix, len) {
19263
- // Hack: len is only != null for unicode escape sequences,
19264
- // where numeric separators are not allowed
19265
- if (len != null) return super.readInt(radix, len)
19266
-
19267
- let start = this.pos, total = 0, acceptUnderscore = false;
19268
- for (;;) {
19269
- let code = this.input.charCodeAt(this.pos), val;
19270
- if (code >= 97) val = code - 97 + 10; // a
19271
- else if (code == 95) {
19272
- if (!acceptUnderscore) this.raise(this.pos, "Invalid numeric separator");
19273
- ++this.pos;
19274
- acceptUnderscore = false;
19275
- continue
19276
- } else if (code >= 65) val = code - 65 + 10; // A
19277
- else if (code >= 48 && code <= 57) val = code - 48; // 0-9
19278
- else val = Infinity;
19279
- if (val >= radix) break
19280
- ++this.pos;
19281
- total = total * radix + val;
19282
- acceptUnderscore = true;
19283
- }
19284
- if (this.pos === start) return null
19285
- if (!acceptUnderscore) this.raise(this.pos - 1, "Invalid numeric separator");
19286
-
19287
- return total
19288
- }
19289
-
19290
- readNumber(startsWithDot) {
19291
- let start = this.pos;
19292
- if (!startsWithDot && this.readInt(10) === null) this.raise(start, "Invalid number");
19293
- let octal = this.pos - start >= 2 && this.input.charCodeAt(start) === 48;
19294
- let octalLike = false;
19295
- if (octal && this.strict) this.raise(start, "Invalid number");
19296
- let next = this.input.charCodeAt(this.pos);
19297
- if (!octal && !startsWithDot && this.options.ecmaVersion >= 11 && next === 110) {
19298
- let str = this.getNumberInput(start, this.pos);
19299
- // eslint-disable-next-line node/no-unsupported-features/es-builtins
19300
- let val = typeof BigInt !== "undefined" ? BigInt(str) : null;
19301
- ++this.pos;
19302
- if (acorn.isIdentifierStart(this.fullCharCodeAtPos())) this.raise(this.pos, "Identifier directly after number");
19303
- return this.finishToken(acorn.tokTypes.num, val)
19304
- }
19305
- if (octal && /[89]/.test(this.input.slice(start, this.pos))) {
19306
- octal = false;
19307
- octalLike = true;
19308
- }
19309
- if (next === 46 && !octal) { // '.'
19310
- ++this.pos;
19311
- this.readInt(10);
19312
- next = this.input.charCodeAt(this.pos);
19313
- }
19314
- if ((next === 69 || next === 101) && !octal) { // 'eE'
19315
- next = this.input.charCodeAt(++this.pos);
19316
- if (next === 43 || next === 45) ++this.pos; // '+-'
19317
- if (this.readInt(10) === null) this.raise(start, "Invalid number");
19318
- }
19319
- if (acorn.isIdentifierStart(this.fullCharCodeAtPos())) this.raise(this.pos, "Identifier directly after number");
19320
- let str = this.getNumberInput(start, this.pos);
19321
- if ((octal || octalLike) && str.length < this.pos - start) {
19322
- this.raise(start, "Invalid number");
19323
- }
19324
-
19325
- let val = octal ? parseInt(str, 8) : parseFloat(str);
19326
- return this.finishToken(acorn.tokTypes.num, val)
19327
- }
19328
-
19329
- parseLiteral(value) {
19330
- const ret = super.parseLiteral(value);
19331
- if (ret.bigint) ret.bigint = ret.bigint.replace(/_/g, "");
19332
- return ret
19333
- }
19334
-
19335
- readRadixNumber(radix) {
19336
- let start = this.pos;
19337
- this.pos += 2; // 0x
19338
- let val = this.readInt(radix);
19339
- if (val == null) { this.raise(this.start + 2, `Expected number in radix ${radix}`); }
19340
- if (this.options.ecmaVersion >= 11 && this.input.charCodeAt(this.pos) === 110) {
19341
- let str = this.getNumberInput(start, this.pos);
19342
- // eslint-disable-next-line node/no-unsupported-features/es-builtins
19343
- val = typeof BigInt !== "undefined" ? BigInt(str) : null;
19344
- ++this.pos;
19345
- } else if (acorn.isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
19346
- return this.finishToken(acorn.tokTypes.num, val)
19347
- }
19348
-
19349
- // This is used by acorn-bigint, which theoretically could be used with acorn@6.2 || acorn@7
19350
- getNumberInput(start, end) {
19351
- return this.input.slice(start, end).replace(/_/g, "")
19352
- }
19353
- }
19354
- }
19355
-
19356
- // eslint-disable-next-line node/no-unsupported-features/es-syntax
19357
- function numericSeparator(Parser) {
19358
- const acorn = Parser.acorn || require$$0;
19359
- const withAcornBigIntSupport = (acorn.version.startsWith("6.") && !(acorn.version.startsWith("6.0.") || acorn.version.startsWith("6.1."))) || acorn.version.startsWith("7.");
19360
-
19361
- return withAcornBigIntSupport ? withAcornBigInt(acorn, Parser) : withoutAcornBigInt(acorn, Parser)
19362
- }
19363
-
19364
- var acornNumericSeparator = numericSeparator;
19365
-
19366
19387
  var acornStaticClassFeatures = function(Parser) {
19367
19388
  const ExtendedParser = acornPrivateClassElements(Parser);
19368
19389
 
@@ -19519,7 +19540,6 @@ const getAcorn$1 = (config) => ({
19519
19540
  const getAcornInjectPlugins = (config) => [
19520
19541
  acornClassFields,
19521
19542
  acornStaticClassFeatures,
19522
- acornNumericSeparator,
19523
19543
  ...ensureArray(config.acornInjectPlugins)
19524
19544
  ];
19525
19545
  const getCache = (config) => {