Skip to content

Commit

Permalink
Handle generating non-inlined imports after inlined ones (#4589)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert authored Jul 27, 2022
1 parent 3be1609 commit 3abd545
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 18 deletions.
5 changes: 1 addition & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
],
Expand Down
1 change: 1 addition & 0 deletions src/ast/nodes/ImportExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export default class ImportExpression extends NodeBase {
accessedGlobalsByScope: Map<ChildScope, Set<string>>
): void {
const { format } = options;
this.inlineNamespace = null;
this.resolution = resolution;
const accessedGlobals = [...(accessedImportGlobals[format] || [])];
let helper: string | null;
Expand Down
6 changes: 2 additions & 4 deletions test/cli/node_modules_rename_me/bar/lib/config.js
Original file line number Diff line number Diff line change
@@ -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 })]
};
Original file line number Diff line number Diff line change
@@ -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 })]
};
14 changes: 14 additions & 0 deletions test/misc/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
});
});
13 changes: 7 additions & 6 deletions test/typescript/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint-disable-next-line import/no-unresolved
import * as rollup from './dist/rollup';

// Plugin API
Expand Down Expand Up @@ -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: ''
}
Expand Down

0 comments on commit 3abd545

Please sign in to comment.