From 19a772797d52cfa65f61d2c1835c8f4c2ba31f94 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Sun, 17 Feb 2019 09:20:55 +0100 Subject: [PATCH] Reimplement variable deconflicting logic (#2689) * Refactor scope structure * Initial draft for new deconflicting solution with variable access tracking * Slightly improve some names * Deconflict CJS interop function * Cache findVariable via accessedOutsideVariables * Get rid of unnecessary parameter and improve name * Use objects instead of Sets to track used names * Only track global outside variables on module scopes, re-unify external variable handling with other import handling * Move warning about missing exports into Graph * Test variables are no longer needlessly deconflicted due to globals in other chunks * Use tree-shaking information when deconflicting * Deconflict build-in names, resolves #2680 * Make sure it resolves #2683 * Clean up chunk deconflicting code * Change priorities so that chunk variable names take precedence over imported variable names * Fix acorn import fix --- rollup.config.js | 2 +- src/Chunk.ts | 148 ++++-------------- src/Graph.ts | 31 +++- src/Module.ts | 2 +- src/ast/nodes/BlockStatement.ts | 3 +- src/ast/nodes/ClassDeclaration.ts | 9 +- src/ast/nodes/ExportDefaultDeclaration.ts | 2 + src/ast/nodes/FunctionDeclaration.ts | 9 +- src/ast/nodes/MemberExpression.ts | 9 ++ src/ast/nodes/ObjectExpression.ts | 3 +- src/ast/nodes/ThisExpression.ts | 4 +- src/ast/nodes/VariableDeclaration.ts | 7 +- src/ast/nodes/shared/ClassNode.ts | 3 +- src/ast/nodes/shared/Node.ts | 8 +- src/ast/nodes/shared/pureFunctions.ts | 4 +- src/ast/scopes/BlockScope.ts | 6 +- src/ast/scopes/ChildScope.ts | 62 ++++++++ src/ast/scopes/FunctionScope.ts | 4 +- src/ast/scopes/GlobalScope.ts | 7 +- src/ast/scopes/ModuleScope.ts | 93 +++++------ src/ast/scopes/ParameterScope.ts | 8 +- src/ast/scopes/Scope.ts | 63 +------- src/ast/variables/ExportDefaultVariable.ts | 28 +++- src/ast/variables/GlobalVariable.ts | 2 - src/ast/variables/Variable.ts | 32 ++-- src/finalisers/cjs.ts | 13 +- src/utils/base64.ts | 4 +- src/utils/deconflictChunk.ts | 143 +++++++++++++++++ src/utils/pluginDriver.ts | 3 +- src/utils/reservedNames.ts | 73 +++++++++ src/utils/safeName.ts | 12 ++ ...itize-file-name.ts => sanitizeFileName.ts} | 0 src/utils/traverseStaticDependencies.ts | 3 +- src/utils/variableNames.ts | 1 + .../basic-chunking/_expected/es/main1.js | 6 +- .../basic-chunking/_expected/es/main2.js | 10 +- .../basic-chunking/_expected/system/main1.js | 8 +- .../basic-chunking/_expected/system/main2.js | 12 +- .../_expected/es/generated-chunk2.js | 10 +- .../_expected/system/generated-chunk2.js | 10 +- .../_expected/amd/generated-chunk.js | 4 +- .../_expected/cjs/generated-chunk.js | 4 +- .../_expected/es/generated-chunk.js | 4 +- .../_expected/system/generated-chunk.js | 4 +- .../_expected/es/main1.js | 4 +- .../_expected/system/main1.js | 4 +- .../_expected/es/main1.js | 2 +- .../_expected/es/main2.js | 2 +- .../_expected/system/main1.js | 2 +- .../_expected/system/main2.js | 2 +- .../chunking-compact/_expected/es/main1.js | 4 +- .../chunking-compact/_expected/es/main2.js | 8 +- .../_expected/system/main1.js | 4 +- .../_expected/system/main2.js | 8 +- .../chunking-externals/_expected/es/main1.js | 6 +- .../chunking-externals/_expected/es/main2.js | 14 +- .../_expected/system/main1.js | 8 +- .../_expected/system/main2.js | 16 +- .../_expected/es/main1.js | 6 +- .../_expected/es/main1.js.map | 2 +- .../_expected/es/main2.js | 10 +- .../_expected/es/main2.js.map | 2 +- .../_expected/system/main1.js | 8 +- .../_expected/system/main1.js.map | 2 +- .../_expected/system/main2.js | 12 +- .../_expected/system/main2.js.map | 2 +- .../_expected/es/main1.js | 10 +- .../_expected/es/main2.js | 10 +- .../_expected/system/main1.js | 10 +- .../_expected/system/main2.js | 10 +- .../samples/deconflict-globals/_config.js | 6 + .../_expected/amd/generated-chunk.js | 7 + .../deconflict-globals/_expected/amd/main1.js | 5 + .../deconflict-globals/_expected/amd/main2.js | 5 + .../_expected/cjs/generated-chunk.js | 5 + .../deconflict-globals/_expected/cjs/main1.js | 5 + .../deconflict-globals/_expected/cjs/main2.js | 5 + .../_expected/es/generated-chunk.js | 3 + .../deconflict-globals/_expected/es/main1.js | 3 + .../deconflict-globals/_expected/es/main2.js | 3 + .../_expected/system/generated-chunk.js | 10 ++ .../_expected/system/main1.js | 14 ++ .../_expected/system/main2.js | 14 ++ .../samples/deconflict-globals/dep.js | 1 + .../samples/deconflict-globals/main1.js | 3 + .../samples/deconflict-globals/main2.js | 3 + .../_expected/es/main1.js | 2 +- .../_expected/es/main2.js | 2 +- .../_expected/system/main1.js | 2 +- .../_expected/system/main2.js | 2 +- .../_expected/es/generated-deps2and3.js | 14 +- .../manual-chunks/_expected/es/main.js | 6 +- .../_expected/system/generated-deps2and3.js | 18 +-- .../manual-chunks/_expected/system/main.js | 10 +- .../_expected/es/main.js | 4 +- .../_expected/system/main.js | 4 +- .../_expected/es/main.js | 6 +- .../_expected/system/main.js | 10 +- .../missing-export/_expected/es/main.js | 6 +- .../missing-export/_expected/system/main.js | 8 +- .../_expected/amd/generated-index.js | 10 +- .../_expected/amd/index.js | 4 +- .../namespace-reexports/_expected/amd/main.js | 4 +- .../_expected/cjs/generated-index.js | 10 +- .../_expected/cjs/index.js | 4 +- .../namespace-reexports/_expected/cjs/main.js | 4 +- .../_expected/es/generated-index.js | 8 +- .../_expected/system/generated-index.js | 10 +- .../_expected/es/deps/dep2.js | 8 +- .../_expected/es/deps/dep3.js | 8 +- .../_expected/system/deps/dep2.js | 10 +- .../_expected/system/deps/dep3.js | 10 +- .../{_expected/es.js => _expected.js} | 4 +- .../_expected/amd.js | 17 -- .../_expected/cjs.js | 15 -- .../_expected/iife.js | 18 --- .../_expected/system.js | 20 --- test/form/samples/compact/_config.js | 1 + test/form/samples/compact/_expected/amd.js | 6 +- test/form/samples/compact/_expected/cjs.js | 6 +- test/form/samples/compact/_expected/es.js | 6 +- test/form/samples/compact/_expected/iife.js | 6 +- test/form/samples/compact/_expected/system.js | 6 +- test/form/samples/compact/_expected/umd.js | 6 +- .../_config.js | 4 + .../_expected/amd.js | 29 ++++ .../_expected/cjs.js | 27 ++++ .../_expected/es.js | 25 +++ .../_expected/iife.js | 30 ++++ .../_expected/system.js | 32 ++++ .../_expected/umd.js | 28 +++- .../main.js | 23 +++ .../_config.js | 4 + .../_expected/amd.js | 8 + .../_expected/cjs.js | 8 + .../_expected/es.js | 4 + .../_expected/iife.js | 9 ++ .../_expected/system.js | 15 ++ .../_expected/umd.js | 12 ++ .../main.js | 4 + .../_config.js | 4 + .../_expected/amd.js | 12 ++ .../_expected/cjs.js | 10 ++ .../_expected/es.js | 8 + .../_expected/iife.js | 13 ++ .../_expected/system.js | 15 ++ .../_expected/umd.js | 16 ++ .../deconflict-format-specific-module/main.js | 6 + .../deconflict-nested-tree-shaking/_config.js | 3 + .../_expected.js | 11 ++ .../deconflict-nested-tree-shaking/dep.js | 1 + .../deconflict-nested-tree-shaking/main.js | 16 ++ .../deconflict-reserved-words/_config.js | 4 + .../deconflict-reserved-words/_expected.js | 47 ++++++ .../samples/deconflict-reserved-words/main.js | 47 ++++++ .../deconflict-tree-shaken-globals/_config.js | 3 + .../_expected.js | 2 + .../deconflict-tree-shaken-globals/main.js | 4 + .../deconflict-tree-shaken-globals/other.js | 3 + .../samples/deconflict-tree-shaken/_config.js | 3 + .../deconflict-tree-shaken/_expected.js | 5 + .../samples/deconflict-tree-shaken/dep1.js | 2 + .../samples/deconflict-tree-shaken/dep2.js | 1 + .../samples/deconflict-tree-shaken/dep3.js | 1 + .../samples/deconflict-tree-shaken/main.js | 6 + test/form/samples/export-globals/main.js | 2 +- .../samples/external-deshadowing/_config.js | 1 + .../external-deshadowing/_expected/amd.js | 10 +- .../external-deshadowing/_expected/cjs.js | 8 +- .../external-deshadowing/_expected/es.js | 12 +- .../external-deshadowing/_expected/iife.js | 12 +- .../external-deshadowing/_expected/system.js | 12 +- .../external-deshadowing/_expected/umd.js | 12 +- .../_expected/es.js | 8 +- .../_expected/system.js | 10 +- .../_expected/es.js | 12 +- .../_expected/system.js | 12 +- .../form/samples/large-var-cnt-deduping/64.js | 4 +- .../form/samples/large-var-cnt-deduping/65.js | 3 + .../large-var-cnt-deduping/_expected.js | 11 +- .../samples/large-var-cnt-deduping/main.js | 137 ++++++++-------- .../namespace-self-import/_expected/amd.js | 6 +- .../namespace-self-import/_expected/cjs.js | 6 +- .../namespace-self-import/_expected/es.js | 6 +- .../namespace-self-import/_expected/iife.js | 6 +- .../namespace-self-import/_expected/system.js | 4 +- .../namespace-self-import/_expected/umd.js | 6 +- .../namespace-tostringtag/_expected/amd.js | 6 +- .../namespace-tostringtag/_expected/cjs.js | 6 +- .../namespace-tostringtag/_expected/es.js | 6 +- .../namespace-tostringtag/_expected/iife.js | 6 +- .../namespace-tostringtag/_expected/system.js | 4 +- .../namespace-tostringtag/_expected/umd.js | 6 +- .../reexport-star-deshadow/_expected/amd.js | 2 +- .../reexport-star-deshadow/_expected/cjs.js | 2 +- .../reexport-star-deshadow/_expected/es.js | 2 +- .../reexport-star-deshadow/_expected/iife.js | 2 +- .../_expected/system.js | 2 +- .../reexport-star-deshadow/_expected/umd.js | 2 +- .../sequence-expression/_expected/amd.js | 6 +- .../sequence-expression/_expected/es.js | 6 +- .../sequence-expression/_expected/iife.js | 6 +- .../sequence-expression/_expected/system.js | 6 +- .../sequence-expression/_expected/umd.js | 6 +- test/function/samples/allow-reserved/main.js | 6 +- .../samples/consistent-renaming-f/main.js | 11 +- .../deconflict-deconflicted/_config.js | 3 + .../samples/deconflict-deconflicted/dep.js | 5 + .../samples/deconflict-deconflicted/main.js | 3 + .../samples/deconflicts-exports-2/_config.js | 8 + .../samples/deconflicts-exports-2/main.js | 15 ++ .../samples/deconflicts-exports-3/_config.js | 8 + .../samples/deconflicts-exports-3/main.js | 7 + .../samples/deconflicts-exports/_config.js | 2 +- .../samples/deconflicts-interop/_config.js | 13 ++ .../samples/deconflicts-interop/main.js | 5 + .../deshadow-respect-existing/_config.js | 8 + .../samples/deshadow-respect-existing/dep.js | 1 + .../samples/deshadow-respect-existing/main.js | 9 ++ .../namespace-missing-export/_config.js | 1 + 220 files changed, 1598 insertions(+), 816 deletions(-) create mode 100644 src/ast/scopes/ChildScope.ts create mode 100644 src/utils/deconflictChunk.ts create mode 100644 src/utils/reservedNames.ts create mode 100644 src/utils/safeName.ts rename src/utils/{sanitize-file-name.ts => sanitizeFileName.ts} (100%) create mode 100644 test/chunking-form/samples/deconflict-globals/_config.js create mode 100644 test/chunking-form/samples/deconflict-globals/_expected/amd/generated-chunk.js create mode 100644 test/chunking-form/samples/deconflict-globals/_expected/amd/main1.js create mode 100644 test/chunking-form/samples/deconflict-globals/_expected/amd/main2.js create mode 100644 test/chunking-form/samples/deconflict-globals/_expected/cjs/generated-chunk.js create mode 100644 test/chunking-form/samples/deconflict-globals/_expected/cjs/main1.js create mode 100644 test/chunking-form/samples/deconflict-globals/_expected/cjs/main2.js create mode 100644 test/chunking-form/samples/deconflict-globals/_expected/es/generated-chunk.js create mode 100644 test/chunking-form/samples/deconflict-globals/_expected/es/main1.js create mode 100644 test/chunking-form/samples/deconflict-globals/_expected/es/main2.js create mode 100644 test/chunking-form/samples/deconflict-globals/_expected/system/generated-chunk.js create mode 100644 test/chunking-form/samples/deconflict-globals/_expected/system/main1.js create mode 100644 test/chunking-form/samples/deconflict-globals/_expected/system/main2.js create mode 100644 test/chunking-form/samples/deconflict-globals/dep.js create mode 100644 test/chunking-form/samples/deconflict-globals/main1.js create mode 100644 test/chunking-form/samples/deconflict-globals/main2.js rename test/form/samples/catch-parameter-shadowing/{_expected/es.js => _expected.js} (54%) delete mode 100644 test/form/samples/catch-parameter-shadowing/_expected/amd.js delete mode 100644 test/form/samples/catch-parameter-shadowing/_expected/cjs.js delete mode 100644 test/form/samples/catch-parameter-shadowing/_expected/iife.js delete mode 100644 test/form/samples/catch-parameter-shadowing/_expected/system.js create mode 100644 test/form/samples/deconflict-format-specific-exports/_config.js create mode 100644 test/form/samples/deconflict-format-specific-exports/_expected/amd.js create mode 100644 test/form/samples/deconflict-format-specific-exports/_expected/cjs.js create mode 100644 test/form/samples/deconflict-format-specific-exports/_expected/es.js create mode 100644 test/form/samples/deconflict-format-specific-exports/_expected/iife.js create mode 100644 test/form/samples/deconflict-format-specific-exports/_expected/system.js rename test/form/samples/{catch-parameter-shadowing => deconflict-format-specific-exports}/_expected/umd.js (53%) create mode 100644 test/form/samples/deconflict-format-specific-exports/main.js create mode 100644 test/form/samples/deconflict-format-specific-interop/_config.js create mode 100644 test/form/samples/deconflict-format-specific-interop/_expected/amd.js create mode 100644 test/form/samples/deconflict-format-specific-interop/_expected/cjs.js create mode 100644 test/form/samples/deconflict-format-specific-interop/_expected/es.js create mode 100644 test/form/samples/deconflict-format-specific-interop/_expected/iife.js create mode 100644 test/form/samples/deconflict-format-specific-interop/_expected/system.js create mode 100644 test/form/samples/deconflict-format-specific-interop/_expected/umd.js create mode 100644 test/form/samples/deconflict-format-specific-interop/main.js create mode 100644 test/form/samples/deconflict-format-specific-module/_config.js create mode 100644 test/form/samples/deconflict-format-specific-module/_expected/amd.js create mode 100644 test/form/samples/deconflict-format-specific-module/_expected/cjs.js create mode 100644 test/form/samples/deconflict-format-specific-module/_expected/es.js create mode 100644 test/form/samples/deconflict-format-specific-module/_expected/iife.js create mode 100644 test/form/samples/deconflict-format-specific-module/_expected/system.js create mode 100644 test/form/samples/deconflict-format-specific-module/_expected/umd.js create mode 100644 test/form/samples/deconflict-format-specific-module/main.js create mode 100644 test/form/samples/deconflict-nested-tree-shaking/_config.js create mode 100644 test/form/samples/deconflict-nested-tree-shaking/_expected.js create mode 100644 test/form/samples/deconflict-nested-tree-shaking/dep.js create mode 100644 test/form/samples/deconflict-nested-tree-shaking/main.js create mode 100644 test/form/samples/deconflict-reserved-words/_config.js create mode 100644 test/form/samples/deconflict-reserved-words/_expected.js create mode 100644 test/form/samples/deconflict-reserved-words/main.js create mode 100644 test/form/samples/deconflict-tree-shaken-globals/_config.js create mode 100644 test/form/samples/deconflict-tree-shaken-globals/_expected.js create mode 100644 test/form/samples/deconflict-tree-shaken-globals/main.js create mode 100644 test/form/samples/deconflict-tree-shaken-globals/other.js create mode 100644 test/form/samples/deconflict-tree-shaken/_config.js create mode 100644 test/form/samples/deconflict-tree-shaken/_expected.js create mode 100644 test/form/samples/deconflict-tree-shaken/dep1.js create mode 100644 test/form/samples/deconflict-tree-shaken/dep2.js create mode 100644 test/form/samples/deconflict-tree-shaken/dep3.js create mode 100644 test/form/samples/deconflict-tree-shaken/main.js create mode 100644 test/form/samples/large-var-cnt-deduping/65.js create mode 100644 test/function/samples/deconflict-deconflicted/_config.js create mode 100644 test/function/samples/deconflict-deconflicted/dep.js create mode 100644 test/function/samples/deconflict-deconflicted/main.js create mode 100644 test/function/samples/deconflicts-exports-2/_config.js create mode 100644 test/function/samples/deconflicts-exports-2/main.js create mode 100644 test/function/samples/deconflicts-exports-3/_config.js create mode 100644 test/function/samples/deconflicts-exports-3/main.js create mode 100644 test/function/samples/deconflicts-interop/_config.js create mode 100644 test/function/samples/deconflicts-interop/main.js create mode 100644 test/function/samples/deshadow-respect-existing/_config.js create mode 100644 test/function/samples/deshadow-respect-existing/dep.js create mode 100644 test/function/samples/deshadow-respect-existing/main.js diff --git a/rollup.config.js b/rollup.config.js index de038a13457..cf36bda461f 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -40,7 +40,7 @@ const onwarn = warning => { throw new Error(warning.message); }; -const expectedAcornImport = "import acorn__default, { tokTypes, Parser } from 'acorn';"; +const expectedAcornImport = /import acorn__default, { tokTypes, Parser( as [\w$]+)? } from 'acorn';/; const newAcornImport = "import * as acorn__default from 'acorn';\nimport { tokTypes, Parser } from 'acorn';"; diff --git a/src/Chunk.ts b/src/Chunk.ts index 8f406deb579..ca2f101b335 100644 --- a/src/Chunk.ts +++ b/src/Chunk.ts @@ -22,6 +22,7 @@ import { import { Addons } from './utils/addons'; import { toBase64 } from './utils/base64'; import collapseSourcemaps from './utils/collapseSourcemaps'; +import { deconflictChunk } from './utils/deconflictChunk'; import { error } from './utils/error'; import { sortByExecutionOrder } from './utils/executionOrder'; import getIndentString from './utils/getIndentString'; @@ -30,7 +31,7 @@ import { basename, dirname, isAbsolute, normalize, relative, resolve } from './u import renderChunk from './utils/renderChunk'; import { RenderOptions } from './utils/renderHelpers'; import { makeUnique, renderNamePattern } from './utils/renderNamePattern'; -import { sanitizeFileName } from './utils/sanitize-file-name'; +import { sanitizeFileName } from './utils/sanitizeFileName'; import { timeEnd, timeStart } from './utils/timers'; import { MISSING_EXPORT_SHIM_VARIABLE } from './utils/variableNames'; @@ -410,126 +411,41 @@ export default class Chunk { } private setIdentifierRenderResolutions(options: OutputOptions) { - this.needsExportsShim = false; - const used = Object.create(null); - const esm = options.format === 'es' || options.format === 'system'; - - // ensure no conflicts with globals - Object.keys(this.graph.scope.variables).forEach(name => (used[name] = 1)); - - function getSafeName(name: string): string { - let safeName = name; - while (used[safeName]) { - safeName = `${name}$${toBase64(used[name]++, true)}`; - } - used[safeName] = 1; - return safeName; - } - - // reserved internal binding names for system format wiring - if (options.format === 'system') { - used._setter = used._starExcludes = used._$p = 1; - } - - const toDeshadow: Set = new Set(); - - if (!esm) { - this.dependencies.forEach(module => { - const safeName = getSafeName(module.variableName); - toDeshadow.add(safeName); - module.variableName = safeName; - }); - } - for (const exportName of Object.keys(this.exportNames)) { const exportVariable = this.exportNames[exportName]; - if (exportVariable instanceof ExportShimVariable) this.needsExportsShim = true; - if (exportVariable && exportVariable.exportName !== exportName) { - exportVariable.exportName = exportName; - } - } - - for (const variable of Array.from(this.imports)) { - let safeName; - - if (variable.module instanceof ExternalModule) { - if (variable.name === '*') { - safeName = variable.module.variableName; - } else if (variable.name === 'default') { - if ( - options.interop !== false && - (variable.module.exportsNamespace || (!esm && variable.module.exportsNames)) - ) { - safeName = `${variable.module.variableName}__default`; - } else { - safeName = variable.module.variableName; - } - } else { - safeName = esm ? variable.name : `${variable.module.variableName}.${variable.name}`; + if (exportVariable) { + if (exportVariable instanceof ExportShimVariable) { + this.needsExportsShim = true; } - if (esm) { - safeName = getSafeName(safeName); - toDeshadow.add(safeName); - } - } else if (esm) { - safeName = getSafeName(variable.name); - toDeshadow.add(safeName); - } else { - const chunk = variable.module.chunk; + exportVariable.exportName = exportName; if ( - chunk.exportMode === 'default' || - (this.graph.preserveModules && variable.isNamespace) + options.format !== 'es' && + options.format !== 'system' && + exportVariable.isReassigned && + !exportVariable.isId && + (!isExportDefaultVariable(exportVariable) || !exportVariable.hasId) ) { - safeName = chunk.variableName; + exportVariable.setRenderNames('exports', exportName); } else { - safeName = `${chunk.variableName}.${variable.module.chunk.getVariableExportName( - variable - )}`; + exportVariable.setRenderNames(null, null); } } - if (safeName) variable.setSafeName(safeName); } - this.orderedModules.forEach(module => { - this.deconflictExportsOfModule(module, getSafeName, esm); - }); - - this.graph.scope.deshadow(toDeshadow, this.orderedModules.map(module => module.scope)); - } - - private deconflictExportsOfModule( - module: Module, - getSafeName: (name: string) => string, - esm: boolean - ) { - Object.keys(module.scope.variables).forEach(variableName => { - const variable = module.scope.variables[variableName]; - if (isExportDefaultVariable(variable) && variable.referencesOriginal()) { - variable.setSafeName(null); - return; - } - if (!(isExportDefaultVariable(variable) && variable.hasId)) { - let safeName; - if (esm || !variable.isReassigned || variable.isId) { - safeName = getSafeName(variable.name); - } else { - const safeExportName = variable.exportName; - if (safeExportName) { - safeName = `exports.${safeExportName}`; - } else { - safeName = getSafeName(variable.name); - } - } - variable.setSafeName(safeName); - } - }); - module.exportShimVariable.setSafeName(null); - - // deconflict reified namespaces - const namespace = module.getOrCreateNamespace(); - if (namespace.included) { - namespace.setSafeName(getSafeName(namespace.name)); + const usedNames = Object.create(null); + if (this.needsExportsShim) { + usedNames[MISSING_EXPORT_SHIM_VARIABLE] = true; } + + deconflictChunk( + this.orderedModules, + this.dependencies, + this.imports, + usedNames, + options.format, + options.interop !== false, + this.graph.preserveModules + ); } private getChunkDependencyDeclarations( @@ -573,13 +489,11 @@ export default class Chunk { if (importsFromDependency.length) { imports = []; for (const variable of importsFromDependency) { - const local = variable.safeName || variable.name; - let imported; - if (variable.module instanceof ExternalModule) { - imported = variable.name; - } else { - imported = variable.module.chunk.getVariableExportName(variable); - } + const local = variable.getName(); + const imported = + variable.module instanceof ExternalModule + ? variable.name + : variable.module.chunk.getVariableExportName(variable); imports.push({ local, imported }); } } diff --git a/src/Graph.ts b/src/Graph.ts index b0268cbdaa0..542db768fb9 100644 --- a/src/Graph.ts +++ b/src/Graph.ts @@ -31,7 +31,6 @@ import { createPluginDriver, PluginDriver } from './utils/pluginDriver'; import relativeId, { getAliasName } from './utils/relativeId'; import { timeEnd, timeStart } from './utils/timers'; import transform from './utils/transform'; -import { MISSING_EXPORT_SHIM_VARIABLE } from './utils/variableNames'; function makeOnwarn() { const warned = Object.create(null); @@ -157,12 +156,7 @@ export default class Graph { } this.shimMissingExports = options.shimMissingExports; - this.scope = new GlobalScope(); - for (const name of ['module', 'exports', '_interopDefault', MISSING_EXPORT_SHIM_VARIABLE]) { - this.scope.findVariable(name); // creates global variable as side-effect - } - this.context = String(options.context); const optionsModuleContext = options.moduleContext; @@ -255,6 +249,31 @@ export default class Graph { for (const module of this.modules) { module.bindReferences(); } + this.warnForMissingExports(); + } + + private warnForMissingExports() { + for (const module of this.modules) { + for (const importName of Object.keys(module.importDescriptions)) { + const importDescription = module.importDescriptions[importName]; + if ( + importDescription.name !== '*' && + !importDescription.module.getVariableForExportName(importDescription.name) + ) { + module.warn( + { + code: 'NON_EXISTENT_EXPORT', + name: importDescription.name, + source: importDescription.module.id, + message: `Non-existent export '${ + importDescription.name + }' is imported from ${relativeId(importDescription.module.id)}` + }, + importDescription.start + ); + } + } + } } includeMarked(modules: Module[]) { diff --git a/src/Module.ts b/src/Module.ts index 282be81f9f1..775353fa1ef 100644 --- a/src/Module.ts +++ b/src/Module.ts @@ -751,7 +751,7 @@ export default class Module { } } - private warn(warning: RollupWarning, pos: number) { + warn(warning: RollupWarning, pos: number) { if (pos !== undefined) { warning.pos = pos; diff --git a/src/ast/nodes/BlockStatement.ts b/src/ast/nodes/BlockStatement.ts index c4fd9d0a2d7..bbe79d6a4ab 100644 --- a/src/ast/nodes/BlockStatement.ts +++ b/src/ast/nodes/BlockStatement.ts @@ -2,6 +2,7 @@ import MagicString from 'magic-string'; import { RenderOptions, renderStatementList } from '../../utils/renderHelpers'; import { ExecutionPathOptions } from '../ExecutionPathOptions'; import BlockScope from '../scopes/BlockScope'; +import ChildScope from '../scopes/ChildScope'; import Scope from '../scopes/Scope'; import { UNKNOWN_EXPRESSION } from '../values'; import * as NodeType from './NodeType'; @@ -24,7 +25,7 @@ export default class BlockStatement extends StatementBase { createScope(parentScope: Scope) { this.scope = (this.parent).preventChildBlockScope - ? parentScope + ? parentScope : new BlockScope(parentScope); } diff --git a/src/ast/nodes/ClassDeclaration.ts b/src/ast/nodes/ClassDeclaration.ts index a02318f04af..f7e485d8e63 100644 --- a/src/ast/nodes/ClassDeclaration.ts +++ b/src/ast/nodes/ClassDeclaration.ts @@ -1,5 +1,6 @@ import MagicString from 'magic-string'; import { RenderOptions } from '../../utils/renderHelpers'; +import ChildScope from '../scopes/ChildScope'; import Identifier from './Identifier'; import * as NodeType from './NodeType'; import ClassNode from './shared/ClassNode'; @@ -22,10 +23,10 @@ export default class ClassDeclaration extends ClassNode { parseNode(esTreeNode: GenericEsTreeNode) { if (esTreeNode.id !== null) { - this.id = new this.context.nodeConstructors.Identifier( - esTreeNode.id, - this, - this.scope.parent + this.id = ( + new this.context.nodeConstructors.Identifier(esTreeNode.id, this, ( + this.scope.parent + )) ); } super.parseNode(esTreeNode); diff --git a/src/ast/nodes/ExportDefaultDeclaration.ts b/src/ast/nodes/ExportDefaultDeclaration.ts index 47c205640bd..cc9ce573401 100644 --- a/src/ast/nodes/ExportDefaultDeclaration.ts +++ b/src/ast/nodes/ExportDefaultDeclaration.ts @@ -5,6 +5,7 @@ import { NodeRenderOptions, RenderOptions } from '../../utils/renderHelpers'; +import ModuleScope from '../scopes/ModuleScope'; import ExportDefaultVariable from '../variables/ExportDefaultVariable'; import ClassDeclaration, { isClassDeclaration } from './ClassDeclaration'; import FunctionDeclaration, { isFunctionDeclaration } from './FunctionDeclaration'; @@ -39,6 +40,7 @@ export function isExportDefaultDeclaration(node: Node): node is ExportDefaultDec export default class ExportDefaultDeclaration extends NodeBase { type: NodeType.tExportDefaultDeclaration; declaration: FunctionDeclaration | ClassDeclaration | ExpressionNode; + scope: ModuleScope; needsBoundaries: true; variable: ExportDefaultVariable; diff --git a/src/ast/nodes/FunctionDeclaration.ts b/src/ast/nodes/FunctionDeclaration.ts index 7a40fb04d7e..9eaf4488edd 100644 --- a/src/ast/nodes/FunctionDeclaration.ts +++ b/src/ast/nodes/FunctionDeclaration.ts @@ -1,3 +1,4 @@ +import ChildScope from '../scopes/ChildScope'; import Identifier from './Identifier'; import * as NodeType from './NodeType'; import FunctionNode from './shared/FunctionNode'; @@ -19,10 +20,10 @@ export default class FunctionDeclaration extends FunctionNode { parseNode(esTreeNode: GenericEsTreeNode) { if (esTreeNode.id !== null) { - this.id = new this.context.nodeConstructors.Identifier( - esTreeNode.id, - this, - this.scope.parent + this.id = ( + new this.context.nodeConstructors.Identifier(esTreeNode.id, this, ( + this.scope.parent + )) ); } super.parseNode(esTreeNode); diff --git a/src/ast/nodes/MemberExpression.ts b/src/ast/nodes/MemberExpression.ts index e494589b17e..57053a88093 100644 --- a/src/ast/nodes/MemberExpression.ts +++ b/src/ast/nodes/MemberExpression.ts @@ -60,6 +60,14 @@ function getPathIfNotComputed(memberExpression: MemberExpression): PathWithPosit return null; } +function getStringFromPath(path: PathWithPositions): string { + let pathString = path[0].key; + for (let index = 1; index < path.length; index++) { + pathString += '.' + path[index].key; + } + return pathString; +} + export function isMemberExpression(node: Node): node is MemberExpression { return node.type === NodeType.MemberExpression; } @@ -92,6 +100,7 @@ export default class MemberExpression extends NodeBase implements DeoptimizableE (resolvedVariable).module.suggestName(path[0].key); } this.variable = resolvedVariable; + this.scope.addNamespaceMemberAccess(getStringFromPath(path), resolvedVariable); } } else { super.bind(); diff --git a/src/ast/nodes/ObjectExpression.ts b/src/ast/nodes/ObjectExpression.ts index 2f6d7ff06e1..85732c33613 100644 --- a/src/ast/nodes/ObjectExpression.ts +++ b/src/ast/nodes/ObjectExpression.ts @@ -1,6 +1,7 @@ import MagicString from 'magic-string'; import { BLANK } from '../../utils/blank'; import { NodeRenderOptions, RenderOptions } from '../../utils/renderHelpers'; +import { NameCollection } from '../../utils/reservedNames'; import CallOptions from '../CallOptions'; import { DeoptimizableEntity } from '../DeoptimizableEntity'; import { ExecutionPathOptions } from '../ExecutionPathOptions'; @@ -45,7 +46,7 @@ export default class ObjectExpression extends NodeBase { private propertyMap: PropertyMap | null; private unmatchablePropertiesRead: (Property | SpreadElement)[] | null; private unmatchablePropertiesWrite: Property[] | null; - private deoptimizedPaths: { [key: string]: true }; + private deoptimizedPaths: NameCollection; private hasUnknownDeoptimizedProperty: boolean; private expressionsToBeDeoptimized: { [key: string]: DeoptimizableEntity[] }; diff --git a/src/ast/nodes/ThisExpression.ts b/src/ast/nodes/ThisExpression.ts index 1501e441f37..f14e95acb04 100644 --- a/src/ast/nodes/ThisExpression.ts +++ b/src/ast/nodes/ThisExpression.ts @@ -1,6 +1,7 @@ import MagicString from 'magic-string'; import { RenderOptions } from '../../utils/renderHelpers'; import { ExecutionPathOptions } from '../ExecutionPathOptions'; +import ModuleScope from '../scopes/ModuleScope'; import { ObjectPath } from '../values'; import ThisVariable from '../variables/ThisVariable'; import * as NodeType from './NodeType'; @@ -28,7 +29,8 @@ export default class ThisExpression extends NodeBase { initialise() { this.included = false; this.variable = null; - this.alias = this.scope.findLexicalBoundary().isModuleScope ? this.context.moduleContext : null; + this.alias = + this.scope.findLexicalBoundary() instanceof ModuleScope ? this.context.moduleContext : null; if (this.alias === 'undefined') { this.context.warn( { diff --git a/src/ast/nodes/VariableDeclaration.ts b/src/ast/nodes/VariableDeclaration.ts index 837f6b03a9f..3aa516c871f 100644 --- a/src/ast/nodes/VariableDeclaration.ts +++ b/src/ast/nodes/VariableDeclaration.ts @@ -15,12 +15,7 @@ import { NodeBase } from './shared/Node'; import VariableDeclarator from './VariableDeclarator'; function isReassignedExportsMember(variable: Variable): boolean { - return ( - variable.safeName && - variable.safeName.indexOf('.') !== -1 && - variable.exportName && - variable.isReassigned - ); + return variable.renderBaseName && variable.exportName && variable.isReassigned; } function areAllDeclarationsIncludedAndNotExported(declarations: VariableDeclarator[]): boolean { diff --git a/src/ast/nodes/shared/ClassNode.ts b/src/ast/nodes/shared/ClassNode.ts index 5605097fea7..9326642599c 100644 --- a/src/ast/nodes/shared/ClassNode.ts +++ b/src/ast/nodes/shared/ClassNode.ts @@ -1,5 +1,6 @@ import CallOptions from '../../CallOptions'; import { ExecutionPathOptions } from '../../ExecutionPathOptions'; +import ChildScope from '../../scopes/ChildScope'; import Scope from '../../scopes/Scope'; import { ObjectPath } from '../../values'; import ClassBody from '../ClassBody'; @@ -12,7 +13,7 @@ export default class ClassNode extends NodeBase { id: Identifier | null; createScope(parentScope: Scope) { - this.scope = new Scope(parentScope); + this.scope = new ChildScope(parentScope); } hasEffectsWhenAccessedAtPath(path: ObjectPath, _options: ExecutionPathOptions) { diff --git a/src/ast/nodes/shared/Node.ts b/src/ast/nodes/shared/Node.ts index b79725d3339..59c74fdf405 100644 --- a/src/ast/nodes/shared/Node.ts +++ b/src/ast/nodes/shared/Node.ts @@ -7,7 +7,7 @@ import { DeoptimizableEntity } from '../../DeoptimizableEntity'; import { Entity } from '../../Entity'; import { ExecutionPathOptions } from '../../ExecutionPathOptions'; import { getAndCreateKeys, keys } from '../../keys'; -import Scope from '../../scopes/Scope'; +import ChildScope from '../../scopes/ChildScope'; import { ImmutableEntityPathTracker } from '../../utils/ImmutableEntityPathTracker'; import { LiteralValueOrUnknown, ObjectPath, UNKNOWN_EXPRESSION, UNKNOWN_VALUE } from '../../values'; import Variable from '../../variables/Variable'; @@ -81,7 +81,7 @@ const NEW_EXECUTION_PATH = ExecutionPathOptions.create(); export class NodeBase implements ExpressionNode { type: string; keys: string[]; - scope: Scope; + scope: ChildScope; start: number; end: number; context: AstContext; @@ -92,7 +92,7 @@ export class NodeBase implements ExpressionNode { esTreeNode: GenericEsTreeNode, // we need to pass down the node constructors to avoid a circular dependency parent: Node | { type: string; context: AstContext }, - parentScope: Scope + parentScope: ChildScope ) { this.keys = keys[esTreeNode.type] || getAndCreateKeys(esTreeNode); this.parent = parent; @@ -125,7 +125,7 @@ export class NodeBase implements ExpressionNode { /** * Override if this node should receive a different scope than the parent scope. */ - createScope(parentScope: Scope) { + createScope(parentScope: ChildScope) { this.scope = parentScope; } diff --git a/src/ast/nodes/shared/pureFunctions.ts b/src/ast/nodes/shared/pureFunctions.ts index e2926568db2..5f0f7607de2 100644 --- a/src/ast/nodes/shared/pureFunctions.ts +++ b/src/ast/nodes/shared/pureFunctions.ts @@ -1,4 +1,6 @@ -const pureFunctions: { [name: string]: boolean } = {}; +import { NameCollection } from '../../../utils/reservedNames'; + +const pureFunctions: NameCollection = {}; const arrayTypes = 'Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array'.split( ' ' diff --git a/src/ast/scopes/BlockScope.ts b/src/ast/scopes/BlockScope.ts index fca384856c0..5464683bda9 100644 --- a/src/ast/scopes/BlockScope.ts +++ b/src/ast/scopes/BlockScope.ts @@ -3,11 +3,9 @@ import Identifier from '../nodes/Identifier'; import { ExpressionEntity } from '../nodes/shared/Expression'; import { UNKNOWN_EXPRESSION } from '../values'; import LocalVariable from '../variables/LocalVariable'; -import Scope from './Scope'; - -export default class BlockScope extends Scope { - parent: Scope; +import ChildScope from './ChildScope'; +export default class BlockScope extends ChildScope { addDeclaration( identifier: Identifier, context: AstContext, diff --git a/src/ast/scopes/ChildScope.ts b/src/ast/scopes/ChildScope.ts new file mode 100644 index 00000000000..8e124d6587e --- /dev/null +++ b/src/ast/scopes/ChildScope.ts @@ -0,0 +1,62 @@ +import { NameCollection } from '../../utils/reservedNames'; +import { getSafeName } from '../../utils/safeName'; +import { ExpressionEntity } from '../nodes/shared/Expression'; +import Variable from '../variables/Variable'; +import Scope from './Scope'; + +export default class ChildScope extends Scope { + accessedOutsideVariables: { [name: string]: Variable } = Object.create(null); + parent: Scope; + + constructor(parent: Scope) { + super(); + this.parent = parent; + parent.children.push(this); + } + + addNamespaceMemberAccess(name: string, variable: Variable) { + this.accessedOutsideVariables[name] = variable; + if (this.parent instanceof ChildScope) { + this.parent.addNamespaceMemberAccess(name, variable); + } + } + + addReturnExpression(expression: ExpressionEntity) { + this.parent instanceof ChildScope && this.parent.addReturnExpression(expression); + } + + contains(name: string): boolean { + return name in this.variables || this.parent.contains(name); + } + + deconflict(forbiddenNames: NameCollection) { + const usedNames: NameCollection = Object.assign(Object.create(null), forbiddenNames); + for (const name of Object.keys(this.accessedOutsideVariables)) { + const variable = this.accessedOutsideVariables[name]; + if (variable.included) { + usedNames[variable.getBaseVariableName()] = true; + } + } + for (const name of Object.keys(this.variables)) { + const variable = this.variables[name]; + if (variable.included) { + variable.setSafeName(getSafeName(name, usedNames)); + } + } + for (const scope of this.children) { + scope.deconflict(forbiddenNames); + } + } + + findLexicalBoundary(): ChildScope { + return this.parent instanceof ChildScope ? this.parent.findLexicalBoundary() : this; + } + + findVariable(name: string): Variable { + const knownVariable = this.variables[name] || this.accessedOutsideVariables[name]; + if (knownVariable) { + return knownVariable; + } + return (this.accessedOutsideVariables[name] = this.parent.findVariable(name)); + } +} diff --git a/src/ast/scopes/FunctionScope.ts b/src/ast/scopes/FunctionScope.ts index 733b7451140..7c16461232b 100644 --- a/src/ast/scopes/FunctionScope.ts +++ b/src/ast/scopes/FunctionScope.ts @@ -8,8 +8,8 @@ import ExternalVariable from '../variables/ExternalVariable'; import GlobalVariable from '../variables/GlobalVariable'; import LocalVariable from '../variables/LocalVariable'; import ThisVariable from '../variables/ThisVariable'; +import ChildScope from './ChildScope'; import ReturnValueScope from './ReturnValueScope'; -import Scope from './Scope'; export default class FunctionScope extends ReturnValueScope { variables: { @@ -19,7 +19,7 @@ export default class FunctionScope extends ReturnValueScope { [name: string]: LocalVariable | GlobalVariable | ExternalVariable | ArgumentsVariable; }; - constructor(parent: Scope, context: AstContext) { + constructor(parent: ChildScope, context: AstContext) { super(parent, context); this.variables.arguments = new ArgumentsVariable(super.getParameterVariables(), context); this.variables.this = new ThisVariable(context); diff --git a/src/ast/scopes/GlobalScope.ts b/src/ast/scopes/GlobalScope.ts index f6001efc084..3975766ad70 100644 --- a/src/ast/scopes/GlobalScope.ts +++ b/src/ast/scopes/GlobalScope.ts @@ -1,5 +1,6 @@ import GlobalVariable from '../variables/GlobalVariable'; import UndefinedVariable from '../variables/UndefinedVariable'; +import Variable from '../variables/Variable'; import Scope from './Scope'; export default class GlobalScope extends Scope { @@ -10,12 +11,8 @@ export default class GlobalScope extends Scope { this.variables.undefined = new UndefinedVariable(); } - findVariable(name: string) { + findVariable(name: string): Variable { if (!this.variables[name]) return (this.variables[name] = new GlobalVariable(name)); return this.variables[name] as GlobalVariable; } - - deshadow(names: Set, children = this.children) { - super.deshadow(names, children); - } } diff --git a/src/ast/scopes/ModuleScope.ts b/src/ast/scopes/ModuleScope.ts index 710f059978b..fe506aaf1c1 100644 --- a/src/ast/scopes/ModuleScope.ts +++ b/src/ast/scopes/ModuleScope.ts @@ -1,70 +1,45 @@ -import Module, { AstContext } from '../../Module'; -import relativeId from '../../utils/relativeId'; +import { AstContext } from '../../Module'; +import { NameCollection } from '../../utils/reservedNames'; +import ExportDefaultDeclaration from '../nodes/ExportDefaultDeclaration'; import { UNDEFINED_EXPRESSION } from '../values'; +import ExportDefaultVariable from '../variables/ExportDefaultVariable'; +import GlobalVariable from '../variables/GlobalVariable'; import LocalVariable from '../variables/LocalVariable'; -import NamespaceVariable from '../variables/NamespaceVariable'; import Variable from '../variables/Variable'; -import Scope from './Scope'; +import ChildScope from './ChildScope'; +import GlobalScope from './GlobalScope'; -const addDeclaredNames = (variable: Variable, names: Set) => { - if (variable.isNamespace && !variable.isExternal) { - for (const name of (variable).context.getExports()) - addDeclaredNames((variable).context.traceExport(name), names); - } - names.add(variable.getName()); -}; - -export default class ModuleScope extends Scope { - parent: Scope; +export default class ModuleScope extends ChildScope { + parent: GlobalScope; context: AstContext; - constructor(parent: Scope, context: AstContext) { + constructor(parent: GlobalScope, context: AstContext) { super(parent); this.context = context; - this.isModuleScope = true; this.variables.this = new LocalVariable('this', null, UNDEFINED_EXPRESSION, context); } - deshadow(names: Set, children = this.children) { - const localNames = new Set(names); - - for (const importName of Object.keys(this.context.importDescriptions)) { - const importDescription = this.context.importDescriptions[importName]; - - if (importDescription.module.isExternal || this.context.isCrossChunkImport(importDescription)) - continue; - - for (const name of (importDescription.module).getAllExports()) - addDeclaredNames(importDescription.module.getVariableForExportName(name), localNames); - - if (importDescription.name !== '*') { - const declaration = importDescription.module.getVariableForExportName( - importDescription.name - ); - if (!declaration) { - this.context.warn( - { - code: 'NON_EXISTENT_EXPORT', - name: importDescription.name, - source: importDescription.module.id, - message: `Non-existent export '${ - importDescription.name - }' is imported from ${relativeId(importDescription.module.id)}` - }, - importDescription.start - ); - continue; - } - - const name = declaration.getName(); - if (name !== importDescription.name) localNames.add(name); + addExportDefaultDeclaration( + name: string, + exportDefaultDeclaration: ExportDefaultDeclaration, + context: AstContext + ): ExportDefaultVariable { + return (this.variables.default = new ExportDefaultVariable( + name, + exportDefaultDeclaration, + context + )); + } - if (importDescription.name !== 'default' && importDescription.name !== importName) - localNames.add(importDescription.name); - } + addNamespaceMemberAccess(_name: string, variable: Variable) { + if (variable instanceof GlobalVariable) { + this.accessedOutsideVariables[variable.name] = variable; } + } - super.deshadow(localNames, children); + deconflict(forbiddenNames: NameCollection) { + // all module level variables are already deconflicted when deconflicting the chunk + for (const scope of this.children) scope.deconflict(forbiddenNames); } findLexicalBoundary() { @@ -72,10 +47,14 @@ export default class ModuleScope extends Scope { } findVariable(name: string) { - if (this.variables[name]) { - return this.variables[name]; + const knownVariable = this.variables[name] || this.accessedOutsideVariables[name]; + if (knownVariable) { + return knownVariable; } - - return this.context.traceVariable(name) || this.parent.findVariable(name); + const variable = this.context.traceVariable(name) || this.parent.findVariable(name); + if (variable instanceof GlobalVariable) { + this.accessedOutsideVariables[name] = variable; + } + return variable; } } diff --git a/src/ast/scopes/ParameterScope.ts b/src/ast/scopes/ParameterScope.ts index dc7cd4d97f9..8d0c0ade1af 100644 --- a/src/ast/scopes/ParameterScope.ts +++ b/src/ast/scopes/ParameterScope.ts @@ -2,11 +2,11 @@ import { AstContext } from '../../Module'; import Identifier from '../nodes/Identifier'; import { UNKNOWN_EXPRESSION } from '../values'; import LocalVariable from '../variables/LocalVariable'; +import ChildScope from './ChildScope'; import Scope from './Scope'; -export default class ParameterScope extends Scope { - parent: Scope; - hoistedBodyVarScope: Scope; +export default class ParameterScope extends ChildScope { + hoistedBodyVarScope: ChildScope; private parameters: LocalVariable[] = []; private context: AstContext; @@ -14,7 +14,7 @@ export default class ParameterScope extends Scope { constructor(parent: Scope, context: AstContext) { super(parent); this.context = context; - this.hoistedBodyVarScope = new Scope(this); + this.hoistedBodyVarScope = new ChildScope(this); } /** diff --git a/src/ast/scopes/Scope.ts b/src/ast/scopes/Scope.ts index 16b83e470c6..25aea78ada4 100644 --- a/src/ast/scopes/Scope.ts +++ b/src/ast/scopes/Scope.ts @@ -1,6 +1,4 @@ import { AstContext } from '../../Module'; -import { toBase64 } from '../../utils/base64'; -import ExportDefaultDeclaration from '../nodes/ExportDefaultDeclaration'; import Identifier from '../nodes/Identifier'; import { ExpressionEntity } from '../nodes/shared/Expression'; import { UNDEFINED_EXPRESSION } from '../values'; @@ -9,24 +7,16 @@ import ExportDefaultVariable from '../variables/ExportDefaultVariable'; import LocalVariable from '../variables/LocalVariable'; import ThisVariable from '../variables/ThisVariable'; import Variable from '../variables/Variable'; +import ChildScope from './ChildScope'; export default class Scope { - parent: Scope | null; variables: { this?: ThisVariable | LocalVariable; default?: ExportDefaultVariable; arguments?: ArgumentsVariable; [name: string]: Variable; - }; - isModuleScope: boolean = false; - children: Scope[]; - - constructor(parent: Scope | null = null) { - this.parent = parent; - this.children = []; - if (this.parent) this.parent.children.push(this); - this.variables = Object.create(null); - } + } = Object.create(null); + children: ChildScope[] = []; addDeclaration( identifier: Identifier, @@ -48,52 +38,11 @@ export default class Scope { return this.variables[name]; } - addExportDefaultDeclaration( - name: string, - exportDefaultDeclaration: ExportDefaultDeclaration, - context: AstContext - ): ExportDefaultVariable { - this.variables.default = new ExportDefaultVariable(name, exportDefaultDeclaration, context); - return this.variables.default; - } - - addReturnExpression(expression: ExpressionEntity) { - this.parent && this.parent.addReturnExpression(expression); - } - contains(name: string): boolean { - return name in this.variables || (this.parent ? this.parent.contains(name) : false); - } - - deshadow(names: Set, children = this.children) { - for (const key of Object.keys(this.variables)) { - const declaration = this.variables[key]; - - // we can disregard exports.foo etc - if (declaration.exportName && declaration.isReassigned && !declaration.isId) continue; - if (declaration.isDefault) continue; - - let name = declaration.getName(true); - if (!names.has(name)) continue; - - name = declaration.name; - let deshadowed, - i = 1; - do { - deshadowed = `${name}$$${toBase64(i++)}`; - } while (names.has(deshadowed)); - - declaration.setSafeName(deshadowed); - } - - for (const scope of children) scope.deshadow(names); - } - - findLexicalBoundary(): Scope { - return this.parent.findLexicalBoundary(); + return name in this.variables; } - findVariable(name: string): Variable { - return this.variables[name] || (this.parent && this.parent.findVariable(name)); + findVariable(_name: string): Variable { + throw new Error('Internal Error: findVariable needs to be implemented by a subclass'); } } diff --git a/src/ast/variables/ExportDefaultVariable.ts b/src/ast/variables/ExportDefaultVariable.ts index 63bfd73e96e..60060f749f2 100644 --- a/src/ast/variables/ExportDefaultVariable.ts +++ b/src/ast/variables/ExportDefaultVariable.ts @@ -43,19 +43,35 @@ export default class ExportDefaultVariable extends LocalVariable { } } - getName(reset?: boolean) { - if (!reset && this.safeName) return this.safeName; - if (this.referencesOriginal()) return this.originalId.variable.getName(); - return this.name; + getName() { + return this.referencesOriginal() ? this.originalId.variable.getName() : super.getName(); + } + + getOriginalVariableName(): string | null { + return (this.originalId && this.originalId.name) || null; } referencesOriginal() { return this.originalId && (this.hasId || !this.originalId.variable.isReassigned); } - getOriginalVariableName(): string | null { - return (this.originalId && this.originalId.name) || null; + setRenderNames(baseName: string | null, name: string | null) { + if (this.referencesOriginal()) { + this.originalId.variable.setRenderNames(baseName, name); + } else { + super.setRenderNames(baseName, name); + } + } + + setSafeName(name: string | null) { + if (this.referencesOriginal()) { + this.originalId.variable.setSafeName(name); + } else { + super.setSafeName(name); + } } } +ExportDefaultVariable.prototype.getBaseVariableName = ExportDefaultVariable.prototype.getName; + ExportDefaultVariable.prototype.isDefault = true; diff --git a/src/ast/variables/GlobalVariable.ts b/src/ast/variables/GlobalVariable.ts index fcaa5280dc2..2ad76c6a6b9 100644 --- a/src/ast/variables/GlobalVariable.ts +++ b/src/ast/variables/GlobalVariable.ts @@ -3,8 +3,6 @@ import { ObjectPath } from '../values'; import Variable from './Variable'; export default class GlobalVariable extends Variable { - included = true; - hasEffectsWhenAccessedAtPath(path: ObjectPath) { // path.length == 0 can also have an effect but we postpone this for now return ( diff --git a/src/ast/variables/Variable.ts b/src/ast/variables/Variable.ts index 2127c0b1282..24dbbbf1f4d 100644 --- a/src/ast/variables/Variable.ts +++ b/src/ast/variables/Variable.ts @@ -10,7 +10,8 @@ import { LiteralValueOrUnknown, ObjectPath, UNKNOWN_EXPRESSION, UNKNOWN_VALUE } export default class Variable implements ExpressionEntity { name: string; - safeName: string; + renderName: string | null = null; + renderBaseName: string | null = null; isExternal?: boolean; isDefault?: boolean; isNamespace?: boolean; @@ -26,7 +27,6 @@ export default class Variable implements ExpressionEntity { constructor(name: string) { this.name = name; - this.safeName = null; } /** @@ -35,18 +35,13 @@ export default class Variable implements ExpressionEntity { */ addReference(_identifier: Identifier) {} - getName(reset?: boolean): string { - if ( - reset && - this.safeName && - this.safeName !== this.name && - this.safeName[this.name.length] === '$' && - this.safeName[this.name.length + 1] === '$' - ) { - this.safeName = null; - return this.name; - } - return this.safeName || this.name; + getBaseVariableName(): string { + return this.renderBaseName || this.renderName || this.name; + } + + getName(): string { + const name = this.renderName || this.name; + return this.renderBaseName ? `${this.renderBaseName}.${name}` : name; } getLiteralValueAtPath( @@ -93,8 +88,13 @@ export default class Variable implements ExpressionEntity { deoptimizePath(_path: ObjectPath) {} - setSafeName(name: string) { - this.safeName = name; + setRenderNames(baseName: string | null, name: string | null) { + this.renderBaseName = baseName; + this.renderName = name; + } + + setSafeName(name: string | null) { + this.renderName = name; } toString() { diff --git a/src/finalisers/cjs.ts b/src/finalisers/cjs.ts index 1e13fb06149..a06b65e208f 100644 --- a/src/finalisers/cjs.ts +++ b/src/finalisers/cjs.ts @@ -1,5 +1,6 @@ import { Bundle as MagicStringBundle } from 'magic-string'; import { OutputOptions } from '../rollup/types'; +import { INTEROP_DEFAULT_VARIABLE } from '../utils/variableNames'; import { FinaliserOptions } from './index'; import { compactEsModuleExport, esModuleExport } from './shared/esModuleExport'; import getExportBlock from './shared/getExportBlock'; @@ -59,8 +60,8 @@ export default function cjs( } else { needsInterop = true; if (exportsNames) - importBlock += `${name}=require('${id}'),${name}__default=_interopDefault(${name})`; - else importBlock += `${name}=_interopDefault(require('${id}'))`; + importBlock += `${name}=require('${id}'),${name}__default=${INTEROP_DEFAULT_VARIABLE}(${name})`; + else importBlock += `${name}=${INTEROP_DEFAULT_VARIABLE}(require('${id}'))`; } } } @@ -89,10 +90,10 @@ export default function cjs( if (exportsNames) return ( `${varOrConst} ${name} = require('${id}');` + - `\n${varOrConst} ${name}__default = _interopDefault(${name});` + `\n${varOrConst} ${name}__default = ${INTEROP_DEFAULT_VARIABLE}(${name});` ); - return `${varOrConst} ${name} = _interopDefault(require('${id}'));`; + return `${varOrConst} ${name} = ${INTEROP_DEFAULT_VARIABLE}(require('${id}'));`; } ) .join('\n'); @@ -100,9 +101,9 @@ export default function cjs( if (needsInterop) { if (options.compact) - intro += `function _interopDefault(e){return(e&&(typeof e==='object')&&'default'in e)?e['default']:e}`; + intro += `function ${INTEROP_DEFAULT_VARIABLE}(e){return(e&&(typeof e==='object')&&'default'in e)?e['default']:e}`; else - intro += `function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }\n\n`; + intro += `function ${INTEROP_DEFAULT_VARIABLE} (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }\n\n`; } if (importBlock) intro += importBlock + n + n; diff --git a/src/utils/base64.ts b/src/utils/base64.ts index 460a7c274e8..7a9db2470eb 100644 --- a/src/utils/base64.ts +++ b/src/utils/base64.ts @@ -1,8 +1,8 @@ const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$'; +const base = 64; -export function toBase64(num: number, base63 = false) { +export function toBase64(num: number) { let outStr = ''; - const base = base63 ? 63 : 64; do { const curDigit = num % base; num = Math.floor(num / base); diff --git a/src/utils/deconflictChunk.ts b/src/utils/deconflictChunk.ts new file mode 100644 index 00000000000..4b2db098e32 --- /dev/null +++ b/src/utils/deconflictChunk.ts @@ -0,0 +1,143 @@ +import ExportDefaultVariable from '../ast/variables/ExportDefaultVariable'; +import Variable from '../ast/variables/Variable'; +import Chunk from '../Chunk'; +import ExternalModule from '../ExternalModule'; +import Module from '../Module'; +import { NameCollection, RESERVED_NAMES_BY_FORMAT } from './reservedNames'; +import { getSafeName } from './safeName'; + +const DECONFLICT_IMPORTED_VARIABLES_BY_FORMAT: { + [format: string]: ( + usedNames: NameCollection, + imports: Set, + dependencies: (ExternalModule | Chunk)[], + interop: boolean, + preserveModules: boolean + ) => void; +} = { + cjs: deconflictImportsOther, + iife: deconflictImportsOther, + amd: deconflictImportsOther, + umd: deconflictImportsOther, + system: deconflictImportsEsm, + es: deconflictImportsEsm +}; + +export function deconflictChunk( + modules: Module[], + dependencies: (ExternalModule | Chunk)[], + imports: Set, + usedNames: NameCollection, + format: string, + interop: boolean, + preserveModules: boolean +) { + const { forbiddenNames, formatGlobals } = RESERVED_NAMES_BY_FORMAT[format]; + Object.assign(usedNames, forbiddenNames); + Object.assign(usedNames, formatGlobals); + addUsedGlobalNames(usedNames, modules); + deconflictTopLevelVariables(usedNames, modules); + DECONFLICT_IMPORTED_VARIABLES_BY_FORMAT[format]( + usedNames, + imports, + dependencies, + interop, + preserveModules + ); + + for (const module of modules) { + module.scope.deconflict(forbiddenNames); + } +} + +function addUsedGlobalNames(usedNames: NameCollection, modules: Module[]) { + const accessedGlobals: { [name: string]: Variable } = Object.assign( + {}, + ...modules.map(module => module.scope.accessedOutsideVariables) + ); + + for (const name of Object.keys(accessedGlobals)) { + const variable = accessedGlobals[name]; + if (variable.included) { + usedNames[name] = true; + } + } +} + +function deconflictImportsEsm( + usedNames: NameCollection, + imports: Set, + _dependencies: (ExternalModule | Chunk)[], + interop: boolean +) { + for (const variable of Array.from(imports)) { + const module = variable.module; + const name = variable.name; + let proposedName: string; + if (module instanceof ExternalModule && (name === '*' || name === 'default')) { + if (name === 'default' && interop && module.exportsNamespace) { + proposedName = module.variableName + '__default'; + } else { + proposedName = module.variableName; + } + } else { + proposedName = name; + } + variable.setRenderNames(null, getSafeName(proposedName, usedNames)); + } +} + +function deconflictImportsOther( + usedNames: NameCollection, + imports: Set, + dependencies: (ExternalModule | Chunk)[], + interop: boolean, + preserveModules: boolean +) { + for (const chunkOrExternalModule of dependencies) { + chunkOrExternalModule.variableName = getSafeName(chunkOrExternalModule.variableName, usedNames); + } + for (const variable of Array.from(imports)) { + const module = variable.module; + if (module instanceof ExternalModule) { + const name = variable.name; + if (name === 'default' && interop && (module.exportsNamespace || module.exportsNames)) { + variable.setRenderNames(null, module.variableName + '__default'); + } else if (name === '*' || name === 'default') { + variable.setRenderNames(null, module.variableName); + } else { + variable.setRenderNames(module.variableName, null); + } + } else { + const chunk = module.chunk; + if (chunk.exportMode === 'default' || (preserveModules && variable.isNamespace)) { + variable.setRenderNames(null, chunk.variableName); + } else { + variable.setRenderNames(chunk.variableName, module.chunk.getVariableExportName(variable)); + } + } + } +} + +function deconflictTopLevelVariables(usedNames: NameCollection, modules: Module[]) { + for (const module of modules) { + const moduleVariables = module.scope.variables; + for (const name of Object.keys(moduleVariables)) { + const variable = moduleVariables[name]; + if ( + variable.included && + // this will only happen for exports in some formats + !( + variable.renderBaseName || + (variable instanceof ExportDefaultVariable && variable.referencesOriginal()) + ) + ) { + variable.setRenderNames(null, getSafeName(variable.name, usedNames)); + } + } + const namespace = module.getOrCreateNamespace(); + if (namespace.included) { + namespace.setRenderNames(null, getSafeName(namespace.name, usedNames)); + } + } +} diff --git a/src/utils/pluginDriver.ts b/src/utils/pluginDriver.ts index 916577fec5d..d99534c98a8 100644 --- a/src/utils/pluginDriver.ts +++ b/src/utils/pluginDriver.ts @@ -15,6 +15,7 @@ import { import { createAssetPluginHooks, EmitAsset } from './assetHooks'; import { getRollupDefaultPlugin } from './defaultPlugin'; import { error } from './error'; +import { NameCollection } from './reservedNames'; export interface PluginDriver { emitAsset: EmitAsset; @@ -57,7 +58,7 @@ export function createPluginDriver( ): PluginDriver { const plugins = [...(options.plugins || []), getRollupDefaultPlugin(options)]; const { emitAsset, getAssetFileName, setAssetSource } = createAssetPluginHooks(graph.assetsById); - const existingPluginKeys: { [key: string]: true } = {}; + const existingPluginKeys: NameCollection = {}; let hasLoadersOrTransforms = false; diff --git a/src/utils/reservedNames.ts b/src/utils/reservedNames.ts new file mode 100644 index 00000000000..c2f4fcb840a --- /dev/null +++ b/src/utils/reservedNames.ts @@ -0,0 +1,73 @@ +import { INTEROP_DEFAULT_VARIABLE } from './variableNames'; + +export interface NameCollection { + [name: string]: true; +} + +const RESERVED_NAMES: NameCollection = Object.assign(Object.create(null), { + await: true, + break: true, + case: true, + catch: true, + class: true, + const: true, + continue: true, + debugger: true, + default: true, + delete: true, + do: true, + else: true, + enum: true, + eval: true, + export: true, + extends: true, + finally: true, + for: true, + function: true, + if: true, + implements: true, + import: true, + in: true, + instanceof: true, + interface: true, + let: true, + new: true, + null: true, + package: true, + private: true, + protected: true, + public: true, + return: true, + static: true, + super: true, + switch: true, + throw: true, + try: true, + typeof: true, + undefined: true, + var: true, + void: true, + while: true, + with: true, + yield: true +}); + +const NONE: NameCollection = {}; +const EXPORTS: NameCollection = { exports: true }; + +export const RESERVED_NAMES_BY_FORMAT: { + [format: string]: { formatGlobals: NameCollection; forbiddenNames: NameCollection }; +} = { + cjs: { + formatGlobals: { exports: true, module: true, [INTEROP_DEFAULT_VARIABLE]: true }, + forbiddenNames: RESERVED_NAMES + }, + iife: { formatGlobals: EXPORTS, forbiddenNames: RESERVED_NAMES }, + amd: { formatGlobals: EXPORTS, forbiddenNames: RESERVED_NAMES }, + umd: { formatGlobals: EXPORTS, forbiddenNames: RESERVED_NAMES }, + system: { + formatGlobals: NONE, + forbiddenNames: Object.assign(Object.create(null), RESERVED_NAMES, EXPORTS) + }, + es: { formatGlobals: NONE, forbiddenNames: RESERVED_NAMES } +}; diff --git a/src/utils/safeName.ts b/src/utils/safeName.ts new file mode 100644 index 00000000000..aad1d49a468 --- /dev/null +++ b/src/utils/safeName.ts @@ -0,0 +1,12 @@ +import { toBase64 } from './base64'; +import { NameCollection } from './reservedNames'; + +export function getSafeName(baseName: string, usedNames: NameCollection): string { + let safeName = baseName; + let count = 1; + while (usedNames[safeName]) { + safeName = `${baseName}$${toBase64(count++)}`; + } + usedNames[safeName] = true; + return safeName; +} diff --git a/src/utils/sanitize-file-name.ts b/src/utils/sanitizeFileName.ts similarity index 100% rename from src/utils/sanitize-file-name.ts rename to src/utils/sanitizeFileName.ts diff --git a/src/utils/traverseStaticDependencies.ts b/src/utils/traverseStaticDependencies.ts index c546b068ca1..a2cb4b12ac3 100644 --- a/src/utils/traverseStaticDependencies.ts +++ b/src/utils/traverseStaticDependencies.ts @@ -1,12 +1,13 @@ import ExternalModule from '../ExternalModule'; import Module from '../Module'; +import { NameCollection } from './reservedNames'; export function visitStaticModuleDependencies( baseModule: Module | ExternalModule, areDependenciesSkipped: (module: Module | ExternalModule) => boolean ) { const modules = [baseModule]; - const visitedModules: { [id: string]: true } = {}; + const visitedModules: NameCollection = {}; for (const module of modules) { if (areDependenciesSkipped(module) || module instanceof ExternalModule) continue; for (const dependency of module.dependencies) { diff --git a/src/utils/variableNames.ts b/src/utils/variableNames.ts index a6494c7b25d..0b69a1cad02 100644 --- a/src/utils/variableNames.ts +++ b/src/utils/variableNames.ts @@ -1 +1,2 @@ export const MISSING_EXPORT_SHIM_VARIABLE = '_missingExportShim'; +export const INTEROP_DEFAULT_VARIABLE = '_interopDefault'; diff --git a/test/chunking-form/samples/basic-chunking/_expected/es/main1.js b/test/chunking-form/samples/basic-chunking/_expected/es/main1.js index cb8fc18ee65..6d4f2531150 100644 --- a/test/chunking-form/samples/basic-chunking/_expected/es/main1.js +++ b/test/chunking-form/samples/basic-chunking/_expected/es/main1.js @@ -1,13 +1,13 @@ -import { a as fn } from './generated-chunk.js'; +import { a as fn$1 } from './generated-chunk.js'; -function fn$1 () { +function fn () { console.log('dep1 fn'); } class Main1 { constructor () { - fn$1(); fn(); + fn$1(); } } diff --git a/test/chunking-form/samples/basic-chunking/_expected/es/main2.js b/test/chunking-form/samples/basic-chunking/_expected/es/main2.js index 9d1a5289463..ac6858dc5af 100644 --- a/test/chunking-form/samples/basic-chunking/_expected/es/main2.js +++ b/test/chunking-form/samples/basic-chunking/_expected/es/main2.js @@ -1,18 +1,18 @@ -import { a as fn } from './generated-chunk.js'; +import { a as fn$2 } from './generated-chunk.js'; -function fn$1 () { +function fn () { console.log('lib1 fn'); } -function fn$2 () { - fn$1(); +function fn$1 () { + fn(); console.log('dep3 fn'); } class Main2 { constructor () { + fn$1(); fn$2(); - fn(); } } diff --git a/test/chunking-form/samples/basic-chunking/_expected/system/main1.js b/test/chunking-form/samples/basic-chunking/_expected/system/main1.js index 3e5709e5f85..f99f3442d10 100644 --- a/test/chunking-form/samples/basic-chunking/_expected/system/main1.js +++ b/test/chunking-form/samples/basic-chunking/_expected/system/main1.js @@ -1,20 +1,20 @@ System.register(['./generated-chunk.js'], function (exports, module) { 'use strict'; - var fn; + var fn$1; return { setters: [function (module) { - fn = module.a; + fn$1 = module.a; }], execute: function () { - function fn$1 () { + function fn () { console.log('dep1 fn'); } class Main1 { constructor () { - fn$1(); fn(); + fn$1(); } } exports('default', Main1); diff --git a/test/chunking-form/samples/basic-chunking/_expected/system/main2.js b/test/chunking-form/samples/basic-chunking/_expected/system/main2.js index f765c580575..25e963f1174 100644 --- a/test/chunking-form/samples/basic-chunking/_expected/system/main2.js +++ b/test/chunking-form/samples/basic-chunking/_expected/system/main2.js @@ -1,25 +1,25 @@ System.register(['./generated-chunk.js'], function (exports, module) { 'use strict'; - var fn; + var fn$2; return { setters: [function (module) { - fn = module.a; + fn$2 = module.a; }], execute: function () { - function fn$1 () { + function fn () { console.log('lib1 fn'); } - function fn$2 () { - fn$1(); + function fn$1 () { + fn(); console.log('dep3 fn'); } class Main2 { constructor () { + fn$1(); fn$2(); - fn(); } } exports('default', Main2); diff --git a/test/chunking-form/samples/chunk-deshadowing-reassignment/_expected/es/generated-chunk2.js b/test/chunking-form/samples/chunk-deshadowing-reassignment/_expected/es/generated-chunk2.js index 0f002866c53..2b1b3288238 100644 --- a/test/chunking-form/samples/chunk-deshadowing-reassignment/_expected/es/generated-chunk2.js +++ b/test/chunking-form/samples/chunk-deshadowing-reassignment/_expected/es/generated-chunk2.js @@ -1,8 +1,8 @@ -import { a as x } from './generated-chunk.js'; -import { a as x$1 } from './generated-chunk3.js'; +import { a as x$1 } from './generated-chunk.js'; +import { a as x$2 } from './generated-chunk3.js'; -var x$2 = x + 1; +var x = x$1 + 1; -var y = x$1 + 1; +var y = x$2 + 1; -export { x$2 as a, y as b }; +export { x as a, y as b }; diff --git a/test/chunking-form/samples/chunk-deshadowing-reassignment/_expected/system/generated-chunk2.js b/test/chunking-form/samples/chunk-deshadowing-reassignment/_expected/system/generated-chunk2.js index c186a80b419..94f6c6b5d9c 100644 --- a/test/chunking-form/samples/chunk-deshadowing-reassignment/_expected/system/generated-chunk2.js +++ b/test/chunking-form/samples/chunk-deshadowing-reassignment/_expected/system/generated-chunk2.js @@ -1,17 +1,17 @@ System.register(['./generated-chunk.js', './generated-chunk3.js'], function (exports, module) { 'use strict'; - var x, x$1; + var x$1, x$2; return { setters: [function (module) { - x = module.a; - }, function (module) { x$1 = module.a; + }, function (module) { + x$2 = module.a; }], execute: function () { - var x$2 = exports('a', x + 1); + var x = exports('a', x$1 + 1); - var y = exports('b', x$1 + 1); + var y = exports('b', x$2 + 1); } }; diff --git a/test/chunking-form/samples/chunk-export-deshadowing/_expected/amd/generated-chunk.js b/test/chunking-form/samples/chunk-export-deshadowing/_expected/amd/generated-chunk.js index ba6de28f7d2..8472dfd4ef7 100644 --- a/test/chunking-form/samples/chunk-export-deshadowing/_expected/amd/generated-chunk.js +++ b/test/chunking-form/samples/chunk-export-deshadowing/_expected/amd/generated-chunk.js @@ -9,10 +9,10 @@ define(['exports'], function (exports) { 'use strict'; console.log(text$1); } - var text$$1 = 'dep1 fn'; + var text = 'dep1 fn'; function fn$2 () { - console.log(text$$1); + console.log(text); } var text$1 = 'dep2 fn'; diff --git a/test/chunking-form/samples/chunk-export-deshadowing/_expected/cjs/generated-chunk.js b/test/chunking-form/samples/chunk-export-deshadowing/_expected/cjs/generated-chunk.js index 21bcb4b8aff..4c001579917 100644 --- a/test/chunking-form/samples/chunk-export-deshadowing/_expected/cjs/generated-chunk.js +++ b/test/chunking-form/samples/chunk-export-deshadowing/_expected/cjs/generated-chunk.js @@ -9,10 +9,10 @@ function fn$1 () { console.log(text$1); } -var text$$1 = 'dep1 fn'; +var text = 'dep1 fn'; function fn$2 () { - console.log(text$$1); + console.log(text); } var text$1 = 'dep2 fn'; diff --git a/test/chunking-form/samples/chunk-export-deshadowing/_expected/es/generated-chunk.js b/test/chunking-form/samples/chunk-export-deshadowing/_expected/es/generated-chunk.js index 491ebf8bcc8..e2414d56caf 100644 --- a/test/chunking-form/samples/chunk-export-deshadowing/_expected/es/generated-chunk.js +++ b/test/chunking-form/samples/chunk-export-deshadowing/_expected/es/generated-chunk.js @@ -7,10 +7,10 @@ function fn$1 () { console.log(text$1); } -var text$$1 = 'dep1 fn'; +var text = 'dep1 fn'; function fn$2 () { - console.log(text$$1); + console.log(text); } var text$1 = 'dep2 fn'; diff --git a/test/chunking-form/samples/chunk-export-deshadowing/_expected/system/generated-chunk.js b/test/chunking-form/samples/chunk-export-deshadowing/_expected/system/generated-chunk.js index b0c3378adbb..8bb6c738e84 100644 --- a/test/chunking-form/samples/chunk-export-deshadowing/_expected/system/generated-chunk.js +++ b/test/chunking-form/samples/chunk-export-deshadowing/_expected/system/generated-chunk.js @@ -17,10 +17,10 @@ System.register([], function (exports, module) { console.log(text$1); } - var text$$1 = 'dep1 fn'; + var text = 'dep1 fn'; function fn$2 () { - console.log(text$$1); + console.log(text); } var text$1 = 'dep2 fn'; diff --git a/test/chunking-form/samples/chunk-import-deshadowing/_expected/es/main1.js b/test/chunking-form/samples/chunk-import-deshadowing/_expected/es/main1.js index 2ff63fa59e8..5124820e88d 100644 --- a/test/chunking-form/samples/chunk-import-deshadowing/_expected/es/main1.js +++ b/test/chunking-form/samples/chunk-import-deshadowing/_expected/es/main1.js @@ -1,8 +1,8 @@ import { a as emptyFunction } from './generated-chunk.js'; function fn () { - var emptyFunction$$1 = emptyFunction; - console.log(emptyFunction$$1); + var emptyFunction$1 = emptyFunction; + console.log(emptyFunction$1); } fn(); diff --git a/test/chunking-form/samples/chunk-import-deshadowing/_expected/system/main1.js b/test/chunking-form/samples/chunk-import-deshadowing/_expected/system/main1.js index 9537d0f581b..3860c007274 100644 --- a/test/chunking-form/samples/chunk-import-deshadowing/_expected/system/main1.js +++ b/test/chunking-form/samples/chunk-import-deshadowing/_expected/system/main1.js @@ -8,8 +8,8 @@ System.register(['./generated-chunk.js'], function (exports, module) { execute: function () { function fn () { - var emptyFunction$$1 = emptyFunction; - console.log(emptyFunction$$1); + var emptyFunction$1 = emptyFunction; + console.log(emptyFunction$1); } fn(); diff --git a/test/chunking-form/samples/chunk-namespace-boundary/_expected/es/main1.js b/test/chunking-form/samples/chunk-namespace-boundary/_expected/es/main1.js index d15d1f254e6..0f9a55a2cdf 100644 --- a/test/chunking-form/samples/chunk-namespace-boundary/_expected/es/main1.js +++ b/test/chunking-form/samples/chunk-namespace-boundary/_expected/es/main1.js @@ -1,6 +1,6 @@ import { a as commonjsGlobal, b as d } from './generated-chunk.js'; -commonjsGlobal.fn = d$$1 => d$$1 + 1; +commonjsGlobal.fn = d => d + 1; var cjs = commonjsGlobal.fn; var main1 = d.map(cjs); diff --git a/test/chunking-form/samples/chunk-namespace-boundary/_expected/es/main2.js b/test/chunking-form/samples/chunk-namespace-boundary/_expected/es/main2.js index 2d2149c12b8..ab97d5286d1 100644 --- a/test/chunking-form/samples/chunk-namespace-boundary/_expected/es/main2.js +++ b/test/chunking-form/samples/chunk-namespace-boundary/_expected/es/main2.js @@ -1,5 +1,5 @@ import { b as d } from './generated-chunk.js'; -var main2 = d.map(d$$1 => d$$1 + 2); +var main2 = d.map(d => d + 2); export default main2; diff --git a/test/chunking-form/samples/chunk-namespace-boundary/_expected/system/main1.js b/test/chunking-form/samples/chunk-namespace-boundary/_expected/system/main1.js index ecd9ba71625..38160286c74 100644 --- a/test/chunking-form/samples/chunk-namespace-boundary/_expected/system/main1.js +++ b/test/chunking-form/samples/chunk-namespace-boundary/_expected/system/main1.js @@ -8,7 +8,7 @@ System.register(['./generated-chunk.js'], function (exports, module) { }], execute: function () { - commonjsGlobal.fn = d$$1 => d$$1 + 1; + commonjsGlobal.fn = d => d + 1; var cjs = commonjsGlobal.fn; var main1 = exports('default', d.map(cjs)); diff --git a/test/chunking-form/samples/chunk-namespace-boundary/_expected/system/main2.js b/test/chunking-form/samples/chunk-namespace-boundary/_expected/system/main2.js index b45cc59b117..6092d6d1d85 100644 --- a/test/chunking-form/samples/chunk-namespace-boundary/_expected/system/main2.js +++ b/test/chunking-form/samples/chunk-namespace-boundary/_expected/system/main2.js @@ -7,7 +7,7 @@ System.register(['./generated-chunk.js'], function (exports, module) { }], execute: function () { - var main2 = exports('default', d.map(d$$1 => d$$1 + 2)); + var main2 = exports('default', d.map(d => d + 2)); } }; diff --git a/test/chunking-form/samples/chunking-compact/_expected/es/main1.js b/test/chunking-form/samples/chunking-compact/_expected/es/main1.js index c75e3edd0f1..4d1a855433b 100644 --- a/test/chunking-form/samples/chunking-compact/_expected/es/main1.js +++ b/test/chunking-form/samples/chunking-compact/_expected/es/main1.js @@ -1,8 +1,8 @@ -import {a as fn}from'./generated-chunk.js';function fn$1 () { +import {a as fn$1}from'./generated-chunk.js';function fn () { console.log('dep1 fn'); }class Main1 { constructor () { - fn$1(); fn(); + fn$1(); } }export default Main1; \ No newline at end of file diff --git a/test/chunking-form/samples/chunking-compact/_expected/es/main2.js b/test/chunking-form/samples/chunking-compact/_expected/es/main2.js index 52563c681cc..e72705fd87e 100644 --- a/test/chunking-form/samples/chunking-compact/_expected/es/main2.js +++ b/test/chunking-form/samples/chunking-compact/_expected/es/main2.js @@ -1,12 +1,12 @@ -import {a as fn$1}from'./generated-chunk.js';import {fn}from'external';function fn$2 () { +import {a as fn$3}from'./generated-chunk.js';import {fn as fn$2}from'external';function fn () { console.log('lib1 fn'); - fn(); -}function fn$3 () { fn$2(); +}function fn$1 () { + fn(); console.log('dep3 fn'); }class Main2 { constructor () { - fn$3(); fn$1(); + fn$3(); } }export default Main2; \ No newline at end of file diff --git a/test/chunking-form/samples/chunking-compact/_expected/system/main1.js b/test/chunking-form/samples/chunking-compact/_expected/system/main1.js index 02c6f81d1e4..ae68d73b0a0 100644 --- a/test/chunking-form/samples/chunking-compact/_expected/system/main1.js +++ b/test/chunking-form/samples/chunking-compact/_expected/system/main1.js @@ -1,8 +1,8 @@ -System.register(['./generated-chunk.js'],function(exports,module){'use strict';var fn;return{setters:[function(module){fn=module.a;}],execute:function(){function fn$1 () { +System.register(['./generated-chunk.js'],function(exports,module){'use strict';var fn$1;return{setters:[function(module){fn$1=module.a;}],execute:function(){function fn () { console.log('dep1 fn'); }class Main1 { constructor () { - fn$1(); fn(); + fn$1(); } } exports('default', Main1);}}}); \ No newline at end of file diff --git a/test/chunking-form/samples/chunking-compact/_expected/system/main2.js b/test/chunking-form/samples/chunking-compact/_expected/system/main2.js index 7108d0e52fb..d58784a5a7a 100644 --- a/test/chunking-form/samples/chunking-compact/_expected/system/main2.js +++ b/test/chunking-form/samples/chunking-compact/_expected/system/main2.js @@ -1,12 +1,12 @@ -System.register(['./generated-chunk.js','external'],function(exports,module){'use strict';var fn$1,fn;return{setters:[function(module){fn$1=module.a;},function(module){fn=module.fn;}],execute:function(){function fn$2 () { +System.register(['./generated-chunk.js','external'],function(exports,module){'use strict';var fn$3,fn$2;return{setters:[function(module){fn$3=module.a;},function(module){fn$2=module.fn;}],execute:function(){function fn () { console.log('lib1 fn'); - fn(); -}function fn$3 () { fn$2(); +}function fn$1 () { + fn(); console.log('dep3 fn'); }class Main2 { constructor () { - fn$3(); fn$1(); + fn$3(); } } exports('default', Main2);}}}); \ No newline at end of file diff --git a/test/chunking-form/samples/chunking-externals/_expected/es/main1.js b/test/chunking-form/samples/chunking-externals/_expected/es/main1.js index cb8fc18ee65..6d4f2531150 100644 --- a/test/chunking-form/samples/chunking-externals/_expected/es/main1.js +++ b/test/chunking-form/samples/chunking-externals/_expected/es/main1.js @@ -1,13 +1,13 @@ -import { a as fn } from './generated-chunk.js'; +import { a as fn$1 } from './generated-chunk.js'; -function fn$1 () { +function fn () { console.log('dep1 fn'); } class Main1 { constructor () { - fn$1(); fn(); + fn$1(); } } diff --git a/test/chunking-form/samples/chunking-externals/_expected/es/main2.js b/test/chunking-form/samples/chunking-externals/_expected/es/main2.js index 405ddf00b64..3743c96a40c 100644 --- a/test/chunking-form/samples/chunking-externals/_expected/es/main2.js +++ b/test/chunking-form/samples/chunking-externals/_expected/es/main2.js @@ -1,20 +1,20 @@ -import { a as fn$1 } from './generated-chunk.js'; -import { fn } from 'external'; +import { a as fn$3 } from './generated-chunk.js'; +import { fn as fn$2 } from 'external'; -function fn$2 () { +function fn () { console.log('lib1 fn'); - fn(); + fn$2(); } -function fn$3 () { - fn$2(); +function fn$1 () { + fn(); console.log('dep3 fn'); } class Main2 { constructor () { - fn$3(); fn$1(); + fn$3(); } } diff --git a/test/chunking-form/samples/chunking-externals/_expected/system/main1.js b/test/chunking-form/samples/chunking-externals/_expected/system/main1.js index 3e5709e5f85..f99f3442d10 100644 --- a/test/chunking-form/samples/chunking-externals/_expected/system/main1.js +++ b/test/chunking-form/samples/chunking-externals/_expected/system/main1.js @@ -1,20 +1,20 @@ System.register(['./generated-chunk.js'], function (exports, module) { 'use strict'; - var fn; + var fn$1; return { setters: [function (module) { - fn = module.a; + fn$1 = module.a; }], execute: function () { - function fn$1 () { + function fn () { console.log('dep1 fn'); } class Main1 { constructor () { - fn$1(); fn(); + fn$1(); } } exports('default', Main1); diff --git a/test/chunking-form/samples/chunking-externals/_expected/system/main2.js b/test/chunking-form/samples/chunking-externals/_expected/system/main2.js index 001e0e6fc54..f418094a95e 100644 --- a/test/chunking-form/samples/chunking-externals/_expected/system/main2.js +++ b/test/chunking-form/samples/chunking-externals/_expected/system/main2.js @@ -1,28 +1,28 @@ System.register(['./generated-chunk.js', 'external'], function (exports, module) { 'use strict'; - var fn$1, fn; + var fn$3, fn$2; return { setters: [function (module) { - fn$1 = module.a; + fn$3 = module.a; }, function (module) { - fn = module.fn; + fn$2 = module.fn; }], execute: function () { - function fn$2 () { + function fn () { console.log('lib1 fn'); - fn(); + fn$2(); } - function fn$3 () { - fn$2(); + function fn$1 () { + fn(); console.log('dep3 fn'); } class Main2 { constructor () { - fn$3(); fn$1(); + fn$3(); } } exports('default', Main2); diff --git a/test/chunking-form/samples/chunking-source-maps/_expected/es/main1.js b/test/chunking-form/samples/chunking-source-maps/_expected/es/main1.js index 6208c9d11d2..f3bb708d5ae 100644 --- a/test/chunking-form/samples/chunking-source-maps/_expected/es/main1.js +++ b/test/chunking-form/samples/chunking-source-maps/_expected/es/main1.js @@ -1,13 +1,13 @@ -import { a as fn } from './generated-chunk.js'; +import { a as fn$1 } from './generated-chunk.js'; -function fn$1 () { +function fn () { console.log('dep1 fn'); } class Main1 { constructor () { - fn$1(); fn(); + fn$1(); } } diff --git a/test/chunking-form/samples/chunking-source-maps/_expected/es/main1.js.map b/test/chunking-form/samples/chunking-source-maps/_expected/es/main1.js.map index 09cdeda88c6..1b7f25f6a93 100644 --- a/test/chunking-form/samples/chunking-source-maps/_expected/es/main1.js.map +++ b/test/chunking-form/samples/chunking-source-maps/_expected/es/main1.js.map @@ -1 +1 @@ -{"version":3,"file":"main1.js","sources":["../../dep1.js","../../main1.js"],"sourcesContent":["export function fn () {\n console.log('dep1 fn');\n}","import { fn } from './dep1.js';\nimport { fn as fn2 } from './dep2.js';\n\nexport default class Main1 {\n constructor () {\n fn();\n fn2();\n }\n}"],"names":["fn","fn2"],"mappings":";;AAAO,SAASA,IAAE,IAAI;EACpB,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;;;CACxB,DCCc,MAAM,KAAK,CAAC;EACzB,WAAW,CAAC,GAAG;IACbA,IAAE,EAAE,CAAC;IACLC,EAAG,EAAE,CAAC;GACP;;;;;"} \ No newline at end of file +{"version":3,"file":"main1.js","sources":["../../dep1.js","../../main1.js"],"sourcesContent":["export function fn () {\n console.log('dep1 fn');\n}","import { fn } from './dep1.js';\nimport { fn as fn2 } from './dep2.js';\n\nexport default class Main1 {\n constructor () {\n fn();\n fn2();\n }\n}"],"names":["fn2"],"mappings":";;AAAO,SAAS,EAAE,IAAI;EACpB,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;;;CACxB,DCCc,MAAM,KAAK,CAAC;EACzB,WAAW,CAAC,GAAG;IACb,EAAE,EAAE,CAAC;IACLA,IAAG,EAAE,CAAC;GACP;;;;;"} \ No newline at end of file diff --git a/test/chunking-form/samples/chunking-source-maps/_expected/es/main2.js b/test/chunking-form/samples/chunking-source-maps/_expected/es/main2.js index 0e4653e679e..808d3dfd2f8 100644 --- a/test/chunking-form/samples/chunking-source-maps/_expected/es/main2.js +++ b/test/chunking-form/samples/chunking-source-maps/_expected/es/main2.js @@ -1,18 +1,18 @@ -import { a as fn } from './generated-chunk.js'; +import { a as fn$2 } from './generated-chunk.js'; -function fn$1 () { +function fn () { console.log('lib1 fn'); } -function fn$2 () { - fn$1(); +function fn$1 () { + fn(); console.log('dep3 fn'); } class Main2 { constructor () { + fn$1(); fn$2(); - fn(); } } diff --git a/test/chunking-form/samples/chunking-source-maps/_expected/es/main2.js.map b/test/chunking-form/samples/chunking-source-maps/_expected/es/main2.js.map index 2878e424e64..bfa2f78f99f 100644 --- a/test/chunking-form/samples/chunking-source-maps/_expected/es/main2.js.map +++ b/test/chunking-form/samples/chunking-source-maps/_expected/es/main2.js.map @@ -1 +1 @@ -{"version":3,"file":"main2.js","sources":["../../lib1.js","../../dep3.js","../../main2.js"],"sourcesContent":["export function fn () {\n console.log('lib1 fn');\n}\n\nexport function treeshaked () {\n console.log('this is tree shaken!');\n}","import { fn as libfn, treeshaked } from './lib1.js';\n\nexport function fn () {\n libfn();\n console.log('dep3 fn');\n}\n\nexport default treeshaked;","import { fn } from './dep2.js';\nimport { fn as fn2, default as treeshaked } from './dep3.js';\n\nif (false) {\n treeshaked();\n}\n\nexport default class Main2 {\n constructor () {\n fn2();\n fn();\n }\n}"],"names":["fn","libfn","fn2"],"mappings":";;AAAO,SAASA,IAAE,IAAI;EACpB,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;CACxB;;ACAM,SAASA,IAAE,IAAI;EACpBC,IAAK,EAAE,CAAC;EACR,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;CACxB;;ACEc,MAAM,KAAK,CAAC;EACzB,WAAW,CAAC,GAAG;IACbC,IAAG,EAAE,CAAC;IACN,EAAE,EAAE,CAAC;GACN;;;;;"} \ No newline at end of file +{"version":3,"file":"main2.js","sources":["../../lib1.js","../../dep3.js","../../main2.js"],"sourcesContent":["export function fn () {\n console.log('lib1 fn');\n}\n\nexport function treeshaked () {\n console.log('this is tree shaken!');\n}","import { fn as libfn, treeshaked } from './lib1.js';\n\nexport function fn () {\n libfn();\n console.log('dep3 fn');\n}\n\nexport default treeshaked;","import { fn } from './dep2.js';\nimport { fn as fn2, default as treeshaked } from './dep3.js';\n\nif (false) {\n treeshaked();\n}\n\nexport default class Main2 {\n constructor () {\n fn2();\n fn();\n }\n}"],"names":["fn","libfn","fn2"],"mappings":";;AAAO,SAAS,EAAE,IAAI;EACpB,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;CACxB;;ACAM,SAASA,IAAE,IAAI;EACpBC,EAAK,EAAE,CAAC;EACR,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;CACxB;;ACEc,MAAM,KAAK,CAAC;EACzB,WAAW,CAAC,GAAG;IACbC,IAAG,EAAE,CAAC;IACNF,IAAE,EAAE,CAAC;GACN;;;;;"} \ No newline at end of file diff --git a/test/chunking-form/samples/chunking-source-maps/_expected/system/main1.js b/test/chunking-form/samples/chunking-source-maps/_expected/system/main1.js index d8c34be1ee6..e3e50420418 100644 --- a/test/chunking-form/samples/chunking-source-maps/_expected/system/main1.js +++ b/test/chunking-form/samples/chunking-source-maps/_expected/system/main1.js @@ -1,20 +1,20 @@ System.register(['./generated-chunk.js'], function (exports, module) { 'use strict'; - var fn; + var fn$1; return { setters: [function (module) { - fn = module.a; + fn$1 = module.a; }], execute: function () { - function fn$1 () { + function fn () { console.log('dep1 fn'); } class Main1 { constructor () { - fn$1(); fn(); + fn$1(); } } exports('default', Main1); diff --git a/test/chunking-form/samples/chunking-source-maps/_expected/system/main1.js.map b/test/chunking-form/samples/chunking-source-maps/_expected/system/main1.js.map index 01e3e947e98..2ddddbf16b7 100644 --- a/test/chunking-form/samples/chunking-source-maps/_expected/system/main1.js.map +++ b/test/chunking-form/samples/chunking-source-maps/_expected/system/main1.js.map @@ -1 +1 @@ -{"version":3,"file":"main1.js","sources":["../../dep1.js","../../main1.js"],"sourcesContent":["export function fn () {\n console.log('dep1 fn');\n}","import { fn } from './dep1.js';\nimport { fn as fn2 } from './dep2.js';\n\nexport default class Main1 {\n constructor () {\n fn();\n fn2();\n }\n}"],"names":["fn","fn2"],"mappings":";;;;;;;;;MAAO,SAASA,IAAE,IAAI;MACtB,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;MACzB;;OAAC,DCCc,MAAM,KAAK,CAAC;MAC3B,EAAE,WAAW,CAAC,GAAG;MACjB,IAAIA,IAAE,EAAE,CAAC;MACT,IAAIC,EAAG,EAAE,CAAC;MACV,GAAG;MACH;;;;;;"} \ No newline at end of file +{"version":3,"file":"main1.js","sources":["../../dep1.js","../../main1.js"],"sourcesContent":["export function fn () {\n console.log('dep1 fn');\n}","import { fn } from './dep1.js';\nimport { fn as fn2 } from './dep2.js';\n\nexport default class Main1 {\n constructor () {\n fn();\n fn2();\n }\n}"],"names":["fn2"],"mappings":";;;;;;;;;MAAO,SAAS,EAAE,IAAI;MACtB,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;MACzB;;OAAC,DCCc,MAAM,KAAK,CAAC;MAC3B,EAAE,WAAW,CAAC,GAAG;MACjB,IAAI,EAAE,EAAE,CAAC;MACT,IAAIA,IAAG,EAAE,CAAC;MACV,GAAG;MACH;;;;;;"} \ No newline at end of file diff --git a/test/chunking-form/samples/chunking-source-maps/_expected/system/main2.js b/test/chunking-form/samples/chunking-source-maps/_expected/system/main2.js index 7fb97a6239c..723a0fb9c85 100644 --- a/test/chunking-form/samples/chunking-source-maps/_expected/system/main2.js +++ b/test/chunking-form/samples/chunking-source-maps/_expected/system/main2.js @@ -1,25 +1,25 @@ System.register(['./generated-chunk.js'], function (exports, module) { 'use strict'; - var fn; + var fn$2; return { setters: [function (module) { - fn = module.a; + fn$2 = module.a; }], execute: function () { - function fn$1 () { + function fn () { console.log('lib1 fn'); } - function fn$2 () { - fn$1(); + function fn$1 () { + fn(); console.log('dep3 fn'); } class Main2 { constructor () { + fn$1(); fn$2(); - fn(); } } exports('default', Main2); diff --git a/test/chunking-form/samples/chunking-source-maps/_expected/system/main2.js.map b/test/chunking-form/samples/chunking-source-maps/_expected/system/main2.js.map index 294acd6bda4..e168c3004c7 100644 --- a/test/chunking-form/samples/chunking-source-maps/_expected/system/main2.js.map +++ b/test/chunking-form/samples/chunking-source-maps/_expected/system/main2.js.map @@ -1 +1 @@ -{"version":3,"file":"main2.js","sources":["../../lib1.js","../../dep3.js","../../main2.js"],"sourcesContent":["export function fn () {\n console.log('lib1 fn');\n}\n\nexport function treeshaked () {\n console.log('this is tree shaken!');\n}","import { fn as libfn, treeshaked } from './lib1.js';\n\nexport function fn () {\n libfn();\n console.log('dep3 fn');\n}\n\nexport default treeshaked;","import { fn } from './dep2.js';\nimport { fn as fn2, default as treeshaked } from './dep3.js';\n\nif (false) {\n treeshaked();\n}\n\nexport default class Main2 {\n constructor () {\n fn2();\n fn();\n }\n}"],"names":["fn","libfn","fn2"],"mappings":";;;;;;;;;MAAO,SAASA,IAAE,IAAI;MACtB,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;MACzB,CAAC;;MCAM,SAASA,IAAE,IAAI;MACtB,EAAEC,IAAK,EAAE,CAAC;MACV,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;MACzB,CAAC;;MCEc,MAAM,KAAK,CAAC;MAC3B,EAAE,WAAW,CAAC,GAAG;MACjB,IAAIC,IAAG,EAAE,CAAC;MACV,IAAI,EAAE,EAAE,CAAC;MACT,GAAG;MACH;;;;;;"} \ No newline at end of file +{"version":3,"file":"main2.js","sources":["../../lib1.js","../../dep3.js","../../main2.js"],"sourcesContent":["export function fn () {\n console.log('lib1 fn');\n}\n\nexport function treeshaked () {\n console.log('this is tree shaken!');\n}","import { fn as libfn, treeshaked } from './lib1.js';\n\nexport function fn () {\n libfn();\n console.log('dep3 fn');\n}\n\nexport default treeshaked;","import { fn } from './dep2.js';\nimport { fn as fn2, default as treeshaked } from './dep3.js';\n\nif (false) {\n treeshaked();\n}\n\nexport default class Main2 {\n constructor () {\n fn2();\n fn();\n }\n}"],"names":["fn","libfn","fn2"],"mappings":";;;;;;;;;MAAO,SAAS,EAAE,IAAI;MACtB,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;MACzB,CAAC;;MCAM,SAASA,IAAE,IAAI;MACtB,EAAEC,EAAK,EAAE,CAAC;MACV,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;MACzB,CAAC;;MCEc,MAAM,KAAK,CAAC;MAC3B,EAAE,WAAW,CAAC,GAAG;MACjB,IAAIC,IAAG,EAAE,CAAC;MACV,IAAIF,IAAE,EAAE,CAAC;MACT,GAAG;MACH;;;;;;"} \ No newline at end of file diff --git a/test/chunking-form/samples/circular-entry-points/_expected/es/main1.js b/test/chunking-form/samples/circular-entry-points/_expected/es/main1.js index 1b41b8707a3..42544cfe1a8 100644 --- a/test/chunking-form/samples/circular-entry-points/_expected/es/main1.js +++ b/test/chunking-form/samples/circular-entry-points/_expected/es/main1.js @@ -1,13 +1,13 @@ -import { p } from './main2.js'; +import { p as p$1 } from './main2.js'; class C { fn (num) { - console.log(num - p); + console.log(num - p$1); } } -var p$1 = 42; +var p = 42; -new C().fn(p$1); +new C().fn(p); -export { p$1 as p }; +export { p }; diff --git a/test/chunking-form/samples/circular-entry-points/_expected/es/main2.js b/test/chunking-form/samples/circular-entry-points/_expected/es/main2.js index 450549fc074..9c6d6a82ad4 100644 --- a/test/chunking-form/samples/circular-entry-points/_expected/es/main2.js +++ b/test/chunking-form/samples/circular-entry-points/_expected/es/main2.js @@ -1,13 +1,13 @@ -import { p } from './main1.js'; +import { p as p$1 } from './main1.js'; class C { fn (num) { - console.log(num - p); + console.log(num - p$1); } } -var p$1 = 43; +var p = 43; -new C().fn(p$1); +new C().fn(p); -export { p$1 as p }; +export { p }; diff --git a/test/chunking-form/samples/circular-entry-points/_expected/system/main1.js b/test/chunking-form/samples/circular-entry-points/_expected/system/main1.js index 18b99439199..836d351f7a4 100644 --- a/test/chunking-form/samples/circular-entry-points/_expected/system/main1.js +++ b/test/chunking-form/samples/circular-entry-points/_expected/system/main1.js @@ -1,21 +1,21 @@ System.register(['./main2.js'], function (exports, module) { 'use strict'; - var p; + var p$1; return { setters: [function (module) { - p = module.p; + p$1 = module.p; }], execute: function () { class C { fn (num) { - console.log(num - p); + console.log(num - p$1); } } - var p$1 = exports('p', 42); + var p = exports('p', 42); - new C().fn(p$1); + new C().fn(p); } }; diff --git a/test/chunking-form/samples/circular-entry-points/_expected/system/main2.js b/test/chunking-form/samples/circular-entry-points/_expected/system/main2.js index 5a668e84329..3d24b81c863 100644 --- a/test/chunking-form/samples/circular-entry-points/_expected/system/main2.js +++ b/test/chunking-form/samples/circular-entry-points/_expected/system/main2.js @@ -1,21 +1,21 @@ System.register(['./main1.js'], function (exports, module) { 'use strict'; - var p; + var p$1; return { setters: [function (module) { - p = module.p; + p$1 = module.p; }], execute: function () { class C { fn (num) { - console.log(num - p); + console.log(num - p$1); } } - var p$1 = exports('p', 43); + var p = exports('p', 43); - new C().fn(p$1); + new C().fn(p); } }; diff --git a/test/chunking-form/samples/deconflict-globals/_config.js b/test/chunking-form/samples/deconflict-globals/_config.js new file mode 100644 index 00000000000..9ffbdeef487 --- /dev/null +++ b/test/chunking-form/samples/deconflict-globals/_config.js @@ -0,0 +1,6 @@ +module.exports = { + description: 'does not deconflict due to global variables used in other chunks', + options: { + input: ['main1.js', 'main2.js'] + } +}; diff --git a/test/chunking-form/samples/deconflict-globals/_expected/amd/generated-chunk.js b/test/chunking-form/samples/deconflict-globals/_expected/amd/generated-chunk.js new file mode 100644 index 00000000000..86200d0b228 --- /dev/null +++ b/test/chunking-form/samples/deconflict-globals/_expected/amd/generated-chunk.js @@ -0,0 +1,7 @@ +define(['exports'], function (exports) { 'use strict'; + + const x = 42; + + exports.x = x; + +}); diff --git a/test/chunking-form/samples/deconflict-globals/_expected/amd/main1.js b/test/chunking-form/samples/deconflict-globals/_expected/amd/main1.js new file mode 100644 index 00000000000..ecf5ce1bd53 --- /dev/null +++ b/test/chunking-form/samples/deconflict-globals/_expected/amd/main1.js @@ -0,0 +1,5 @@ +define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; + + console.log(__chunk_1.x); + +}); diff --git a/test/chunking-form/samples/deconflict-globals/_expected/amd/main2.js b/test/chunking-form/samples/deconflict-globals/_expected/amd/main2.js new file mode 100644 index 00000000000..178cb27ad02 --- /dev/null +++ b/test/chunking-form/samples/deconflict-globals/_expected/amd/main2.js @@ -0,0 +1,5 @@ +define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; + + console.log(x, __chunk_1.x); + +}); diff --git a/test/chunking-form/samples/deconflict-globals/_expected/cjs/generated-chunk.js b/test/chunking-form/samples/deconflict-globals/_expected/cjs/generated-chunk.js new file mode 100644 index 00000000000..fb016839358 --- /dev/null +++ b/test/chunking-form/samples/deconflict-globals/_expected/cjs/generated-chunk.js @@ -0,0 +1,5 @@ +'use strict'; + +const x = 42; + +exports.x = x; diff --git a/test/chunking-form/samples/deconflict-globals/_expected/cjs/main1.js b/test/chunking-form/samples/deconflict-globals/_expected/cjs/main1.js new file mode 100644 index 00000000000..ec89a94037f --- /dev/null +++ b/test/chunking-form/samples/deconflict-globals/_expected/cjs/main1.js @@ -0,0 +1,5 @@ +'use strict'; + +var __chunk_1 = require('./generated-chunk.js'); + +console.log(__chunk_1.x); diff --git a/test/chunking-form/samples/deconflict-globals/_expected/cjs/main2.js b/test/chunking-form/samples/deconflict-globals/_expected/cjs/main2.js new file mode 100644 index 00000000000..3fac3def85e --- /dev/null +++ b/test/chunking-form/samples/deconflict-globals/_expected/cjs/main2.js @@ -0,0 +1,5 @@ +'use strict'; + +var __chunk_1 = require('./generated-chunk.js'); + +console.log(x, __chunk_1.x); diff --git a/test/chunking-form/samples/deconflict-globals/_expected/es/generated-chunk.js b/test/chunking-form/samples/deconflict-globals/_expected/es/generated-chunk.js new file mode 100644 index 00000000000..cb011160c44 --- /dev/null +++ b/test/chunking-form/samples/deconflict-globals/_expected/es/generated-chunk.js @@ -0,0 +1,3 @@ +const x = 42; + +export { x as a }; diff --git a/test/chunking-form/samples/deconflict-globals/_expected/es/main1.js b/test/chunking-form/samples/deconflict-globals/_expected/es/main1.js new file mode 100644 index 00000000000..2052f3c6b15 --- /dev/null +++ b/test/chunking-form/samples/deconflict-globals/_expected/es/main1.js @@ -0,0 +1,3 @@ +import { a as x } from './generated-chunk.js'; + +console.log(x); diff --git a/test/chunking-form/samples/deconflict-globals/_expected/es/main2.js b/test/chunking-form/samples/deconflict-globals/_expected/es/main2.js new file mode 100644 index 00000000000..ac086ef15d8 --- /dev/null +++ b/test/chunking-form/samples/deconflict-globals/_expected/es/main2.js @@ -0,0 +1,3 @@ +import { a as x$1 } from './generated-chunk.js'; + +console.log(x, x$1); diff --git a/test/chunking-form/samples/deconflict-globals/_expected/system/generated-chunk.js b/test/chunking-form/samples/deconflict-globals/_expected/system/generated-chunk.js new file mode 100644 index 00000000000..3a036eab566 --- /dev/null +++ b/test/chunking-form/samples/deconflict-globals/_expected/system/generated-chunk.js @@ -0,0 +1,10 @@ +System.register([], function (exports, module) { + 'use strict'; + return { + execute: function () { + + const x = exports('a', 42); + + } + }; +}); diff --git a/test/chunking-form/samples/deconflict-globals/_expected/system/main1.js b/test/chunking-form/samples/deconflict-globals/_expected/system/main1.js new file mode 100644 index 00000000000..b25cd155ee5 --- /dev/null +++ b/test/chunking-form/samples/deconflict-globals/_expected/system/main1.js @@ -0,0 +1,14 @@ +System.register(['./generated-chunk.js'], function (exports, module) { + 'use strict'; + var x; + return { + setters: [function (module) { + x = module.a; + }], + execute: function () { + + console.log(x); + + } + }; +}); diff --git a/test/chunking-form/samples/deconflict-globals/_expected/system/main2.js b/test/chunking-form/samples/deconflict-globals/_expected/system/main2.js new file mode 100644 index 00000000000..d93652bc11f --- /dev/null +++ b/test/chunking-form/samples/deconflict-globals/_expected/system/main2.js @@ -0,0 +1,14 @@ +System.register(['./generated-chunk.js'], function (exports, module) { + 'use strict'; + var x$1; + return { + setters: [function (module) { + x$1 = module.a; + }], + execute: function () { + + console.log(x, x$1); + + } + }; +}); diff --git a/test/chunking-form/samples/deconflict-globals/dep.js b/test/chunking-form/samples/deconflict-globals/dep.js new file mode 100644 index 00000000000..310d1059fd1 --- /dev/null +++ b/test/chunking-form/samples/deconflict-globals/dep.js @@ -0,0 +1 @@ +export const x = 42; diff --git a/test/chunking-form/samples/deconflict-globals/main1.js b/test/chunking-form/samples/deconflict-globals/main1.js new file mode 100644 index 00000000000..7ccc3169ae4 --- /dev/null +++ b/test/chunking-form/samples/deconflict-globals/main1.js @@ -0,0 +1,3 @@ +import { x } from './dep.js'; + +console.log(x); diff --git a/test/chunking-form/samples/deconflict-globals/main2.js b/test/chunking-form/samples/deconflict-globals/main2.js new file mode 100644 index 00000000000..7ee085948b0 --- /dev/null +++ b/test/chunking-form/samples/deconflict-globals/main2.js @@ -0,0 +1,3 @@ +import { x as y } from './dep.js'; + +console.log(x, y); diff --git a/test/chunking-form/samples/default-identifier-renaming/_expected/es/main1.js b/test/chunking-form/samples/default-identifier-renaming/_expected/es/main1.js index b66386a2c4f..5e2ae12f26e 100644 --- a/test/chunking-form/samples/default-identifier-renaming/_expected/es/main1.js +++ b/test/chunking-form/samples/default-identifier-renaming/_expected/es/main1.js @@ -1,5 +1,5 @@ import { a as d } from './generated-chunk.js'; -var main1 = d.map(d$$1 => d$$1 + 1); +var main1 = d.map(d => d + 1); export default main1; diff --git a/test/chunking-form/samples/default-identifier-renaming/_expected/es/main2.js b/test/chunking-form/samples/default-identifier-renaming/_expected/es/main2.js index 66bc1c37724..b5b4434b163 100644 --- a/test/chunking-form/samples/default-identifier-renaming/_expected/es/main2.js +++ b/test/chunking-form/samples/default-identifier-renaming/_expected/es/main2.js @@ -1,5 +1,5 @@ import { a as d } from './generated-chunk.js'; -var main2 = d.map(d$$1 => d$$1 + 2); +var main2 = d.map(d => d + 2); export default main2; diff --git a/test/chunking-form/samples/default-identifier-renaming/_expected/system/main1.js b/test/chunking-form/samples/default-identifier-renaming/_expected/system/main1.js index 40e1ba5acaa..75db721a82c 100644 --- a/test/chunking-form/samples/default-identifier-renaming/_expected/system/main1.js +++ b/test/chunking-form/samples/default-identifier-renaming/_expected/system/main1.js @@ -7,7 +7,7 @@ System.register(['./generated-chunk.js'], function (exports, module) { }], execute: function () { - var main1 = exports('default', d.map(d$$1 => d$$1 + 1)); + var main1 = exports('default', d.map(d => d + 1)); } }; diff --git a/test/chunking-form/samples/default-identifier-renaming/_expected/system/main2.js b/test/chunking-form/samples/default-identifier-renaming/_expected/system/main2.js index a5ca28287e9..c5e348faf5f 100644 --- a/test/chunking-form/samples/default-identifier-renaming/_expected/system/main2.js +++ b/test/chunking-form/samples/default-identifier-renaming/_expected/system/main2.js @@ -7,7 +7,7 @@ System.register(['./generated-chunk.js'], function (exports, module) { }], execute: function () { - var main2 = exports('default', d.map(d$$1 => d$$1 + 2)); + var main2 = exports('default', d.map(d => d + 2)); } }; diff --git a/test/chunking-form/samples/manual-chunks/_expected/es/generated-deps2and3.js b/test/chunking-form/samples/manual-chunks/_expected/es/generated-deps2and3.js index 5553f9d81f9..d9be84c542f 100644 --- a/test/chunking-form/samples/manual-chunks/_expected/es/generated-deps2and3.js +++ b/test/chunking-form/samples/manual-chunks/_expected/es/generated-deps2and3.js @@ -1,17 +1,17 @@ -import { a as fn } from './generated-lib1.js'; +import { a as fn$3 } from './generated-lib1.js'; -function fn$1 () { +function fn () { console.log('lib2 fn'); } -function fn$2 () { - fn$1(); +function fn$1 () { + fn(); console.log('dep2 fn'); } -function fn$3 () { - fn(); +function fn$2 () { + fn$3(); console.log('dep3 fn'); } -export { fn$2 as a, fn$3 as b }; +export { fn$1 as a, fn$2 as b }; diff --git a/test/chunking-form/samples/manual-chunks/_expected/es/main.js b/test/chunking-form/samples/manual-chunks/_expected/es/main.js index bd4665fa093..676f34a10e9 100644 --- a/test/chunking-form/samples/manual-chunks/_expected/es/main.js +++ b/test/chunking-form/samples/manual-chunks/_expected/es/main.js @@ -1,15 +1,15 @@ -import { a as fn, b as fn$1 } from './generated-deps2and3.js'; +import { a as fn$1, b as fn$2 } from './generated-deps2and3.js'; import './generated-lib1.js'; -function fn$2 () { +function fn () { console.log('dep1 fn'); } class Main { constructor () { - fn$2(); fn(); fn$1(); + fn$2(); } } diff --git a/test/chunking-form/samples/manual-chunks/_expected/system/generated-deps2and3.js b/test/chunking-form/samples/manual-chunks/_expected/system/generated-deps2and3.js index 7fe6746bb8b..844ae56c574 100644 --- a/test/chunking-form/samples/manual-chunks/_expected/system/generated-deps2and3.js +++ b/test/chunking-form/samples/manual-chunks/_expected/system/generated-deps2and3.js @@ -1,28 +1,28 @@ System.register(['./generated-lib1.js'], function (exports, module) { 'use strict'; - var fn; + var fn$3; return { setters: [function (module) { - fn = module.a; + fn$3 = module.a; }], execute: function () { exports({ - a: fn$2, - b: fn$3 + a: fn$1, + b: fn$2 }); - function fn$1 () { + function fn () { console.log('lib2 fn'); } - function fn$2 () { - fn$1(); + function fn$1 () { + fn(); console.log('dep2 fn'); } - function fn$3 () { - fn(); + function fn$2 () { + fn$3(); console.log('dep3 fn'); } diff --git a/test/chunking-form/samples/manual-chunks/_expected/system/main.js b/test/chunking-form/samples/manual-chunks/_expected/system/main.js index 1c07e7716a3..e8d21361a0a 100644 --- a/test/chunking-form/samples/manual-chunks/_expected/system/main.js +++ b/test/chunking-form/samples/manual-chunks/_expected/system/main.js @@ -1,22 +1,22 @@ System.register(['./generated-deps2and3.js', './generated-lib1.js'], function (exports, module) { 'use strict'; - var fn, fn$1; + var fn$1, fn$2; return { setters: [function (module) { - fn = module.a; - fn$1 = module.b; + fn$1 = module.a; + fn$2 = module.b; }, function () {}], execute: function () { - function fn$2 () { + function fn () { console.log('dep1 fn'); } class Main { constructor () { - fn$2(); fn(); fn$1(); + fn$2(); } } exports('default', Main); diff --git a/test/chunking-form/samples/missing-export-compact/_expected/es/main.js b/test/chunking-form/samples/missing-export-compact/_expected/es/main.js index ac1e69ef80f..f1d0a6754a0 100644 --- a/test/chunking-form/samples/missing-export-compact/_expected/es/main.js +++ b/test/chunking-form/samples/missing-export-compact/_expected/es/main.js @@ -1,2 +1,2 @@ -import {missingFn as _missingExportShim$1,x}from'./dep.js';_missingExportShim$1(); -x(_missingExportShim$1); \ No newline at end of file +import {missingFn as _missingExportShim,x}from'./dep.js';_missingExportShim(); +x(_missingExportShim); \ No newline at end of file diff --git a/test/chunking-form/samples/missing-export-compact/_expected/system/main.js b/test/chunking-form/samples/missing-export-compact/_expected/system/main.js index 2526542b862..68308ec298a 100644 --- a/test/chunking-form/samples/missing-export-compact/_expected/system/main.js +++ b/test/chunking-form/samples/missing-export-compact/_expected/system/main.js @@ -1,2 +1,2 @@ -System.register(['./dep.js'],function(exports,module){'use strict';var _missingExportShim$1,x;return{setters:[function(module){_missingExportShim$1=module.missingFn;x=module.x;}],execute:function(){_missingExportShim$1(); -x(_missingExportShim$1);}}}); \ No newline at end of file +System.register(['./dep.js'],function(exports,module){'use strict';var _missingExportShim,x;return{setters:[function(module){_missingExportShim=module.missingFn;x=module.x;}],execute:function(){_missingExportShim(); +x(_missingExportShim);}}}); \ No newline at end of file diff --git a/test/chunking-form/samples/missing-export-reused-deconflicting/_expected/es/main.js b/test/chunking-form/samples/missing-export-reused-deconflicting/_expected/es/main.js index 92a53c97ac5..ea2616a1c8c 100644 --- a/test/chunking-form/samples/missing-export-reused-deconflicting/_expected/es/main.js +++ b/test/chunking-form/samples/missing-export-reused-deconflicting/_expected/es/main.js @@ -1,4 +1,4 @@ -import { missing1 as _missingExportShim$1 } from './dep1.js'; -import { missing2 as _missingExportShim$2, previousShimmedExport as _missingExportShim$3 } from './dep2.js'; +import { missing1 as _missingExportShim } from './dep1.js'; +import { missing2 as _missingExportShim$1, previousShimmedExport as _missingExportShim$2 } from './dep2.js'; -console.log(_missingExportShim$1, _missingExportShim$2, _missingExportShim$3); +console.log(_missingExportShim, _missingExportShim$1, _missingExportShim$2); diff --git a/test/chunking-form/samples/missing-export-reused-deconflicting/_expected/system/main.js b/test/chunking-form/samples/missing-export-reused-deconflicting/_expected/system/main.js index 286d38bda38..0fb8136ac7c 100644 --- a/test/chunking-form/samples/missing-export-reused-deconflicting/_expected/system/main.js +++ b/test/chunking-form/samples/missing-export-reused-deconflicting/_expected/system/main.js @@ -1,16 +1,16 @@ System.register(['./dep1.js', './dep2.js'], function (exports, module) { 'use strict'; - var _missingExportShim$1, _missingExportShim$2, _missingExportShim$3; + var _missingExportShim, _missingExportShim$1, _missingExportShim$2; return { setters: [function (module) { - _missingExportShim$1 = module.missing1; + _missingExportShim = module.missing1; }, function (module) { - _missingExportShim$2 = module.missing2; - _missingExportShim$3 = module.previousShimmedExport; + _missingExportShim$1 = module.missing2; + _missingExportShim$2 = module.previousShimmedExport; }], execute: function () { - console.log(_missingExportShim$1, _missingExportShim$2, _missingExportShim$3); + console.log(_missingExportShim, _missingExportShim$1, _missingExportShim$2); } }; diff --git a/test/chunking-form/samples/missing-export/_expected/es/main.js b/test/chunking-form/samples/missing-export/_expected/es/main.js index f539ec1208a..42ed3d2bae5 100644 --- a/test/chunking-form/samples/missing-export/_expected/es/main.js +++ b/test/chunking-form/samples/missing-export/_expected/es/main.js @@ -1,4 +1,4 @@ -import { missingFn as _missingExportShim$1, x } from './dep.js'; +import { missingFn as _missingExportShim, x } from './dep.js'; -_missingExportShim$1(); -x(_missingExportShim$1, _missingExportShim$1); +_missingExportShim(); +x(_missingExportShim, _missingExportShim); diff --git a/test/chunking-form/samples/missing-export/_expected/system/main.js b/test/chunking-form/samples/missing-export/_expected/system/main.js index 77d033e0e64..8aeac7a4e88 100644 --- a/test/chunking-form/samples/missing-export/_expected/system/main.js +++ b/test/chunking-form/samples/missing-export/_expected/system/main.js @@ -1,15 +1,15 @@ System.register(['./dep.js'], function (exports, module) { 'use strict'; - var _missingExportShim$1, x; + var _missingExportShim, x; return { setters: [function (module) { - _missingExportShim$1 = module.missingFn; + _missingExportShim = module.missingFn; x = module.x; }], execute: function () { - _missingExportShim$1(); - x(_missingExportShim$1, _missingExportShim$1); + _missingExportShim(); + x(_missingExportShim, _missingExportShim); } }; diff --git a/test/chunking-form/samples/namespace-reexports/_expected/amd/generated-index.js b/test/chunking-form/samples/namespace-reexports/_expected/amd/generated-index.js index 9b004ebccc7..cbc8db134cb 100644 --- a/test/chunking-form/samples/namespace-reexports/_expected/amd/generated-index.js +++ b/test/chunking-form/samples/namespace-reexports/_expected/amd/generated-index.js @@ -1,14 +1,14 @@ -define(['exports', './hsl2hsv.js'], function (exports, hsl2hsv) { 'use strict'; +define(['exports', './hsl2hsv.js'], function (exports, hsl2hsv$1) { 'use strict'; - var hsl2hsv$1 = 'asdf'; + var hsl2hsv = 'asdf'; - console.log(hsl2hsv$1); + console.log(hsl2hsv); var lib = /*#__PURE__*/Object.freeze({ - hsl2hsv: hsl2hsv.default + hsl2hsv: hsl2hsv$1.default }); - exports.hsl2hsv = hsl2hsv.default; + exports.hsl2hsv = hsl2hsv$1.default; exports.lib = lib; }); diff --git a/test/chunking-form/samples/namespace-reexports/_expected/amd/index.js b/test/chunking-form/samples/namespace-reexports/_expected/amd/index.js index 60f6d952bf6..c51c47b4df8 100644 --- a/test/chunking-form/samples/namespace-reexports/_expected/amd/index.js +++ b/test/chunking-form/samples/namespace-reexports/_expected/amd/index.js @@ -1,8 +1,8 @@ -define(['exports', './hsl2hsv.js', './generated-index.js'], function (exports, hsl2hsv, index) { 'use strict'; +define(['exports', './hsl2hsv.js', './generated-index.js'], function (exports, hsl2hsv$1, index) { 'use strict'; - exports.hsl2hsv = hsl2hsv.default; + exports.hsl2hsv = hsl2hsv$1.default; Object.defineProperty(exports, '__esModule', { value: true }); diff --git a/test/chunking-form/samples/namespace-reexports/_expected/amd/main.js b/test/chunking-form/samples/namespace-reexports/_expected/amd/main.js index 895f9d9905c..71dd02c2f28 100644 --- a/test/chunking-form/samples/namespace-reexports/_expected/amd/main.js +++ b/test/chunking-form/samples/namespace-reexports/_expected/amd/main.js @@ -1,6 +1,6 @@ -define(['exports', './hsl2hsv.js', './generated-index.js'], function (exports, hsl2hsv, index) { 'use strict'; +define(['exports', './hsl2hsv.js', './generated-index.js'], function (exports, hsl2hsv$1, index) { 'use strict'; - console.log(hsl2hsv.p); + console.log(hsl2hsv$1.p); var main = new Map(Object.entries(index.lib)); exports.default = main; diff --git a/test/chunking-form/samples/namespace-reexports/_expected/cjs/generated-index.js b/test/chunking-form/samples/namespace-reexports/_expected/cjs/generated-index.js index 0b3ca132f28..dd171505ad1 100644 --- a/test/chunking-form/samples/namespace-reexports/_expected/cjs/generated-index.js +++ b/test/chunking-form/samples/namespace-reexports/_expected/cjs/generated-index.js @@ -1,14 +1,14 @@ 'use strict'; -var hsl2hsv = require('./hsl2hsv.js'); +var hsl2hsv$1 = require('./hsl2hsv.js'); -var hsl2hsv$1 = 'asdf'; +var hsl2hsv = 'asdf'; -console.log(hsl2hsv$1); +console.log(hsl2hsv); var lib = /*#__PURE__*/Object.freeze({ - hsl2hsv: hsl2hsv.default + hsl2hsv: hsl2hsv$1.default }); -exports.hsl2hsv = hsl2hsv.default; +exports.hsl2hsv = hsl2hsv$1.default; exports.lib = lib; diff --git a/test/chunking-form/samples/namespace-reexports/_expected/cjs/index.js b/test/chunking-form/samples/namespace-reexports/_expected/cjs/index.js index c2a0180929c..cd95edf7d26 100644 --- a/test/chunking-form/samples/namespace-reexports/_expected/cjs/index.js +++ b/test/chunking-form/samples/namespace-reexports/_expected/cjs/index.js @@ -2,9 +2,9 @@ Object.defineProperty(exports, '__esModule', { value: true }); -var hsl2hsv = require('./hsl2hsv.js'); +var hsl2hsv$1 = require('./hsl2hsv.js'); require('./generated-index.js'); -exports.hsl2hsv = hsl2hsv.default; +exports.hsl2hsv = hsl2hsv$1.default; diff --git a/test/chunking-form/samples/namespace-reexports/_expected/cjs/main.js b/test/chunking-form/samples/namespace-reexports/_expected/cjs/main.js index 2ca1ab022e7..f56ee42c2ad 100644 --- a/test/chunking-form/samples/namespace-reexports/_expected/cjs/main.js +++ b/test/chunking-form/samples/namespace-reexports/_expected/cjs/main.js @@ -2,10 +2,10 @@ Object.defineProperty(exports, '__esModule', { value: true }); -var hsl2hsv = require('./hsl2hsv.js'); +var hsl2hsv$1 = require('./hsl2hsv.js'); var index = require('./generated-index.js'); -console.log(hsl2hsv.p); +console.log(hsl2hsv$1.p); var main = new Map(Object.entries(index.lib)); exports.default = main; diff --git a/test/chunking-form/samples/namespace-reexports/_expected/es/generated-index.js b/test/chunking-form/samples/namespace-reexports/_expected/es/generated-index.js index 3ac4915370c..fdae9a7b094 100644 --- a/test/chunking-form/samples/namespace-reexports/_expected/es/generated-index.js +++ b/test/chunking-form/samples/namespace-reexports/_expected/es/generated-index.js @@ -1,12 +1,12 @@ -import hsl2hsv from './hsl2hsv.js'; +import hsl2hsv$1 from './hsl2hsv.js'; export { default as b } from './hsl2hsv.js'; -var hsl2hsv$1 = 'asdf'; +var hsl2hsv = 'asdf'; -console.log(hsl2hsv$1); +console.log(hsl2hsv); var lib = /*#__PURE__*/Object.freeze({ - hsl2hsv: hsl2hsv + hsl2hsv: hsl2hsv$1 }); export { lib as a }; diff --git a/test/chunking-form/samples/namespace-reexports/_expected/system/generated-index.js b/test/chunking-form/samples/namespace-reexports/_expected/system/generated-index.js index d0a0491b975..e0ee5ac921d 100644 --- a/test/chunking-form/samples/namespace-reexports/_expected/system/generated-index.js +++ b/test/chunking-form/samples/namespace-reexports/_expected/system/generated-index.js @@ -1,19 +1,19 @@ System.register(['./hsl2hsv.js'], function (exports, module) { 'use strict'; - var hsl2hsv; + var hsl2hsv$1; return { setters: [function (module) { - hsl2hsv = module.default; + hsl2hsv$1 = module.default; exports('b', module.default); }], execute: function () { - var hsl2hsv$1 = 'asdf'; + var hsl2hsv = 'asdf'; - console.log(hsl2hsv$1); + console.log(hsl2hsv); var lib = /*#__PURE__*/Object.freeze({ - hsl2hsv: hsl2hsv + hsl2hsv: hsl2hsv$1 }); exports('a', lib); diff --git a/test/chunking-form/samples/preserve-modules/_expected/es/deps/dep2.js b/test/chunking-form/samples/preserve-modules/_expected/es/deps/dep2.js index 1a6bce7872f..233b8235a07 100644 --- a/test/chunking-form/samples/preserve-modules/_expected/es/deps/dep2.js +++ b/test/chunking-form/samples/preserve-modules/_expected/es/deps/dep2.js @@ -1,8 +1,8 @@ -import { fn } from '../lib/lib2.js'; +import { fn as fn$1 } from '../lib/lib2.js'; -function fn$1 () { - fn(); +function fn () { + fn$1(); console.log('dep2 fn'); } -export { fn$1 as fn }; +export { fn }; diff --git a/test/chunking-form/samples/preserve-modules/_expected/es/deps/dep3.js b/test/chunking-form/samples/preserve-modules/_expected/es/deps/dep3.js index 37a799dca5c..e01b47ef194 100644 --- a/test/chunking-form/samples/preserve-modules/_expected/es/deps/dep3.js +++ b/test/chunking-form/samples/preserve-modules/_expected/es/deps/dep3.js @@ -1,8 +1,8 @@ -import { fn } from '../lib/lib1.js'; +import { fn as fn$1 } from '../lib/lib1.js'; -function fn$1 () { - fn(); +function fn () { + fn$1(); console.log('dep3 fn'); } -export { fn$1 as fn }; +export { fn }; diff --git a/test/chunking-form/samples/preserve-modules/_expected/system/deps/dep2.js b/test/chunking-form/samples/preserve-modules/_expected/system/deps/dep2.js index a0de7bf50a0..2346c04ce26 100644 --- a/test/chunking-form/samples/preserve-modules/_expected/system/deps/dep2.js +++ b/test/chunking-form/samples/preserve-modules/_expected/system/deps/dep2.js @@ -1,16 +1,16 @@ System.register(['../lib/lib2.js'], function (exports, module) { 'use strict'; - var fn; + var fn$1; return { setters: [function (module) { - fn = module.fn; + fn$1 = module.fn; }], execute: function () { - exports('fn', fn$1); + exports('fn', fn); - function fn$1 () { - fn(); + function fn () { + fn$1(); console.log('dep2 fn'); } diff --git a/test/chunking-form/samples/preserve-modules/_expected/system/deps/dep3.js b/test/chunking-form/samples/preserve-modules/_expected/system/deps/dep3.js index a6ad419f143..3e8250b3b5b 100644 --- a/test/chunking-form/samples/preserve-modules/_expected/system/deps/dep3.js +++ b/test/chunking-form/samples/preserve-modules/_expected/system/deps/dep3.js @@ -1,16 +1,16 @@ System.register(['../lib/lib1.js'], function (exports, module) { 'use strict'; - var fn; + var fn$1; return { setters: [function (module) { - fn = module.fn; + fn$1 = module.fn; }], execute: function () { - exports('fn', fn$1); + exports('fn', fn); - function fn$1 () { - fn(); + function fn () { + fn$1(); console.log('dep3 fn'); } diff --git a/test/form/samples/catch-parameter-shadowing/_expected/es.js b/test/form/samples/catch-parameter-shadowing/_expected.js similarity index 54% rename from test/form/samples/catch-parameter-shadowing/_expected/es.js rename to test/form/samples/catch-parameter-shadowing/_expected.js index 559defc39da..9d0fa366968 100644 --- a/test/form/samples/catch-parameter-shadowing/_expected/es.js +++ b/test/form/samples/catch-parameter-shadowing/_expected.js @@ -3,8 +3,8 @@ const e = 2.7182818284; function something () { try { console.log( e ); - } catch ( e$$1 ) { // the catch identifier shadows the import - console.error( e$$1 ); + } catch ( e ) { // the catch identifier shadows the import + console.error( e ); } } diff --git a/test/form/samples/catch-parameter-shadowing/_expected/amd.js b/test/form/samples/catch-parameter-shadowing/_expected/amd.js deleted file mode 100644 index 3d4b2da98ba..00000000000 --- a/test/form/samples/catch-parameter-shadowing/_expected/amd.js +++ /dev/null @@ -1,17 +0,0 @@ -define(['exports'], function (exports) { 'use strict'; - - const e = 2.7182818284; - - function something () { - try { - console.log( e ); - } catch ( e$$1 ) { // the catch identifier shadows the import - console.error( e$$1 ); - } - } - - exports.something = something; - - Object.defineProperty(exports, '__esModule', { value: true }); - -}); diff --git a/test/form/samples/catch-parameter-shadowing/_expected/cjs.js b/test/form/samples/catch-parameter-shadowing/_expected/cjs.js deleted file mode 100644 index d544c6d1f1d..00000000000 --- a/test/form/samples/catch-parameter-shadowing/_expected/cjs.js +++ /dev/null @@ -1,15 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, '__esModule', { value: true }); - -const e = 2.7182818284; - -function something () { - try { - console.log( e ); - } catch ( e$$1 ) { // the catch identifier shadows the import - console.error( e$$1 ); - } -} - -exports.something = something; diff --git a/test/form/samples/catch-parameter-shadowing/_expected/iife.js b/test/form/samples/catch-parameter-shadowing/_expected/iife.js deleted file mode 100644 index 97a935d848b..00000000000 --- a/test/form/samples/catch-parameter-shadowing/_expected/iife.js +++ /dev/null @@ -1,18 +0,0 @@ -var bundle = (function (exports) { - 'use strict'; - - const e = 2.7182818284; - - function something () { - try { - console.log( e ); - } catch ( e$$1 ) { // the catch identifier shadows the import - console.error( e$$1 ); - } - } - - exports.something = something; - - return exports; - -}({})); diff --git a/test/form/samples/catch-parameter-shadowing/_expected/system.js b/test/form/samples/catch-parameter-shadowing/_expected/system.js deleted file mode 100644 index 43feb02e16d..00000000000 --- a/test/form/samples/catch-parameter-shadowing/_expected/system.js +++ /dev/null @@ -1,20 +0,0 @@ -System.register('bundle', [], function (exports, module) { - 'use strict'; - return { - execute: function () { - - exports('something', something); - - const e = 2.7182818284; - - function something () { - try { - console.log( e ); - } catch ( e$$1 ) { // the catch identifier shadows the import - console.error( e$$1 ); - } - } - - } - }; -}); diff --git a/test/form/samples/compact/_config.js b/test/form/samples/compact/_config.js index 870f5f3a0d0..c4b7e180e18 100644 --- a/test/form/samples/compact/_config.js +++ b/test/form/samples/compact/_config.js @@ -1,6 +1,7 @@ module.exports = { description: 'compact output with compact: true', options: { + external: ['external'], output: { name: 'foo', compact: true, diff --git a/test/form/samples/compact/_expected/amd.js b/test/form/samples/compact/_expected/amd.js index 99d0972df45..c0c925741aa 100644 --- a/test/form/samples/compact/_expected/amd.js +++ b/test/form/samples/compact/_expected/amd.js @@ -1,6 +1,6 @@ -define(['external'],function(x){'use strict';x=x&&x.hasOwnProperty('default')?x['default']:x;var self = {get default(){return foo$$1}};if(typeof Symbol!=='undefined'&&Symbol.toStringTag)Object.defineProperty(self,Symbol.toStringTag,{value:'Module'});else Object.defineProperty(self,'toString',{value:function(){return'[object Module]';}});/*#__PURE__*/Object.freeze(self);console.log(self); -function foo$$1 () { +define(['external'],function(x){'use strict';x=x&&x.hasOwnProperty('default')?x['default']:x;var self = {get default(){return foo}};if(typeof Symbol!=='undefined'&&Symbol.toStringTag)Object.defineProperty(self,Symbol.toStringTag,{value:'Module'});else Object.defineProperty(self,'toString',{value:function(){return'[object Module]';}});/*#__PURE__*/Object.freeze(self);console.log(self); +function foo () { console.log( x ); } // trailing comment -return foo$$1;}); \ No newline at end of file +return foo;}); diff --git a/test/form/samples/compact/_expected/cjs.js b/test/form/samples/compact/_expected/cjs.js index 9879460689f..c0276a75f26 100644 --- a/test/form/samples/compact/_expected/cjs.js +++ b/test/form/samples/compact/_expected/cjs.js @@ -1,6 +1,6 @@ -'use strict';function _interopDefault(e){return(e&&(typeof e==='object')&&'default'in e)?e['default']:e}var x=_interopDefault(require('external'));var self = {get default(){return foo$$1}};if(typeof Symbol!=='undefined'&&Symbol.toStringTag)Object.defineProperty(self,Symbol.toStringTag,{value:'Module'});else Object.defineProperty(self,'toString',{value:function(){return'[object Module]';}});/*#__PURE__*/Object.freeze(self);console.log(self); -function foo$$1 () { +'use strict';function _interopDefault(e){return(e&&(typeof e==='object')&&'default'in e)?e['default']:e}var x=_interopDefault(require('external'));var self = {get default(){return foo}};if(typeof Symbol!=='undefined'&&Symbol.toStringTag)Object.defineProperty(self,Symbol.toStringTag,{value:'Module'});else Object.defineProperty(self,'toString',{value:function(){return'[object Module]';}});/*#__PURE__*/Object.freeze(self);console.log(self); +function foo () { console.log( x ); } // trailing comment -module.exports=foo$$1; \ No newline at end of file +module.exports=foo; diff --git a/test/form/samples/compact/_expected/es.js b/test/form/samples/compact/_expected/es.js index 8f810503d10..16cecd7ccd7 100644 --- a/test/form/samples/compact/_expected/es.js +++ b/test/form/samples/compact/_expected/es.js @@ -1,6 +1,6 @@ -import x from'external';var self = {get default(){return foo$$1}};if(typeof Symbol!=='undefined'&&Symbol.toStringTag)Object.defineProperty(self,Symbol.toStringTag,{value:'Module'});else Object.defineProperty(self,'toString',{value:function(){return'[object Module]';}});/*#__PURE__*/Object.freeze(self);console.log(self); -function foo$$1 () { +import x from'external';var self = {get default(){return foo}};if(typeof Symbol!=='undefined'&&Symbol.toStringTag)Object.defineProperty(self,Symbol.toStringTag,{value:'Module'});else Object.defineProperty(self,'toString',{value:function(){return'[object Module]';}});/*#__PURE__*/Object.freeze(self);console.log(self); +function foo () { console.log( x ); } // trailing comment -export default foo$$1; \ No newline at end of file +export default foo; diff --git a/test/form/samples/compact/_expected/iife.js b/test/form/samples/compact/_expected/iife.js index 3f2bf173d83..1f8ea4d384d 100644 --- a/test/form/samples/compact/_expected/iife.js +++ b/test/form/samples/compact/_expected/iife.js @@ -1,6 +1,6 @@ -var foo=(function(x){'use strict';x=x&&x.hasOwnProperty('default')?x['default']:x;var self = {get default(){return foo$$1}};if(typeof Symbol!=='undefined'&&Symbol.toStringTag)Object.defineProperty(self,Symbol.toStringTag,{value:'Module'});else Object.defineProperty(self,'toString',{value:function(){return'[object Module]';}});/*#__PURE__*/Object.freeze(self);console.log(self); -function foo$$1 () { +var foo=(function(x){'use strict';x=x&&x.hasOwnProperty('default')?x['default']:x;var self = {get default(){return foo}};if(typeof Symbol!=='undefined'&&Symbol.toStringTag)Object.defineProperty(self,Symbol.toStringTag,{value:'Module'});else Object.defineProperty(self,'toString',{value:function(){return'[object Module]';}});/*#__PURE__*/Object.freeze(self);console.log(self); +function foo () { console.log( x ); } // trailing comment -return foo$$1;}(x)); \ No newline at end of file +return foo;}(x)); diff --git a/test/form/samples/compact/_expected/system.js b/test/form/samples/compact/_expected/system.js index e421580bee1..a49e388d827 100644 --- a/test/form/samples/compact/_expected/system.js +++ b/test/form/samples/compact/_expected/system.js @@ -1,6 +1,6 @@ -System.register('foo',['external'],function(exports,module){'use strict';var x;return{setters:[function(module){x=module.default;}],execute:function(){exports('default',foo$$1);var self = {get default(){return foo$$1}};if(typeof Symbol!=='undefined'&&Symbol.toStringTag)Object.defineProperty(self,Symbol.toStringTag,{value:'Module'});else Object.defineProperty(self,'toString',{value:function(){return'[object Module]';}});/*#__PURE__*/Object.freeze(self);console.log(self); -function foo$$1 () { +System.register('foo',['external'],function(exports,module){'use strict';var x;return{setters:[function(module){x=module.default;}],execute:function(){exports('default',foo);var self = {get default(){return foo}};if(typeof Symbol!=='undefined'&&Symbol.toStringTag)Object.defineProperty(self,Symbol.toStringTag,{value:'Module'});else Object.defineProperty(self,'toString',{value:function(){return'[object Module]';}});/*#__PURE__*/Object.freeze(self);console.log(self); +function foo () { console.log( x ); } // trailing comment -}}}); \ No newline at end of file +}}}); diff --git a/test/form/samples/compact/_expected/umd.js b/test/form/samples/compact/_expected/umd.js index ea9dbe3f7da..7902ad4e3ff 100644 --- a/test/form/samples/compact/_expected/umd.js +++ b/test/form/samples/compact/_expected/umd.js @@ -1,6 +1,6 @@ -(function(g,f){typeof exports==='object'&&typeof module!=='undefined'?module.exports=f(require('external')):typeof define==='function'&&define.amd?define(['external'],f):(g=g||self,g.foo=f(g.x));}(this,function(x){'use strict';x=x&&x.hasOwnProperty('default')?x['default']:x;var self = {get default(){return foo$$1}};if(typeof Symbol!=='undefined'&&Symbol.toStringTag)Object.defineProperty(self,Symbol.toStringTag,{value:'Module'});else Object.defineProperty(self,'toString',{value:function(){return'[object Module]';}});/*#__PURE__*/Object.freeze(self);console.log(self); -function foo$$1 () { +(function(g,f){typeof exports==='object'&&typeof module!=='undefined'?module.exports=f(require('external')):typeof define==='function'&&define.amd?define(['external'],f):(g=g||self,g.foo=f(g.x));}(this,function(x){'use strict';x=x&&x.hasOwnProperty('default')?x['default']:x;var self = {get default(){return foo}};if(typeof Symbol!=='undefined'&&Symbol.toStringTag)Object.defineProperty(self,Symbol.toStringTag,{value:'Module'});else Object.defineProperty(self,'toString',{value:function(){return'[object Module]';}});/*#__PURE__*/Object.freeze(self);console.log(self); +function foo () { console.log( x ); } // trailing comment -return foo$$1;})); \ No newline at end of file +return foo;})); diff --git a/test/form/samples/deconflict-format-specific-exports/_config.js b/test/form/samples/deconflict-format-specific-exports/_config.js new file mode 100644 index 00000000000..3618b693baf --- /dev/null +++ b/test/form/samples/deconflict-format-specific-exports/_config.js @@ -0,0 +1,4 @@ +module.exports = { + description: 'only deconflict "exports" for formats where it is necessary', + options: { output: { name: 'bundle' } } +}; diff --git a/test/form/samples/deconflict-format-specific-exports/_expected/amd.js b/test/form/samples/deconflict-format-specific-exports/_expected/amd.js new file mode 100644 index 00000000000..e060619b182 --- /dev/null +++ b/test/form/samples/deconflict-format-specific-exports/_expected/amd.js @@ -0,0 +1,29 @@ +define(['exports'], function (exports) { 'use strict'; + + const exports$1 = { + x: 42 + }; + console.log(exports$1); + + function nestedConflict() { + const exports$1 = { + x: 42 + }; + console.log(exports$1); + exports.x++; + } + + function nestedNoConflict() { + const exports = { + x: 42 + }; + console.log(exports); + } + + exports.x = 43; + nestedConflict(); + nestedNoConflict(); + + Object.defineProperty(exports, '__esModule', { value: true }); + +}); diff --git a/test/form/samples/deconflict-format-specific-exports/_expected/cjs.js b/test/form/samples/deconflict-format-specific-exports/_expected/cjs.js new file mode 100644 index 00000000000..21cadc195ec --- /dev/null +++ b/test/form/samples/deconflict-format-specific-exports/_expected/cjs.js @@ -0,0 +1,27 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +const exports$1 = { + x: 42 +}; +console.log(exports$1); + +function nestedConflict() { + const exports$1 = { + x: 42 + }; + console.log(exports$1); + exports.x++; +} + +function nestedNoConflict() { + const exports = { + x: 42 + }; + console.log(exports); +} + +exports.x = 43; +nestedConflict(); +nestedNoConflict(); diff --git a/test/form/samples/deconflict-format-specific-exports/_expected/es.js b/test/form/samples/deconflict-format-specific-exports/_expected/es.js new file mode 100644 index 00000000000..131a3701263 --- /dev/null +++ b/test/form/samples/deconflict-format-specific-exports/_expected/es.js @@ -0,0 +1,25 @@ +const exports = { + x: 42 +}; +console.log(exports); + +function nestedConflict() { + const exports = { + x: 42 + }; + console.log(exports); + x++; +} + +function nestedNoConflict() { + const exports = { + x: 42 + }; + console.log(exports); +} + +var x = 43; +nestedConflict(); +nestedNoConflict(); + +export { x }; diff --git a/test/form/samples/deconflict-format-specific-exports/_expected/iife.js b/test/form/samples/deconflict-format-specific-exports/_expected/iife.js new file mode 100644 index 00000000000..0ec8042b07c --- /dev/null +++ b/test/form/samples/deconflict-format-specific-exports/_expected/iife.js @@ -0,0 +1,30 @@ +var bundle = (function (exports) { + 'use strict'; + + const exports$1 = { + x: 42 + }; + console.log(exports$1); + + function nestedConflict() { + const exports$1 = { + x: 42 + }; + console.log(exports$1); + exports.x++; + } + + function nestedNoConflict() { + const exports = { + x: 42 + }; + console.log(exports); + } + + exports.x = 43; + nestedConflict(); + nestedNoConflict(); + + return exports; + +}({})); diff --git a/test/form/samples/deconflict-format-specific-exports/_expected/system.js b/test/form/samples/deconflict-format-specific-exports/_expected/system.js new file mode 100644 index 00000000000..b78cf175a69 --- /dev/null +++ b/test/form/samples/deconflict-format-specific-exports/_expected/system.js @@ -0,0 +1,32 @@ +System.register('bundle', [], function (exports, module) { + 'use strict'; + return { + execute: function () { + + const exports$1 = { + x: 42 + }; + console.log(exports$1); + + function nestedConflict() { + const exports$1 = { + x: 42 + }; + console.log(exports$1); + (exports('x', x + 1), x++); + } + + function nestedNoConflict() { + const exports$1 = { + x: 42 + }; + console.log(exports$1); + } + + var x = exports('x', 43); + nestedConflict(); + nestedNoConflict(); + + } + }; +}); diff --git a/test/form/samples/catch-parameter-shadowing/_expected/umd.js b/test/form/samples/deconflict-format-specific-exports/_expected/umd.js similarity index 53% rename from test/form/samples/catch-parameter-shadowing/_expected/umd.js rename to test/form/samples/deconflict-format-specific-exports/_expected/umd.js index 70e934b73d5..e05a4449c51 100644 --- a/test/form/samples/catch-parameter-shadowing/_expected/umd.js +++ b/test/form/samples/deconflict-format-specific-exports/_expected/umd.js @@ -4,17 +4,29 @@ (global = global || self, factory(global.bundle = {})); }(this, function (exports) { 'use strict'; - const e = 2.7182818284; + const exports$1 = { + x: 42 + }; + console.log(exports$1); - function something () { - try { - console.log( e ); - } catch ( e$$1 ) { // the catch identifier shadows the import - console.error( e$$1 ); - } + function nestedConflict() { + const exports$1 = { + x: 42 + }; + console.log(exports$1); + exports.x++; } - exports.something = something; + function nestedNoConflict() { + const exports = { + x: 42 + }; + console.log(exports); + } + + exports.x = 43; + nestedConflict(); + nestedNoConflict(); Object.defineProperty(exports, '__esModule', { value: true }); diff --git a/test/form/samples/deconflict-format-specific-exports/main.js b/test/form/samples/deconflict-format-specific-exports/main.js new file mode 100644 index 00000000000..26fd218756a --- /dev/null +++ b/test/form/samples/deconflict-format-specific-exports/main.js @@ -0,0 +1,23 @@ +const exports = { + x: 42 +}; +console.log(exports); + +function nestedConflict() { + const exports = { + x: 42 + }; + console.log(exports); + x++; +} + +function nestedNoConflict() { + const exports = { + x: 42 + }; + console.log(exports); +} + +export var x = 43; +nestedConflict(); +nestedNoConflict(); diff --git a/test/form/samples/deconflict-format-specific-interop/_config.js b/test/form/samples/deconflict-format-specific-interop/_config.js new file mode 100644 index 00000000000..4194988127c --- /dev/null +++ b/test/form/samples/deconflict-format-specific-interop/_config.js @@ -0,0 +1,4 @@ +module.exports = { + description: 'only deconflict "interop" for formats where it is necessary', + options: { external: ['external'] } +}; diff --git a/test/form/samples/deconflict-format-specific-interop/_expected/amd.js b/test/form/samples/deconflict-format-specific-interop/_expected/amd.js new file mode 100644 index 00000000000..a1ffe6c9326 --- /dev/null +++ b/test/form/samples/deconflict-format-specific-interop/_expected/amd.js @@ -0,0 +1,8 @@ +define(['external'], function (external) { 'use strict'; + + external = external && external.hasOwnProperty('default') ? external['default'] : external; + + const _interopDefault = 42; + console.log(external, _interopDefault); + +}); diff --git a/test/form/samples/deconflict-format-specific-interop/_expected/cjs.js b/test/form/samples/deconflict-format-specific-interop/_expected/cjs.js new file mode 100644 index 00000000000..f201edb1286 --- /dev/null +++ b/test/form/samples/deconflict-format-specific-interop/_expected/cjs.js @@ -0,0 +1,8 @@ +'use strict'; + +function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } + +var external = _interopDefault(require('external')); + +const _interopDefault$1 = 42; +console.log(external, _interopDefault$1); diff --git a/test/form/samples/deconflict-format-specific-interop/_expected/es.js b/test/form/samples/deconflict-format-specific-interop/_expected/es.js new file mode 100644 index 00000000000..f89c64b5b23 --- /dev/null +++ b/test/form/samples/deconflict-format-specific-interop/_expected/es.js @@ -0,0 +1,4 @@ +import external from 'external'; + +const _interopDefault = 42; +console.log(external, _interopDefault); diff --git a/test/form/samples/deconflict-format-specific-interop/_expected/iife.js b/test/form/samples/deconflict-format-specific-interop/_expected/iife.js new file mode 100644 index 00000000000..6d52d475b9b --- /dev/null +++ b/test/form/samples/deconflict-format-specific-interop/_expected/iife.js @@ -0,0 +1,9 @@ +(function (external) { + 'use strict'; + + external = external && external.hasOwnProperty('default') ? external['default'] : external; + + const _interopDefault = 42; + console.log(external, _interopDefault); + +}(external)); diff --git a/test/form/samples/deconflict-format-specific-interop/_expected/system.js b/test/form/samples/deconflict-format-specific-interop/_expected/system.js new file mode 100644 index 00000000000..7d25adfa650 --- /dev/null +++ b/test/form/samples/deconflict-format-specific-interop/_expected/system.js @@ -0,0 +1,15 @@ +System.register(['external'], function (exports, module) { + 'use strict'; + var external; + return { + setters: [function (module) { + external = module.default; + }], + execute: function () { + + const _interopDefault = 42; + console.log(external, _interopDefault); + + } + }; +}); diff --git a/test/form/samples/deconflict-format-specific-interop/_expected/umd.js b/test/form/samples/deconflict-format-specific-interop/_expected/umd.js new file mode 100644 index 00000000000..d28769cf89b --- /dev/null +++ b/test/form/samples/deconflict-format-specific-interop/_expected/umd.js @@ -0,0 +1,12 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('external')) : + typeof define === 'function' && define.amd ? define(['external'], factory) : + (global = global || self, factory(global.external)); +}(this, function (external) { 'use strict'; + + external = external && external.hasOwnProperty('default') ? external['default'] : external; + + const _interopDefault = 42; + console.log(external, _interopDefault); + +})); diff --git a/test/form/samples/deconflict-format-specific-interop/main.js b/test/form/samples/deconflict-format-specific-interop/main.js new file mode 100644 index 00000000000..f89c64b5b23 --- /dev/null +++ b/test/form/samples/deconflict-format-specific-interop/main.js @@ -0,0 +1,4 @@ +import external from 'external'; + +const _interopDefault = 42; +console.log(external, _interopDefault); diff --git a/test/form/samples/deconflict-format-specific-module/_config.js b/test/form/samples/deconflict-format-specific-module/_config.js new file mode 100644 index 00000000000..8ba567b9a9c --- /dev/null +++ b/test/form/samples/deconflict-format-specific-module/_config.js @@ -0,0 +1,4 @@ +module.exports = { + description: 'only deconflict "module" for formats where it is necessary', + options: { output: { name: 'bundle' } } +}; diff --git a/test/form/samples/deconflict-format-specific-module/_expected/amd.js b/test/form/samples/deconflict-format-specific-module/_expected/amd.js new file mode 100644 index 00000000000..8801f2c2a58 --- /dev/null +++ b/test/form/samples/deconflict-format-specific-module/_expected/amd.js @@ -0,0 +1,12 @@ +define(function () { 'use strict'; + + const module = { + exports: 99 + }; + console.log(module); + + var main = 42; + + return main; + +}); diff --git a/test/form/samples/deconflict-format-specific-module/_expected/cjs.js b/test/form/samples/deconflict-format-specific-module/_expected/cjs.js new file mode 100644 index 00000000000..27b7aa822ad --- /dev/null +++ b/test/form/samples/deconflict-format-specific-module/_expected/cjs.js @@ -0,0 +1,10 @@ +'use strict'; + +const module$1 = { + exports: 99 +}; +console.log(module$1); + +var main = 42; + +module.exports = main; diff --git a/test/form/samples/deconflict-format-specific-module/_expected/es.js b/test/form/samples/deconflict-format-specific-module/_expected/es.js new file mode 100644 index 00000000000..6bde991495b --- /dev/null +++ b/test/form/samples/deconflict-format-specific-module/_expected/es.js @@ -0,0 +1,8 @@ +const module = { + exports: 99 +}; +console.log(module); + +var main = 42; + +export default main; diff --git a/test/form/samples/deconflict-format-specific-module/_expected/iife.js b/test/form/samples/deconflict-format-specific-module/_expected/iife.js new file mode 100644 index 00000000000..d9bc6034233 --- /dev/null +++ b/test/form/samples/deconflict-format-specific-module/_expected/iife.js @@ -0,0 +1,13 @@ +var bundle = (function () { + 'use strict'; + + const module = { + exports: 99 + }; + console.log(module); + + var main = 42; + + return main; + +}()); diff --git a/test/form/samples/deconflict-format-specific-module/_expected/system.js b/test/form/samples/deconflict-format-specific-module/_expected/system.js new file mode 100644 index 00000000000..700ce53af0e --- /dev/null +++ b/test/form/samples/deconflict-format-specific-module/_expected/system.js @@ -0,0 +1,15 @@ +System.register('bundle', [], function (exports, module) { + 'use strict'; + return { + execute: function () { + + const module = { + exports: 99 + }; + console.log(module); + + var main = exports('default', 42); + + } + }; +}); diff --git a/test/form/samples/deconflict-format-specific-module/_expected/umd.js b/test/form/samples/deconflict-format-specific-module/_expected/umd.js new file mode 100644 index 00000000000..239341b049a --- /dev/null +++ b/test/form/samples/deconflict-format-specific-module/_expected/umd.js @@ -0,0 +1,16 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + typeof define === 'function' && define.amd ? define(factory) : + (global = global || self, global.bundle = factory()); +}(this, function () { 'use strict'; + + const module = { + exports: 99 + }; + console.log(module); + + var main = 42; + + return main; + +})); diff --git a/test/form/samples/deconflict-format-specific-module/main.js b/test/form/samples/deconflict-format-specific-module/main.js new file mode 100644 index 00000000000..eeb42d0c4c2 --- /dev/null +++ b/test/form/samples/deconflict-format-specific-module/main.js @@ -0,0 +1,6 @@ +const module = { + exports: 99 +}; +console.log(module); + +export default 42; diff --git a/test/form/samples/deconflict-nested-tree-shaking/_config.js b/test/form/samples/deconflict-nested-tree-shaking/_config.js new file mode 100644 index 00000000000..f423de7c702 --- /dev/null +++ b/test/form/samples/deconflict-nested-tree-shaking/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'does not consider nested tree-shaken variables when deconflicting' +}; diff --git a/test/form/samples/deconflict-nested-tree-shaking/_expected.js b/test/form/samples/deconflict-nested-tree-shaking/_expected.js new file mode 100644 index 00000000000..f04fec28340 --- /dev/null +++ b/test/form/samples/deconflict-nested-tree-shaking/_expected.js @@ -0,0 +1,11 @@ +const conflict = 'dep'; + +function getValue() { + function nestedGetValue() { + const conflict$1 = 'nested'; + return conflict$1; + } + return conflict + nestedGetValue(); +} + +console.log(getValue()); diff --git a/test/form/samples/deconflict-nested-tree-shaking/dep.js b/test/form/samples/deconflict-nested-tree-shaking/dep.js new file mode 100644 index 00000000000..6dc751a9ddb --- /dev/null +++ b/test/form/samples/deconflict-nested-tree-shaking/dep.js @@ -0,0 +1 @@ +export const conflict = 'dep'; diff --git a/test/form/samples/deconflict-nested-tree-shaking/main.js b/test/form/samples/deconflict-nested-tree-shaking/main.js new file mode 100644 index 00000000000..6b1032cf3f6 --- /dev/null +++ b/test/form/samples/deconflict-nested-tree-shaking/main.js @@ -0,0 +1,16 @@ +import * as dep from './dep.js'; + +function getValue() { + function nestedGetValue() { + const conflict$1 = 'nested'; + if (false) { + console.log(conflict); + } + return conflict$1; + } + + const conflict = 'main'; + return dep.conflict + nestedGetValue(); +} + +console.log(getValue()); diff --git a/test/form/samples/deconflict-reserved-words/_config.js b/test/form/samples/deconflict-reserved-words/_config.js new file mode 100644 index 00000000000..0be4d22cb9c --- /dev/null +++ b/test/form/samples/deconflict-reserved-words/_config.js @@ -0,0 +1,4 @@ +module.exports = { + description: 'deconflict reserved words when inlining namespace imports', + options: { external: ['dep'] } +}; diff --git a/test/form/samples/deconflict-reserved-words/_expected.js b/test/form/samples/deconflict-reserved-words/_expected.js new file mode 100644 index 00000000000..8f11287671e --- /dev/null +++ b/test/form/samples/deconflict-reserved-words/_expected.js @@ -0,0 +1,47 @@ +import dep__default, { await as await$1, break as break$1, case as case$1, catch as catch$1, class as class$1, const as const$1, continue as continue$1, debugger as debugger$1, delete as delete$1, do as do$1, else as else$1, enum as enum$1, eval as eval$1, export as export$1, extends as extends$1, finally as finally$1, for as for$1, function as function$1, if as if$1, implements as implements$1, import as import$1, in as in$1, instanceof as instanceof$1, interface as interface$1, let as let$1, new as new$1, null as null$1, package as package$1, private as private$1, protected as protected$1, public as public$1, return as return$1, static as static$1, super as super$1, switch as switch$1, throw as throw$1, try as try$1, typeof as typeof$1, undefined as undefined$1, var as var$1, void as void$1, while as while$1, with as with$1, yield as yield$1 } from 'dep'; + +console.log(await$1); +console.log(break$1); +console.log(case$1); +console.log(catch$1); +console.log(class$1); +console.log(const$1); +console.log(continue$1); +console.log(debugger$1); +console.log(dep__default); +console.log(delete$1); +console.log(do$1); +console.log(else$1); +console.log(enum$1); +console.log(eval$1); +console.log(export$1); +console.log(extends$1); +console.log(finally$1); +console.log(for$1); +console.log(function$1); +console.log(if$1); +console.log(implements$1); +console.log(import$1); +console.log(in$1); +console.log(instanceof$1); +console.log(interface$1); +console.log(let$1); +console.log(new$1); +console.log(null$1); +console.log(package$1); +console.log(private$1); +console.log(protected$1); +console.log(public$1); +console.log(return$1); +console.log(static$1); +console.log(super$1); +console.log(switch$1); +console.log(throw$1); +console.log(try$1); +console.log(typeof$1); +console.log(undefined$1); +console.log(var$1); +console.log(void$1); +console.log(while$1); +console.log(with$1); +console.log(yield$1); diff --git a/test/form/samples/deconflict-reserved-words/main.js b/test/form/samples/deconflict-reserved-words/main.js new file mode 100644 index 00000000000..0081bb9fb1f --- /dev/null +++ b/test/form/samples/deconflict-reserved-words/main.js @@ -0,0 +1,47 @@ +import * as dep from 'dep'; + +console.log(dep.await); +console.log(dep.break); +console.log(dep.case); +console.log(dep.catch); +console.log(dep.class); +console.log(dep.const); +console.log(dep.continue); +console.log(dep.debugger); +console.log(dep.default); +console.log(dep.delete); +console.log(dep.do); +console.log(dep.else); +console.log(dep.enum); +console.log(dep.eval); +console.log(dep.export); +console.log(dep.extends); +console.log(dep.finally); +console.log(dep.for); +console.log(dep.function); +console.log(dep.if); +console.log(dep.implements); +console.log(dep.import); +console.log(dep.in); +console.log(dep.instanceof); +console.log(dep.interface); +console.log(dep.let); +console.log(dep.new); +console.log(dep.null); +console.log(dep.package); +console.log(dep.private); +console.log(dep.protected); +console.log(dep.public); +console.log(dep.return); +console.log(dep.static); +console.log(dep.super); +console.log(dep.switch); +console.log(dep.throw); +console.log(dep.try); +console.log(dep.typeof); +console.log(dep.undefined); +console.log(dep.var); +console.log(dep.void); +console.log(dep.while); +console.log(dep.with); +console.log(dep.yield); diff --git a/test/form/samples/deconflict-tree-shaken-globals/_config.js b/test/form/samples/deconflict-tree-shaken-globals/_config.js new file mode 100644 index 00000000000..233206fcd76 --- /dev/null +++ b/test/form/samples/deconflict-tree-shaken-globals/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'does not deconflict due to tree-shaken global variables' +}; diff --git a/test/form/samples/deconflict-tree-shaken-globals/_expected.js b/test/form/samples/deconflict-tree-shaken-globals/_expected.js new file mode 100644 index 00000000000..d887c27dfed --- /dev/null +++ b/test/form/samples/deconflict-tree-shaken-globals/_expected.js @@ -0,0 +1,2 @@ +const globalName = 42; +console.log( globalName ); diff --git a/test/form/samples/deconflict-tree-shaken-globals/main.js b/test/form/samples/deconflict-tree-shaken-globals/main.js new file mode 100644 index 00000000000..6e68c119b97 --- /dev/null +++ b/test/form/samples/deconflict-tree-shaken-globals/main.js @@ -0,0 +1,4 @@ +import './other.js'; + +const globalName = 42; +console.log( globalName ); diff --git a/test/form/samples/deconflict-tree-shaken-globals/other.js b/test/form/samples/deconflict-tree-shaken-globals/other.js new file mode 100644 index 00000000000..6089f89b141 --- /dev/null +++ b/test/form/samples/deconflict-tree-shaken-globals/other.js @@ -0,0 +1,3 @@ +if (false) { + console.log( globalName ); +} diff --git a/test/form/samples/deconflict-tree-shaken/_config.js b/test/form/samples/deconflict-tree-shaken/_config.js new file mode 100644 index 00000000000..96c6ef18178 --- /dev/null +++ b/test/form/samples/deconflict-tree-shaken/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'does not consider tree-shaken variables when deconflicting' +}; diff --git a/test/form/samples/deconflict-tree-shaken/_expected.js b/test/form/samples/deconflict-tree-shaken/_expected.js new file mode 100644 index 00000000000..686b74f7b05 --- /dev/null +++ b/test/form/samples/deconflict-tree-shaken/_expected.js @@ -0,0 +1,5 @@ +const x = 1; +console.log(x); + +const x$1 = 0; +console.log(x$1); diff --git a/test/form/samples/deconflict-tree-shaken/dep1.js b/test/form/samples/deconflict-tree-shaken/dep1.js new file mode 100644 index 00000000000..59046901804 --- /dev/null +++ b/test/form/samples/deconflict-tree-shaken/dep1.js @@ -0,0 +1,2 @@ +const x = 1; +console.log(x); diff --git a/test/form/samples/deconflict-tree-shaken/dep2.js b/test/form/samples/deconflict-tree-shaken/dep2.js new file mode 100644 index 00000000000..324c759345c --- /dev/null +++ b/test/form/samples/deconflict-tree-shaken/dep2.js @@ -0,0 +1 @@ +const x = 2; diff --git a/test/form/samples/deconflict-tree-shaken/dep3.js b/test/form/samples/deconflict-tree-shaken/dep3.js new file mode 100644 index 00000000000..380baf7dc8e --- /dev/null +++ b/test/form/samples/deconflict-tree-shaken/dep3.js @@ -0,0 +1 @@ +const x = 3; diff --git a/test/form/samples/deconflict-tree-shaken/main.js b/test/form/samples/deconflict-tree-shaken/main.js new file mode 100644 index 00000000000..74461329884 --- /dev/null +++ b/test/form/samples/deconflict-tree-shaken/main.js @@ -0,0 +1,6 @@ +import './dep1.js'; +import './dep2.js'; +import './dep3.js'; + +const x = 0; +console.log(x); diff --git a/test/form/samples/export-globals/main.js b/test/form/samples/export-globals/main.js index 1893ec111e0..4bdd4e4d9d8 100644 --- a/test/form/samples/export-globals/main.js +++ b/test/form/samples/export-globals/main.js @@ -1,2 +1,2 @@ import * as Number from './Number'; -export const isNaN = Number.isNaN; \ No newline at end of file +export const isNaN = Number.isNaN; diff --git a/test/form/samples/external-deshadowing/_config.js b/test/form/samples/external-deshadowing/_config.js index 19d3c7fbb44..dc40b0c0f27 100644 --- a/test/form/samples/external-deshadowing/_config.js +++ b/test/form/samples/external-deshadowing/_config.js @@ -1,6 +1,7 @@ module.exports = { description: 'Externals aliases with deshadowing', options: { + external: ['a', 'b'], output: { name: 'myBundle' } diff --git a/test/form/samples/external-deshadowing/_expected/amd.js b/test/form/samples/external-deshadowing/_expected/amd.js index 4f3add24cc4..ddf292350fa 100644 --- a/test/form/samples/external-deshadowing/_expected/amd.js +++ b/test/form/samples/external-deshadowing/_expected/amd.js @@ -1,16 +1,16 @@ -define(['exports', 'a', 'b'], function (exports, a, Test) { 'use strict'; +define(['exports', 'a', 'b'], function (exports, a, Test$1) { 'use strict'; - Test = Test && Test.hasOwnProperty('default') ? Test['default'] : Test; + Test$1 = Test$1 && Test$1.hasOwnProperty('default') ? Test$1['default'] : Test$1; - const Test$1 = () => { + const Test = () => { console.log(a.Test); }; const Test1 = () => { - console.log(Test); + console.log(Test$1); }; - exports.Test = Test$1; + exports.Test = Test; exports.Test1 = Test1; Object.defineProperty(exports, '__esModule', { value: true }); diff --git a/test/form/samples/external-deshadowing/_expected/cjs.js b/test/form/samples/external-deshadowing/_expected/cjs.js index 22b1da93995..dba5d8ef93f 100644 --- a/test/form/samples/external-deshadowing/_expected/cjs.js +++ b/test/form/samples/external-deshadowing/_expected/cjs.js @@ -5,15 +5,15 @@ Object.defineProperty(exports, '__esModule', { value: true }); function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } var a = require('a'); -var Test = _interopDefault(require('b')); +var Test$1 = _interopDefault(require('b')); -const Test$1 = () => { +const Test = () => { console.log(a.Test); }; const Test1 = () => { - console.log(Test); + console.log(Test$1); }; -exports.Test = Test$1; +exports.Test = Test; exports.Test1 = Test1; diff --git a/test/form/samples/external-deshadowing/_expected/es.js b/test/form/samples/external-deshadowing/_expected/es.js index 2ef2beb8a4d..5ad8833d3c4 100644 --- a/test/form/samples/external-deshadowing/_expected/es.js +++ b/test/form/samples/external-deshadowing/_expected/es.js @@ -1,12 +1,12 @@ -import { Test } from 'a'; -import Test$1 from 'b'; +import { Test as Test$1 } from 'a'; +import Test$1$1 from 'b'; -const Test$2 = () => { - console.log(Test); +const Test = () => { + console.log(Test$1); }; const Test1 = () => { - console.log(Test$1); + console.log(Test$1$1); }; -export { Test$2 as Test, Test1 }; +export { Test, Test1 }; diff --git a/test/form/samples/external-deshadowing/_expected/iife.js b/test/form/samples/external-deshadowing/_expected/iife.js index 93c2a4475dc..2a6e6f66ee7 100644 --- a/test/form/samples/external-deshadowing/_expected/iife.js +++ b/test/form/samples/external-deshadowing/_expected/iife.js @@ -1,19 +1,19 @@ -var myBundle = (function (exports, a, Test) { +var myBundle = (function (exports, a, Test$1) { 'use strict'; - Test = Test && Test.hasOwnProperty('default') ? Test['default'] : Test; + Test$1 = Test$1 && Test$1.hasOwnProperty('default') ? Test$1['default'] : Test$1; - const Test$1 = () => { + const Test = () => { console.log(a.Test); }; const Test1 = () => { - console.log(Test); + console.log(Test$1); }; - exports.Test = Test$1; + exports.Test = Test; exports.Test1 = Test1; return exports; -}({}, a, Test)); +}({}, a, Test$1)); diff --git a/test/form/samples/external-deshadowing/_expected/system.js b/test/form/samples/external-deshadowing/_expected/system.js index 15fccaded78..cbfb0157a2f 100644 --- a/test/form/samples/external-deshadowing/_expected/system.js +++ b/test/form/samples/external-deshadowing/_expected/system.js @@ -1,20 +1,20 @@ System.register('myBundle', ['a', 'b'], function (exports, module) { 'use strict'; - var Test, Test$1; + var Test$1, Test$1$1; return { setters: [function (module) { - Test = module.Test; + Test$1 = module.Test; }, function (module) { - Test$1 = module.default; + Test$1$1 = module.default; }], execute: function () { - const Test$2 = exports('Test', () => { - console.log(Test); + const Test = exports('Test', () => { + console.log(Test$1); }); const Test1 = exports('Test1', () => { - console.log(Test$1); + console.log(Test$1$1); }); } diff --git a/test/form/samples/external-deshadowing/_expected/umd.js b/test/form/samples/external-deshadowing/_expected/umd.js index 8d2072edebb..853b3144677 100644 --- a/test/form/samples/external-deshadowing/_expected/umd.js +++ b/test/form/samples/external-deshadowing/_expected/umd.js @@ -1,20 +1,20 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('a'), require('b')) : typeof define === 'function' && define.amd ? define(['exports', 'a', 'b'], factory) : - (global = global || self, factory(global.myBundle = {}, global.a, global.Test)); -}(this, function (exports, a, Test) { 'use strict'; + (global = global || self, factory(global.myBundle = {}, global.a, global.Test$1)); +}(this, function (exports, a, Test$1) { 'use strict'; - Test = Test && Test.hasOwnProperty('default') ? Test['default'] : Test; + Test$1 = Test$1 && Test$1.hasOwnProperty('default') ? Test$1['default'] : Test$1; - const Test$1 = () => { + const Test = () => { console.log(a.Test); }; const Test1 = () => { - console.log(Test); + console.log(Test$1); }; - exports.Test = Test$1; + exports.Test = Test; exports.Test1 = Test1; Object.defineProperty(exports, '__esModule', { value: true }); diff --git a/test/form/samples/external-import-alias-shadow/_expected/es.js b/test/form/samples/external-import-alias-shadow/_expected/es.js index 2750231146c..4cd40fd9981 100644 --- a/test/form/samples/external-import-alias-shadow/_expected/es.js +++ b/test/form/samples/external-import-alias-shadow/_expected/es.js @@ -1,7 +1,7 @@ -import { parse } from 'acorn'; +import { parse as parse$1 } from 'acorn'; -function parse$1(source) { - return parse(source, { ecmaVersion: 6 }); +function parse(source) { + return parse$1(source, { ecmaVersion: 6 }); } -console.log(parse$1('foo')); +console.log(parse('foo')); diff --git a/test/form/samples/external-import-alias-shadow/_expected/system.js b/test/form/samples/external-import-alias-shadow/_expected/system.js index 6c926769e44..4342c7cb32a 100644 --- a/test/form/samples/external-import-alias-shadow/_expected/system.js +++ b/test/form/samples/external-import-alias-shadow/_expected/system.js @@ -1,17 +1,17 @@ System.register(['acorn'], function (exports, module) { 'use strict'; - var parse; + var parse$1; return { setters: [function (module) { - parse = module.parse; + parse$1 = module.parse; }], execute: function () { - function parse$1(source) { - return parse(source, { ecmaVersion: 6 }); + function parse(source) { + return parse$1(source, { ecmaVersion: 6 }); } - console.log(parse$1('foo')); + console.log(parse('foo')); } }; diff --git a/test/form/samples/import-specifier-deshadowing/_expected/es.js b/test/form/samples/import-specifier-deshadowing/_expected/es.js index b4be7cffb77..9cfd965e950 100644 --- a/test/form/samples/import-specifier-deshadowing/_expected/es.js +++ b/test/form/samples/import-specifier-deshadowing/_expected/es.js @@ -1,11 +1,11 @@ -import { Sticky } from 'react-sticky'; +import { Sticky as Sticky$1 } from 'react-sticky'; -var Sticky$1 = function () { - function Sticky$$1() {} +var Sticky = function () { + function Sticky() {} - Sticky$$1.foo = Sticky; + Sticky.foo = Sticky$1; - return Sticky$$1; + return Sticky; }(); -export default Sticky$1; +export default Sticky; diff --git a/test/form/samples/import-specifier-deshadowing/_expected/system.js b/test/form/samples/import-specifier-deshadowing/_expected/system.js index ebc10764e9c..1e45c67cb31 100644 --- a/test/form/samples/import-specifier-deshadowing/_expected/system.js +++ b/test/form/samples/import-specifier-deshadowing/_expected/system.js @@ -1,18 +1,18 @@ System.register('Sticky', ['react-sticky'], function (exports, module) { 'use strict'; - var Sticky; + var Sticky$1; return { setters: [function (module) { - Sticky = module.Sticky; + Sticky$1 = module.Sticky; }], execute: function () { - var Sticky$1 = exports('default', function () { - function Sticky$$1() {} + var Sticky = exports('default', function () { + function Sticky() {} - Sticky$$1.foo = Sticky; + Sticky.foo = Sticky$1; - return Sticky$$1; + return Sticky; }()); } diff --git a/test/form/samples/large-var-cnt-deduping/64.js b/test/form/samples/large-var-cnt-deduping/64.js index 90ff419f631..c47f51908c3 100644 --- a/test/form/samples/large-var-cnt-deduping/64.js +++ b/test/form/samples/large-var-cnt-deduping/64.js @@ -1,3 +1,3 @@ -var x = "0"; +var x = "$"; -export var result = `64 = ${x}`; \ No newline at end of file +export var result = `64 = ${x}`; diff --git a/test/form/samples/large-var-cnt-deduping/65.js b/test/form/samples/large-var-cnt-deduping/65.js new file mode 100644 index 00000000000..772bf8dfbab --- /dev/null +++ b/test/form/samples/large-var-cnt-deduping/65.js @@ -0,0 +1,3 @@ +var x = "0"; + +export var result = `65 = ${x}`; diff --git a/test/form/samples/large-var-cnt-deduping/_expected.js b/test/form/samples/large-var-cnt-deduping/_expected.js index 6aad9a352a7..a18245a2d43 100644 --- a/test/form/samples/large-var-cnt-deduping/_expected.js +++ b/test/form/samples/large-var-cnt-deduping/_expected.js @@ -250,9 +250,13 @@ var x$_ = "_"; var result$_ = `63 = ${x$_}`; +var x$$ = "$"; + +var result$$ = `64 = ${x$$}`; + var x$10 = "0"; -var result$10 = `64 = ${x$10}`; +var result$10 = `65 = ${x$10}`; var results = [result, result$1, @@ -317,9 +321,8 @@ result$X, result$Y, result$Z, result$_, +result$$, result$10 ]; -results.forEach( ( result$$1 ) => { - console.log( result$$1 ); -} ); +console.log(results); diff --git a/test/form/samples/large-var-cnt-deduping/main.js b/test/form/samples/large-var-cnt-deduping/main.js index 0cdcef49044..a13d8ae0b23 100644 --- a/test/form/samples/large-var-cnt-deduping/main.js +++ b/test/form/samples/large-var-cnt-deduping/main.js @@ -1,68 +1,68 @@ - -import { result as result1 } from "./1.js"; -import { result as result2 } from "./2.js"; -import { result as result3 } from "./3.js"; -import { result as result4 } from "./4.js"; -import { result as result5 } from "./5.js"; -import { result as result6 } from "./6.js"; -import { result as result7 } from "./7.js"; -import { result as result8 } from "./8.js"; -import { result as result9 } from "./9.js"; -import { result as result10 } from "./10.js"; -import { result as result11 } from "./11.js"; -import { result as result12 } from "./12.js"; -import { result as result13 } from "./13.js"; -import { result as result14 } from "./14.js"; -import { result as result15 } from "./15.js"; -import { result as result16 } from "./16.js"; -import { result as result17 } from "./17.js"; -import { result as result18 } from "./18.js"; -import { result as result19 } from "./19.js"; -import { result as result20 } from "./20.js"; -import { result as result21 } from "./21.js"; -import { result as result22 } from "./22.js"; -import { result as result23 } from "./23.js"; -import { result as result24 } from "./24.js"; -import { result as result25 } from "./25.js"; -import { result as result26 } from "./26.js"; -import { result as result27 } from "./27.js"; -import { result as result28 } from "./28.js"; -import { result as result29 } from "./29.js"; -import { result as result30 } from "./30.js"; -import { result as result31 } from "./31.js"; -import { result as result32 } from "./32.js"; -import { result as result33 } from "./33.js"; -import { result as result34 } from "./34.js"; -import { result as result35 } from "./35.js"; -import { result as result36 } from "./36.js"; -import { result as result37 } from "./37.js"; -import { result as result38 } from "./38.js"; -import { result as result39 } from "./39.js"; -import { result as result40 } from "./40.js"; -import { result as result41 } from "./41.js"; -import { result as result42 } from "./42.js"; -import { result as result43 } from "./43.js"; -import { result as result44 } from "./44.js"; -import { result as result45 } from "./45.js"; -import { result as result46 } from "./46.js"; -import { result as result47 } from "./47.js"; -import { result as result48 } from "./48.js"; -import { result as result49 } from "./49.js"; -import { result as result50 } from "./50.js"; -import { result as result51 } from "./51.js"; -import { result as result52 } from "./52.js"; -import { result as result53 } from "./53.js"; -import { result as result54 } from "./54.js"; -import { result as result55 } from "./55.js"; -import { result as result56 } from "./56.js"; -import { result as result57 } from "./57.js"; -import { result as result58 } from "./58.js"; -import { result as result59 } from "./59.js"; -import { result as result60 } from "./60.js"; -import { result as result61 } from "./61.js"; -import { result as result62 } from "./62.js"; -import { result as result63 } from "./63.js"; -import { result as result64 } from "./64.js"; +import { result as result1 } from './1.js'; +import { result as result2 } from './2.js'; +import { result as result3 } from './3.js'; +import { result as result4 } from './4.js'; +import { result as result5 } from './5.js'; +import { result as result6 } from './6.js'; +import { result as result7 } from './7.js'; +import { result as result8 } from './8.js'; +import { result as result9 } from './9.js'; +import { result as result10 } from './10.js'; +import { result as result11 } from './11.js'; +import { result as result12 } from './12.js'; +import { result as result13 } from './13.js'; +import { result as result14 } from './14.js'; +import { result as result15 } from './15.js'; +import { result as result16 } from './16.js'; +import { result as result17 } from './17.js'; +import { result as result18 } from './18.js'; +import { result as result19 } from './19.js'; +import { result as result20 } from './20.js'; +import { result as result21 } from './21.js'; +import { result as result22 } from './22.js'; +import { result as result23 } from './23.js'; +import { result as result24 } from './24.js'; +import { result as result25 } from './25.js'; +import { result as result26 } from './26.js'; +import { result as result27 } from './27.js'; +import { result as result28 } from './28.js'; +import { result as result29 } from './29.js'; +import { result as result30 } from './30.js'; +import { result as result31 } from './31.js'; +import { result as result32 } from './32.js'; +import { result as result33 } from './33.js'; +import { result as result34 } from './34.js'; +import { result as result35 } from './35.js'; +import { result as result36 } from './36.js'; +import { result as result37 } from './37.js'; +import { result as result38 } from './38.js'; +import { result as result39 } from './39.js'; +import { result as result40 } from './40.js'; +import { result as result41 } from './41.js'; +import { result as result42 } from './42.js'; +import { result as result43 } from './43.js'; +import { result as result44 } from './44.js'; +import { result as result45 } from './45.js'; +import { result as result46 } from './46.js'; +import { result as result47 } from './47.js'; +import { result as result48 } from './48.js'; +import { result as result49 } from './49.js'; +import { result as result50 } from './50.js'; +import { result as result51 } from './51.js'; +import { result as result52 } from './52.js'; +import { result as result53 } from './53.js'; +import { result as result54 } from './54.js'; +import { result as result55 } from './55.js'; +import { result as result56 } from './56.js'; +import { result as result57 } from './57.js'; +import { result as result58 } from './58.js'; +import { result as result59 } from './59.js'; +import { result as result60 } from './60.js'; +import { result as result61 } from './61.js'; +import { result as result62 } from './62.js'; +import { result as result63 } from './63.js'; +import { result as result64 } from './64.js'; +import { result as result65 } from './65.js'; var results = [result1, result2, @@ -127,9 +127,8 @@ result60, result61, result62, result63, -result64 +result64, +result65 ]; -results.forEach( ( result ) => { - console.log( result ); -} ); \ No newline at end of file +console.log(results); diff --git a/test/form/samples/namespace-self-import/_expected/amd.js b/test/form/samples/namespace-self-import/_expected/amd.js index e83bb820940..50271286157 100644 --- a/test/form/samples/namespace-self-import/_expected/amd.js +++ b/test/form/samples/namespace-self-import/_expected/amd.js @@ -1,14 +1,14 @@ define(['exports'], function (exports) { 'use strict'; var self = /*#__PURE__*/Object.freeze({ - get p () { return p$$1; } + get p () { return p; } }); console.log(Object.keys(self)); - var p$$1 = 5; + var p = 5; - exports.p = p$$1; + exports.p = p; Object.defineProperty(exports, '__esModule', { value: true }); diff --git a/test/form/samples/namespace-self-import/_expected/cjs.js b/test/form/samples/namespace-self-import/_expected/cjs.js index 0e5213bd4bf..0b8cb24fa60 100644 --- a/test/form/samples/namespace-self-import/_expected/cjs.js +++ b/test/form/samples/namespace-self-import/_expected/cjs.js @@ -3,11 +3,11 @@ Object.defineProperty(exports, '__esModule', { value: true }); var self = /*#__PURE__*/Object.freeze({ - get p () { return p$$1; } + get p () { return p; } }); console.log(Object.keys(self)); -var p$$1 = 5; +var p = 5; -exports.p = p$$1; +exports.p = p; diff --git a/test/form/samples/namespace-self-import/_expected/es.js b/test/form/samples/namespace-self-import/_expected/es.js index b3b9402de65..af88cc937ef 100644 --- a/test/form/samples/namespace-self-import/_expected/es.js +++ b/test/form/samples/namespace-self-import/_expected/es.js @@ -1,9 +1,9 @@ var self = /*#__PURE__*/Object.freeze({ - get p () { return p$$1; } + get p () { return p; } }); console.log(Object.keys(self)); -var p$$1 = 5; +var p = 5; -export { p$$1 as p }; +export { p }; diff --git a/test/form/samples/namespace-self-import/_expected/iife.js b/test/form/samples/namespace-self-import/_expected/iife.js index 56f37786e25..5b03aaa5b6b 100644 --- a/test/form/samples/namespace-self-import/_expected/iife.js +++ b/test/form/samples/namespace-self-import/_expected/iife.js @@ -2,14 +2,14 @@ var iife = (function (exports) { 'use strict'; var self = /*#__PURE__*/Object.freeze({ - get p () { return p$$1; } + get p () { return p; } }); console.log(Object.keys(self)); - var p$$1 = 5; + var p = 5; - exports.p = p$$1; + exports.p = p; return exports; diff --git a/test/form/samples/namespace-self-import/_expected/system.js b/test/form/samples/namespace-self-import/_expected/system.js index 6bd607efd2e..086d12383e9 100644 --- a/test/form/samples/namespace-self-import/_expected/system.js +++ b/test/form/samples/namespace-self-import/_expected/system.js @@ -4,12 +4,12 @@ System.register('iife', [], function (exports, module) { execute: function () { var self = /*#__PURE__*/Object.freeze({ - get p () { return p$$1; } + get p () { return p; } }); console.log(Object.keys(self)); - var p$$1 = exports('p', 5); + var p = exports('p', 5); } }; diff --git a/test/form/samples/namespace-self-import/_expected/umd.js b/test/form/samples/namespace-self-import/_expected/umd.js index 8c689ceb032..611c0f7a26e 100644 --- a/test/form/samples/namespace-self-import/_expected/umd.js +++ b/test/form/samples/namespace-self-import/_expected/umd.js @@ -5,14 +5,14 @@ }(this, function (exports) { 'use strict'; var self = /*#__PURE__*/Object.freeze({ - get p () { return p$$1; } + get p () { return p; } }); console.log(Object.keys(self)); - var p$$1 = 5; + var p = 5; - exports.p = p$$1; + exports.p = p; Object.defineProperty(exports, '__esModule', { value: true }); diff --git a/test/form/samples/namespace-tostringtag/_expected/amd.js b/test/form/samples/namespace-tostringtag/_expected/amd.js index 7e9c85d873c..d93c8311ca5 100644 --- a/test/form/samples/namespace-tostringtag/_expected/amd.js +++ b/test/form/samples/namespace-tostringtag/_expected/amd.js @@ -1,7 +1,7 @@ define(['exports'], function (exports) { 'use strict'; var self = { - get p () { return p$$1; } + get p () { return p; } }; if (typeof Symbol !== 'undefined' && Symbol.toStringTag) Object.defineProperty(self, Symbol.toStringTag, { value: 'Module' }); @@ -11,9 +11,9 @@ define(['exports'], function (exports) { 'use strict'; console.log(Object.keys(self)); - var p$$1 = 5; + var p = 5; - exports.p = p$$1; + exports.p = p; Object.defineProperty(exports, '__esModule', { value: true }); diff --git a/test/form/samples/namespace-tostringtag/_expected/cjs.js b/test/form/samples/namespace-tostringtag/_expected/cjs.js index 2a56e21148d..72abfebab30 100644 --- a/test/form/samples/namespace-tostringtag/_expected/cjs.js +++ b/test/form/samples/namespace-tostringtag/_expected/cjs.js @@ -3,7 +3,7 @@ Object.defineProperty(exports, '__esModule', { value: true }); var self = { - get p () { return p$$1; } + get p () { return p; } }; if (typeof Symbol !== 'undefined' && Symbol.toStringTag) Object.defineProperty(self, Symbol.toStringTag, { value: 'Module' }); @@ -13,6 +13,6 @@ else console.log(Object.keys(self)); -var p$$1 = 5; +var p = 5; -exports.p = p$$1; +exports.p = p; diff --git a/test/form/samples/namespace-tostringtag/_expected/es.js b/test/form/samples/namespace-tostringtag/_expected/es.js index af30ba08511..53fea534eb9 100644 --- a/test/form/samples/namespace-tostringtag/_expected/es.js +++ b/test/form/samples/namespace-tostringtag/_expected/es.js @@ -1,5 +1,5 @@ var self = { - get p () { return p$$1; } + get p () { return p; } }; if (typeof Symbol !== 'undefined' && Symbol.toStringTag) Object.defineProperty(self, Symbol.toStringTag, { value: 'Module' }); @@ -9,6 +9,6 @@ else console.log(Object.keys(self)); -var p$$1 = 5; +var p = 5; -export { p$$1 as p }; +export { p }; diff --git a/test/form/samples/namespace-tostringtag/_expected/iife.js b/test/form/samples/namespace-tostringtag/_expected/iife.js index f55034a28be..2ab56c69888 100644 --- a/test/form/samples/namespace-tostringtag/_expected/iife.js +++ b/test/form/samples/namespace-tostringtag/_expected/iife.js @@ -2,7 +2,7 @@ var iife = (function (exports) { 'use strict'; var self = { - get p () { return p$$1; } + get p () { return p; } }; if (typeof Symbol !== 'undefined' && Symbol.toStringTag) Object.defineProperty(self, Symbol.toStringTag, { value: 'Module' }); @@ -12,9 +12,9 @@ var iife = (function (exports) { console.log(Object.keys(self)); - var p$$1 = 5; + var p = 5; - exports.p = p$$1; + exports.p = p; return exports; diff --git a/test/form/samples/namespace-tostringtag/_expected/system.js b/test/form/samples/namespace-tostringtag/_expected/system.js index 5936aafeaa6..36439e28fa5 100644 --- a/test/form/samples/namespace-tostringtag/_expected/system.js +++ b/test/form/samples/namespace-tostringtag/_expected/system.js @@ -4,7 +4,7 @@ System.register('iife', [], function (exports, module) { execute: function () { var self = { - get p () { return p$$1; } + get p () { return p; } }; if (typeof Symbol !== 'undefined' && Symbol.toStringTag) Object.defineProperty(self, Symbol.toStringTag, { value: 'Module' }); @@ -14,7 +14,7 @@ System.register('iife', [], function (exports, module) { console.log(Object.keys(self)); - var p$$1 = exports('p', 5); + var p = exports('p', 5); } }; diff --git a/test/form/samples/namespace-tostringtag/_expected/umd.js b/test/form/samples/namespace-tostringtag/_expected/umd.js index 770a07c5e35..f32ddad473c 100644 --- a/test/form/samples/namespace-tostringtag/_expected/umd.js +++ b/test/form/samples/namespace-tostringtag/_expected/umd.js @@ -5,7 +5,7 @@ }(this, function (exports) { 'use strict'; var self = { - get p () { return p$$1; } + get p () { return p; } }; if (typeof Symbol !== 'undefined' && Symbol.toStringTag) Object.defineProperty(self, Symbol.toStringTag, { value: 'Module' }); @@ -15,9 +15,9 @@ console.log(Object.keys(self)); - var p$$1 = 5; + var p = 5; - exports.p = p$$1; + exports.p = p; Object.defineProperty(exports, '__esModule', { value: true }); diff --git a/test/form/samples/reexport-star-deshadow/_expected/amd.js b/test/form/samples/reexport-star-deshadow/_expected/amd.js index 6b216f9d6d7..a33e579e64a 100644 --- a/test/form/samples/reexport-star-deshadow/_expected/amd.js +++ b/test/form/samples/reexport-star-deshadow/_expected/amd.js @@ -2,7 +2,7 @@ define(function () { 'use strict'; function foo() { return true; } - var baz = function foo$$1() { + var baz = function foo$1() { return foo(); }; diff --git a/test/form/samples/reexport-star-deshadow/_expected/cjs.js b/test/form/samples/reexport-star-deshadow/_expected/cjs.js index 533fb03e10f..405e873f7c5 100644 --- a/test/form/samples/reexport-star-deshadow/_expected/cjs.js +++ b/test/form/samples/reexport-star-deshadow/_expected/cjs.js @@ -2,7 +2,7 @@ function foo() { return true; } -var baz = function foo$$1() { +var baz = function foo$1() { return foo(); }; diff --git a/test/form/samples/reexport-star-deshadow/_expected/es.js b/test/form/samples/reexport-star-deshadow/_expected/es.js index 6193e19684a..c8aa8e7443a 100644 --- a/test/form/samples/reexport-star-deshadow/_expected/es.js +++ b/test/form/samples/reexport-star-deshadow/_expected/es.js @@ -1,6 +1,6 @@ function foo() { return true; } -var baz = function foo$$1() { +var baz = function foo$1() { return foo(); }; diff --git a/test/form/samples/reexport-star-deshadow/_expected/iife.js b/test/form/samples/reexport-star-deshadow/_expected/iife.js index 7fa5b17115c..bff2fd8fc3d 100644 --- a/test/form/samples/reexport-star-deshadow/_expected/iife.js +++ b/test/form/samples/reexport-star-deshadow/_expected/iife.js @@ -3,7 +3,7 @@ function foo() { return true; } - var baz = function foo$$1() { + var baz = function foo$1() { return foo(); }; diff --git a/test/form/samples/reexport-star-deshadow/_expected/system.js b/test/form/samples/reexport-star-deshadow/_expected/system.js index 2de9cba83e1..96cae578834 100644 --- a/test/form/samples/reexport-star-deshadow/_expected/system.js +++ b/test/form/samples/reexport-star-deshadow/_expected/system.js @@ -5,7 +5,7 @@ System.register('myBundle', [], function (exports, module) { function foo() { return true; } - var baz = function foo$$1() { + var baz = function foo$1() { return foo(); }; diff --git a/test/form/samples/reexport-star-deshadow/_expected/umd.js b/test/form/samples/reexport-star-deshadow/_expected/umd.js index 72d69ee592d..13b7c992fb5 100644 --- a/test/form/samples/reexport-star-deshadow/_expected/umd.js +++ b/test/form/samples/reexport-star-deshadow/_expected/umd.js @@ -5,7 +5,7 @@ function foo() { return true; } - var baz = function foo$$1() { + var baz = function foo$1() { return foo(); }; diff --git a/test/form/samples/sequence-expression/_expected/amd.js b/test/form/samples/sequence-expression/_expected/amd.js index 1bb396422fc..3bc5a88aa06 100644 --- a/test/form/samples/sequence-expression/_expected/amd.js +++ b/test/form/samples/sequence-expression/_expected/amd.js @@ -20,8 +20,8 @@ define(function () { 'use strict'; var g = ((() => {console.log(foo$1());})(), 1); // should maintain this context - var module$1 = {}; - module$1.bar = function () { console.log( 'bar' );}; - var h = (0, module$1.bar)(); + var module = {}; + module.bar = function () { console.log( 'bar' );}; + var h = (0, module.bar)(); }); diff --git a/test/form/samples/sequence-expression/_expected/es.js b/test/form/samples/sequence-expression/_expected/es.js index a8781ec0593..8de2bf8164d 100644 --- a/test/form/samples/sequence-expression/_expected/es.js +++ b/test/form/samples/sequence-expression/_expected/es.js @@ -18,6 +18,6 @@ var e = (foo$1()); var g = ((() => {console.log(foo$1());})(), 1); // should maintain this context -var module$1 = {}; -module$1.bar = function () { console.log( 'bar' );}; -var h = (0, module$1.bar)(); +var module = {}; +module.bar = function () { console.log( 'bar' );}; +var h = (0, module.bar)(); diff --git a/test/form/samples/sequence-expression/_expected/iife.js b/test/form/samples/sequence-expression/_expected/iife.js index d77362f8477..10ed645ca68 100644 --- a/test/form/samples/sequence-expression/_expected/iife.js +++ b/test/form/samples/sequence-expression/_expected/iife.js @@ -21,8 +21,8 @@ var g = ((() => {console.log(foo$1());})(), 1); // should maintain this context - var module$1 = {}; - module$1.bar = function () { console.log( 'bar' );}; - var h = (0, module$1.bar)(); + var module = {}; + module.bar = function () { console.log( 'bar' );}; + var h = (0, module.bar)(); }()); diff --git a/test/form/samples/sequence-expression/_expected/system.js b/test/form/samples/sequence-expression/_expected/system.js index fafae7d3e52..b8cc9f0b2f2 100644 --- a/test/form/samples/sequence-expression/_expected/system.js +++ b/test/form/samples/sequence-expression/_expected/system.js @@ -23,9 +23,9 @@ System.register([], function (exports, module) { var g = ((() => {console.log(foo$1());})(), 1); // should maintain this context - var module$1 = {}; - module$1.bar = function () { console.log( 'bar' );}; - var h = (0, module$1.bar)(); + var module = {}; + module.bar = function () { console.log( 'bar' );}; + var h = (0, module.bar)(); } }; diff --git a/test/form/samples/sequence-expression/_expected/umd.js b/test/form/samples/sequence-expression/_expected/umd.js index 059d87f43de..5ce2c02cb76 100644 --- a/test/form/samples/sequence-expression/_expected/umd.js +++ b/test/form/samples/sequence-expression/_expected/umd.js @@ -23,8 +23,8 @@ var g = ((() => {console.log(foo$1());})(), 1); // should maintain this context - var module$1 = {}; - module$1.bar = function () { console.log( 'bar' );}; - var h = (0, module$1.bar)(); + var module = {}; + module.bar = function () { console.log( 'bar' );}; + var h = (0, module.bar)(); })); diff --git a/test/function/samples/allow-reserved/main.js b/test/function/samples/allow-reserved/main.js index 547a9a5311d..00782b93d9c 100644 --- a/test/function/samples/allow-reserved/main.js +++ b/test/function/samples/allow-reserved/main.js @@ -1,2 +1,4 @@ -var x = function await () {} -assert.equal( x.name, 'await' ); +var x = function await() { + return 42; +}; +assert.equal(x(), 42); diff --git a/test/function/samples/consistent-renaming-f/main.js b/test/function/samples/consistent-renaming-f/main.js index c9015d18a8a..cd334341067 100644 --- a/test/function/samples/consistent-renaming-f/main.js +++ b/test/function/samples/consistent-renaming-f/main.js @@ -1,11 +1,8 @@ import bar from './bar'; -export default function foo () {} - -foo.prototype.a = function ( foo ) { - var foo = foo; - foo(); +function test( foo ) { + assert.equal(foo, 1); return bar(); -}; +} -assert.equal( new foo().a(function () {}), 'consistent' ); +assert.equal( test(1), 'consistent' ); diff --git a/test/function/samples/deconflict-deconflicted/_config.js b/test/function/samples/deconflict-deconflicted/_config.js new file mode 100644 index 00000000000..a3fcda5c37c --- /dev/null +++ b/test/function/samples/deconflict-deconflicted/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'also deconflict variables which already appear to be deconflicted (#2683)' +}; diff --git a/test/function/samples/deconflict-deconflicted/dep.js b/test/function/samples/deconflict-deconflicted/dep.js new file mode 100644 index 00000000000..e9c523549f3 --- /dev/null +++ b/test/function/samples/deconflict-deconflicted/dep.js @@ -0,0 +1,5 @@ +var value = '1'; + +export function x(value$1) { + return value$1 + value; +} diff --git a/test/function/samples/deconflict-deconflicted/main.js b/test/function/samples/deconflict-deconflicted/main.js new file mode 100644 index 00000000000..8db44ecb0bd --- /dev/null +++ b/test/function/samples/deconflict-deconflicted/main.js @@ -0,0 +1,3 @@ +import { x } from './dep.js'; + +assert.equal(x('name'), 'name1'); diff --git a/test/function/samples/deconflicts-exports-2/_config.js b/test/function/samples/deconflicts-exports-2/_config.js new file mode 100644 index 00000000000..4847f2e53b6 --- /dev/null +++ b/test/function/samples/deconflicts-exports-2/_config.js @@ -0,0 +1,8 @@ +const assert = require('assert'); + +module.exports = { + description: 'renames nested variables named "exports" if necessary', + exports(exports) { + assert.equal(exports.x, 2); + } +}; diff --git a/test/function/samples/deconflicts-exports-2/main.js b/test/function/samples/deconflicts-exports-2/main.js new file mode 100644 index 00000000000..63a6302912b --- /dev/null +++ b/test/function/samples/deconflicts-exports-2/main.js @@ -0,0 +1,15 @@ +function nested() { + var exports = { + x: 99 + }; + exports.x++; + assert.equal(exports.x, 100); + assert.equal(x, 1); + x++; + assert.equal(exports.x, 100); + assert.equal(x, 2); +} + +export var x = 1; + +nested(); diff --git a/test/function/samples/deconflicts-exports-3/_config.js b/test/function/samples/deconflicts-exports-3/_config.js new file mode 100644 index 00000000000..880946bafe3 --- /dev/null +++ b/test/function/samples/deconflicts-exports-3/_config.js @@ -0,0 +1,8 @@ +const assert = require('assert'); + +module.exports = { + description: 'renames variables named "module" if necessary', + exports(exports) { + assert.equal(exports, 1); + } +}; diff --git a/test/function/samples/deconflicts-exports-3/main.js b/test/function/samples/deconflicts-exports-3/main.js new file mode 100644 index 00000000000..8b1e3ab2ba0 --- /dev/null +++ b/test/function/samples/deconflicts-exports-3/main.js @@ -0,0 +1,7 @@ +var module = { + exports: 99 +}; + +assert.equal(module.exports, 99); + +export default 1; diff --git a/test/function/samples/deconflicts-exports/_config.js b/test/function/samples/deconflicts-exports/_config.js index 9eba9d1bb30..60fb3ef5dc4 100644 --- a/test/function/samples/deconflicts-exports/_config.js +++ b/test/function/samples/deconflicts-exports/_config.js @@ -1,7 +1,7 @@ const assert = require('assert'); module.exports = { - description: 'renames variables named `exports` if necessary', + description: 'renames variables named "exports" if necessary', exports(exports) { assert.deepEqual(Object.keys(exports), ['a', 'b']); assert.equal(exports.a, 'A'); diff --git a/test/function/samples/deconflicts-interop/_config.js b/test/function/samples/deconflicts-interop/_config.js new file mode 100644 index 00000000000..a9cdd634b7b --- /dev/null +++ b/test/function/samples/deconflicts-interop/_config.js @@ -0,0 +1,13 @@ +module.exports = { + description: 'deconflicts the interop function', + options: { + external: ['external1', 'external2'] + }, + context: { + require: id => { + if (id === 'external1') return 42; + if (id === 'external2') return 43; + return require(id); + } + } +}; diff --git a/test/function/samples/deconflicts-interop/main.js b/test/function/samples/deconflicts-interop/main.js new file mode 100644 index 00000000000..07c982c1bb9 --- /dev/null +++ b/test/function/samples/deconflicts-interop/main.js @@ -0,0 +1,5 @@ +import _interopDefault from 'external1'; +import ext from 'external2'; + +assert.equal( _interopDefault, 42 ); +assert.equal( ext, 43 ); diff --git a/test/function/samples/deshadow-respect-existing/_config.js b/test/function/samples/deshadow-respect-existing/_config.js new file mode 100644 index 00000000000..e8f57bf497a --- /dev/null +++ b/test/function/samples/deshadow-respect-existing/_config.js @@ -0,0 +1,8 @@ +const assert = require('assert'); + +module.exports = { + description: 'respect existing variable names when deshadowing', + exports(exports) { + assert.equal(exports.getValue(), 'mainmainmainmaindep'); + } +}; diff --git a/test/function/samples/deshadow-respect-existing/dep.js b/test/function/samples/deshadow-respect-existing/dep.js new file mode 100644 index 00000000000..6dc751a9ddb --- /dev/null +++ b/test/function/samples/deshadow-respect-existing/dep.js @@ -0,0 +1 @@ +export const conflict = 'dep'; diff --git a/test/function/samples/deshadow-respect-existing/main.js b/test/function/samples/deshadow-respect-existing/main.js new file mode 100644 index 00000000000..7a45b5dec9f --- /dev/null +++ b/test/function/samples/deshadow-respect-existing/main.js @@ -0,0 +1,9 @@ +import * as dep from './dep.js'; + +export function getValue() { + const conflict = 'main'; + const conflict1 = 'main'; + const conflict$1 = 'main'; + const conflict$$1 = 'main'; + return conflict + conflict1 + conflict$1 + conflict$$1 + dep.conflict; +} diff --git a/test/function/samples/namespace-missing-export/_config.js b/test/function/samples/namespace-missing-export/_config.js index e996462328f..0f7460cb2c7 100644 --- a/test/function/samples/namespace-missing-export/_config.js +++ b/test/function/samples/namespace-missing-export/_config.js @@ -1,6 +1,7 @@ const path = require('path'); module.exports = { + description: 'replaces missing namespace members with undefined and warns about them', warnings: [ { code: 'MISSING_EXPORT',