From 3c031cff3c7729dfbe792831c978d5401a1da0e2 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Mon, 3 May 2021 14:31:51 +0200 Subject: [PATCH] Refine namespace conflict handling to ignore and warn for known conflicts --- cli/run/batchWarnings.ts | 36 +++--- src/ExternalModule.ts | 31 ++--- src/Module.ts | 111 +++++++++++++----- src/ast/variables/NamespaceVariable.ts | 7 +- src/finalisers/shared/warnOnBuiltins.ts | 13 +- src/utils/error.ts | 39 ++++-- src/utils/printStringList.ts | 11 ++ .../samples/warn-broken-sourcemap/_config.js | 2 +- .../samples/warn-broken-sourcemaps/_config.js | 2 +- .../cli/samples/warn-import-export/_config.js | 4 +- test/cli/samples/warn-multiple/_config.js | 2 +- .../namespace-reexport-name/_expected/amd.js | 6 - .../namespace-reexport-name/_expected/cjs.js | 6 - .../namespace-reexport-name/_expected/es.js | 2 +- .../namespace-reexport-name/_expected/iife.js | 6 - .../_expected/system.js | 3 +- .../namespace-reexport-name/_expected/umd.js | 6 - .../external-reexport.js | 2 +- .../namespace-reexport-name/overrides.js | 2 +- .../named-import-external/_config.js | 30 +++++ .../named-import-external/_expected/amd.js | 29 +++++ .../named-import-external/_expected/cjs.js | 29 +++++ .../named-import-external/_expected/es.js | 7 ++ .../named-import-external/_expected/iife.js | 32 +++++ .../named-import-external/_expected/system.js | 22 ++++ .../named-import-external/_expected/umd.js | 33 ++++++ .../named-import-external/main.js | 3 + .../named-import-external/reexport.js | 2 + .../named-import/_config.js | 30 +++++ .../named-import/_expected/amd.js | 29 +++++ .../named-import/_expected/cjs.js | 29 +++++ .../named-import/_expected/es.js | 7 ++ .../named-import/_expected/iife.js | 32 +++++ .../named-import/_expected/system.js | 22 ++++ .../named-import/_expected/umd.js | 33 ++++++ .../named-import/first.js | 1 + .../named-import/main.js | 3 + .../named-import/reexport.js | 2 + .../named-import/second.js | 1 + .../namespace-import/_config.js | 35 ++++++ .../namespace-import/_expected/amd.js | 29 +++++ .../namespace-import/_expected/cjs.js | 29 +++++ .../namespace-import/_expected/es.js | 7 ++ .../namespace-import/_expected/iife.js | 32 +++++ .../namespace-import/_expected/system.js | 22 ++++ .../namespace-import/_expected/umd.js | 33 ++++++ .../namespace-import/first.js | 2 + .../namespace-import/main.js | 4 + .../namespace-import/reexport.js | 2 + .../namespace-import/second.js | 2 + .../same-binding/_config.js | 3 + .../same-binding/_expected/amd.js | 29 +++++ .../same-binding/_expected/cjs.js | 29 +++++ .../same-binding/_expected/es.js | 7 ++ .../same-binding/_expected/iife.js | 32 +++++ .../same-binding/_expected/system.js | 22 ++++ .../same-binding/_expected/umd.js | 33 ++++++ .../same-binding/first.js | 1 + .../same-binding/main.js | 3 + .../same-binding/reexport.js | 2 + .../same-binding/second.js | 1 + .../same-binding/shared.js | 1 + .../function/samples/unused-import/_config.js | 6 +- .../warn-on-namespace-conflict/_config.js | 2 +- .../warn-on-namespace-conflict/main.js | 3 +- test/misc/misc.js | 2 +- 66 files changed, 906 insertions(+), 134 deletions(-) create mode 100644 src/utils/printStringList.ts create mode 100644 test/function/samples/conflicting-reexports/named-import-external/_config.js create mode 100644 test/function/samples/conflicting-reexports/named-import-external/_expected/amd.js create mode 100644 test/function/samples/conflicting-reexports/named-import-external/_expected/cjs.js create mode 100644 test/function/samples/conflicting-reexports/named-import-external/_expected/es.js create mode 100644 test/function/samples/conflicting-reexports/named-import-external/_expected/iife.js create mode 100644 test/function/samples/conflicting-reexports/named-import-external/_expected/system.js create mode 100644 test/function/samples/conflicting-reexports/named-import-external/_expected/umd.js create mode 100644 test/function/samples/conflicting-reexports/named-import-external/main.js create mode 100644 test/function/samples/conflicting-reexports/named-import-external/reexport.js create mode 100644 test/function/samples/conflicting-reexports/named-import/_config.js create mode 100644 test/function/samples/conflicting-reexports/named-import/_expected/amd.js create mode 100644 test/function/samples/conflicting-reexports/named-import/_expected/cjs.js create mode 100644 test/function/samples/conflicting-reexports/named-import/_expected/es.js create mode 100644 test/function/samples/conflicting-reexports/named-import/_expected/iife.js create mode 100644 test/function/samples/conflicting-reexports/named-import/_expected/system.js create mode 100644 test/function/samples/conflicting-reexports/named-import/_expected/umd.js create mode 100644 test/function/samples/conflicting-reexports/named-import/first.js create mode 100644 test/function/samples/conflicting-reexports/named-import/main.js create mode 100644 test/function/samples/conflicting-reexports/named-import/reexport.js create mode 100644 test/function/samples/conflicting-reexports/named-import/second.js create mode 100644 test/function/samples/conflicting-reexports/namespace-import/_config.js create mode 100644 test/function/samples/conflicting-reexports/namespace-import/_expected/amd.js create mode 100644 test/function/samples/conflicting-reexports/namespace-import/_expected/cjs.js create mode 100644 test/function/samples/conflicting-reexports/namespace-import/_expected/es.js create mode 100644 test/function/samples/conflicting-reexports/namespace-import/_expected/iife.js create mode 100644 test/function/samples/conflicting-reexports/namespace-import/_expected/system.js create mode 100644 test/function/samples/conflicting-reexports/namespace-import/_expected/umd.js create mode 100644 test/function/samples/conflicting-reexports/namespace-import/first.js create mode 100644 test/function/samples/conflicting-reexports/namespace-import/main.js create mode 100644 test/function/samples/conflicting-reexports/namespace-import/reexport.js create mode 100644 test/function/samples/conflicting-reexports/namespace-import/second.js create mode 100644 test/function/samples/conflicting-reexports/same-binding/_config.js create mode 100644 test/function/samples/conflicting-reexports/same-binding/_expected/amd.js create mode 100644 test/function/samples/conflicting-reexports/same-binding/_expected/cjs.js create mode 100644 test/function/samples/conflicting-reexports/same-binding/_expected/es.js create mode 100644 test/function/samples/conflicting-reexports/same-binding/_expected/iife.js create mode 100644 test/function/samples/conflicting-reexports/same-binding/_expected/system.js create mode 100644 test/function/samples/conflicting-reexports/same-binding/_expected/umd.js create mode 100644 test/function/samples/conflicting-reexports/same-binding/first.js create mode 100644 test/function/samples/conflicting-reexports/same-binding/main.js create mode 100644 test/function/samples/conflicting-reexports/same-binding/reexport.js create mode 100644 test/function/samples/conflicting-reexports/same-binding/second.js create mode 100644 test/function/samples/conflicting-reexports/same-binding/shared.js diff --git a/cli/run/batchWarnings.ts b/cli/run/batchWarnings.ts index 508c65e325a..729130ab4c5 100644 --- a/cli/run/batchWarnings.ts +++ b/cli/run/batchWarnings.ts @@ -1,6 +1,7 @@ import { bold, gray, yellow } from 'colorette'; import { RollupWarning } from '../../src/rollup/types'; import { getOrCreate } from '../../src/utils/getOrCreate'; +import { printQuotedStringList } from '../../src/utils/printStringList'; import relativeId from '../../src/utils/relativeId'; import { stderr } from '../logging'; @@ -79,15 +80,10 @@ const immediateHandlers: { MISSING_NODE_BUILTINS: warning => { title(`Missing shims for Node.js built-ins`); - const detail = - warning.modules!.length === 1 - ? `'${warning.modules![0]}'` - : `${warning - .modules!.slice(0, -1) - .map((name: string) => `'${name}'`) - .join(', ')} and '${warning.modules!.slice(-1)}'`; stderr( - `Creating a browser bundle that depends on ${detail}. You might need to include https://github.com/ionic-team/rollup-plugin-node-polyfills` + `Creating a browser bundle that depends on ${printQuotedStringList( + warning.modules! + )}. You might need to include https://github.com/ionic-team/rollup-plugin-node-polyfills` ); } }; @@ -162,11 +158,11 @@ const deferredHandlers: { title(`Conflicting re-exports`); for (const warning of warnings) { stderr( - `${bold(relativeId(warning.reexporter!))} re-exports '${ + `"${bold(relativeId(warning.reexporter!))}" re-exports "${ warning.name - }' from both ${relativeId(warning.sources![0])} and ${relativeId( + }" from both "${relativeId(warning.sources![0])}" and "${relativeId( warning.sources![1] - )} (will be ignored)` + )}" (will be ignored)` ); } }, @@ -207,16 +203,14 @@ const deferredHandlers: { title(`Broken sourcemap`); info('https://rollupjs.org/guide/en/#warning-sourcemap-is-likely-to-be-incorrect'); - const plugins = Array.from(new Set(warnings.map(w => w.plugin).filter(Boolean))); - const detail = - plugins.length > 1 - ? ` (such as ${plugins - .slice(0, -1) - .map(p => `'${p}'`) - .join(', ')} and '${plugins.slice(-1)}')` - : ` (such as '${plugins[0]}')`; - - stderr(`Plugins that transform code${detail} should generate accompanying sourcemaps`); + const plugins = [ + ...new Set(warnings.map(warning => warning.plugin).filter(Boolean)) + ] as string[]; + stderr( + `Plugins that transform code (such as ${printQuotedStringList( + plugins + )}) should generate accompanying sourcemaps` + ); }, THIS_IS_UNDEFINED(warnings) { diff --git a/src/ExternalModule.ts b/src/ExternalModule.ts index 282edb1d07a..cc320ce4806 100644 --- a/src/ExternalModule.ts +++ b/src/ExternalModule.ts @@ -8,6 +8,8 @@ import { import { EMPTY_ARRAY } from './utils/blank'; import { makeLegal } from './utils/identifierHelpers'; import { normalize, relative } from './utils/path'; +import { printQuotedStringList } from './utils/printStringList'; +import relativeId from './utils/relativeId'; export default class ExternalModule { chunk: void; @@ -99,32 +101,23 @@ export default class ExternalModule { const declaration = this.declarations[name]; return !declaration.included && !this.reexported && !declaration.referenced; }); - if (unused.length === 0) return; - const names = - unused.length === 1 - ? `'${unused[0]}' is` - : `${unused - .slice(0, -1) - .map(name => `'${name}'`) - .join(', ')} and '${unused.slice(-1)}' are`; - const importersSet = new Set(); for (const name of unused) { - const { importers, dynamicImporters } = this.declarations[name].module; - - if (Array.isArray(importers)) importers.forEach(v => importersSet.add(v)); - if (Array.isArray(dynamicImporters)) dynamicImporters.forEach(v => importersSet.add(v)); + const { importers } = this.declarations[name].module; + for (const importer of importers) { + importersSet.add(importer); + } } - - const importersArray = Array.from(importersSet); - - const importerList = ' in' + importersArray.map(s => `\n\t${s};`); - + const importersArray = [...importersSet]; this.options.onwarn({ code: 'UNUSED_EXTERNAL_IMPORT', - message: `${names} imported from external module '${this.id}' but never used${importerList}`, + message: `${printQuotedStringList(unused, ['is', 'are'])} imported from external module "${ + this.id + }" but never used in ${printQuotedStringList( + importersArray.map(importer => relativeId(importer)) + )}.`, names: unused, source: this.id, sources: importersArray diff --git a/src/Module.ts b/src/Module.ts index e2e253fd268..26d896a5901 100644 --- a/src/Module.ts +++ b/src/Module.ts @@ -48,6 +48,7 @@ import { import { EMPTY_OBJECT } from './utils/blank'; import { augmentCodeLocation, + errAmbiguousExternalNamespaces, errCircularReexport, errMissingExport, errNamespaceConflict, @@ -258,6 +259,7 @@ export default class Module { private exportNamesByVariable: Map | null = null; private exportShimVariable: ExportShimVariable = new ExportShimVariable(this); private magicString!: MagicString; + private namespaceReexportsByName: Record = Object.create(null); private relevantDependencies: Set | null = null; private syntheticExports = new Map(); private syntheticNamespace: Variable | null | undefined = null; @@ -369,7 +371,10 @@ export default class Module { ) { dependencyVariables = new Set(dependencyVariables); for (const exportName of [...this.getReexports(), ...this.getExports()]) { - dependencyVariables.add(this.getVariableForExportName(exportName)!); + const exportedVariable = this.getVariableForExportName(exportName); + if (exportedVariable) { + dependencyVariables.add(exportedVariable); + } } } for (let variable of dependencyVariables) { @@ -553,33 +558,17 @@ export default class Module { } if (name !== 'default') { - let foundSyntheticDeclaration: SyntheticNamedExportVariable | null = null; - const skipExternalNamespaceValues = new Set([true, skipExternalNamespaceReexports]); - for (const skipExternalNamespaces of skipExternalNamespaceValues) { - for (const module of this.exportAllModules) { - if (module instanceof Module || !skipExternalNamespaces) { - const declaration = getVariableForExportNameRecursive( - module, + const foundNamespaceReexport = + name in this.namespaceReexportsByName + ? this.namespaceReexportsByName[name] + : (this.namespaceReexportsByName[name] = this.getVariableFromNamespaceReexports( name, importerForSideEffects, - true, searchedNamesAndModules, - skipExternalNamespaces - ); - - if (declaration) { - if (!(declaration instanceof SyntheticNamedExportVariable)) { - return declaration; - } - if (!foundSyntheticDeclaration) { - foundSyntheticDeclaration = declaration; - } - } - } - } - } - if (foundSyntheticDeclaration) { - return foundSyntheticDeclaration; + skipExternalNamespaceReexports + )); + if (foundNamespaceReexport) { + return foundNamespaceReexport; } } @@ -638,13 +627,15 @@ export default class Module { } for (const name of this.getReexports()) { - const variable = this.getVariableForExportName(name)!; - variable.deoptimizePath(UNKNOWN_PATH); - if (!variable.included) { - this.includeVariable(variable); - } - if (variable instanceof ExternalVariable) { - variable.module.reexported = true; + const variable = this.getVariableForExportName(name); + if (variable) { + variable.deoptimizePath(UNKNOWN_PATH); + if (!variable.included) { + this.includeVariable(variable); + } + if (variable instanceof ExternalVariable) { + variable.module.reexported = true; + } } } @@ -1050,6 +1041,62 @@ export default class Module { addSideEffectDependencies(alwaysCheckedDependencies); } + private getVariableFromNamespaceReexports( + name: string, + importerForSideEffects?: Module, + searchedNamesAndModules?: Map>, + skipExternalNamespaceReexports = false + ): Variable | null { + let foundSyntheticDeclaration: SyntheticNamedExportVariable | null = null; + const skipExternalNamespaceValues = new Set([true, skipExternalNamespaceReexports]); + for (const skipExternalNamespaces of skipExternalNamespaceValues) { + const foundDeclarations = new Set(); + for (const module of this.exportAllModules) { + if (module instanceof Module || !skipExternalNamespaces) { + const declaration = getVariableForExportNameRecursive( + module, + name, + importerForSideEffects, + true, + searchedNamesAndModules, + skipExternalNamespaces + ); + + if (declaration) { + if (!(declaration instanceof SyntheticNamedExportVariable)) { + foundDeclarations.add(declaration); + } else if (!foundSyntheticDeclaration) { + foundSyntheticDeclaration = declaration; + } + } + } + } + if (foundDeclarations.size === 1) { + return [...foundDeclarations][0]; + } + if (foundDeclarations.size > 1) { + if (skipExternalNamespaces) { + return null; + } + const foundDeclarationList = [...(foundDeclarations as Set)]; + const usedDeclaration = foundDeclarationList[0]; + this.options.onwarn( + errAmbiguousExternalNamespaces( + name, + this.id, + usedDeclaration.module.id, + foundDeclarationList.map(declaration => declaration.module.id) + ) + ); + return usedDeclaration; + } + } + if (foundSyntheticDeclaration) { + return foundSyntheticDeclaration; + } + return null; + } + private includeAndGetAdditionalMergedNamespaces(): Variable[] { const mergedNamespaces: Variable[] = []; for (const module of this.exportAllModules) { diff --git a/src/ast/variables/NamespaceVariable.ts b/src/ast/variables/NamespaceVariable.ts index 5312518e013..a01a59d6678 100644 --- a/src/ast/variables/NamespaceVariable.ts +++ b/src/ast/variables/NamespaceVariable.ts @@ -44,10 +44,13 @@ export default class NamespaceVariable extends Variable { if (this.memberVariables) { return this.memberVariables; } - const memberVariables = Object.create(null); + const memberVariables: { [name: string]: Variable } = Object.create(null); for (const name of this.context.getExports().concat(this.context.getReexports())) { if (name[0] !== '*' && name !== this.module.info.syntheticNamedExports) { - memberVariables[name] = this.context.traceExport(name); + const exportedVariable = this.context.traceExport(name); + if (exportedVariable) { + memberVariables[name] = exportedVariable; + } } } return (this.memberVariables = memberVariables); diff --git a/src/finalisers/shared/warnOnBuiltins.ts b/src/finalisers/shared/warnOnBuiltins.ts index 2fe1c8015e8..838d9ad255d 100644 --- a/src/finalisers/shared/warnOnBuiltins.ts +++ b/src/finalisers/shared/warnOnBuiltins.ts @@ -1,5 +1,6 @@ import { ChunkDependencies } from '../../Chunk'; import { RollupWarning } from '../../rollup/types'; +import { printQuotedStringList } from '../../utils/printStringList'; const builtins = { assert: true, @@ -33,17 +34,11 @@ export default function warnOnBuiltins( if (!externalBuiltins.length) return; - const detail = - externalBuiltins.length === 1 - ? `module ('${externalBuiltins[0]}')` - : `modules (${externalBuiltins - .slice(0, -1) - .map(name => `'${name}'`) - .join(', ')} and '${externalBuiltins.slice(-1)}')`; - warn({ code: 'MISSING_NODE_BUILTINS', - 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`, + message: `Creating a browser bundle that depends on Node.js built-in modules (${printQuotedStringList( + externalBuiltins + )}). You might need to include https://github.com/ionic-team/rollup-plugin-node-polyfills`, modules: externalBuiltins }); } diff --git a/src/utils/error.ts b/src/utils/error.ts index 176a8fc3312..a0e3d01fd59 100644 --- a/src/utils/error.ts +++ b/src/utils/error.ts @@ -8,6 +8,7 @@ import { WarningHandler } from '../rollup/types'; import getCodeFrame from './getCodeFrame'; +import { printQuotedStringList } from './printStringList'; import relativeId from './relativeId'; export function error(base: Error | RollupError): never { @@ -63,6 +64,7 @@ export const enum Errors { MISSING_IMPLICIT_DEPENDANT = 'MISSING_IMPLICIT_DEPENDANT', MIXED_EXPORTS = 'MIXED_EXPORTS', NAMESPACE_CONFLICT = 'NAMESPACE_CONFLICT', + AMBIGUOUS_EXTERNAL_NAMESPACES = 'AMBIGUOUS_EXTERNAL_NAMESPACES', NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE = 'NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE', PLUGIN_ERROR = 'PLUGIN_ERROR', PREFER_NAMED_EXPORTS = 'PREFER_NAMED_EXPORTS', @@ -307,13 +309,11 @@ export function errImplicitDependantIsNotIncluded(module: Module) { ).sort(); return { code: Errors.MISSING_IMPLICIT_DEPENDANT, - message: `Module "${relativeId(module.id)}" that should be implicitly loaded before "${ - implicitDependencies.length === 1 - ? implicitDependencies[0] - : `${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.` + message: `Module "${relativeId( + module.id + )}" that should be implicitly loaded before ${printQuotedStringList( + implicitDependencies + )} 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.` }; } @@ -337,17 +337,36 @@ export function errNamespaceConflict( ) { return { code: Errors.NAMESPACE_CONFLICT, - message: `Conflicting namespaces: ${relativeId( + message: `Conflicting namespaces: "${relativeId( reexportingModule.id - )} re-exports '${name}' from both ${relativeId( + )}" re-exports "${name}" from both "${relativeId( reexportingModule.exportsAll[name] - )} and ${relativeId(additionalExportAllModule.exportsAll[name])} (will be ignored)`, + )}" and "${relativeId(additionalExportAllModule.exportsAll[name])}" (will be ignored)`, name, reexporter: reexportingModule.id, sources: [reexportingModule.exportsAll[name], additionalExportAllModule.exportsAll[name]] }; } +export function errAmbiguousExternalNamespaces( + name: string, + reexportingModule: string, + usedExternalModule: string, + externalModules: string[] +) { + return { + code: Errors.AMBIGUOUS_EXTERNAL_NAMESPACES, + message: `Ambiguous external namespace resolution: "${relativeId( + reexportingModule + )}" re-exports "${name}" from one of the external modules ${printQuotedStringList( + externalModules.map(module => relativeId(module)) + )}, guessing "${relativeId(usedExternalModule)}".`, + name, + reexporter: reexportingModule, + sources: externalModules + }; +} + export function errNoTransformMapOrAstWithoutCode(pluginName: string) { return { code: Errors.NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE, diff --git a/src/utils/printStringList.ts b/src/utils/printStringList.ts new file mode 100644 index 00000000000..19c80ce5e60 --- /dev/null +++ b/src/utils/printStringList.ts @@ -0,0 +1,11 @@ +export function printQuotedStringList(list: string[], verbs?: [string, string]): string { + const isSingleItem = list.length <= 1; + const quotedList = list.map(item => `"${item}"`); + let output = isSingleItem + ? quotedList[0] + : `${quotedList.slice(0, -1).join(', ')} and ${quotedList.slice(-1)[0]}`; + if (verbs) { + output += ` ${isSingleItem ? verbs[0] : verbs[1]}`; + } + return output; +} diff --git a/test/cli/samples/warn-broken-sourcemap/_config.js b/test/cli/samples/warn-broken-sourcemap/_config.js index 072e9c77998..44597f2d557 100644 --- a/test/cli/samples/warn-broken-sourcemap/_config.js +++ b/test/cli/samples/warn-broken-sourcemap/_config.js @@ -12,7 +12,7 @@ module.exports = { stderr, '(!) Broken sourcemap\n' + 'https://rollupjs.org/guide/en/#warning-sourcemap-is-likely-to-be-incorrect\n' + - "Plugins that transform code (such as 'test-plugin1') should generate accompanying sourcemaps\n" + 'Plugins that transform code (such as "test-plugin1") should generate accompanying sourcemaps\n' ); } }; diff --git a/test/cli/samples/warn-broken-sourcemaps/_config.js b/test/cli/samples/warn-broken-sourcemaps/_config.js index 3b7fd70a5eb..b3e2e2ba768 100644 --- a/test/cli/samples/warn-broken-sourcemaps/_config.js +++ b/test/cli/samples/warn-broken-sourcemaps/_config.js @@ -12,7 +12,7 @@ module.exports = { stderr, '(!) Broken sourcemap\n' + 'https://rollupjs.org/guide/en/#warning-sourcemap-is-likely-to-be-incorrect\n' + - "Plugins that transform code (such as 'test-plugin1', 'test-plugin2' and 'test-plugin3') should generate accompanying sourcemaps" + 'Plugins that transform code (such as "test-plugin1", "test-plugin2" and "test-plugin3") should generate accompanying sourcemaps' ); } }; diff --git a/test/cli/samples/warn-import-export/_config.js b/test/cli/samples/warn-import-export/_config.js index 904557f5686..c0c549251e3 100644 --- a/test/cli/samples/warn-import-export/_config.js +++ b/test/cli/samples/warn-import-export/_config.js @@ -43,8 +43,8 @@ module.exports = { assertIncludes( stderr, '(!) Conflicting re-exports\n' + - "main.js re-exports 'foo' from both dep.js and dep2.js (will be ignored)\n" + - "main.js re-exports 'bar' from both dep.js and dep2.js (will be ignored)\n" + '"main.js" re-exports "foo" from both "dep.js" and "dep2.js" (will be ignored)\n' + + '"main.js" re-exports "bar" from both "dep.js" and "dep2.js" (will be ignored)\n' ); assertIncludes( stderr, diff --git a/test/cli/samples/warn-multiple/_config.js b/test/cli/samples/warn-multiple/_config.js index 3b3474524de..596134d0beb 100644 --- a/test/cli/samples/warn-multiple/_config.js +++ b/test/cli/samples/warn-multiple/_config.js @@ -7,7 +7,7 @@ module.exports = { assertIncludes( stderr, '(!) Missing shims for Node.js built-ins\n' + - "Creating a browser bundle that depends on 'url', 'assert' and 'path'. You might need to include https://github.com/ionic-team/rollup-plugin-node-polyfills\n" + 'Creating a browser bundle that depends on "url", "assert" and "path". You might need to include https://github.com/ionic-team/rollup-plugin-node-polyfills\n' ); assertIncludes( stderr, diff --git a/test/form/samples/namespace-reexport-name/_expected/amd.js b/test/form/samples/namespace-reexport-name/_expected/amd.js index 51db3c2f884..ece2f161a68 100644 --- a/test/form/samples/namespace-reexport-name/_expected/amd.js +++ b/test/form/samples/namespace-reexport-name/_expected/amd.js @@ -2,12 +2,6 @@ define(['exports', 'external'], function (exports, external) { 'use strict'; const renamedIndirectOverride = external.indirectOverride; - Object.defineProperty(exports, 'noOverride', { - enumerable: true, - get: function () { - return external.noOverride; - } - }); Object.defineProperty(exports, 'renamedDirectOverride', { enumerable: true, get: function () { diff --git a/test/form/samples/namespace-reexport-name/_expected/cjs.js b/test/form/samples/namespace-reexport-name/_expected/cjs.js index a418ea4d048..90b60e75b83 100644 --- a/test/form/samples/namespace-reexport-name/_expected/cjs.js +++ b/test/form/samples/namespace-reexport-name/_expected/cjs.js @@ -6,12 +6,6 @@ var external = require('external'); const renamedIndirectOverride = external.indirectOverride; -Object.defineProperty(exports, 'noOverride', { - enumerable: true, - get: function () { - return external.noOverride; - } -}); Object.defineProperty(exports, 'renamedDirectOverride', { enumerable: true, get: function () { diff --git a/test/form/samples/namespace-reexport-name/_expected/es.js b/test/form/samples/namespace-reexport-name/_expected/es.js index 0ee20f7e12a..5eb8042653f 100644 --- a/test/form/samples/namespace-reexport-name/_expected/es.js +++ b/test/form/samples/namespace-reexport-name/_expected/es.js @@ -1,6 +1,6 @@ import { indirectOverride } from 'external'; export * from 'external'; -export { noOverride, directOverride as renamedDirectOverride } from 'external'; +export { directOverride as renamedDirectOverride } from 'external'; const renamedIndirectOverride = indirectOverride; diff --git a/test/form/samples/namespace-reexport-name/_expected/iife.js b/test/form/samples/namespace-reexport-name/_expected/iife.js index d0a35613f05..826262beb4e 100644 --- a/test/form/samples/namespace-reexport-name/_expected/iife.js +++ b/test/form/samples/namespace-reexport-name/_expected/iife.js @@ -3,12 +3,6 @@ var bundle = (function (exports, external) { const renamedIndirectOverride = external.indirectOverride; - Object.defineProperty(exports, 'noOverride', { - enumerable: true, - get: function () { - return external.noOverride; - } - }); Object.defineProperty(exports, 'renamedDirectOverride', { enumerable: true, get: function () { diff --git a/test/form/samples/namespace-reexport-name/_expected/system.js b/test/form/samples/namespace-reexport-name/_expected/system.js index 03a96a02255..fe702072d4c 100644 --- a/test/form/samples/namespace-reexport-name/_expected/system.js +++ b/test/form/samples/namespace-reexport-name/_expected/system.js @@ -1,6 +1,6 @@ System.register('bundle', ['external'], function (exports) { 'use strict'; - var _starExcludes = { renamedIndirectOverride: 1, default: 1, noOverride: 1, renamedDirectOverride: 1 }; + var _starExcludes = { renamedIndirectOverride: 1, default: 1, renamedDirectOverride: 1 }; var indirectOverride; return { setters: [function (module) { @@ -9,7 +9,6 @@ System.register('bundle', ['external'], function (exports) { for (var _$p in module) { if (!_starExcludes[_$p]) _setter[_$p] = module[_$p]; } - _setter.noOverride = module.noOverride; _setter.renamedDirectOverride = module.directOverride; exports(_setter); }], diff --git a/test/form/samples/namespace-reexport-name/_expected/umd.js b/test/form/samples/namespace-reexport-name/_expected/umd.js index 45efa714a1e..cba692f44ca 100644 --- a/test/form/samples/namespace-reexport-name/_expected/umd.js +++ b/test/form/samples/namespace-reexport-name/_expected/umd.js @@ -6,12 +6,6 @@ const renamedIndirectOverride = external.indirectOverride; - Object.defineProperty(exports, 'noOverride', { - enumerable: true, - get: function () { - return external.noOverride; - } - }); Object.defineProperty(exports, 'renamedDirectOverride', { enumerable: true, get: function () { diff --git a/test/form/samples/namespace-reexport-name/external-reexport.js b/test/form/samples/namespace-reexport-name/external-reexport.js index 3686fed7868..c4be4108af2 100644 --- a/test/form/samples/namespace-reexport-name/external-reexport.js +++ b/test/form/samples/namespace-reexport-name/external-reexport.js @@ -1,2 +1,2 @@ export * from 'external'; -export { noOverride } from 'external'; +export { conflictOverride } from 'external'; diff --git a/test/form/samples/namespace-reexport-name/overrides.js b/test/form/samples/namespace-reexport-name/overrides.js index b2f9383bf39..172928cbe16 100644 --- a/test/form/samples/namespace-reexport-name/overrides.js +++ b/test/form/samples/namespace-reexport-name/overrides.js @@ -2,4 +2,4 @@ import { indirectOverride, ignoredOverride } from './external-reexport'; export { directOverride as renamedDirectOverride } from './external-reexport'; export const renamedIndirectOverride = indirectOverride; -export const noOverride = ignoredOverride; +export const conflictOverride = ignoredOverride; diff --git a/test/function/samples/conflicting-reexports/named-import-external/_config.js b/test/function/samples/conflicting-reexports/named-import-external/_config.js new file mode 100644 index 00000000000..ca9bfc542de --- /dev/null +++ b/test/function/samples/conflicting-reexports/named-import-external/_config.js @@ -0,0 +1,30 @@ +const path = require('path'); +const REEXPORT_ID = path.join(__dirname, 'reexport.js'); + +module.exports = { + description: + 'warns when a conflicting binding is imported via a named import from external namespaces', + warnings: [ + { + code: 'AMBIGUOUS_EXTERNAL_NAMESPACES', + message: + 'Ambiguous external namespace resolution: "reexport.js" re-exports "foo" from one of the external modules "first" and "second", guessing "first".', + name: 'foo', + reexporter: REEXPORT_ID, + sources: ['first', 'second'] + }, + { + code: 'UNUSED_EXTERNAL_IMPORT', + message: '"foo" is imported from external module "second" but never used in "reexport.js".', + names: ['foo'], + source: 'second', + sources: [REEXPORT_ID] + } + ], + options: { external: ['first', 'second'] }, + context: { + require(id) { + return { foo: id }; + } + } +}; diff --git a/test/function/samples/conflicting-reexports/named-import-external/_expected/amd.js b/test/function/samples/conflicting-reexports/named-import-external/_expected/amd.js new file mode 100644 index 00000000000..51db3c2f884 --- /dev/null +++ b/test/function/samples/conflicting-reexports/named-import-external/_expected/amd.js @@ -0,0 +1,29 @@ +define(['exports', 'external'], function (exports, external) { 'use strict'; + + const renamedIndirectOverride = external.indirectOverride; + + Object.defineProperty(exports, 'noOverride', { + enumerable: true, + get: function () { + return external.noOverride; + } + }); + Object.defineProperty(exports, 'renamedDirectOverride', { + enumerable: true, + get: function () { + return external.directOverride; + } + }); + exports.renamedIndirectOverride = renamedIndirectOverride; + Object.keys(external).forEach(function (k) { + if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, { + enumerable: true, + get: function () { + return external[k]; + } + }); + }); + + Object.defineProperty(exports, '__esModule', { value: true }); + +}); diff --git a/test/function/samples/conflicting-reexports/named-import-external/_expected/cjs.js b/test/function/samples/conflicting-reexports/named-import-external/_expected/cjs.js new file mode 100644 index 00000000000..a418ea4d048 --- /dev/null +++ b/test/function/samples/conflicting-reexports/named-import-external/_expected/cjs.js @@ -0,0 +1,29 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +var external = require('external'); + +const renamedIndirectOverride = external.indirectOverride; + +Object.defineProperty(exports, 'noOverride', { + enumerable: true, + get: function () { + return external.noOverride; + } +}); +Object.defineProperty(exports, 'renamedDirectOverride', { + enumerable: true, + get: function () { + return external.directOverride; + } +}); +exports.renamedIndirectOverride = renamedIndirectOverride; +Object.keys(external).forEach(function (k) { + if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, { + enumerable: true, + get: function () { + return external[k]; + } + }); +}); diff --git a/test/function/samples/conflicting-reexports/named-import-external/_expected/es.js b/test/function/samples/conflicting-reexports/named-import-external/_expected/es.js new file mode 100644 index 00000000000..0ee20f7e12a --- /dev/null +++ b/test/function/samples/conflicting-reexports/named-import-external/_expected/es.js @@ -0,0 +1,7 @@ +import { indirectOverride } from 'external'; +export * from 'external'; +export { noOverride, directOverride as renamedDirectOverride } from 'external'; + +const renamedIndirectOverride = indirectOverride; + +export { renamedIndirectOverride }; diff --git a/test/function/samples/conflicting-reexports/named-import-external/_expected/iife.js b/test/function/samples/conflicting-reexports/named-import-external/_expected/iife.js new file mode 100644 index 00000000000..d0a35613f05 --- /dev/null +++ b/test/function/samples/conflicting-reexports/named-import-external/_expected/iife.js @@ -0,0 +1,32 @@ +var bundle = (function (exports, external) { + 'use strict'; + + const renamedIndirectOverride = external.indirectOverride; + + Object.defineProperty(exports, 'noOverride', { + enumerable: true, + get: function () { + return external.noOverride; + } + }); + Object.defineProperty(exports, 'renamedDirectOverride', { + enumerable: true, + get: function () { + return external.directOverride; + } + }); + exports.renamedIndirectOverride = renamedIndirectOverride; + Object.keys(external).forEach(function (k) { + if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, { + enumerable: true, + get: function () { + return external[k]; + } + }); + }); + + Object.defineProperty(exports, '__esModule', { value: true }); + + return exports; + +}({}, external)); diff --git a/test/function/samples/conflicting-reexports/named-import-external/_expected/system.js b/test/function/samples/conflicting-reexports/named-import-external/_expected/system.js new file mode 100644 index 00000000000..03a96a02255 --- /dev/null +++ b/test/function/samples/conflicting-reexports/named-import-external/_expected/system.js @@ -0,0 +1,22 @@ +System.register('bundle', ['external'], function (exports) { + 'use strict'; + var _starExcludes = { renamedIndirectOverride: 1, default: 1, noOverride: 1, renamedDirectOverride: 1 }; + var indirectOverride; + return { + setters: [function (module) { + indirectOverride = module.indirectOverride; + var _setter = {}; + for (var _$p in module) { + if (!_starExcludes[_$p]) _setter[_$p] = module[_$p]; + } + _setter.noOverride = module.noOverride; + _setter.renamedDirectOverride = module.directOverride; + exports(_setter); + }], + execute: function () { + + const renamedIndirectOverride = exports('renamedIndirectOverride', indirectOverride); + + } + }; +}); diff --git a/test/function/samples/conflicting-reexports/named-import-external/_expected/umd.js b/test/function/samples/conflicting-reexports/named-import-external/_expected/umd.js new file mode 100644 index 00000000000..45efa714a1e --- /dev/null +++ b/test/function/samples/conflicting-reexports/named-import-external/_expected/umd.js @@ -0,0 +1,33 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('external')) : + typeof define === 'function' && define.amd ? define(['exports', 'external'], factory) : + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.bundle = {}, global.external)); +}(this, (function (exports, external) { 'use strict'; + + const renamedIndirectOverride = external.indirectOverride; + + Object.defineProperty(exports, 'noOverride', { + enumerable: true, + get: function () { + return external.noOverride; + } + }); + Object.defineProperty(exports, 'renamedDirectOverride', { + enumerable: true, + get: function () { + return external.directOverride; + } + }); + exports.renamedIndirectOverride = renamedIndirectOverride; + Object.keys(external).forEach(function (k) { + if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, { + enumerable: true, + get: function () { + return external[k]; + } + }); + }); + + Object.defineProperty(exports, '__esModule', { value: true }); + +}))); diff --git a/test/function/samples/conflicting-reexports/named-import-external/main.js b/test/function/samples/conflicting-reexports/named-import-external/main.js new file mode 100644 index 00000000000..c76b16a35ad --- /dev/null +++ b/test/function/samples/conflicting-reexports/named-import-external/main.js @@ -0,0 +1,3 @@ +import { foo } from './reexport.js'; + +assert.strictEqual(foo, 'first'); diff --git a/test/function/samples/conflicting-reexports/named-import-external/reexport.js b/test/function/samples/conflicting-reexports/named-import-external/reexport.js new file mode 100644 index 00000000000..914892c4459 --- /dev/null +++ b/test/function/samples/conflicting-reexports/named-import-external/reexport.js @@ -0,0 +1,2 @@ +export * from 'first'; +export * from 'second'; diff --git a/test/function/samples/conflicting-reexports/named-import/_config.js b/test/function/samples/conflicting-reexports/named-import/_config.js new file mode 100644 index 00000000000..7f116153a8e --- /dev/null +++ b/test/function/samples/conflicting-reexports/named-import/_config.js @@ -0,0 +1,30 @@ +const path = require('path'); + +const ID_MAIN = path.join(__dirname, 'main.js'); + +module.exports = { + description: 'throws when a conflicting binding is imported via a named import', + error: { + code: 'MISSING_EXPORT', + frame: ` +1: import { foo } from './reexport.js'; + ^ +2: +3: assert.strictEqual(foo, 1);`, + id: ID_MAIN, + loc: { + column: 9, + file: ID_MAIN, + line: 1 + }, + message: "'foo' is not exported by reexport.js, imported by main.js", + pos: 9, + url: 'https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module', + watchFiles: [ + ID_MAIN, + path.join(__dirname, 'reexport.js'), + path.join(__dirname, 'first.js'), + path.join(__dirname, 'second.js') + ] + } +}; diff --git a/test/function/samples/conflicting-reexports/named-import/_expected/amd.js b/test/function/samples/conflicting-reexports/named-import/_expected/amd.js new file mode 100644 index 00000000000..51db3c2f884 --- /dev/null +++ b/test/function/samples/conflicting-reexports/named-import/_expected/amd.js @@ -0,0 +1,29 @@ +define(['exports', 'external'], function (exports, external) { 'use strict'; + + const renamedIndirectOverride = external.indirectOverride; + + Object.defineProperty(exports, 'noOverride', { + enumerable: true, + get: function () { + return external.noOverride; + } + }); + Object.defineProperty(exports, 'renamedDirectOverride', { + enumerable: true, + get: function () { + return external.directOverride; + } + }); + exports.renamedIndirectOverride = renamedIndirectOverride; + Object.keys(external).forEach(function (k) { + if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, { + enumerable: true, + get: function () { + return external[k]; + } + }); + }); + + Object.defineProperty(exports, '__esModule', { value: true }); + +}); diff --git a/test/function/samples/conflicting-reexports/named-import/_expected/cjs.js b/test/function/samples/conflicting-reexports/named-import/_expected/cjs.js new file mode 100644 index 00000000000..a418ea4d048 --- /dev/null +++ b/test/function/samples/conflicting-reexports/named-import/_expected/cjs.js @@ -0,0 +1,29 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +var external = require('external'); + +const renamedIndirectOverride = external.indirectOverride; + +Object.defineProperty(exports, 'noOverride', { + enumerable: true, + get: function () { + return external.noOverride; + } +}); +Object.defineProperty(exports, 'renamedDirectOverride', { + enumerable: true, + get: function () { + return external.directOverride; + } +}); +exports.renamedIndirectOverride = renamedIndirectOverride; +Object.keys(external).forEach(function (k) { + if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, { + enumerable: true, + get: function () { + return external[k]; + } + }); +}); diff --git a/test/function/samples/conflicting-reexports/named-import/_expected/es.js b/test/function/samples/conflicting-reexports/named-import/_expected/es.js new file mode 100644 index 00000000000..0ee20f7e12a --- /dev/null +++ b/test/function/samples/conflicting-reexports/named-import/_expected/es.js @@ -0,0 +1,7 @@ +import { indirectOverride } from 'external'; +export * from 'external'; +export { noOverride, directOverride as renamedDirectOverride } from 'external'; + +const renamedIndirectOverride = indirectOverride; + +export { renamedIndirectOverride }; diff --git a/test/function/samples/conflicting-reexports/named-import/_expected/iife.js b/test/function/samples/conflicting-reexports/named-import/_expected/iife.js new file mode 100644 index 00000000000..d0a35613f05 --- /dev/null +++ b/test/function/samples/conflicting-reexports/named-import/_expected/iife.js @@ -0,0 +1,32 @@ +var bundle = (function (exports, external) { + 'use strict'; + + const renamedIndirectOverride = external.indirectOverride; + + Object.defineProperty(exports, 'noOverride', { + enumerable: true, + get: function () { + return external.noOverride; + } + }); + Object.defineProperty(exports, 'renamedDirectOverride', { + enumerable: true, + get: function () { + return external.directOverride; + } + }); + exports.renamedIndirectOverride = renamedIndirectOverride; + Object.keys(external).forEach(function (k) { + if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, { + enumerable: true, + get: function () { + return external[k]; + } + }); + }); + + Object.defineProperty(exports, '__esModule', { value: true }); + + return exports; + +}({}, external)); diff --git a/test/function/samples/conflicting-reexports/named-import/_expected/system.js b/test/function/samples/conflicting-reexports/named-import/_expected/system.js new file mode 100644 index 00000000000..03a96a02255 --- /dev/null +++ b/test/function/samples/conflicting-reexports/named-import/_expected/system.js @@ -0,0 +1,22 @@ +System.register('bundle', ['external'], function (exports) { + 'use strict'; + var _starExcludes = { renamedIndirectOverride: 1, default: 1, noOverride: 1, renamedDirectOverride: 1 }; + var indirectOverride; + return { + setters: [function (module) { + indirectOverride = module.indirectOverride; + var _setter = {}; + for (var _$p in module) { + if (!_starExcludes[_$p]) _setter[_$p] = module[_$p]; + } + _setter.noOverride = module.noOverride; + _setter.renamedDirectOverride = module.directOverride; + exports(_setter); + }], + execute: function () { + + const renamedIndirectOverride = exports('renamedIndirectOverride', indirectOverride); + + } + }; +}); diff --git a/test/function/samples/conflicting-reexports/named-import/_expected/umd.js b/test/function/samples/conflicting-reexports/named-import/_expected/umd.js new file mode 100644 index 00000000000..45efa714a1e --- /dev/null +++ b/test/function/samples/conflicting-reexports/named-import/_expected/umd.js @@ -0,0 +1,33 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('external')) : + typeof define === 'function' && define.amd ? define(['exports', 'external'], factory) : + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.bundle = {}, global.external)); +}(this, (function (exports, external) { 'use strict'; + + const renamedIndirectOverride = external.indirectOverride; + + Object.defineProperty(exports, 'noOverride', { + enumerable: true, + get: function () { + return external.noOverride; + } + }); + Object.defineProperty(exports, 'renamedDirectOverride', { + enumerable: true, + get: function () { + return external.directOverride; + } + }); + exports.renamedIndirectOverride = renamedIndirectOverride; + Object.keys(external).forEach(function (k) { + if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, { + enumerable: true, + get: function () { + return external[k]; + } + }); + }); + + Object.defineProperty(exports, '__esModule', { value: true }); + +}))); diff --git a/test/function/samples/conflicting-reexports/named-import/first.js b/test/function/samples/conflicting-reexports/named-import/first.js new file mode 100644 index 00000000000..bb1843d113a --- /dev/null +++ b/test/function/samples/conflicting-reexports/named-import/first.js @@ -0,0 +1 @@ +export const foo = 1; diff --git a/test/function/samples/conflicting-reexports/named-import/main.js b/test/function/samples/conflicting-reexports/named-import/main.js new file mode 100644 index 00000000000..38098ddc140 --- /dev/null +++ b/test/function/samples/conflicting-reexports/named-import/main.js @@ -0,0 +1,3 @@ +import { foo } from './reexport.js'; + +assert.strictEqual(foo, 1); diff --git a/test/function/samples/conflicting-reexports/named-import/reexport.js b/test/function/samples/conflicting-reexports/named-import/reexport.js new file mode 100644 index 00000000000..7216b37efc0 --- /dev/null +++ b/test/function/samples/conflicting-reexports/named-import/reexport.js @@ -0,0 +1,2 @@ +export * from './first.js'; +export * from './second.js'; diff --git a/test/function/samples/conflicting-reexports/named-import/second.js b/test/function/samples/conflicting-reexports/named-import/second.js new file mode 100644 index 00000000000..cc57a55e257 --- /dev/null +++ b/test/function/samples/conflicting-reexports/named-import/second.js @@ -0,0 +1 @@ +export const foo = 2; diff --git a/test/function/samples/conflicting-reexports/namespace-import/_config.js b/test/function/samples/conflicting-reexports/namespace-import/_config.js new file mode 100644 index 00000000000..a83afe3ee0c --- /dev/null +++ b/test/function/samples/conflicting-reexports/namespace-import/_config.js @@ -0,0 +1,35 @@ +const path = require('path'); + +module.exports = { + description: 'warns when a conflicting binding is imported via a namespace import', + warnings: [ + { + code: 'NAMESPACE_CONFLICT', + message: + 'Conflicting namespaces: "reexport.js" re-exports "foo" from both "first.js" and "second.js" (will be ignored)', + name: 'foo', + reexporter: path.join(__dirname, 'reexport.js'), + sources: [path.join(__dirname, 'first.js'), path.join(__dirname, 'second.js')] + }, + { + code: 'MISSING_EXPORT', + exporter: 'reexport.js', + frame: ` +2: +3: assert.deepStrictEqual(ns, { __proto__: null, bar: 1, baz: 2 }); +4: assert.strictEqual(ns.foo, undefined) + ^`, + id: path.join(__dirname, 'main.js'), + importer: 'main.js', + loc: { + column: 22, + file: path.join(__dirname, 'main.js'), + line: 4 + }, + message: "'foo' is not exported by 'reexport.js'", + missing: 'foo', + pos: 125, + url: 'https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module' + } + ] +}; diff --git a/test/function/samples/conflicting-reexports/namespace-import/_expected/amd.js b/test/function/samples/conflicting-reexports/namespace-import/_expected/amd.js new file mode 100644 index 00000000000..51db3c2f884 --- /dev/null +++ b/test/function/samples/conflicting-reexports/namespace-import/_expected/amd.js @@ -0,0 +1,29 @@ +define(['exports', 'external'], function (exports, external) { 'use strict'; + + const renamedIndirectOverride = external.indirectOverride; + + Object.defineProperty(exports, 'noOverride', { + enumerable: true, + get: function () { + return external.noOverride; + } + }); + Object.defineProperty(exports, 'renamedDirectOverride', { + enumerable: true, + get: function () { + return external.directOverride; + } + }); + exports.renamedIndirectOverride = renamedIndirectOverride; + Object.keys(external).forEach(function (k) { + if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, { + enumerable: true, + get: function () { + return external[k]; + } + }); + }); + + Object.defineProperty(exports, '__esModule', { value: true }); + +}); diff --git a/test/function/samples/conflicting-reexports/namespace-import/_expected/cjs.js b/test/function/samples/conflicting-reexports/namespace-import/_expected/cjs.js new file mode 100644 index 00000000000..a418ea4d048 --- /dev/null +++ b/test/function/samples/conflicting-reexports/namespace-import/_expected/cjs.js @@ -0,0 +1,29 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +var external = require('external'); + +const renamedIndirectOverride = external.indirectOverride; + +Object.defineProperty(exports, 'noOverride', { + enumerable: true, + get: function () { + return external.noOverride; + } +}); +Object.defineProperty(exports, 'renamedDirectOverride', { + enumerable: true, + get: function () { + return external.directOverride; + } +}); +exports.renamedIndirectOverride = renamedIndirectOverride; +Object.keys(external).forEach(function (k) { + if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, { + enumerable: true, + get: function () { + return external[k]; + } + }); +}); diff --git a/test/function/samples/conflicting-reexports/namespace-import/_expected/es.js b/test/function/samples/conflicting-reexports/namespace-import/_expected/es.js new file mode 100644 index 00000000000..0ee20f7e12a --- /dev/null +++ b/test/function/samples/conflicting-reexports/namespace-import/_expected/es.js @@ -0,0 +1,7 @@ +import { indirectOverride } from 'external'; +export * from 'external'; +export { noOverride, directOverride as renamedDirectOverride } from 'external'; + +const renamedIndirectOverride = indirectOverride; + +export { renamedIndirectOverride }; diff --git a/test/function/samples/conflicting-reexports/namespace-import/_expected/iife.js b/test/function/samples/conflicting-reexports/namespace-import/_expected/iife.js new file mode 100644 index 00000000000..d0a35613f05 --- /dev/null +++ b/test/function/samples/conflicting-reexports/namespace-import/_expected/iife.js @@ -0,0 +1,32 @@ +var bundle = (function (exports, external) { + 'use strict'; + + const renamedIndirectOverride = external.indirectOverride; + + Object.defineProperty(exports, 'noOverride', { + enumerable: true, + get: function () { + return external.noOverride; + } + }); + Object.defineProperty(exports, 'renamedDirectOverride', { + enumerable: true, + get: function () { + return external.directOverride; + } + }); + exports.renamedIndirectOverride = renamedIndirectOverride; + Object.keys(external).forEach(function (k) { + if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, { + enumerable: true, + get: function () { + return external[k]; + } + }); + }); + + Object.defineProperty(exports, '__esModule', { value: true }); + + return exports; + +}({}, external)); diff --git a/test/function/samples/conflicting-reexports/namespace-import/_expected/system.js b/test/function/samples/conflicting-reexports/namespace-import/_expected/system.js new file mode 100644 index 00000000000..03a96a02255 --- /dev/null +++ b/test/function/samples/conflicting-reexports/namespace-import/_expected/system.js @@ -0,0 +1,22 @@ +System.register('bundle', ['external'], function (exports) { + 'use strict'; + var _starExcludes = { renamedIndirectOverride: 1, default: 1, noOverride: 1, renamedDirectOverride: 1 }; + var indirectOverride; + return { + setters: [function (module) { + indirectOverride = module.indirectOverride; + var _setter = {}; + for (var _$p in module) { + if (!_starExcludes[_$p]) _setter[_$p] = module[_$p]; + } + _setter.noOverride = module.noOverride; + _setter.renamedDirectOverride = module.directOverride; + exports(_setter); + }], + execute: function () { + + const renamedIndirectOverride = exports('renamedIndirectOverride', indirectOverride); + + } + }; +}); diff --git a/test/function/samples/conflicting-reexports/namespace-import/_expected/umd.js b/test/function/samples/conflicting-reexports/namespace-import/_expected/umd.js new file mode 100644 index 00000000000..45efa714a1e --- /dev/null +++ b/test/function/samples/conflicting-reexports/namespace-import/_expected/umd.js @@ -0,0 +1,33 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('external')) : + typeof define === 'function' && define.amd ? define(['exports', 'external'], factory) : + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.bundle = {}, global.external)); +}(this, (function (exports, external) { 'use strict'; + + const renamedIndirectOverride = external.indirectOverride; + + Object.defineProperty(exports, 'noOverride', { + enumerable: true, + get: function () { + return external.noOverride; + } + }); + Object.defineProperty(exports, 'renamedDirectOverride', { + enumerable: true, + get: function () { + return external.directOverride; + } + }); + exports.renamedIndirectOverride = renamedIndirectOverride; + Object.keys(external).forEach(function (k) { + if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, { + enumerable: true, + get: function () { + return external[k]; + } + }); + }); + + Object.defineProperty(exports, '__esModule', { value: true }); + +}))); diff --git a/test/function/samples/conflicting-reexports/namespace-import/first.js b/test/function/samples/conflicting-reexports/namespace-import/first.js new file mode 100644 index 00000000000..572a5ca84a0 --- /dev/null +++ b/test/function/samples/conflicting-reexports/namespace-import/first.js @@ -0,0 +1,2 @@ +export const foo = 1; +export const bar = 1; diff --git a/test/function/samples/conflicting-reexports/namespace-import/main.js b/test/function/samples/conflicting-reexports/namespace-import/main.js new file mode 100644 index 00000000000..dbee2dc6cd6 --- /dev/null +++ b/test/function/samples/conflicting-reexports/namespace-import/main.js @@ -0,0 +1,4 @@ +import * as ns from './reexport.js'; + +assert.deepStrictEqual(ns, { __proto__: null, bar: 1, baz: 2 }); +assert.strictEqual(ns.foo, undefined) \ No newline at end of file diff --git a/test/function/samples/conflicting-reexports/namespace-import/reexport.js b/test/function/samples/conflicting-reexports/namespace-import/reexport.js new file mode 100644 index 00000000000..7216b37efc0 --- /dev/null +++ b/test/function/samples/conflicting-reexports/namespace-import/reexport.js @@ -0,0 +1,2 @@ +export * from './first.js'; +export * from './second.js'; diff --git a/test/function/samples/conflicting-reexports/namespace-import/second.js b/test/function/samples/conflicting-reexports/namespace-import/second.js new file mode 100644 index 00000000000..2a2835dba0f --- /dev/null +++ b/test/function/samples/conflicting-reexports/namespace-import/second.js @@ -0,0 +1,2 @@ +export const foo = 2; +export const baz = 2; diff --git a/test/function/samples/conflicting-reexports/same-binding/_config.js b/test/function/samples/conflicting-reexports/same-binding/_config.js new file mode 100644 index 00000000000..3f46afb5feb --- /dev/null +++ b/test/function/samples/conflicting-reexports/same-binding/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'does not fail when the same binding is reexported from different files' +}; diff --git a/test/function/samples/conflicting-reexports/same-binding/_expected/amd.js b/test/function/samples/conflicting-reexports/same-binding/_expected/amd.js new file mode 100644 index 00000000000..51db3c2f884 --- /dev/null +++ b/test/function/samples/conflicting-reexports/same-binding/_expected/amd.js @@ -0,0 +1,29 @@ +define(['exports', 'external'], function (exports, external) { 'use strict'; + + const renamedIndirectOverride = external.indirectOverride; + + Object.defineProperty(exports, 'noOverride', { + enumerable: true, + get: function () { + return external.noOverride; + } + }); + Object.defineProperty(exports, 'renamedDirectOverride', { + enumerable: true, + get: function () { + return external.directOverride; + } + }); + exports.renamedIndirectOverride = renamedIndirectOverride; + Object.keys(external).forEach(function (k) { + if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, { + enumerable: true, + get: function () { + return external[k]; + } + }); + }); + + Object.defineProperty(exports, '__esModule', { value: true }); + +}); diff --git a/test/function/samples/conflicting-reexports/same-binding/_expected/cjs.js b/test/function/samples/conflicting-reexports/same-binding/_expected/cjs.js new file mode 100644 index 00000000000..a418ea4d048 --- /dev/null +++ b/test/function/samples/conflicting-reexports/same-binding/_expected/cjs.js @@ -0,0 +1,29 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +var external = require('external'); + +const renamedIndirectOverride = external.indirectOverride; + +Object.defineProperty(exports, 'noOverride', { + enumerable: true, + get: function () { + return external.noOverride; + } +}); +Object.defineProperty(exports, 'renamedDirectOverride', { + enumerable: true, + get: function () { + return external.directOverride; + } +}); +exports.renamedIndirectOverride = renamedIndirectOverride; +Object.keys(external).forEach(function (k) { + if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, { + enumerable: true, + get: function () { + return external[k]; + } + }); +}); diff --git a/test/function/samples/conflicting-reexports/same-binding/_expected/es.js b/test/function/samples/conflicting-reexports/same-binding/_expected/es.js new file mode 100644 index 00000000000..0ee20f7e12a --- /dev/null +++ b/test/function/samples/conflicting-reexports/same-binding/_expected/es.js @@ -0,0 +1,7 @@ +import { indirectOverride } from 'external'; +export * from 'external'; +export { noOverride, directOverride as renamedDirectOverride } from 'external'; + +const renamedIndirectOverride = indirectOverride; + +export { renamedIndirectOverride }; diff --git a/test/function/samples/conflicting-reexports/same-binding/_expected/iife.js b/test/function/samples/conflicting-reexports/same-binding/_expected/iife.js new file mode 100644 index 00000000000..d0a35613f05 --- /dev/null +++ b/test/function/samples/conflicting-reexports/same-binding/_expected/iife.js @@ -0,0 +1,32 @@ +var bundle = (function (exports, external) { + 'use strict'; + + const renamedIndirectOverride = external.indirectOverride; + + Object.defineProperty(exports, 'noOverride', { + enumerable: true, + get: function () { + return external.noOverride; + } + }); + Object.defineProperty(exports, 'renamedDirectOverride', { + enumerable: true, + get: function () { + return external.directOverride; + } + }); + exports.renamedIndirectOverride = renamedIndirectOverride; + Object.keys(external).forEach(function (k) { + if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, { + enumerable: true, + get: function () { + return external[k]; + } + }); + }); + + Object.defineProperty(exports, '__esModule', { value: true }); + + return exports; + +}({}, external)); diff --git a/test/function/samples/conflicting-reexports/same-binding/_expected/system.js b/test/function/samples/conflicting-reexports/same-binding/_expected/system.js new file mode 100644 index 00000000000..03a96a02255 --- /dev/null +++ b/test/function/samples/conflicting-reexports/same-binding/_expected/system.js @@ -0,0 +1,22 @@ +System.register('bundle', ['external'], function (exports) { + 'use strict'; + var _starExcludes = { renamedIndirectOverride: 1, default: 1, noOverride: 1, renamedDirectOverride: 1 }; + var indirectOverride; + return { + setters: [function (module) { + indirectOverride = module.indirectOverride; + var _setter = {}; + for (var _$p in module) { + if (!_starExcludes[_$p]) _setter[_$p] = module[_$p]; + } + _setter.noOverride = module.noOverride; + _setter.renamedDirectOverride = module.directOverride; + exports(_setter); + }], + execute: function () { + + const renamedIndirectOverride = exports('renamedIndirectOverride', indirectOverride); + + } + }; +}); diff --git a/test/function/samples/conflicting-reexports/same-binding/_expected/umd.js b/test/function/samples/conflicting-reexports/same-binding/_expected/umd.js new file mode 100644 index 00000000000..45efa714a1e --- /dev/null +++ b/test/function/samples/conflicting-reexports/same-binding/_expected/umd.js @@ -0,0 +1,33 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('external')) : + typeof define === 'function' && define.amd ? define(['exports', 'external'], factory) : + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.bundle = {}, global.external)); +}(this, (function (exports, external) { 'use strict'; + + const renamedIndirectOverride = external.indirectOverride; + + Object.defineProperty(exports, 'noOverride', { + enumerable: true, + get: function () { + return external.noOverride; + } + }); + Object.defineProperty(exports, 'renamedDirectOverride', { + enumerable: true, + get: function () { + return external.directOverride; + } + }); + exports.renamedIndirectOverride = renamedIndirectOverride; + Object.keys(external).forEach(function (k) { + if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, { + enumerable: true, + get: function () { + return external[k]; + } + }); + }); + + Object.defineProperty(exports, '__esModule', { value: true }); + +}))); diff --git a/test/function/samples/conflicting-reexports/same-binding/first.js b/test/function/samples/conflicting-reexports/same-binding/first.js new file mode 100644 index 00000000000..1fd2a2d127f --- /dev/null +++ b/test/function/samples/conflicting-reexports/same-binding/first.js @@ -0,0 +1 @@ +export { foo } from './shared.js'; diff --git a/test/function/samples/conflicting-reexports/same-binding/main.js b/test/function/samples/conflicting-reexports/same-binding/main.js new file mode 100644 index 00000000000..38098ddc140 --- /dev/null +++ b/test/function/samples/conflicting-reexports/same-binding/main.js @@ -0,0 +1,3 @@ +import { foo } from './reexport.js'; + +assert.strictEqual(foo, 1); diff --git a/test/function/samples/conflicting-reexports/same-binding/reexport.js b/test/function/samples/conflicting-reexports/same-binding/reexport.js new file mode 100644 index 00000000000..7216b37efc0 --- /dev/null +++ b/test/function/samples/conflicting-reexports/same-binding/reexport.js @@ -0,0 +1,2 @@ +export * from './first.js'; +export * from './second.js'; diff --git a/test/function/samples/conflicting-reexports/same-binding/second.js b/test/function/samples/conflicting-reexports/same-binding/second.js new file mode 100644 index 00000000000..1fd2a2d127f --- /dev/null +++ b/test/function/samples/conflicting-reexports/same-binding/second.js @@ -0,0 +1 @@ +export { foo } from './shared.js'; diff --git a/test/function/samples/conflicting-reexports/same-binding/shared.js b/test/function/samples/conflicting-reexports/same-binding/shared.js new file mode 100644 index 00000000000..bb1843d113a --- /dev/null +++ b/test/function/samples/conflicting-reexports/same-binding/shared.js @@ -0,0 +1 @@ +export const foo = 1; diff --git a/test/function/samples/unused-import/_config.js b/test/function/samples/unused-import/_config.js index 2961ff4fe62..60d328da78d 100644 --- a/test/function/samples/unused-import/_config.js +++ b/test/function/samples/unused-import/_config.js @@ -15,10 +15,8 @@ module.exports = { code: 'UNUSED_EXTERNAL_IMPORT', source: 'external', names: ['notused', 'neverused'], - message: `'notused' and 'neverused' are imported from external module 'external' but never used in\n\t${path.resolve(__dirname, './main.js')};`, - sources: [ - path.resolve(__dirname, './main.js') - ] + message: `"notused" and "neverused" are imported from external module "external" but never used in "main.js".`, + sources: [path.resolve(__dirname, './main.js')] } ] }; diff --git a/test/function/samples/warn-on-namespace-conflict/_config.js b/test/function/samples/warn-on-namespace-conflict/_config.js index 78cd978cddf..bf046da2768 100644 --- a/test/function/samples/warn-on-namespace-conflict/_config.js +++ b/test/function/samples/warn-on-namespace-conflict/_config.js @@ -8,7 +8,7 @@ module.exports = { name: 'foo', reexporter: path.join(__dirname, 'main.js'), sources: [path.join(__dirname, 'foo.js'), path.join(__dirname, 'deep.js')], - message: `Conflicting namespaces: main.js re-exports 'foo' from both foo.js and deep.js (will be ignored)` + message: `Conflicting namespaces: "main.js" re-exports "foo" from both "foo.js" and "deep.js" (will be ignored)` } ] }; diff --git a/test/function/samples/warn-on-namespace-conflict/main.js b/test/function/samples/warn-on-namespace-conflict/main.js index ae6aade26bd..853b4be0f64 100644 --- a/test/function/samples/warn-on-namespace-conflict/main.js +++ b/test/function/samples/warn-on-namespace-conflict/main.js @@ -1,2 +1,3 @@ export * from './foo.js'; -export * from './bar.js'; \ No newline at end of file +export * from './bar.js'; +export const retained = 1; \ No newline at end of file diff --git a/test/misc/misc.js b/test/misc/misc.js index 347cd46f3f5..313811cfea2 100644 --- a/test/misc/misc.js +++ b/test/misc/misc.js @@ -49,7 +49,7 @@ describe('misc', () => { assert.equal(relevantWarnings.length, 1); assert.equal( relevantWarnings[0].message, - `Creating a browser bundle that depends on Node.js built-in module ('util'). You might need to include https://github.com/ionic-team/rollup-plugin-node-polyfills` + `Creating a browser bundle that depends on Node.js built-in modules ("util"). You might need to include https://github.com/ionic-team/rollup-plugin-node-polyfills` ); }); });