Skip to content

Commit

Permalink
Handle generating non-inlined imports after inlined ones
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jul 27, 2022
1 parent 3be1609 commit 2d76951
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 18 deletions.
5 changes: 1 addition & 4 deletions .eslintrc.js
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
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
@@ -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 })]
};
@@ -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
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' });
});
});
12 changes: 6 additions & 6 deletions test/typescript/index.ts
Expand Up @@ -32,24 +32,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 2d76951

Please sign in to comment.