diff --git a/src/rules/dynamic-import-chunkname.js b/src/rules/dynamic-import-chunkname.js index 2ad03bf30e..93e1bd5e09 100644 --- a/src/rules/dynamic-import-chunkname.js +++ b/src/rules/dynamic-import-chunkname.js @@ -103,6 +103,14 @@ module.exports = { } } + if (isChunknamePresent && isEagerModePresent) { + context.report({ + node, + message: + `dynamic imports should not have both webpackChunkName and webpackMode: "eager"`, + }); + } + if (!isChunknamePresent && !allowEmpty && !isEagerModePresent) { context.report({ node, diff --git a/tests/src/rules/dynamic-import-chunkname.js b/tests/src/rules/dynamic-import-chunkname.js index 65467f45e7..8995d7ff8b 100644 --- a/tests/src/rules/dynamic-import-chunkname.js +++ b/tests/src/rules/dynamic-import-chunkname.js @@ -28,6 +28,7 @@ const invalidSyntaxCommentError = 'dynamic imports require a "webpack" comment w const commentFormatError = `dynamic imports require a "webpack" comment with valid syntax`; const chunkNameFormatError = `dynamic imports require a leading comment in the form /* webpackChunkName: ["']${commentFormat}["'],? */`; const pickyChunkNameFormatError = `dynamic imports require a leading comment in the form /* webpackChunkName: ["']${pickyCommentFormat}["'],? */`; +const eagerModeError = `dynamic imports should not have both webpackChunkName and webpackMode: "eager"`; ruleTester.run('dynamic-import-chunkname', rule, { valid: [ @@ -352,15 +353,6 @@ ruleTester.run('dynamic-import-chunkname', rule, { options, parser, }, - { - code: `import( - /* webpackChunkName: "someModule" */ - /* webpackMode: "eager" */ - 'someModule' - )`, - options, - parser, - }, { code: `import( /* webpackChunkName: "someModule" */ @@ -412,7 +404,7 @@ ruleTester.run('dynamic-import-chunkname', rule, { /* webpackPrefetch: true */ /* webpackPreload: true */ /* webpackIgnore: false */ - /* webpackMode: "eager" */ + /* webpackMode: "lazy" */ /* webpackExports: ["default", "named"] */ 'someModule' )`, @@ -989,6 +981,24 @@ ruleTester.run('dynamic-import-chunkname', rule, { type: 'CallExpression', }], }, + { + code: `import( + /* webpackChunkName: "someModule" */ + /* webpackMode: "eager" */ + 'someModule' + )`, + options, + parser, + output: `import( + /* webpackChunkName: "someModule" */ + /* webpackMode: "eager" */ + 'someModule' + )`, + errors: [{ + message: eagerModeError, + type: 'CallExpression', + }], + }, ], }); @@ -1247,15 +1257,6 @@ context('TypeScript', () => { options, parser: typescriptParser, }, - { - code: `import( - /* webpackChunkName: "someModule" */ - /* webpackMode: "eager" */ - 'someModule' - )`, - options, - parser: typescriptParser, - }, { code: `import( /* webpackChunkName: "someModule" */ @@ -1307,13 +1308,21 @@ context('TypeScript', () => { /* webpackPrefetch: true */ /* webpackPreload: true */ /* webpackIgnore: false */ - /* webpackMode: "eager" */ + /* webpackMode: "lazy" */ /* webpackExports: ["default", "named"] */ 'someModule' )`, options, parser: typescriptParser, }, + { + code: `import( + /* webpackMode: 'eager' */ + 'someModule' + )`, + options, + parser: typescriptParser, + }, ], invalid: [ { @@ -1760,6 +1769,24 @@ context('TypeScript', () => { type: nodeType, }], }, + { + code: `import( + /* webpackChunkName: "someModule" */ + /* webpackMode: "eager" */ + 'someModule' + )`, + options, + parser: typescriptParser, + output: `import( + /* webpackChunkName: "someModule" */ + /* webpackMode: "eager" */ + 'someModule' + )`, + errors: [{ + message: eagerModeError, + type: nodeType, + }], + }, ], }); });