diff --git a/packages/commonjs/src/generate-exports.js b/packages/commonjs/src/generate-exports.js index 52bcde142..dac2727b4 100644 --- a/packages/commonjs/src/generate-exports.js +++ b/packages/commonjs/src/generate-exports.js @@ -21,81 +21,104 @@ export function rewriteExportsAndGetExportsBlock( code, uses, HELPERS_NAME, - id + id, + replacesModuleExports ) { - const exportDeclarations = [ - `export { exports as __moduleExports } from ${JSON.stringify(wrapId(id, MODULE_SUFFIX))}` - ]; - const moduleExportsPropertyAssignments = []; + const exportDeclarations = []; - if (wrapped) { - if (defineCompiledEsmExpressions.length > 0 || code.indexOf('__esModule') >= 0) { - // eslint-disable-next-line no-param-reassign - uses.commonjsHelpers = true; - exportDeclarations.push( - `export default /*@__PURE__*/${HELPERS_NAME}.getDefaultExportFromCjs(${moduleName}.exports);` - ); + // TODO Lukas maybe introduce an export mode with + // - 'replace' + // - 'wrapped' + // - 'module' + // - 'exports' + // then consider extracting parts that "getExportDeclarations" + if (replacesModuleExports) { + if (topLevelModuleExportsAssignments.length > 0) { + for (const { left } of topLevelModuleExportsAssignments) { + magicString.overwrite(left.start, left.end, `var ${moduleName}`); + } } else { - exportDeclarations.push(`export default ${moduleName}.exports;`); + exportDeclarations.unshift(`var ${moduleName} = {};`); } + exportDeclarations.push( + `export { ${moduleName} as __moduleExports };`, + `export { ${moduleName} as default };` + ); } else { - let deconflictedDefaultExportName; + exportDeclarations.push( + `export { exports as __moduleExports } from ${JSON.stringify(wrapId(id, MODULE_SUFFIX))}` + ); + if (wrapped) { + if (defineCompiledEsmExpressions.length > 0 || code.indexOf('__esModule') >= 0) { + // eslint-disable-next-line no-param-reassign + uses.commonjsHelpers = true; + exportDeclarations.push( + `export default /*@__PURE__*/${HELPERS_NAME}.getDefaultExportFromCjs(${moduleName}.exports);` + ); + } else { + exportDeclarations.push(`export default ${moduleName}.exports;`); + } + } else { + let deconflictedDefaultExportName; - // Collect and rewrite module.exports assignments - for (const { left } of topLevelModuleExportsAssignments) { - magicString.overwrite(left.start, left.end, `${moduleName}.exports`); - } + // TODO Lukas if we have an assignment to module.exports and assignments to exports.foo or usages of exports we need to wrap + // TODO Lukas remove? + // Collect and rewrite module.exports assignments + for (const { left } of topLevelModuleExportsAssignments) { + magicString.overwrite(left.start, left.end, `${moduleName}.exports`); + } - // Collect and rewrite named exports - for (const [exportName, node] of topLevelExportsAssignmentsByName) { - const deconflicted = deconflict(exportName); - magicString.overwrite(node.start, node.left.end, `var ${deconflicted}`); + // Collect and rewrite named exports + for (const [exportName, node] of topLevelExportsAssignmentsByName) { + const deconflicted = deconflict(exportName); + magicString.overwrite(node.start, node.left.end, `var ${deconflicted}`); - if (exportName === 'default') { - deconflictedDefaultExportName = deconflicted; - } else { - exportDeclarations.push( - exportName === deconflicted - ? `export { ${exportName} };` - : `export { ${deconflicted} as ${exportName} };` + if (exportName === 'default') { + deconflictedDefaultExportName = deconflicted; + } else { + exportDeclarations.push( + exportName === deconflicted + ? `export { ${exportName} };` + : `export { ${deconflicted} as ${exportName} };` + ); + } + + magicString.appendLeft( + code[node.end] === ';' ? node.end + 1 : node.end, + `\n${moduleName}.exports.${exportName} = ${deconflicted};` ); } - magicString.appendLeft( - code[node.end] === ';' ? node.end + 1 : node.end, - `\n${moduleName}.exports.${exportName} = ${deconflicted};` - ); - } - - // Collect and rewrite exports.__esModule assignments - let isRestorableCompiledEsm = false; - for (const expression of defineCompiledEsmExpressions) { - isRestorableCompiledEsm = true; - const moduleExportsExpression = - expression.type === 'CallExpression' ? expression.arguments[0] : expression.left.object; - magicString.overwrite( - moduleExportsExpression.start, - moduleExportsExpression.end, - `${moduleName}.exports` - ); - } + // Collect and rewrite exports.__esModule assignments + let isRestorableCompiledEsm = false; + for (const expression of defineCompiledEsmExpressions) { + isRestorableCompiledEsm = true; + const moduleExportsExpression = + expression.type === 'CallExpression' ? expression.arguments[0] : expression.left.object; + magicString.overwrite( + moduleExportsExpression.start, + moduleExportsExpression.end, + `${moduleName}.exports` + ); + } - if (isRestorableCompiledEsm) { - exportDeclarations.push( - deconflictedDefaultExportName - ? `export {${deconflictedDefaultExportName} as default};` - : `export default ${moduleName}.exports;` - ); - } else if (deconflictedDefaultExportName && code.indexOf('__esModule') >= 0) { - // eslint-disable-next-line no-param-reassign - uses.commonjsHelpers = true; - exportDeclarations.push( - `export default /*@__PURE__*/${HELPERS_NAME}.getDefaultExportFromCjs(${moduleName}.exports);` - ); - } else { - exportDeclarations.push(`export default ${moduleName}.exports;`); + if (isRestorableCompiledEsm) { + exportDeclarations.push( + deconflictedDefaultExportName + ? `export {${deconflictedDefaultExportName} as default};` + : `export default ${moduleName}.exports;` + ); + } else if (deconflictedDefaultExportName && code.indexOf('__esModule') >= 0) { + // eslint-disable-next-line no-param-reassign + uses.commonjsHelpers = true; + exportDeclarations.push( + `export default /*@__PURE__*/${HELPERS_NAME}.getDefaultExportFromCjs(${moduleName}.exports);` + ); + } else { + exportDeclarations.push(`export default ${moduleName}.exports;`); + } } } - return `\n\n${exportDeclarations.concat(moduleExportsPropertyAssignments).join('\n')}`; + return `\n\n${exportDeclarations.join('\n')}`; } diff --git a/packages/commonjs/src/generate-imports.js b/packages/commonjs/src/generate-imports.js index 981ccce66..b02e4783d 100644 --- a/packages/commonjs/src/generate-imports.js +++ b/packages/commonjs/src/generate-imports.js @@ -124,7 +124,8 @@ export function getRequireHandlers() { helpersNameIfUsed, dynamicRegisterSources, moduleName, - id + id, + replacesModuleExports ) { const removedDeclarators = getDeclaratorsReplacedByImportsAndSetImportNames( topLevelRequireDeclarators, @@ -141,9 +142,15 @@ export function getRequireHandlers() { ? [`import * as ${helpersNameIfUsed} from "${HELPERS_ID}";`] : [] ) - .concat([ - `import { __module as ${moduleName} } from ${JSON.stringify(wrapId(id, MODULE_SUFFIX))}` - ]) + .concat( + replacesModuleExports + ? [] + : [ + `import { __module as ${moduleName} } from ${JSON.stringify( + wrapId(id, MODULE_SUFFIX) + )}` + ] + ) .concat( // dynamic registers first, as the may be required in the other modules [...dynamicRegisterSources].map( diff --git a/packages/commonjs/src/index.js b/packages/commonjs/src/index.js index bec2c9cb7..8fcb2c107 100644 --- a/packages/commonjs/src/index.js +++ b/packages/commonjs/src/index.js @@ -24,7 +24,7 @@ import { PROXY_SUFFIX, unwrapId } from './helpers'; -import { setIsCjsPromise } from './is-cjs'; +import { setCommonJSMetaPromise } from './is-cjs'; import { hasCjsKeywords } from './parse'; import { getDynamicJsonProxy, @@ -141,14 +141,12 @@ export default function commonjs(options = {}) { // TODO Lukas in Rollup, ensure synthetic namespace is only rendered when needed // TODO Lukas + // - Use foo?exports instead of foo?module if there are no assignments to module.exports // - Only wrap if // - there is an assignment to module.exports (also check destructuring) or // - unchecked usages of module or // - direct eassignment to exports (also check destructuring) - // - Use foo?exports instead of foo?module if there are no assignments to module.exports // (also check destructring) - // - Do not use foo?module and do not wrap if there are only direct top-level module.exports - // assignments and no exports property assignments load(id) { if (id === HELPERS_ID) { return getHelpersModule(isDynamicRequireModulesEnabled); @@ -234,14 +232,11 @@ export default function commonjs(options = {}) { }, moduleParsed({ id, meta: { commonjs: commonjsMeta } }) { - if (commonjsMeta) { - const isCjs = commonjsMeta.isCommonJS; - if (isCjs != null) { - setIsCjsPromise(id, isCjs); - return; - } + if (commonjsMeta?.isCommonJS != null) { + setCommonJSMetaPromise(id, commonjsMeta); + return; } - setIsCjsPromise(id, null); + setCommonJSMetaPromise(id, null); } }; } diff --git a/packages/commonjs/src/is-cjs.js b/packages/commonjs/src/is-cjs.js index 5f4496c3a..0a4362f53 100644 --- a/packages/commonjs/src/is-cjs.js +++ b/packages/commonjs/src/is-cjs.js @@ -1,29 +1,29 @@ -const isCjsPromises = new Map(); +const commonJSMetaPromises = new Map(); -export function getIsCjsPromise(id) { - let isCjsPromise = isCjsPromises.get(id); - if (isCjsPromise) return isCjsPromise.promise; +export function getCommonJSMetaPromise(id) { + let commonJSMetaPromise = commonJSMetaPromises.get(id); + if (commonJSMetaPromise) return commonJSMetaPromise.promise; const promise = new Promise((resolve) => { - isCjsPromise = { + commonJSMetaPromise = { resolve, promise: null }; - isCjsPromises.set(id, isCjsPromise); + commonJSMetaPromises.set(id, commonJSMetaPromise); }); - isCjsPromise.promise = promise; + commonJSMetaPromise.promise = promise; return promise; } -export function setIsCjsPromise(id, resolution) { - const isCjsPromise = isCjsPromises.get(id); - if (isCjsPromise) { - if (isCjsPromise.resolve) { - isCjsPromise.resolve(resolution); - isCjsPromise.resolve = null; +export function setCommonJSMetaPromise(id, commonjsMeta) { + const commonJSMetaPromise = commonJSMetaPromises.get(id); + if (commonJSMetaPromise) { + if (commonJSMetaPromise.resolve) { + commonJSMetaPromise.resolve(commonjsMeta); + commonJSMetaPromise.resolve = null; } } else { - isCjsPromises.set(id, { promise: Promise.resolve(resolution), resolve: null }); + commonJSMetaPromises.set(id, { promise: Promise.resolve(commonjsMeta), resolve: null }); } } diff --git a/packages/commonjs/src/proxies.js b/packages/commonjs/src/proxies.js index f57db47c7..6e7cfa0d0 100644 --- a/packages/commonjs/src/proxies.js +++ b/packages/commonjs/src/proxies.js @@ -1,7 +1,7 @@ import { readFileSync } from 'fs'; -import { DYNAMIC_JSON_PREFIX, MODULE_SUFFIX, HELPERS_ID, wrapId } from './helpers'; -import { getIsCjsPromise } from './is-cjs'; +import { DYNAMIC_JSON_PREFIX, HELPERS_ID } from './helpers'; +import { getCommonJSMetaPromise } from './is-cjs'; import { getName, getVirtualPathForDynamicRequirePath, normalizePathSlashes } from './utils'; // e.g. id === "commonjsHelpers?commonjsRegister" @@ -49,13 +49,13 @@ export async function getStaticRequireProxy( esModulesWithNamedExports ) { const name = getName(id); - const isCjs = await getIsCjsPromise(id); - if (isCjs) { - return `export { exports as default } from ${JSON.stringify(wrapId(id, MODULE_SUFFIX))};`; - } else if (isCjs === null) { + const commonjsMeta = await getCommonJSMetaPromise(id); + if (commonjsMeta?.isCommonJS) { + return `export { __moduleExports as default } from ${JSON.stringify(id)};`; + } else if (commonjsMeta === null) { return getUnknownRequireProxy(id, requireReturnsDefault); } else if (!requireReturnsDefault) { - return `import {getAugmentedNamespace} from "${HELPERS_ID}"; import * as ${name} from ${JSON.stringify( + return `import { getAugmentedNamespace } from "${HELPERS_ID}"; import * as ${name} from ${JSON.stringify( id )}; export default /*@__PURE__*/getAugmentedNamespace(${name});`; } else if ( @@ -66,5 +66,5 @@ export async function getStaticRequireProxy( ) { return `import * as ${name} from ${JSON.stringify(id)}; export default ${name};`; } - return `export {default} from ${JSON.stringify(id)};`; + return `export { default } from ${JSON.stringify(id)};`; } diff --git a/packages/commonjs/src/transform-commonjs.js b/packages/commonjs/src/transform-commonjs.js index 069cf3a34..b4696ffcb 100644 --- a/packages/commonjs/src/transform-commonjs.js +++ b/packages/commonjs/src/transform-commonjs.js @@ -349,6 +349,24 @@ export default function transformCommonjs( magicString.remove(0, commentEnd).trim(); } + // TODO Lukas test all cases + const replacesModuleExports = + !shouldWrap && + topLevelExportsAssignmentsByName.size === 0 && + defineCompiledEsmExpressions.length === 0; + + const importBlock = rewriteRequireExpressionsAndGetImportBlock( + magicString, + topLevelDeclarations, + topLevelRequireDeclarators, + reassignedNames, + uses.commonjsHelpers && HELPERS_NAME, + dynamicRegisterSources, + moduleName, + id, + replacesModuleExports + ); + const exportBlock = isEsModule ? '' : rewriteExportsAndGetExportsBlock( @@ -362,20 +380,10 @@ export default function transformCommonjs( code, uses, HELPERS_NAME, - id + id, + replacesModuleExports ); - const importBlock = rewriteRequireExpressionsAndGetImportBlock( - magicString, - topLevelDeclarations, - topLevelRequireDeclarators, - reassignedNames, - uses.commonjsHelpers && HELPERS_NAME, - dynamicRegisterSources, - moduleName, - id - ); - if (shouldWrap) { wrapCode(magicString, uses, moduleName, HELPERS_NAME, virtualDynamicRequirePath); } diff --git a/packages/commonjs/test/fixtures/form/async-function/output.js b/packages/commonjs/test/fixtures/form/async-function/output.js index 884d233ad..1e2af6d52 100644 --- a/packages/commonjs/test/fixtures/form/async-function/output.js +++ b/packages/commonjs/test/fixtures/form/async-function/output.js @@ -1,8 +1,6 @@ -import { __module as input } from "\u0000fixtures/form/async-function/input.js?commonjs-module" - -input.exports = async function () { +var input = async function () { // TODO }; -export { exports as __moduleExports } from "\u0000fixtures/form/async-function/input.js?commonjs-module" -export default input.exports; +export { input as __moduleExports }; +export { input as default }; diff --git a/packages/commonjs/test/fixtures/form/constant-template-literal/output.js b/packages/commonjs/test/fixtures/form/constant-template-literal/output.js index 223e0dc4b..6089e7687 100644 --- a/packages/commonjs/test/fixtures/form/constant-template-literal/output.js +++ b/packages/commonjs/test/fixtures/form/constant-template-literal/output.js @@ -1,8 +1,8 @@ -import { __module as input } from "\u0000fixtures/form/constant-template-literal/input.js?commonjs-module" import "\u0000tape?commonjs-require"; import foo from "\u0000tape?commonjs-proxy"; console.log(foo); -export { exports as __moduleExports } from "\u0000fixtures/form/constant-template-literal/input.js?commonjs-module" -export default input.exports; +var input = {}; +export { input as __moduleExports }; +export { input as default }; diff --git a/packages/commonjs/test/fixtures/form/dynamic-template-literal/output.js b/packages/commonjs/test/fixtures/form/dynamic-template-literal/output.js index dfd7ed9de..9da671696 100644 --- a/packages/commonjs/test/fixtures/form/dynamic-template-literal/output.js +++ b/packages/commonjs/test/fixtures/form/dynamic-template-literal/output.js @@ -1,9 +1,9 @@ import * as commonjsHelpers from "_commonjsHelpers.js"; -import { __module as input } from "\u0000fixtures/form/dynamic-template-literal/input.js?commonjs-module" var pe = 'pe'; var foo = commonjsHelpers.commonjsRequire(`ta${pe}`); console.log(foo); -export { exports as __moduleExports } from "\u0000fixtures/form/dynamic-template-literal/input.js?commonjs-module" -export default input.exports; +var input = {}; +export { input as __moduleExports }; +export { input as default }; diff --git a/packages/commonjs/test/fixtures/form/ignore-ids-function/output.js b/packages/commonjs/test/fixtures/form/ignore-ids-function/output.js index 3af8548ea..33fe73d8a 100644 --- a/packages/commonjs/test/fixtures/form/ignore-ids-function/output.js +++ b/packages/commonjs/test/fixtures/form/ignore-ids-function/output.js @@ -1,8 +1,8 @@ -import { __module as input } from "\u0000fixtures/form/ignore-ids-function/input.js?commonjs-module" import "\u0000bar?commonjs-require"; import bar from "\u0000bar?commonjs-proxy"; var foo = require( 'foo' ); -export { exports as __moduleExports } from "\u0000fixtures/form/ignore-ids-function/input.js?commonjs-module" -export default input.exports; +var input = {}; +export { input as __moduleExports }; +export { input as default }; diff --git a/packages/commonjs/test/fixtures/form/ignore-ids/output.js b/packages/commonjs/test/fixtures/form/ignore-ids/output.js index 643f43b71..33fe73d8a 100644 --- a/packages/commonjs/test/fixtures/form/ignore-ids/output.js +++ b/packages/commonjs/test/fixtures/form/ignore-ids/output.js @@ -1,8 +1,8 @@ -import { __module as input } from "\u0000fixtures/form/ignore-ids/input.js?commonjs-module" import "\u0000bar?commonjs-require"; import bar from "\u0000bar?commonjs-proxy"; var foo = require( 'foo' ); -export { exports as __moduleExports } from "\u0000fixtures/form/ignore-ids/input.js?commonjs-module" -export default input.exports; +var input = {}; +export { input as __moduleExports }; +export { input as default }; diff --git a/packages/commonjs/test/fixtures/form/multi-entry-module-exports/output1.js b/packages/commonjs/test/fixtures/form/multi-entry-module-exports/output1.js index 1caf471d3..f160c4acf 100644 --- a/packages/commonjs/test/fixtures/form/multi-entry-module-exports/output1.js +++ b/packages/commonjs/test/fixtures/form/multi-entry-module-exports/output1.js @@ -1,9 +1,8 @@ -import { __module as input1 } from "\u0000fixtures/form/multi-entry-module-exports/input1.js?commonjs-module" import "\u0000./input2.js?commonjs-require"; import t2 from "\u0000./input2.js?commonjs-proxy"; console.log(t2); -input1.exports = 1; +var input1 = 1; -export { exports as __moduleExports } from "\u0000fixtures/form/multi-entry-module-exports/input1.js?commonjs-module" -export default input1.exports; +export { input1 as __moduleExports }; +export { input1 as default }; diff --git a/packages/commonjs/test/fixtures/form/multi-entry-module-exports/output2.js b/packages/commonjs/test/fixtures/form/multi-entry-module-exports/output2.js index 59d92915c..cbcac4dd3 100644 --- a/packages/commonjs/test/fixtures/form/multi-entry-module-exports/output2.js +++ b/packages/commonjs/test/fixtures/form/multi-entry-module-exports/output2.js @@ -1,8 +1,6 @@ -import { __module as input2 } from "\u0000fixtures/form/multi-entry-module-exports/input2.js?commonjs-module" - -input2.exports = { +var input2 = { a: 2 }; -export { exports as __moduleExports } from "\u0000fixtures/form/multi-entry-module-exports/input2.js?commonjs-module" -export default input2.exports; +export { input2 as __moduleExports }; +export { input2 as default }; diff --git a/packages/commonjs/test/fixtures/form/multiple-var-declarations-b/output.js b/packages/commonjs/test/fixtures/form/multiple-var-declarations-b/output.js index 0d6a11bdd..a9fe93adb 100644 --- a/packages/commonjs/test/fixtures/form/multiple-var-declarations-b/output.js +++ b/packages/commonjs/test/fixtures/form/multiple-var-declarations-b/output.js @@ -1,4 +1,3 @@ -import { __module as input } from "\u0000fixtures/form/multiple-var-declarations-b/input.js?commonjs-module" import "\u0000./a?commonjs-require"; import a from "\u0000./a?commonjs-proxy"; @@ -6,5 +5,6 @@ var b = 42; console.log( a, b ); -export { exports as __moduleExports } from "\u0000fixtures/form/multiple-var-declarations-b/input.js?commonjs-module" -export default input.exports; +var input = {}; +export { input as __moduleExports }; +export { input as default }; diff --git a/packages/commonjs/test/fixtures/form/multiple-var-declarations-c/output.js b/packages/commonjs/test/fixtures/form/multiple-var-declarations-c/output.js index 98dde00a7..2fd95219f 100644 --- a/packages/commonjs/test/fixtures/form/multiple-var-declarations-c/output.js +++ b/packages/commonjs/test/fixtures/form/multiple-var-declarations-c/output.js @@ -1,4 +1,3 @@ -import { __module as input } from "\u0000fixtures/form/multiple-var-declarations-c/input.js?commonjs-module" import "\u0000./b?commonjs-require"; import b from "\u0000./b?commonjs-proxy"; @@ -7,5 +6,6 @@ var a = 'a' console.log( a, b, c ); -export { exports as __moduleExports } from "\u0000fixtures/form/multiple-var-declarations-c/input.js?commonjs-module" -export default input.exports; +var input = {}; +export { input as __moduleExports }; +export { input as default }; diff --git a/packages/commonjs/test/fixtures/form/multiple-var-declarations/output.js b/packages/commonjs/test/fixtures/form/multiple-var-declarations/output.js index 5b00f4178..23f91c592 100644 --- a/packages/commonjs/test/fixtures/form/multiple-var-declarations/output.js +++ b/packages/commonjs/test/fixtures/form/multiple-var-declarations/output.js @@ -1,4 +1,3 @@ -import { __module as input } from "\u0000fixtures/form/multiple-var-declarations/input.js?commonjs-module" import "\u0000./a?commonjs-require"; import "\u0000./b?commonjs-require"; import require$$0 from "\u0000./a?commonjs-proxy"; @@ -8,5 +7,6 @@ var a = require$$0(); console.log( a, b ); -export { exports as __moduleExports } from "\u0000fixtures/form/multiple-var-declarations/input.js?commonjs-module" -export default input.exports; +var input = {}; +export { input as __moduleExports }; +export { input as default }; diff --git a/packages/commonjs/test/fixtures/form/no-exports-entry/output.js b/packages/commonjs/test/fixtures/form/no-exports-entry/output.js index 8d90bf882..fc7a0f5c5 100644 --- a/packages/commonjs/test/fixtures/form/no-exports-entry/output.js +++ b/packages/commonjs/test/fixtures/form/no-exports-entry/output.js @@ -1,4 +1,3 @@ -import { __module as input_1 } from "\u0000fixtures/form/no-exports-entry/input.js?commonjs-module" import "\u0000./dummy?commonjs-require"; import dummy from "\u0000./dummy?commonjs-proxy"; @@ -8,5 +7,6 @@ var foo = function () { var input = 42; -export { exports as __moduleExports } from "\u0000fixtures/form/no-exports-entry/input.js?commonjs-module" -export default input_1.exports; +var input_1 = {}; +export { input_1 as __moduleExports }; +export { input_1 as default }; diff --git a/packages/commonjs/test/fixtures/form/no-toplevel-return/output.js b/packages/commonjs/test/fixtures/form/no-toplevel-return/output.js index f89906c2d..42c7be60c 100644 --- a/packages/commonjs/test/fixtures/form/no-toplevel-return/output.js +++ b/packages/commonjs/test/fixtures/form/no-toplevel-return/output.js @@ -1,5 +1,3 @@ -import { __module as input } from "\u0000fixtures/form/no-toplevel-return/input.js?commonjs-module" - var foo = function () { return; }; @@ -12,7 +10,7 @@ function baz () { return; } -input.exports = 42; +var input = 42; -export { exports as __moduleExports } from "\u0000fixtures/form/no-toplevel-return/input.js?commonjs-module" -export default input.exports; +export { input as __moduleExports }; +export { input as default }; diff --git a/packages/commonjs/test/fixtures/form/optimised-default-export-function-double-assign/output.js b/packages/commonjs/test/fixtures/form/optimised-default-export-function-double-assign/output.js index dc1c09c7a..be314e512 100644 --- a/packages/commonjs/test/fixtures/form/optimised-default-export-function-double-assign/output.js +++ b/packages/commonjs/test/fixtures/form/optimised-default-export-function-double-assign/output.js @@ -1,7 +1,5 @@ -import { __module as input } from "\u0000fixtures/form/optimised-default-export-function-double-assign/input.js?commonjs-module" - var bar; -input.exports = bar = function foo () {}; +var input = bar = function foo () {}; -export { exports as __moduleExports } from "\u0000fixtures/form/optimised-default-export-function-double-assign/input.js?commonjs-module" -export default input.exports; +export { input as __moduleExports }; +export { input as default }; diff --git a/packages/commonjs/test/fixtures/form/optimised-default-export-function/output.js b/packages/commonjs/test/fixtures/form/optimised-default-export-function/output.js index 4ddbb740b..e2703bdb1 100644 --- a/packages/commonjs/test/fixtures/form/optimised-default-export-function/output.js +++ b/packages/commonjs/test/fixtures/form/optimised-default-export-function/output.js @@ -1,6 +1,4 @@ -import { __module as input } from "\u0000fixtures/form/optimised-default-export-function/input.js?commonjs-module" +var input = function foo () {}; -input.exports = function foo () {}; - -export { exports as __moduleExports } from "\u0000fixtures/form/optimised-default-export-function/input.js?commonjs-module" -export default input.exports; +export { input as __moduleExports }; +export { input as default }; diff --git a/packages/commonjs/test/fixtures/form/optimised-default-export-iife/output.js b/packages/commonjs/test/fixtures/form/optimised-default-export-iife/output.js index 8664cabb8..3fd8be215 100644 --- a/packages/commonjs/test/fixtures/form/optimised-default-export-iife/output.js +++ b/packages/commonjs/test/fixtures/form/optimised-default-export-iife/output.js @@ -1,8 +1,6 @@ -import { __module as input } from "\u0000fixtures/form/optimised-default-export-iife/input.js?commonjs-module" - -input.exports = (function foo () { +var input = (function foo () { return function fooChild() {}; }()); -export { exports as __moduleExports } from "\u0000fixtures/form/optimised-default-export-iife/input.js?commonjs-module" -export default input.exports; +export { input as __moduleExports }; +export { input as default }; diff --git a/packages/commonjs/test/fixtures/form/optimised-default-export/output.js b/packages/commonjs/test/fixtures/form/optimised-default-export/output.js index c1f5101a8..4c8feaff3 100644 --- a/packages/commonjs/test/fixtures/form/optimised-default-export/output.js +++ b/packages/commonjs/test/fixtures/form/optimised-default-export/output.js @@ -1,6 +1,4 @@ -import { __module as input } from "\u0000fixtures/form/optimised-default-export/input.js?commonjs-module" +var input = 42; -input.exports = 42; - -export { exports as __moduleExports } from "\u0000fixtures/form/optimised-default-export/input.js?commonjs-module" -export default input.exports; +export { input as __moduleExports }; +export { input as default }; diff --git a/packages/commonjs/test/fixtures/form/require-collision/output.js b/packages/commonjs/test/fixtures/form/require-collision/output.js index 458519ed9..b4095344d 100644 --- a/packages/commonjs/test/fixtures/form/require-collision/output.js +++ b/packages/commonjs/test/fixtures/form/require-collision/output.js @@ -1,4 +1,3 @@ -import { __module as input } from "\u0000fixtures/form/require-collision/input.js?commonjs-module" import "\u0000foo?commonjs-require"; import require$$1 from "\u0000foo?commonjs-proxy"; @@ -8,5 +7,6 @@ import require$$1 from "\u0000foo?commonjs-proxy"; console.log(foo); })(); -export { exports as __moduleExports } from "\u0000fixtures/form/require-collision/input.js?commonjs-module" -export default input.exports; +var input = {}; +export { input as __moduleExports }; +export { input as default }; diff --git a/packages/commonjs/test/fixtures/form/unambiguous-with-default-export/output.js b/packages/commonjs/test/fixtures/form/unambiguous-with-default-export/output.js index 6381f6a22..9bf9ff524 100644 --- a/packages/commonjs/test/fixtures/form/unambiguous-with-default-export/output.js +++ b/packages/commonjs/test/fixtures/form/unambiguous-with-default-export/output.js @@ -1,4 +1,3 @@ -import { __module as input } from "\u0000fixtures/form/unambiguous-with-default-export/input.js?commonjs-module" import "\u0000./foo.js?commonjs-require"; import "\u0000./foo.js?commonjs-proxy"; diff --git a/packages/commonjs/test/fixtures/form/unambiguous-with-import/output.js b/packages/commonjs/test/fixtures/form/unambiguous-with-import/output.js index 82ea86b83..8ac8cbdd3 100644 --- a/packages/commonjs/test/fixtures/form/unambiguous-with-import/output.js +++ b/packages/commonjs/test/fixtures/form/unambiguous-with-import/output.js @@ -1,4 +1,3 @@ -import { __module as input } from "\u0000fixtures/form/unambiguous-with-import/input.js?commonjs-module" import "\u0000./foo.js?commonjs-require"; import "\u0000./foo.js?commonjs-proxy"; diff --git a/packages/commonjs/test/fixtures/form/unambiguous-with-named-export/output.js b/packages/commonjs/test/fixtures/form/unambiguous-with-named-export/output.js index 8b55d2b68..1fe2c644d 100644 --- a/packages/commonjs/test/fixtures/form/unambiguous-with-named-export/output.js +++ b/packages/commonjs/test/fixtures/form/unambiguous-with-named-export/output.js @@ -1,4 +1,3 @@ -import { __module as input } from "\u0000fixtures/form/unambiguous-with-named-export/input.js?commonjs-module" import "\u0000./foo.js?commonjs-require"; import "\u0000./foo.js?commonjs-proxy"; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/_config.js b/packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/_config.js index e00385421..6d8a12332 100755 --- a/packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/_config.js +++ b/packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/_config.js @@ -4,7 +4,10 @@ module.exports = { input: [ 'fixtures/function/dynamic-require-code-splitting/main', 'fixtures/function/dynamic-require-code-splitting/main2' - ] + ], + output: { + chunkFileNames: 'generated-[name].js' + } }, pluginOptions: { dynamicRequireTargets: ['fixtures/function/dynamic-require-code-splitting/target?.js'], diff --git a/packages/commonjs/test/snapshots/function.js.md b/packages/commonjs/test/snapshots/function.js.md index 59458ff4e..9e3fdcca8 100644 --- a/packages/commonjs/test/snapshots/function.js.md +++ b/packages/commonjs/test/snapshots/function.js.md @@ -85,16 +85,11 @@ Generated by [AVA](https://avajs.dev). { 'main.js': `'use strict';␊ ␊ - var main = {exports: {}};␊ - ␊ - var foo = {exports: {}};␊ - ␊ - foo.exports = 21;␊ + var foo = 21;␊ ␊ - main.exports = foo.exports * 2;␊ - var main$1 = main.exports;␊ + var main = foo * 2;␊ ␊ - module.exports = main$1;␊ + module.exports = main;␊ `, } @@ -168,12 +163,9 @@ Generated by [AVA](https://avajs.dev). { 'bundle.js': `'use strict';␊ ␊ - var dashName = {exports: {}};␊ - ␊ - dashName.exports = true;␊ - var value = dashName.exports;␊ + var dashName = true;␊ ␊ - t.truthy(value);␊ + t.truthy(dashName);␊ `, } @@ -202,16 +194,13 @@ Generated by [AVA](https://avajs.dev). { 'main.js': `'use strict';␊ ␊ - var main = {exports: {}};␊ - ␊ - var foo_bar = {exports: {}};␊ + var foo_bar = 'fubar';␊ ␊ - foo_bar.exports = 'fubar';␊ + t.is(foo_bar, 'fubar');␊ ␊ - t.is(foo_bar.exports, 'fubar');␊ - var main$1 = main.exports;␊ + var main = {};␊ ␊ - module.exports = main$1;␊ + module.exports = main;␊ `, } @@ -241,13 +230,10 @@ Generated by [AVA](https://avajs.dev). { 'main.js': `'use strict';␊ ␊ - var dep = {exports: {}};␊ - ␊ - dep.exports = 'first';␊ - dep.exports = 'second';␊ - var dep$1 = dep.exports;␊ + var dep = 'first';␊ + var dep = 'second';␊ ␊ - t.is(dep$1, 'second');␊ + t.is(dep, 'second');␊ `, } @@ -520,16 +506,6 @@ Generated by [AVA](https://avajs.dev). ␊ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ - function createModule(modulePath) {␊ - return {␊ - path: modulePath,␊ - exports: {},␊ - require: function (path, base) {␊ - return commonjsRequire(path, base == null ? modulePath : base);␊ - }␊ - };␊ - }␊ - ␊ function commonjsRegister (path, loader) {␊ DYNAMIC_REQUIRE_LOADERS[path] = loader;␊ }␊ @@ -666,8 +642,6 @@ Generated by [AVA](https://avajs.dev). ␊ commonjsRequire.cache = DYNAMIC_REQUIRE_CACHE;␊ ␊ - var main = createModule("/$$rollup_base$$/fixtures/function/dynamic-require");␊ - ␊ commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require/submodule.js", function (module, exports) {␊ module.exports = function() {␊ return 'Hello there';␊ @@ -691,9 +665,10 @@ Generated by [AVA](https://avajs.dev). }␊ ␊ t.is(message, 'Hello there');␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -852,8 +827,6 @@ Generated by [AVA](https://avajs.dev). ␊ commonjsRequire.cache = DYNAMIC_REQUIRE_CACHE;␊ ␊ - var main = createModule("/$$rollup_base$$/fixtures/function/dynamic-require-absolute-import");␊ - ␊ commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-absolute-import/sub/node_modules/module/direct.js", function (module, exports) {␊ module.exports = 'direct';␊ ␊ @@ -891,9 +864,10 @@ Generated by [AVA](https://avajs.dev). moduleNested: 'nested',␊ parentModule: 'parent'␊ });␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -912,16 +886,6 @@ Generated by [AVA](https://avajs.dev). ␊ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ - function createModule(modulePath) {␊ - return {␊ - path: modulePath,␊ - exports: {},␊ - require: function (path, base) {␊ - return commonjsRequire(path, base == null ? modulePath : base);␊ - }␊ - };␊ - }␊ - ␊ function commonjsRegister (path, loader) {␊ DYNAMIC_REQUIRE_LOADERS[path] = loader;␊ }␊ @@ -1058,8 +1022,6 @@ Generated by [AVA](https://avajs.dev). ␊ commonjsRequire.cache = DYNAMIC_REQUIRE_CACHE;␊ ␊ - var main = createModule("/$$rollup_base$$/fixtures/function/dynamic-require-absolute-paths");␊ - ␊ commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-absolute-paths/submodule.js", function (module, exports) {␊ module.exports = 'submodule';␊ ␊ @@ -1072,9 +1034,10 @@ Generated by [AVA](https://avajs.dev). const basePath = `${process.cwd()}/fixtures/function/dynamic-require-absolute-paths`;␊ ␊ t.is(commonjsRequire(Path__default['default'].resolve(`${basePath}/submodule.js`),"/$$rollup_base$$/fixtures/function/dynamic-require-absolute-paths"), 'submodule');␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -1083,7 +1046,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 { - 'lib2-9ad56b7a.js': `'use strict';␊ + 'generated-lib2.js': `'use strict';␊ ␊ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ @@ -1250,7 +1213,7 @@ Generated by [AVA](https://avajs.dev). `, 'main.js': `'use strict';␊ ␊ - var lib2 = require('./lib2-9ad56b7a.js');␊ + var lib2 = require('./generated-lib2.js');␊ ␊ /* eslint-disable import/no-dynamic-require, global-require */␊ ␊ @@ -1267,7 +1230,7 @@ Generated by [AVA](https://avajs.dev). `, 'main2.js': `'use strict';␊ ␊ - require('./lib2-9ad56b7a.js');␊ + require('./generated-lib2.js');␊ ␊ `, } @@ -1281,16 +1244,6 @@ Generated by [AVA](https://avajs.dev). ␊ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ - function createModule(modulePath) {␊ - return {␊ - path: modulePath,␊ - exports: {},␊ - require: function (path, base) {␊ - return commonjsRequire(path, base == null ? modulePath : base);␊ - }␊ - };␊ - }␊ - ␊ function commonjsRegister (path, loader) {␊ DYNAMIC_REQUIRE_LOADERS[path] = loader;␊ }␊ @@ -1432,18 +1385,15 @@ Generated by [AVA](https://avajs.dev). ␊ });␊ ␊ - var importer = createModule("/$$rollup_base$$/fixtures/function/dynamic-require-es-entry");␊ - ␊ /* eslint-disable import/no-dynamic-require, global-require */␊ ␊ function takeModule(withName) {␊ return commonjsRequire(`./${withName}`,"/$$rollup_base$$/fixtures/function/dynamic-require-es-entry");␊ }␊ ␊ - importer.exports = takeModule('submodule.js');␊ - var result = importer.exports;␊ + var importer = takeModule('submodule.js');␊ ␊ - t.is(result, 'submodule');␊ + t.is(importer, 'submodule');␊ `, } @@ -1456,16 +1406,6 @@ Generated by [AVA](https://avajs.dev). ␊ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ - function createModule(modulePath) {␊ - return {␊ - path: modulePath,␊ - exports: {},␊ - require: function (path, base) {␊ - return commonjsRequire(path, base == null ? modulePath : base);␊ - }␊ - };␊ - }␊ - ␊ function commonjsRegister (path, loader) {␊ DYNAMIC_REQUIRE_LOADERS[path] = loader;␊ }␊ @@ -1602,8 +1542,6 @@ Generated by [AVA](https://avajs.dev). ␊ commonjsRequire.cache = DYNAMIC_REQUIRE_CACHE;␊ ␊ - var main = createModule("/$$rollup_base$$/fixtures/function/dynamic-require-extensions");␊ - ␊ commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-extensions/submodule.js", function (module, exports) {␊ module.exports = { name: 'submodule', value: null };␊ ␊ @@ -1624,9 +1562,10 @@ Generated by [AVA](https://avajs.dev). withExtension.value = 'mutated';␊ ␊ t.is(withoutExtension.value, 'mutated');␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -1639,16 +1578,6 @@ Generated by [AVA](https://avajs.dev). ␊ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ - function createModule(modulePath) {␊ - return {␊ - path: modulePath,␊ - exports: {},␊ - require: function (path, base) {␊ - return commonjsRequire(path, base == null ? modulePath : base);␊ - }␊ - };␊ - }␊ - ␊ function commonjsRegister (path, loader) {␊ DYNAMIC_REQUIRE_LOADERS[path] = loader;␊ }␊ @@ -1785,8 +1714,6 @@ Generated by [AVA](https://avajs.dev). ␊ commonjsRequire.cache = DYNAMIC_REQUIRE_CACHE;␊ ␊ - var main = createModule("/$$rollup_base$$/fixtures/function/dynamic-require-globs");␊ - ␊ commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-globs/submodule1.js", function (module, exports) {␊ module.exports = 'submodule1';␊ ␊ @@ -1820,9 +1747,10 @@ Generated by [AVA](https://avajs.dev). hasThrown = true;␊ }␊ t.truthy(hasThrown);␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -1835,16 +1763,6 @@ Generated by [AVA](https://avajs.dev). ␊ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ - function createModule(modulePath) {␊ - return {␊ - path: modulePath,␊ - exports: {},␊ - require: function (path, base) {␊ - return commonjsRequire(path, base == null ? modulePath : base);␊ - }␊ - };␊ - }␊ - ␊ function commonjsRegister (path, loader) {␊ DYNAMIC_REQUIRE_LOADERS[path] = loader;␊ }␊ @@ -1981,8 +1899,6 @@ Generated by [AVA](https://avajs.dev). ␊ commonjsRequire.cache = DYNAMIC_REQUIRE_CACHE;␊ ␊ - var main = createModule("/$$rollup_base$$/fixtures/function/dynamic-require-instances");␊ - ␊ commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-instances/direct/index.js", function (module, exports) {␊ module.exports = { name: 'direct', value: null };␊ ␊ @@ -2013,9 +1929,10 @@ Generated by [AVA](https://avajs.dev). takeModule('./package').value = 'package-instance';␊ t.is(takeModule('./package/main.js').value, 'package-instance');␊ t.is(commonjsRequire("./package/main.js", "/$$rollup_base$$/fixtures/function/dynamic-require-instances").value, 'package-instance');␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -2028,16 +1945,6 @@ Generated by [AVA](https://avajs.dev). ␊ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ - function createModule(modulePath) {␊ - return {␊ - path: modulePath,␊ - exports: {},␊ - require: function (path, base) {␊ - return commonjsRequire(path, base == null ? modulePath : base);␊ - }␊ - };␊ - }␊ - ␊ function commonjsRegister (path, loader) {␊ DYNAMIC_REQUIRE_LOADERS[path] = loader;␊ }␊ @@ -2174,8 +2081,6 @@ Generated by [AVA](https://avajs.dev). ␊ commonjsRequire.cache = DYNAMIC_REQUIRE_CACHE;␊ ␊ - var main = createModule("/$$rollup_base$$/fixtures/function/dynamic-require-json");␊ - ␊ var value = "present";␊ var require$$0 = {␊ value: value␊ @@ -2193,9 +2098,10 @@ Generated by [AVA](https://avajs.dev). ␊ t.deepEqual(takeModule('dynamic.json'), { value: 'present' });␊ t.deepEqual(takeModule('dynamic'), { value: 'present' });␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -2208,16 +2114,6 @@ Generated by [AVA](https://avajs.dev). ␊ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ - function createModule(modulePath) {␊ - return {␊ - path: modulePath,␊ - exports: {},␊ - require: function (path, base) {␊ - return commonjsRequire(path, base == null ? modulePath : base);␊ - }␊ - };␊ - }␊ - ␊ function commonjsRegister (path, loader) {␊ DYNAMIC_REQUIRE_LOADERS[path] = loader;␊ }␊ @@ -2354,39 +2250,29 @@ Generated by [AVA](https://avajs.dev). ␊ commonjsRequire.cache = DYNAMIC_REQUIRE_CACHE;␊ ␊ - var main = createModule("/$$rollup_base$$/fixtures/function/dynamic-require-package");␊ - ␊ - var entry = createModule("/$$rollup_base$$/fixtures/function/dynamic-require-package");␊ - ␊ - entry.exports = 'same-directory';␊ - ␊ - var entry$1 = createModule("/$$rollup_base$$/fixtures/function/dynamic-require-package/sub");␊ + var entry = 'same-directory';␊ ␊ - entry$1.exports = 'sub';␊ + var entry$1 = 'sub';␊ ␊ - var entry$2 = createModule("/$$rollup_base$$/fixtures/function/dynamic-require-package/node_modules/custom-module");␊ - ␊ - entry$2.exports = 'custom-module';␊ + var entry$2 = 'custom-module';␊ ␊ commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-package", function (module, exports) {␊ - module.exports = entry.exports;␊ + module.exports = entry;␊ });␊ commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-package/sub", function (module, exports) {␊ - module.exports = entry$1.exports;␊ + module.exports = entry$1;␊ });␊ commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-package/node_modules/custom-module", function (module, exports) {␊ - module.exports = entry$2.exports;␊ + module.exports = entry$2;␊ });␊ ␊ - var sub = createModule("/$$rollup_base$$/fixtures/function/dynamic-require-package/sub");␊ - ␊ /* eslint-disable import/no-dynamic-require, global-require */␊ ␊ function takeModule(name) {␊ return commonjsRequire(name,"/$$rollup_base$$/fixtures/function/dynamic-require-package/sub");␊ }␊ ␊ - sub.exports = {␊ + var sub = {␊ parent: takeModule('..'),␊ customModule: takeModule('custom-module')␊ };␊ @@ -2404,10 +2290,11 @@ Generated by [AVA](https://avajs.dev). t.is(takeModule$1('./sub'), 'sub');␊ ␊ t.is(takeModule$1('custom-module'), 'custom-module');␊ - t.deepEqual(sub.exports, { parent: 'same-directory', customModule: 'custom-module' });␊ - var main$1 = main.exports;␊ + t.deepEqual(sub, { parent: 'same-directory', customModule: 'custom-module' });␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -2420,16 +2307,6 @@ Generated by [AVA](https://avajs.dev). ␊ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ - function createModule(modulePath) {␊ - return {␊ - path: modulePath,␊ - exports: {},␊ - require: function (path, base) {␊ - return commonjsRequire(path, base == null ? modulePath : base);␊ - }␊ - };␊ - }␊ - ␊ function commonjsRegister (path, loader) {␊ DYNAMIC_REQUIRE_LOADERS[path] = loader;␊ }␊ @@ -2566,8 +2443,6 @@ Generated by [AVA](https://avajs.dev). ␊ commonjsRequire.cache = DYNAMIC_REQUIRE_CACHE;␊ ␊ - var entry = createModule("/$$rollup_base$$/fixtures/function/dynamic-require-package-sub/sub");␊ - ␊ commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-package-sub/node_modules/custom-module/entry.js", function (module, exports) {␊ module.exports = 'custom-module';␊ ␊ @@ -2587,9 +2462,10 @@ Generated by [AVA](https://avajs.dev). });␊ ␊ t.is(commonjsRequire("custom-module", "/$$rollup_base$$/fixtures/function/dynamic-require-package-sub/sub"), 'custom-module');␊ - var entry$1 = entry.exports;␊ ␊ - module.exports = entry$1;␊ + var entry = {};␊ + ␊ + module.exports = entry;␊ `, } @@ -2602,16 +2478,6 @@ Generated by [AVA](https://avajs.dev). ␊ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ - function createModule(modulePath) {␊ - return {␊ - path: modulePath,␊ - exports: {},␊ - require: function (path, base) {␊ - return commonjsRequire(path, base == null ? modulePath : base);␊ - }␊ - };␊ - }␊ - ␊ function commonjsRegister (path, loader) {␊ DYNAMIC_REQUIRE_LOADERS[path] = loader;␊ }␊ @@ -2748,8 +2614,6 @@ Generated by [AVA](https://avajs.dev). ␊ commonjsRequire.cache = DYNAMIC_REQUIRE_CACHE;␊ ␊ - var main = createModule("/$$rollup_base$$/fixtures/function/dynamic-require-relative-paths");␊ - ␊ commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-relative-paths/sub/submodule.js", function (module, exports) {␊ module.exports = 'submodule';␊ ␊ @@ -2770,9 +2634,10 @@ Generated by [AVA](https://avajs.dev). t.is(takeModuleWithDelimiter('sub=subsub=subsubmodule.js', '/'), 'subsubmodule');␊ t.is(takeModuleWithDelimiter('sub=submodule.js', '\\\\'), 'submodule');␊ t.is(takeModuleWithDelimiter('sub=subsub=subsubmodule.js', '\\\\'), 'subsubmodule');␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -2785,16 +2650,6 @@ Generated by [AVA](https://avajs.dev). ␊ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ - function createModule(modulePath) {␊ - return {␊ - path: modulePath,␊ - exports: {},␊ - require: function (path, base) {␊ - return commonjsRequire(path, base == null ? modulePath : base);␊ - }␊ - };␊ - }␊ - ␊ function commonjsRegister (path, loader) {␊ DYNAMIC_REQUIRE_LOADERS[path] = loader;␊ }␊ @@ -2931,39 +2786,29 @@ Generated by [AVA](https://avajs.dev). ␊ commonjsRequire.cache = DYNAMIC_REQUIRE_CACHE;␊ ␊ - var main = createModule("/$$rollup_base$$/fixtures/function/dynamic-require-resolve-index");␊ - ␊ - var dynamicRequireResolveIndex = createModule("/$$rollup_base$$/fixtures/function/dynamic-require-resolve-index");␊ - ␊ - dynamicRequireResolveIndex.exports = 'same-directory';␊ + var dynamicRequireResolveIndex = 'same-directory';␊ ␊ - var sub = createModule("/$$rollup_base$$/fixtures/function/dynamic-require-resolve-index/sub");␊ + var sub = 'sub';␊ ␊ - sub.exports = 'sub';␊ - ␊ - var customModule = createModule("/$$rollup_base$$/fixtures/function/dynamic-require-resolve-index/node_modules/custom-module");␊ - ␊ - customModule.exports = 'custom-module';␊ + var customModule = 'custom-module';␊ ␊ commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-resolve-index", function (module, exports) {␊ - module.exports = dynamicRequireResolveIndex.exports;␊ + module.exports = dynamicRequireResolveIndex;␊ });␊ commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-resolve-index/sub", function (module, exports) {␊ - module.exports = sub.exports;␊ + module.exports = sub;␊ });␊ commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-resolve-index/node_modules/custom-module", function (module, exports) {␊ - module.exports = customModule.exports;␊ + module.exports = customModule;␊ });␊ ␊ - var sub$1 = createModule("/$$rollup_base$$/fixtures/function/dynamic-require-resolve-index/sub");␊ - ␊ /* eslint-disable import/no-dynamic-require, global-require */␊ ␊ function takeModule(name) {␊ return commonjsRequire(name,"/$$rollup_base$$/fixtures/function/dynamic-require-resolve-index/sub");␊ }␊ ␊ - sub$1.exports = {␊ + var sub$1 = {␊ parent: takeModule('..'),␊ customModule: takeModule('custom-module')␊ };␊ @@ -2981,10 +2826,11 @@ Generated by [AVA](https://avajs.dev). t.is(takeModule$1('./sub'), 'sub');␊ ␊ t.is(takeModule$1('custom-module'), 'custom-module');␊ - t.deepEqual(sub$1.exports, { parent: 'same-directory', customModule: 'custom-module' });␊ - var main$1 = main.exports;␊ + t.deepEqual(sub$1, { parent: 'same-directory', customModule: 'custom-module' });␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -3038,16 +2884,15 @@ Generated by [AVA](https://avajs.dev). var externalMixed__default = /*#__PURE__*/_interopDefaultLegacy(externalMixed);␊ var externalDefault__default = /*#__PURE__*/_interopDefaultLegacy(externalDefault);␊ ␊ - var main = {exports: {}};␊ - ␊ t.deepEqual(externalExports__default['default'], { foo: 'foo' }, 'external exports');␊ t.deepEqual(externalModuleExports__default['default'], 'bar', 'external module exports');␊ t.deepEqual(externalNamed__default['default'], { foo: 'foo' }, 'external named');␊ t.deepEqual(externalMixed__default['default'], 'bar', 'external mixed');␊ t.deepEqual(externalDefault__default['default'], 'bar', 'external default');␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -3092,8 +2937,6 @@ Generated by [AVA](https://avajs.dev). var externalMixed__default = /*#__PURE__*/_interopDefaultLegacy(externalMixed);␊ var externalEsmDefault__namespace = /*#__PURE__*/_interopNamespace(externalEsmDefault);␊ ␊ - var main = {exports: {}};␊ - ␊ function getAugmentedNamespace(n) {␊ if (n.__esModule) return n;␊ var a = Object.defineProperty({}, '__esModule', {value: true});␊ @@ -3116,9 +2959,10 @@ Generated by [AVA](https://avajs.dev). t.deepEqual(externalNamed__default['default'], { foo: 'foo' }, 'external named');␊ t.deepEqual(externalMixed__default['default'], 'bar', 'external mixed');␊ t.deepEqual(externalDefault, { default: 'bar' }, 'external default');␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -3163,8 +3007,6 @@ Generated by [AVA](https://avajs.dev). var externalMixed__default = /*#__PURE__*/_interopDefaultLegacy(externalMixed);␊ var externalEsmDefault__namespace = /*#__PURE__*/_interopNamespace(externalEsmDefault);␊ ␊ - var main = {exports: {}};␊ - ␊ function getAugmentedNamespace(n) {␊ if (n.__esModule) return n;␊ var a = Object.defineProperty({}, '__esModule', {value: true});␊ @@ -3187,9 +3029,10 @@ Generated by [AVA](https://avajs.dev). t.deepEqual(externalNamed__default['default'], { foo: 'foo' }, 'external named');␊ t.deepEqual(externalMixed__default['default'], 'bar', 'external mixed');␊ t.deepEqual(externalDefault, { default: 'bar' }, 'external default');␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -3228,8 +3071,6 @@ Generated by [AVA](https://avajs.dev). var externalEsmMixed__namespace = /*#__PURE__*/_interopNamespace(externalEsmMixed);␊ var externalEsmDefault__namespace = /*#__PURE__*/_interopNamespace(externalEsmDefault);␊ ␊ - var main = {exports: {}};␊ - ␊ function getAugmentedNamespace(n) {␊ if (n.__esModule) return n;␊ var a = Object.defineProperty({}, '__esModule', {value: true});␊ @@ -3254,9 +3095,10 @@ Generated by [AVA](https://avajs.dev). t.deepEqual(externalNamed, { foo: 'foo' }, 'external named');␊ t.deepEqual(externalMixed, { default: 'bar', foo: 'foo' }, 'external mixed');␊ t.deepEqual(externalDefault, { default: 'bar' }, 'external default');␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -3281,16 +3123,15 @@ Generated by [AVA](https://avajs.dev). var externalMixed__default = /*#__PURE__*/_interopDefaultLegacy(externalMixed);␊ var externalDefault__default = /*#__PURE__*/_interopDefaultLegacy(externalDefault);␊ ␊ - var main = {exports: {}};␊ - ␊ t.deepEqual(externalExports__default['default'], { foo: 'foo' }, 'external exports');␊ t.deepEqual(externalModuleExports__default['default'], 'bar', 'external module exports');␊ t.deepEqual(externalNamed__default['default'], { foo: 'foo' }, 'external named');␊ t.deepEqual(externalMixed__default['default'], 'bar', 'external mixed');␊ t.deepEqual(externalDefault__default['default'], 'bar', 'external default');␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -3301,14 +3142,13 @@ Generated by [AVA](https://avajs.dev). { 'main.js': `'use strict';␊ ␊ - var main = {exports: {}};␊ - ␊ var require$$0 = 'default export';␊ ␊ t.is(require$$0, 'default export');␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -3319,8 +3159,6 @@ Generated by [AVA](https://avajs.dev). { 'main.js': `'use strict';␊ ␊ - var main = {exports: {}};␊ - ␊ var foo = {exports: {}};␊ ␊ var bar = 'BAR';␊ @@ -3331,10 +3169,9 @@ Generated by [AVA](https://avajs.dev). const { bar: bar$1 } = foo.exports;␊ const { baz: baz$1 } = foo.exports;␊ ␊ - main.exports = bar$1 + baz$1;␊ - var main$1 = main.exports;␊ + var main = bar$1 + baz$1;␊ ␊ - module.exports = main$1;␊ + module.exports = main;␊ `, } @@ -3351,12 +3188,9 @@ Generated by [AVA](https://avajs.dev). `, 'other.js': `'use strict';␊ ␊ - var other = {exports: {}};␊ - ␊ - other.exports = 'foo';␊ - var foo = other.exports;␊ + var other = 'foo';␊ ␊ - module.exports = foo;␊ + module.exports = other;␊ `, } @@ -3373,12 +3207,9 @@ Generated by [AVA](https://avajs.dev). ␊ var foo__default = /*#__PURE__*/_interopDefaultLegacy(foo);␊ ␊ - var main = {exports: {}};␊ - ␊ - main.exports = foo__default['default'];␊ - var main$1 = main.exports;␊ + var main = foo__default['default'];␊ ␊ - module.exports = main$1;␊ + module.exports = main;␊ `, } @@ -3389,8 +3220,6 @@ Generated by [AVA](https://avajs.dev). { 'main.js': `'use strict';␊ ␊ - var main = {exports: {}};␊ - ␊ /* eslint-disable */␊ var one = 1;␊ ␊ @@ -3421,9 +3250,10 @@ Generated by [AVA](https://avajs.dev). ␊ t.is(foo$1.one, 1);␊ t.is(foo$1.two, 2);␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -3471,8 +3301,6 @@ Generated by [AVA](https://avajs.dev). ␊ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ - var main = {exports: {}};␊ - ␊ /* eslint-disable */␊ ␊ function foo() {␊ @@ -3485,10 +3313,9 @@ Generated by [AVA](https://avajs.dev). t.truthy(notGlobal.modified);␊ t.truthy(!commonjsGlobal.modified);␊ ␊ - main.exports = {};␊ - var main$1 = main.exports;␊ + var main = {};␊ ␊ - module.exports = main$1;␊ + module.exports = main;␊ `, } @@ -3527,8 +3354,6 @@ Generated by [AVA](https://avajs.dev). var externalEsmMixed__namespace = /*#__PURE__*/_interopNamespace(externalEsmMixed);␊ var externalEsmDefault__namespace = /*#__PURE__*/_interopNamespace(externalEsmDefault);␊ ␊ - var main = {exports: {}};␊ - ␊ const foo = 'foo';␊ ␊ var named = /*#__PURE__*/Object.freeze({␊ @@ -3568,9 +3393,10 @@ Generated by [AVA](https://avajs.dev). t.deepEqual(externalNamed, { foo: 'foo' }, 'external named');␊ t.deepEqual(externalMixed, { foo: 'foo', default: 'bar' }, 'external mixed');␊ t.deepEqual(externalDefault, 'bar', 'external default');␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -3609,8 +3435,6 @@ Generated by [AVA](https://avajs.dev). var externalEsmMixed__namespace = /*#__PURE__*/_interopNamespace(externalEsmMixed);␊ var externalEsmDefault__namespace = /*#__PURE__*/_interopNamespace(externalEsmDefault);␊ ␊ - var main = {exports: {}};␊ - ␊ const foo = 'foo';␊ ␊ var named = /*#__PURE__*/Object.freeze({␊ @@ -3674,9 +3498,10 @@ Generated by [AVA](https://avajs.dev). t.deepEqual(externalNamed, { foo: 'foo' }, 'external named');␊ t.deepEqual(externalMixed, { foo: 'foo', default: 'bar' }, 'external mixed');␊ t.deepEqual(externalDefault, { default: 'bar' }, 'external default');␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -3687,8 +3512,6 @@ Generated by [AVA](https://avajs.dev). { 'main.js': `'use strict';␊ ␊ - var main = {exports: {}};␊ - ␊ var dep_false_default_ = 'default';␊ ␊ var dep_false_default_$1 = /*#__PURE__*/Object.freeze({␊ @@ -3778,9 +3601,10 @@ Generated by [AVA](https://avajs.dev). ␊ t.deepEqual(trueDefault, 'default', 'true default');␊ t.deepEqual(trueMixed, 'default', 'true mixed');␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -3791,8 +3615,6 @@ Generated by [AVA](https://avajs.dev). { 'main.js': `'use strict';␊ ␊ - var main = {exports: {}};␊ - ␊ var other = 'other.js';␊ ␊ var both = 'both.js';␊ @@ -3800,13 +3622,14 @@ Generated by [AVA](https://avajs.dev). t.deepEqual(other, 'other.js', 'other other');␊ t.deepEqual(both, 'both.js', 'other both');␊ ␊ - var main$1 = 'main.js';␊ + var main = 'main.js';␊ ␊ - t.deepEqual(main$1, 'main.js', 'main main');␊ + t.deepEqual(main, 'main.js', 'main main');␊ t.deepEqual(both, 'both.js', 'main both');␊ - var main$2 = main.exports;␊ ␊ - module.exports = main$2;␊ + var main_1 = {};␊ + ␊ + module.exports = main_1;␊ `, } @@ -3847,8 +3670,6 @@ Generated by [AVA](https://avajs.dev). var externalMixed__default = /*#__PURE__*/_interopDefaultLegacy(externalMixed);␊ var externalEsmDefault__namespace = /*#__PURE__*/_interopNamespace(externalEsmDefault);␊ ␊ - var main = {exports: {}};␊ - ␊ function getDefaultExportFromNamespaceIfNotNamed (n) {␊ return n && Object.prototype.hasOwnProperty.call(n, 'default') && Object.keys(n).length === 1 ? n['default'] : n;␊ }␊ @@ -3875,9 +3696,10 @@ Generated by [AVA](https://avajs.dev). t.deepEqual(externalNamed, { foo: 'foo' }, 'named');␊ t.deepEqual(externalMixed__default['default'], 'bar', 'mixed');␊ t.deepEqual(externalDefault, { default: 'bar' }, 'default');␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -3916,8 +3738,6 @@ Generated by [AVA](https://avajs.dev). var externalEsmMixed__namespace = /*#__PURE__*/_interopNamespace(externalEsmMixed);␊ var externalEsmDefault__namespace = /*#__PURE__*/_interopNamespace(externalEsmDefault);␊ ␊ - var main = {exports: {}};␊ - ␊ const foo = 'foo';␊ ␊ var named = /*#__PURE__*/Object.freeze({␊ @@ -3952,9 +3772,10 @@ Generated by [AVA](https://avajs.dev). t.deepEqual(externalEsmNamed__namespace, { foo: 'foo' }, 'external named');␊ t.deepEqual(externalEsmMixed__namespace, { foo: 'foo', default: 'bar' }, 'external mixed');␊ t.deepEqual(externalEsmDefault__namespace, { default: 'bar' }, 'external default');␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -3993,8 +3814,6 @@ Generated by [AVA](https://avajs.dev). var externalEsmMixed__namespace = /*#__PURE__*/_interopNamespace(externalEsmMixed);␊ var externalEsmDefault__namespace = /*#__PURE__*/_interopNamespace(externalEsmDefault);␊ ␊ - var main = {exports: {}};␊ - ␊ const foo = 'foo';␊ ␊ var named = /*#__PURE__*/Object.freeze({␊ @@ -4027,9 +3846,10 @@ Generated by [AVA](https://avajs.dev). t.deepEqual(externalNamed, { foo: 'foo' }, 'external named');␊ t.deepEqual(externalMixed, 'bar', 'external mixed');␊ t.deepEqual(externalDefault, 'bar', 'external default');␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -4050,8 +3870,6 @@ Generated by [AVA](https://avajs.dev). var externalMixed__default = /*#__PURE__*/_interopDefaultLegacy(externalMixed);␊ var externalDefault__default = /*#__PURE__*/_interopDefaultLegacy(externalDefault);␊ ␊ - var main = {exports: {}};␊ - ␊ var mixedExports = 'bar';␊ ␊ var defaultExport = 'bar';␊ @@ -4061,9 +3879,10 @@ Generated by [AVA](https://avajs.dev). t.deepEqual(externalNamed__default['default'], { foo: 'foo' }, 'external named');␊ t.deepEqual(externalMixed__default['default'], 'bar', 'external mixed');␊ t.deepEqual(externalDefault__default['default'], 'bar', 'external default');␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -4102,8 +3921,6 @@ Generated by [AVA](https://avajs.dev). var externalEsmMixed__namespace = /*#__PURE__*/_interopNamespace(externalEsmMixed);␊ var externalEsmDefault__namespace = /*#__PURE__*/_interopNamespace(externalEsmDefault);␊ ␊ - var main = {exports: {}};␊ - ␊ const foo = 'foo';␊ ␊ var named = /*#__PURE__*/Object.freeze({␊ @@ -4167,9 +3984,10 @@ Generated by [AVA](https://avajs.dev). t.deepEqual(externalNamed, { foo: 'foo' }, 'external named');␊ t.deepEqual(externalMixed, { foo: 'foo', default: 'bar' }, 'external mixed');␊ t.deepEqual(externalDefault, { default: 'bar' }, 'external default');␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -4180,8 +3998,6 @@ Generated by [AVA](https://avajs.dev). { 'main.js': `'use strict';␊ ␊ - var main = {exports: {}};␊ - ␊ /* eslint-disable import/no-mutable-exports */␊ let foo = 'foo';␊ let bar = 'bar';␊ @@ -4228,9 +4044,10 @@ Generated by [AVA](https://avajs.dev). lib$1.update('newFoo', 'newBar');␊ t.is(lib__default['default'], 'newFoo');␊ t.is(lib$1.bar, 'newBar');␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -4241,16 +4058,13 @@ Generated by [AVA](https://avajs.dev). { 'main.js': `'use strict';␊ ␊ - var main = {exports: {}};␊ + var foo = 42;␊ ␊ - var foo = {exports: {}};␊ + t.is(foo, 42);␊ ␊ - foo.exports = 42;␊ + var main = {};␊ ␊ - t.is(foo.exports, 42);␊ - var main$1 = main.exports;␊ - ␊ - module.exports = main$1;␊ + module.exports = main;␊ `, } @@ -4261,26 +4075,19 @@ Generated by [AVA](https://avajs.dev). { 'main.js': `'use strict';␊ ␊ - var main = {exports: {}};␊ - ␊ - var multiply = {exports: {}};␊ - ␊ - multiply.exports = function(a, b) {␊ + var multiply = function(a, b) {␊ return a * b;␊ };␊ ␊ - var foo = {exports: {}};␊ - ␊ - foo.exports = 1;␊ + var foo = 1;␊ ␊ /* eslint-disable global-require */␊ ␊ - main.exports = function() {␊ - return multiply.exports(2, foo.exports);␊ + var main = function() {␊ + return multiply(2, foo);␊ };␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + module.exports = main;␊ `, } @@ -4360,32 +4167,19 @@ Generated by [AVA](https://avajs.dev). { 'main.js': `'use strict';␊ ␊ - var other = require('./other2.js');␊ + var other = require('./other.js');␊ ␊ - var main = {exports: {}};␊ + t.is(other, 'foo');␊ ␊ - t.is(other.other.exports, 'foo');␊ - var main$1 = main.exports;␊ + var main = {};␊ ␊ - module.exports = main$1;␊ + module.exports = main;␊ `, 'other.js': `'use strict';␊ ␊ - var other = require('./other2.js');␊ - ␊ - ␊ + var other = 'foo';␊ ␊ - module.exports = other.other$1;␊ - `, - 'other2.js': `'use strict';␊ - ␊ - var other = {exports: {}};␊ - ␊ - other.exports = 'foo';␊ - var other$1 = other.exports;␊ - ␊ - exports.other = other;␊ - exports.other$1 = other$1;␊ + module.exports = other;␊ `, } @@ -4396,16 +4190,13 @@ Generated by [AVA](https://avajs.dev). { 'main.js': `'use strict';␊ ␊ - var main = {exports: {}};␊ - ␊ /*␊ * This comment could be really important and should not be removed␊ */␊ ␊ - main.exports = 'bar';␊ - var main$1 = main.exports;␊ + var main = 'bar';␊ ␊ - module.exports = main$1;␊ + module.exports = main;␊ `, } @@ -4422,8 +4213,6 @@ Generated by [AVA](https://avajs.dev). ␊ var externalExports__default = /*#__PURE__*/_interopDefaultLegacy(externalExports);␊ ␊ - var main = {exports: {}};␊ - ␊ /*␊ * This comment could be really important and should not be removed␊ */␊ @@ -4431,9 +4220,10 @@ Generated by [AVA](https://avajs.dev). ␊ ␊ t.is(externalExports__default['default'].foo, 'foo');␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -4472,16 +4262,11 @@ Generated by [AVA](https://avajs.dev). { 'main.js': `'use strict';␊ ␊ - var main = {exports: {}};␊ - ␊ - var foo = {exports: {}};␊ + var foo = 21;␊ ␊ - foo.exports = 21;␊ + var main = foo * 2;␊ ␊ - main.exports = foo.exports * 2;␊ - var main$1 = main.exports;␊ - ␊ - module.exports = main$1;␊ + module.exports = main;␊ `, } @@ -4593,16 +4378,14 @@ Generated by [AVA](https://avajs.dev). { 'main.js': `'use strict';␊ ␊ - var reexport = {exports: {}};␊ - ␊ var _export = {exports: {}};␊ ␊ var named = 2;␊ _export.exports.named = named;␊ ␊ - reexport.exports = _export.exports;␊ + var reexport = _export.exports;␊ ␊ - t.is(reexport.exports.named, 2);␊ + t.is(reexport.named, 2);␊ `, } @@ -4698,16 +4481,13 @@ Generated by [AVA](https://avajs.dev). { 'main.js': `'use strict';␊ ␊ - var main = {exports: {}};␊ - ␊ - var dep = {exports: {}};␊ + var dep = 42;␊ ␊ - dep.exports = 42;␊ + t.is(dep, 42);␊ ␊ - t.is(dep.exports, 42);␊ - var main$1 = main.exports;␊ + var main = {};␊ ␊ - module.exports = main$1;␊ + module.exports = main;␊ `, } @@ -4718,25 +4498,20 @@ Generated by [AVA](https://avajs.dev). { 'main.js': `'use strict';␊ ␊ - var main = {exports: {}};␊ - ␊ - var shared = {exports: {}};␊ - ␊ - shared.exports = {␊ + var shared = {␊ fooLoaded: false␊ };␊ ␊ // Mutate the shared module␊ - shared.exports.fooLoaded = true;␊ + shared.fooLoaded = true;␊ ␊ - var bar = {exports: {}};␊ + var bar = shared.fooLoaded;␊ ␊ - bar.exports = shared.exports.fooLoaded;␊ + t.truthy(bar);␊ ␊ - t.truthy(bar.exports);␊ - var main$1 = main.exports;␊ + var main = {};␊ ␊ - module.exports = main$1;␊ + module.exports = main;␊ `, } @@ -4757,11 +4532,9 @@ Generated by [AVA](https://avajs.dev). ␊ var requiring = {exports: {}};␊ ␊ - var fooRequired = {exports: {}};␊ + var fooRequired = 'required';␊ ␊ - fooRequired.exports = 'required';␊ - ␊ - var foo$1 = fooRequired.exports;␊ + var foo$1 = fooRequired;␊ requiring.exports.foo = foo$1;␊ ␊ var barPromise = Promise.resolve().then(function () { return require('./bar-imported-49e0dbcf.js'); });␊ @@ -4810,26 +4583,23 @@ Generated by [AVA](https://avajs.dev). { 'main.js': `'use strict';␊ ␊ - var main = {exports: {}};␊ + function foo() {}␊ + foo.something = false;␊ ␊ - var foo = {exports: {}};␊ - ␊ - function foo$1() {}␊ - foo$1.something = false;␊ + var foo_1 = foo;␊ ␊ - foo.exports = foo$1;␊ + let foo$1 = foo_1;␊ ␊ - let foo$2 = foo.exports;␊ - ␊ - if (!foo$2.something) {␊ - foo$2 = function somethingElse() {};␊ - foo$2.something = true;␊ + if (!foo$1.something) {␊ + foo$1 = function somethingElse() {};␊ + foo$1.something = true;␊ }␊ ␊ - t.truthy(foo$2.something);␊ - var main$1 = main.exports;␊ + t.truthy(foo$1.something);␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -4840,8 +4610,6 @@ Generated by [AVA](https://avajs.dev). { 'main.js': `'use strict';␊ ␊ - var main = {exports: {}};␊ - ␊ const foo = 'foo';␊ var other = 'bar';␊ ␊ @@ -4860,9 +4628,10 @@ Generated by [AVA](https://avajs.dev). });␊ ␊ t.deepEqual(dep$1, { default: 'default', ns: { default: 'bar', foo: 'foo' } });␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -4873,8 +4642,6 @@ Generated by [AVA](https://avajs.dev). { 'main.js': `'use strict';␊ ␊ - var main = {exports: {}};␊ - ␊ const foo = 'foo';␊ ␊ var dep = 'default';␊ @@ -4886,9 +4653,10 @@ Generated by [AVA](https://avajs.dev). });␊ ␊ t.deepEqual(dep$1, { default: 'default', foo: 'foo' });␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -4899,8 +4667,6 @@ Generated by [AVA](https://avajs.dev). { 'main.js': `'use strict';␊ ␊ - var main = {exports: {}};␊ - ␊ const foo = 'foo';␊ var other = 'bar';␊ ␊ @@ -4911,9 +4677,10 @@ Generated by [AVA](https://avajs.dev). });␊ ␊ t.deepEqual(other$1, { default: 'bar', foo: 'foo' });␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -4924,8 +4691,6 @@ Generated by [AVA](https://avajs.dev). { 'main.js': `'use strict';␊ ␊ - var main = {exports: {}};␊ - ␊ const foo = 'foo';␊ ␊ var dep = /*#__PURE__*/Object.freeze({␊ @@ -4934,9 +4699,10 @@ Generated by [AVA](https://avajs.dev). });␊ ␊ t.deepEqual(dep, { foo: 'foo' });␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -4947,8 +4713,6 @@ Generated by [AVA](https://avajs.dev). { 'main.js': `'use strict';␊ ␊ - var main = {exports: {}};␊ - ␊ const result = 'second';␊ ␊ var second = /*#__PURE__*/Object.freeze({␊ @@ -4974,9 +4738,10 @@ Generated by [AVA](https://avajs.dev). var require$$0 = /*@__PURE__*/getAugmentedNamespace(second);␊ ␊ t.is(require$$0.result, 'second');␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -4987,8 +4752,6 @@ Generated by [AVA](https://avajs.dev). { 'main.js': `'use strict';␊ ␊ - var main = {exports: {}};␊ - ␊ const result = 'second';␊ ␊ var second = /*#__PURE__*/Object.freeze({␊ @@ -5014,9 +4777,10 @@ Generated by [AVA](https://avajs.dev). var require$$0 = /*@__PURE__*/getAugmentedNamespace(second);␊ ␊ t.is(require$$0.result, 'second');␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -5027,13 +4791,9 @@ Generated by [AVA](https://avajs.dev). { 'main.js': `'use strict';␊ ␊ - var main = {exports: {}};␊ - ␊ - var foo = {exports: {}};␊ - ␊ - foo.exports = 'foo';␊ + var foo = 'foo';␊ ␊ - const foo$1 = foo.exports;␊ + const foo$1 = foo;␊ ␊ t.is(foo$1, 'foo');␊ ␊ @@ -5041,13 +4801,14 @@ Generated by [AVA](https://avajs.dev). // eslint-disable-next-line no-shadow␊ const foo$1 = 'wrong';␊ // eslint-disable-next-line global-require␊ - const bar = foo.exports;␊ + const bar = foo;␊ t.is(foo$1, 'wrong');␊ t.is(bar, 'foo');␊ }␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -5079,21 +4840,16 @@ Generated by [AVA](https://avajs.dev). { 'main.js': `'use strict';␊ ␊ - var main = {exports: {}};␊ - ␊ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ - var b = {exports: {}};␊ - ␊ commonjsGlobal.b = 2;␊ - b.exports = 'b';␊ + var b = 'b';␊ ␊ /* eslint-disable */␊ ␊ - main.exports = b.exports ;␊ - var main$1 = main.exports;␊ + var main = b ;␊ ␊ - module.exports = main$1;␊ + module.exports = main;␊ `, } @@ -5106,24 +4862,21 @@ Generated by [AVA](https://avajs.dev). ␊ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ - var main = {exports: {}};␊ - ␊ - var foo = {exports: {}};␊ - ␊ - foo.exports = function augmentThis() {␊ + var foo = function augmentThis() {␊ this.x = 'x';␊ };␊ ␊ commonjsGlobal.y = 'y';␊ ␊ const obj = {};␊ - foo.exports.call(obj);␊ + foo.call(obj);␊ ␊ t.is(obj.x, 'x');␊ t.is(commonjsGlobal.y, 'y');␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -5134,14 +4887,11 @@ Generated by [AVA](https://avajs.dev). { 'main.js': `'use strict';␊ ␊ - var main = {exports: {}};␊ - ␊ /* eslint-disable */␊ ␊ - main.exports = 'foo';␊ - var main$1 = main.exports;␊ + var main = 'foo';␊ ␊ - module.exports = main$1;␊ + module.exports = main;␊ `, } @@ -5152,28 +4902,18 @@ Generated by [AVA](https://avajs.dev). { 'main.js': `'use strict';␊ ␊ - var main = {exports: {}};␊ - ␊ var foo = {exports: {}};␊ ␊ - var bar = {exports: {}};␊ - ␊ - bar.exports = function() {␊ - return true;␊ - };␊ - ␊ (function (module) {␊ module.exports = 'bar';␊ - if (bar.exports()) {␊ + {␊ return;␊ }␊ - module.exports = 'foo';␊ }(foo));␊ ␊ - main.exports = foo.exports;␊ - var main$1 = main.exports;␊ + var main = foo.exports;␊ ␊ - module.exports = main$1;␊ + module.exports = main;␊ `, } @@ -5184,16 +4924,13 @@ Generated by [AVA](https://avajs.dev). { 'main.js': `'use strict';␊ ␊ - var main = {exports: {}};␊ - ␊ - var foo = {exports: {}};␊ + var foo = 42;␊ ␊ - foo.exports = 42;␊ + t.is(foo, 42);␊ ␊ - t.is(foo.exports, 42);␊ - var main$1 = main.exports;␊ + var main = {};␊ ␊ - module.exports = main$1;␊ + module.exports = main;␊ `, } @@ -5204,13 +4941,11 @@ Generated by [AVA](https://avajs.dev). { 'main.js': `'use strict';␊ ␊ - var other = {exports: {}};␊ - ␊ - other.exports = 'other';␊ + var other = 'other';␊ ␊ var dep = /*#__PURE__*/Object.freeze({␊ __proto__: null,␊ - other: other.exports␊ + other: other␊ });␊ ␊ function getAugmentedNamespace(n) {␊ @@ -5230,7 +4965,7 @@ Generated by [AVA](https://avajs.dev). ␊ var dep$1 = /*@__PURE__*/getAugmentedNamespace(dep);␊ ␊ - t.is(other.exports, 'other');␊ + t.is(other, 'other');␊ t.deepEqual(dep$1, { other: 'other' });␊ `, } @@ -5631,8 +5366,6 @@ Generated by [AVA](https://avajs.dev). { 'main.js': `'use strict';␊ ␊ - var main = {exports: {}};␊ - ␊ var dep = {exports: {}};␊ ␊ Object.defineProperty(dep.exports, '__esModule', { value: true });␊ @@ -5648,9 +5381,10 @@ Generated by [AVA](https://avajs.dev). ␊ // eslint-disable-next-line no-prototype-builtins␊ t.is(dep.exports.hasOwnProperty('named'), true);␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -5661,8 +5395,6 @@ Generated by [AVA](https://avajs.dev). { 'main.js': `'use strict';␊ ␊ - var main = {exports: {}};␊ - ␊ var dep = {exports: {}};␊ ␊ Object.defineProperty(dep.exports, '__esModule', { value: true });␊ @@ -5676,9 +5408,10 @@ Generated by [AVA](https://avajs.dev). t.is(dep.exports.__esModule, true);␊ const dep__default = /* #__PURE__*/ _interopDefault$1(dep.exports);␊ t.is(dep__default.default, 'default');␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -5747,12 +5480,11 @@ Generated by [AVA](https://avajs.dev). ␊ var path__default = /*#__PURE__*/_interopDefaultLegacy(path);␊ ␊ - var main = {exports: {}};␊ - ␊ t.is(typeof path__default['default'].resolve, 'function');␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ `, } @@ -5767,8 +5499,6 @@ Generated by [AVA](https://avajs.dev). throw new Error('Could not dynamically require "' + target + '". Please configure the dynamicRequireTargets option of @rollup/plugin-commonjs appropriately for this require call to behave properly.');␊ }␊ ␊ - var main = {exports: {}};␊ - ␊ // eslint-disable-next-line global-require,import/no-dynamic-require␊ t.throws(() => commonjsRequire(getRequireTarget()), {␊ message:␊ @@ -5778,8 +5508,26 @@ Generated by [AVA](https://avajs.dev). function getRequireTarget() {␊ return 'foo-bar';␊ }␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ + `, + } + +## aaa + +> Snapshot 1 + + { + 'main.js': `'use strict';␊ + ␊ + var dep = {exports: {}};␊ + ␊ + dep.exports = {};␊ + var foo = 'x';␊ + dep.exports.foo = foo;␊ + ␊ + t.is(dep.exports.x, 'foo');␊ `, } diff --git a/packages/commonjs/test/snapshots/function.js.snap b/packages/commonjs/test/snapshots/function.js.snap index 40c5e2cf4..7a94248ac 100644 Binary files a/packages/commonjs/test/snapshots/function.js.snap and b/packages/commonjs/test/snapshots/function.js.snap differ diff --git a/packages/commonjs/test/snapshots/test.js.md b/packages/commonjs/test/snapshots/test.js.md index b6263c52d..73d3daa46 100644 --- a/packages/commonjs/test/snapshots/test.js.md +++ b/packages/commonjs/test/snapshots/test.js.md @@ -10,19 +10,16 @@ Generated by [AVA](https://avajs.dev). `'use strict';␊ ␊ - var main = {exports: {}};␊ - ␊ const obj = {␊ a: 'b',␊ b: 'c'␊ };␊ ␊ - main.exports = {␊ + var main = {␊ ...obj␊ };␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + module.exports = main;␊ ` ## handles array destructuring assignment @@ -58,20 +55,17 @@ Generated by [AVA](https://avajs.dev). `'use strict';␊ ␊ - var main = {exports: {}};␊ - ␊ - var _export = {exports: {}};␊ - ␊ - _export.exports = {␊ + var _export = {␊ test: 42␊ };␊ ␊ - const { test } = _export.exports;␊ + const { test } = _export;␊ ␊ console.log(test);␊ - var main$1 = main.exports;␊ ␊ - module.exports = main$1;␊ + var main = {};␊ + ␊ + module.exports = main;␊ ` ## produces optimized code when importing esm with a known default export @@ -80,14 +74,11 @@ Generated by [AVA](https://avajs.dev). `'use strict';␊ ␊ - var main = {exports: {}};␊ - ␊ var require$$0 = "default";␊ ␊ - main.exports = require$$0;␊ - var main$1 = main.exports;␊ + var main = require$$0;␊ ␊ - module.exports = main$1;␊ + module.exports = main;␊ ` ## produces optimized code when importing esm without a default export @@ -96,8 +87,6 @@ Generated by [AVA](https://avajs.dev). `'use strict';␊ ␊ - var main = {exports: {}};␊ - ␊ const value = "value";␊ ␊ var esm = /*#__PURE__*/Object.freeze({␊ @@ -122,8 +111,7 @@ Generated by [AVA](https://avajs.dev). ␊ var require$$0 = /*@__PURE__*/getAugmentedNamespace(esm);␊ ␊ - main.exports = require$$0;␊ - var main$1 = main.exports;␊ + var main = require$$0;␊ ␊ - module.exports = main$1;␊ + module.exports = main;␊ ` diff --git a/packages/commonjs/test/snapshots/test.js.snap b/packages/commonjs/test/snapshots/test.js.snap index dac7a0b56..4816a5d25 100644 Binary files a/packages/commonjs/test/snapshots/test.js.snap and b/packages/commonjs/test/snapshots/test.js.snap differ