From c4355bf1c23649a009a4db089c1172a8cf09464a Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Wed, 27 Jul 2022 06:08:53 +0200 Subject: [PATCH] Handle generating non-inlined imports after inlined ones --- .eslintrc.js | 5 +---- src/ast/nodes/ImportExpression.ts | 1 + test/cli/node_modules_rename_me/bar/lib/config.js | 6 ++---- .../rollup-config-foo/lib/config.js | 6 ++---- test/misc/misc.js | 14 ++++++++++++++ test/typescript/index.ts | 13 +++++++------ 6 files changed, 27 insertions(+), 18 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 6061d199bdd..67153a21346 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -15,11 +15,8 @@ module.exports = { ignorePatterns: [ 'node_modules', 'dist', - '/test', 'perf', - '!/test/*.js', - '!/test/*/*.js', - '/test/node_modules', + '/test/*/samples/**/*.*', '!/test/*/samples/**/_config.js', '!/test/*/samples/**/rollup.config.js' ], diff --git a/src/ast/nodes/ImportExpression.ts b/src/ast/nodes/ImportExpression.ts index 6f9d8ae4e05..8f9121ea603 100644 --- a/src/ast/nodes/ImportExpression.ts +++ b/src/ast/nodes/ImportExpression.ts @@ -102,6 +102,7 @@ export default class ImportExpression extends NodeBase { accessedGlobalsByScope: Map> ): void { const { format } = options; + this.inlineNamespace = null; this.resolution = resolution; const accessedGlobals = [...(accessedImportGlobals[format] || [])]; let helper: string | null; diff --git a/test/cli/node_modules_rename_me/bar/lib/config.js b/test/cli/node_modules_rename_me/bar/lib/config.js index 96c8860be97..1fe16463eb7 100644 --- a/test/cli/node_modules_rename_me/bar/lib/config.js +++ b/test/cli/node_modules_rename_me/bar/lib/config.js @@ -1,11 +1,9 @@ -const replace = require( '@rollup/plugin-replace' ); +const replace = require('@rollup/plugin-replace'); module.exports = { input: 'main.js', output: { format: 'cjs' }, - plugins: [ - replace( { preventAssignment: true, ANSWER: 42 } ) - ] + plugins: [replace({ preventAssignment: true, ANSWER: 42 })] }; diff --git a/test/cli/node_modules_rename_me/rollup-config-foo/lib/config.js b/test/cli/node_modules_rename_me/rollup-config-foo/lib/config.js index 96c8860be97..1fe16463eb7 100644 --- a/test/cli/node_modules_rename_me/rollup-config-foo/lib/config.js +++ b/test/cli/node_modules_rename_me/rollup-config-foo/lib/config.js @@ -1,11 +1,9 @@ -const replace = require( '@rollup/plugin-replace' ); +const replace = require('@rollup/plugin-replace'); module.exports = { input: 'main.js', output: { format: 'cjs' }, - plugins: [ - replace( { preventAssignment: true, ANSWER: 42 } ) - ] + plugins: [replace({ preventAssignment: true, ANSWER: 42 })] }; diff --git a/test/misc/misc.js b/test/misc/misc.js index 76132722719..6f2f27dae36 100644 --- a/test/misc/misc.js +++ b/test/misc/misc.js @@ -274,4 +274,18 @@ console.log(x); assert.strictEqual(err.name, 'Error'); } }); + + it('supports rendering es after rendering iife with inlined dynamic imports', async () => { + const bundle = await rollup.rollup({ + input: 'main.js', + plugins: [ + loader({ + 'main.js': "import('other.js');", + 'other.js': "export const foo = 'bar';" + }) + ] + }); + const first = await bundle.generate({ format: 'iife', inlineDynamicImports: true }); + const second = await bundle.generate({ format: 'es', exports: 'auto' }); + }); }); diff --git a/test/typescript/index.ts b/test/typescript/index.ts index c89d4408f54..a8b838b388e 100644 --- a/test/typescript/index.ts +++ b/test/typescript/index.ts @@ -1,3 +1,4 @@ +// eslint-disable-next-line import/no-unresolved import * as rollup from './dist/rollup'; // Plugin API @@ -32,24 +33,24 @@ const amdOutputOptions: rollup.OutputOptions['amd'][] = [ autoId: false }, { - // @ts-expect-error + // @ts-expect-error for "basePath", "autoId" needs to be true autoId: false, basePath: '', - // @ts-expect-error + // @ts-expect-error cannot combine "id" and "basePath" id: 'a' }, { - // @ts-expect-error + // @ts-expect-error cannot combine "id" and "autoId" autoId: true, - // @ts-expect-error + // @ts-expect-error cannot combine "id" and "autoId" id: 'a' }, { basePath: '', - // @ts-expect-error + // @ts-expect-error cannot combine "id" and "basePath" id: 'a' }, - // @ts-expect-error + // @ts-expect-error needs "autoId" for "basePath" { basePath: '' }