From 404f48253272fdfe552e0e60e59f5c24c474137a Mon Sep 17 00:00:00 2001 From: Max Burmagin Date: Sat, 18 Dec 2021 17:59:22 +0300 Subject: [PATCH 1/2] [Tests] `dynamic-import-chunkname`: remove unused "errors" from valid tests --- tests/src/rules/dynamic-import-chunkname.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tests/src/rules/dynamic-import-chunkname.js b/tests/src/rules/dynamic-import-chunkname.js index 7e482cf03..2731084f0 100644 --- a/tests/src/rules/dynamic-import-chunkname.js +++ b/tests/src/rules/dynamic-import-chunkname.js @@ -53,10 +53,6 @@ ruleTester.run('dynamic-import-chunkname', rule, { 'someModule' )`, options: pickyCommentOptions, - errors: [{ - message: pickyCommentFormatError, - type: 'CallExpression', - }], }, { code: `import( @@ -147,10 +143,6 @@ ruleTester.run('dynamic-import-chunkname', rule, { )`, options: pickyCommentOptions, parser, - errors: [{ - message: pickyCommentFormatError, - type: 'CallExpression', - }], }, ...SYNTAX_CASES, ], From 47b529e0ac127f8e203bbb2d3f46d821cf43341e Mon Sep 17 00:00:00 2001 From: Max Burmagin Date: Sat, 18 Dec 2021 17:59:22 +0300 Subject: [PATCH 2/2] [Fix] `dynamic-import-chunkname`: add handling webpack magic comments --- CHANGELOG.md | 3 + src/rules/dynamic-import-chunkname.js | 6 +- tests/src/rules/dynamic-import-chunkname.js | 1017 ++++++++++++++++++- 3 files changed, 971 insertions(+), 55 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27c59ac03..5f9cfc0a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange - [`order`]: require with member expression could not be fixed if alphabetize.order was used ([#2490], thanks [@msvab]) - [`order`]: leave more space in rankings for consecutive path groups ([#2506], thanks [@Pearce-Ropion]) - [`no-cycle`]: add ExportNamedDeclaration statements to dependencies ([#2511], thanks [@BenoitZugmeyer]) +- [`dynamic-import-chunkname`]: prevent false report on a valid webpack magic comment ([#2330], thanks [@mhmadhamster]) ### Changed - [Tests] `named`: Run all TypeScript test ([#2427], thanks [@ProdigySim]) @@ -1027,6 +1028,7 @@ for info on changes for earlier releases. [#2358]: https://github.com/import-js/eslint-plugin-import/pull/2358 [#2341]: https://github.com/import-js/eslint-plugin-import/pull/2341 [#2334]: https://github.com/import-js/eslint-plugin-import/pull/2334 +[#2330]: https://github.com/import-js/eslint-plugin-import/pull/2330 [#2305]: https://github.com/import-js/eslint-plugin-import/pull/2305 [#2299]: https://github.com/import-js/eslint-plugin-import/pull/2299 [#2297]: https://github.com/import-js/eslint-plugin-import/pull/2297 @@ -1652,6 +1654,7 @@ for info on changes for earlier releases. [@maxkomarychev]: https://github.com/maxkomarychev [@maxmalov]: https://github.com/maxmalov [@mgwalker]: https://github.com/mgwalker +[@mhmadhamster]: https://github.com/MhMadHamster [@MikeyBeLike]: https://github.com/MikeyBeLike [@mplewis]: https://github.com/mplewis [@mrmckeb]: https://github.com/mrmckeb diff --git a/src/rules/dynamic-import-chunkname.js b/src/rules/dynamic-import-chunkname.js index 859e9fea4..2c59d35e5 100644 --- a/src/rules/dynamic-import-chunkname.js +++ b/src/rules/dynamic-import-chunkname.js @@ -27,10 +27,10 @@ module.exports = { create(context) { const config = context.options[0]; const { importFunctions = [] } = config || {}; - const { webpackChunknameFormat = '[0-9a-zA-Z-_/.]+' } = config || {}; + const { webpackChunknameFormat = '([0-9a-zA-Z-_/.]|\\[(request|index)\\])+' } = config || {}; const paddedCommentRegex = /^ (\S[\s\S]+\S) $/; - const commentStyleRegex = /^( \w+: (["'][^"']*["']|\d+|false|true),?)+ $/; + const commentStyleRegex = /^( ((webpackChunkName: .+)|((webpackPrefetch|webpackPreload): (true|false|-?[0-9]+))|(webpackIgnore: (true|false))|((webpackInclude|webpackExclude): \/.*\/)|(webpackMode: ["'](lazy|lazy-once|eager|weak)["'])|(webpackExports: (['"]\w+['"]|\[(['"]\w+['"], *)+(['"]\w+['"]*)\]))),?)+ $/; const chunkSubstrFormat = ` webpackChunkName: ["']${webpackChunknameFormat}["'],? `; const chunkSubstrRegex = new RegExp(chunkSubstrFormat); @@ -83,7 +83,7 @@ module.exports = { context.report({ node, message: - `dynamic imports require a leading comment in the form /*${chunkSubstrFormat}*/`, + `dynamic imports require a "webpack" comment with valid syntax`, }); return; } diff --git a/tests/src/rules/dynamic-import-chunkname.js b/tests/src/rules/dynamic-import-chunkname.js index 2731084f0..46a1b97af 100644 --- a/tests/src/rules/dynamic-import-chunkname.js +++ b/tests/src/rules/dynamic-import-chunkname.js @@ -5,7 +5,7 @@ import semver from 'semver'; const rule = require('rules/dynamic-import-chunkname'); const ruleTester = new RuleTester(); -const commentFormat = '[0-9a-zA-Z-_/.]+'; +const commentFormat = '([0-9a-zA-Z-_/.]|\\[(request|index)\\])+'; const pickyCommentFormat = '[a-zA-Z-_/.]+'; const options = [{ importFunctions: ['dynamicImport'] }]; const pickyCommentOptions = [{ @@ -21,8 +21,9 @@ const noLeadingCommentError = 'dynamic imports require a leading comment with th const nonBlockCommentError = 'dynamic imports require a /* foo */ style comment, not a // foo comment'; const noPaddingCommentError = 'dynamic imports require a block comment padded with spaces - /* foo */'; const invalidSyntaxCommentError = 'dynamic imports require a "webpack" comment with valid syntax'; -const commentFormatError = `dynamic imports require a leading comment in the form /* webpackChunkName: ["']${commentFormat}["'],? */`; -const pickyCommentFormatError = `dynamic imports require a leading comment in the form /* webpackChunkName: ["']${pickyCommentFormat}["'],? */`; +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}["'],? */`; ruleTester.run('dynamic-import-chunkname', rule, { valid: [ @@ -54,6 +55,34 @@ ruleTester.run('dynamic-import-chunkname', rule, { )`, options: pickyCommentOptions, }, + { + code: `dynamicImport( + /* webpackChunkName: "[request]" */ + 'someModule' + )`, + options, + }, + { + code: `dynamicImport( + /* webpackChunkName: "my-chunk-[request]-custom" */ + 'someModule' + )`, + options, + }, + { + code: `dynamicImport( + /* webpackChunkName: '[index]' */ + 'someModule' + )`, + options, + }, + { + code: `dynamicImport( + /* webpackChunkName: 'my-chunk.[index].with-index' */ + 'someModule' + )`, + options, + }, { code: `import( /* webpackChunkName: "someModule" */ @@ -128,6 +157,24 @@ ruleTester.run('dynamic-import-chunkname', rule, { options, parser, }, + { + code: `import( + /* webpackChunkName: "someModule" */ + /* webpackPrefetch: 12 */ + 'test' + )`, + options, + parser, + }, + { + code: `import( + /* webpackChunkName: "someModule" */ + /* webpackPrefetch: -30 */ + 'test' + )`, + options, + parser, + }, { code: `import( /* webpackChunkName: 'someModule' */ @@ -144,6 +191,217 @@ ruleTester.run('dynamic-import-chunkname', rule, { options: pickyCommentOptions, parser, }, + { + code: `import( + /* webpackChunkName: "[request]" */ + 'someModule' + )`, + options, + parser, + }, + { + code: `import( + /* webpackChunkName: "my-chunk-[request]-custom" */ + 'someModule' + )`, + options, + parser, + }, + { + code: `import( + /* webpackChunkName: '[index]' */ + 'someModule' + )`, + options, + parser, + }, + { + code: `import( + /* webpackChunkName: 'my-chunk.[index].with-index' */ + 'someModule' + )`, + options, + parser, + }, + { + code: `import( + /* webpackChunkName: "someModule" */ + /* webpackInclude: /\\.json$/ */ + 'someModule' + )`, + options, + parser, + }, + { + code: `import( + /* webpackChunkName: "someModule", webpackInclude: /\\.json$/ */ + 'someModule' + )`, + options, + parser, + }, + { + code: `import( + /* webpackChunkName: "someModule" */ + /* webpackExclude: /\\.json$/ */ + 'someModule' + )`, + options, + parser, + }, + { + code: `import( + /* webpackChunkName: "someModule", webpackExclude: /\\.json$/ */ + 'someModule' + )`, + options, + parser, + }, + { + code: `import( + /* webpackChunkName: "someModule" */ + /* webpackPreload: true */ + 'someModule' + )`, + options, + parser, + }, + { + code: `import( + /* webpackChunkName: "someModule" */ + /* webpackPreload: 0 */ + 'someModule' + )`, + options, + parser, + }, + { + code: `import( + /* webpackChunkName: "someModule" */ + /* webpackPreload: -2 */ + 'someModule' + )`, + options, + parser, + }, + { + code: `import( + /* webpackChunkName: "someModule", webpackPreload: false */ + 'someModule' + )`, + options, + parser, + }, + { + code: `import( + /* webpackChunkName: "someModule" */ + /* webpackIgnore: false */ + 'someModule' + )`, + options, + parser, + }, + { + code: `import( + /* webpackChunkName: "someModule", webpackIgnore: true */ + 'someModule' + )`, + options, + parser, + }, + { + code: `import( + /* webpackChunkName: "someModule" */ + /* webpackMode: "lazy" */ + 'someModule' + )`, + options, + parser, + }, + { + code: `import( + /* webpackChunkName: 'someModule', webpackMode: 'lazy' */ + 'someModule' + )`, + options, + parser, + }, + { + code: `import( + /* webpackChunkName: "someModule" */ + /* webpackMode: "lazy-once" */ + 'someModule' + )`, + options, + parser, + }, + { + code: `import( + /* webpackChunkName: "someModule" */ + /* webpackMode: "eager" */ + 'someModule' + )`, + options, + parser, + }, + { + code: `import( + /* webpackChunkName: "someModule" */ + /* webpackMode: "weak" */ + 'someModule' + )`, + options, + parser, + }, + { + code: `import( + /* webpackChunkName: "someModule" */ + /* webpackExports: "default" */ + 'someModule' + )`, + options, + parser, + }, + { + code: `import( + /* webpackChunkName: "someModule", webpackExports: "named" */ + 'someModule' + )`, + options, + parser, + }, + { + code: `import( + /* webpackChunkName: "someModule" */ + /* webpackExports: ["default", "named"] */ + 'someModule' + )`, + options, + parser, + }, + { + code: `import( + /* webpackChunkName: 'someModule', webpackExports: ['default', 'named'] */ + 'someModule' + )`, + options, + parser, + }, + { + code: `import( + /* webpackChunkName: "someModule" */ + /* webpackInclude: /\\.json$/ */ + /* webpackExclude: /\\.json$/ */ + /* webpackPrefetch: true */ + /* webpackPreload: true */ + /* webpackIgnore: false */ + /* webpackMode: "eager" */ + /* webpackExports: ["default", "named"] */ + 'someModule' + )`, + options, + parser, + }, ...SYNTAX_CASES, ], @@ -256,79 +514,77 @@ ruleTester.run('dynamic-import-chunkname', rule, { }, { code: `import( - /*webpackChunkName: "someModule"*/ + /* webpackChunkName: true */ 'someModule' )`, options, parser, output: `import( - /*webpackChunkName: "someModule"*/ + /* webpackChunkName: true */ 'someModule' )`, errors: [{ - message: noPaddingCommentError, + message: chunkNameFormatError, type: 'CallExpression', }], }, { code: `import( - /* webpackChunkName : "someModule" */ + /* webpackChunkName: "my-module-[id]" */ 'someModule' )`, options, parser, output: `import( - /* webpackChunkName : "someModule" */ + /* webpackChunkName: "my-module-[id]" */ 'someModule' )`, errors: [{ - message: commentFormatError, + message: chunkNameFormatError, type: 'CallExpression', }], }, { code: `import( - /* webpackChunkName: "someModule" ; */ + /* webpackChunkName: ["request"] */ 'someModule' )`, options, parser, output: `import( - /* webpackChunkName: "someModule" ; */ + /* webpackChunkName: ["request"] */ 'someModule' )`, errors: [{ - message: invalidSyntaxCommentError, + message: chunkNameFormatError, type: 'CallExpression', }], }, { code: `import( - /* totally not webpackChunkName: "someModule" */ + /*webpackChunkName: "someModule"*/ 'someModule' )`, options, parser, output: `import( - /* totally not webpackChunkName: "someModule" */ + /*webpackChunkName: "someModule"*/ 'someModule' )`, errors: [{ - message: invalidSyntaxCommentError, + message: noPaddingCommentError, type: 'CallExpression', }], }, { code: `import( - /* webpackPrefetch: true */ - /* webpackChunk: "someModule" */ + /* webpackChunkName : "someModule" */ 'someModule' )`, options, parser, output: `import( - /* webpackPrefetch: true */ - /* webpackChunk: "someModule" */ + /* webpackChunkName : "someModule" */ 'someModule' )`, errors: [{ @@ -338,33 +594,259 @@ ruleTester.run('dynamic-import-chunkname', rule, { }, { code: `import( - /* webpackPrefetch: true, webpackChunk: "someModule" */ + /* webpackChunkName: "someModule" ; */ 'someModule' )`, options, parser, output: `import( - /* webpackPrefetch: true, webpackChunk: "someModule" */ + /* webpackChunkName: "someModule" ; */ 'someModule' )`, errors: [{ - message: commentFormatError, + message: invalidSyntaxCommentError, type: 'CallExpression', }], }, { code: `import( - /* webpackChunkName: "someModule123" */ + /* totally not webpackChunkName: "someModule" */ 'someModule' )`, - options: pickyCommentOptions, + options, parser, output: `import( - /* webpackChunkName: "someModule123" */ + /* totally not webpackChunkName: "someModule" */ 'someModule' )`, errors: [{ - message: pickyCommentFormatError, + message: invalidSyntaxCommentError, + type: 'CallExpression', + }], + }, + { + code: `import( + /* webpackPrefetch: true */ + /* webpackChunk: "someModule" */ + 'someModule' + )`, + options, + parser, + output: `import( + /* webpackPrefetch: true */ + /* webpackChunk: "someModule" */ + 'someModule' + )`, + errors: [{ + message: commentFormatError, + type: 'CallExpression', + }], + }, + { + code: `import( + /* webpackPrefetch: true, webpackChunk: "someModule" */ + 'someModule' + )`, + options, + parser, + output: `import( + /* webpackPrefetch: true, webpackChunk: "someModule" */ + 'someModule' + )`, + errors: [{ + message: commentFormatError, + type: 'CallExpression', + }], + }, + { + code: `import( + /* webpackChunkName: "someModule123" */ + 'someModule' + )`, + options: pickyCommentOptions, + parser, + output: `import( + /* webpackChunkName: "someModule123" */ + 'someModule' + )`, + errors: [{ + message: pickyChunkNameFormatError, + type: 'CallExpression', + }], + }, + { + code: `import( + /* webpackPrefetch: "module", webpackChunkName: "someModule" */ + 'someModule' + )`, + options, + parser, + output: `import( + /* webpackPrefetch: "module", webpackChunkName: "someModule" */ + 'someModule' + )`, + errors: [{ + message: commentFormatError, + type: 'CallExpression', + }], + }, + { + code: `import( + /* webpackPreload: "module", webpackChunkName: "someModule" */ + 'someModule' + )`, + options, + parser, + output: `import( + /* webpackPreload: "module", webpackChunkName: "someModule" */ + 'someModule' + )`, + errors: [{ + message: commentFormatError, + type: 'CallExpression', + }], + }, + { + code: `import( + /* webpackIgnore: "no", webpackChunkName: "someModule" */ + 'someModule' + )`, + options, + parser, + output: `import( + /* webpackIgnore: "no", webpackChunkName: "someModule" */ + 'someModule' + )`, + errors: [{ + message: commentFormatError, + type: 'CallExpression', + }], + }, + { + code: `import( + /* webpackInclude: "someModule", webpackChunkName: "someModule" */ + 'someModule' + )`, + options, + parser, + output: `import( + /* webpackInclude: "someModule", webpackChunkName: "someModule" */ + 'someModule' + )`, + errors: [{ + message: commentFormatError, + type: 'CallExpression', + }], + }, + { + code: `import( + /* webpackInclude: true, webpackChunkName: "someModule" */ + 'someModule' + )`, + options, + parser, + output: `import( + /* webpackInclude: true, webpackChunkName: "someModule" */ + 'someModule' + )`, + errors: [{ + message: commentFormatError, + type: 'CallExpression', + }], + }, + { + code: `import( + /* webpackExclude: "someModule", webpackChunkName: "someModule" */ + 'someModule' + )`, + options, + parser, + output: `import( + /* webpackExclude: "someModule", webpackChunkName: "someModule" */ + 'someModule' + )`, + errors: [{ + message: commentFormatError, + type: 'CallExpression', + }], + }, + { + code: `import( + /* webpackExclude: true, webpackChunkName: "someModule" */ + 'someModule' + )`, + options, + parser, + output: `import( + /* webpackExclude: true, webpackChunkName: "someModule" */ + 'someModule' + )`, + errors: [{ + message: commentFormatError, + type: 'CallExpression', + }], + }, + { + code: `import( + /* webpackMode: "fast", webpackChunkName: "someModule" */ + 'someModule' + )`, + options, + parser, + output: `import( + /* webpackMode: "fast", webpackChunkName: "someModule" */ + 'someModule' + )`, + errors: [{ + message: commentFormatError, + type: 'CallExpression', + }], + }, + { + code: `import( + /* webpackMode: true, webpackChunkName: "someModule" */ + 'someModule' + )`, + options, + parser, + output: `import( + /* webpackMode: true, webpackChunkName: "someModule" */ + 'someModule' + )`, + errors: [{ + message: commentFormatError, + type: 'CallExpression', + }], + }, + { + code: `import( + /* webpackExports: true, webpackChunkName: "someModule" */ + 'someModule' + )`, + options, + parser, + output: `import( + /* webpackExports: true, webpackChunkName: "someModule" */ + 'someModule' + )`, + errors: [{ + message: commentFormatError, + type: 'CallExpression', + }], + }, + { + code: `import( + /* webpackExports: /default/, webpackChunkName: "someModule" */ + 'someModule' + )`, + options, + parser, + output: `import( + /* webpackExports: /default/, webpackChunkName: "someModule" */ + 'someModule' + )`, + errors: [{ + message: commentFormatError, type: 'CallExpression', }], }, @@ -478,7 +960,7 @@ ruleTester.run('dynamic-import-chunkname', rule, { 'someModule' )`, errors: [{ - message: pickyCommentFormatError, + message: pickyChunkNameFormatError, type: 'CallExpression', }], }, @@ -496,64 +978,242 @@ context('TypeScript', () => { { code: `import( /* webpackChunkName: "someModule" */ - 'test' + 'test' + )`, + options, + parser: typescriptParser, + }, + { + code: `import( + /* webpackChunkName: "Some_Other_Module" */ + "test" + )`, + options, + parser: typescriptParser, + }, + { + code: `import( + /* webpackChunkName: "SomeModule123" */ + "test" + )`, + options, + parser: typescriptParser, + }, + { + code: `import( + /* webpackChunkName: "someModule", webpackPrefetch: true */ + 'test' + )`, + options, + parser: typescriptParser, + }, + { + code: `import( + /* webpackChunkName: "someModule", webpackPrefetch: true, */ + 'test' + )`, + options, + parser: typescriptParser, + }, + { + code: `import( + /* webpackPrefetch: true, webpackChunkName: "someModule" */ + 'test' + )`, + options, + parser: typescriptParser, + }, + { + code: `import( + /* webpackPrefetch: true, webpackChunkName: "someModule", */ + 'test' + )`, + options, + parser: typescriptParser, + }, + { + code: `import( + /* webpackPrefetch: true */ + /* webpackChunkName: "someModule" */ + 'test' + )`, + options, + parser: typescriptParser, + }, + { + code: `import( + /* webpackChunkName: "someModule" */ + /* webpackPrefetch: true */ + 'test' + )`, + options, + parser: typescriptParser, + }, + { + code: `import( + /* webpackChunkName: "someModule" */ + /* webpackPrefetch: 11 */ + 'test' + )`, + options, + parser: typescriptParser, + }, + { + code: `import( + /* webpackChunkName: "someModule" */ + /* webpackPrefetch: -11 */ + 'test' + )`, + options, + parser: typescriptParser, + }, + { + code: `import( + /* webpackChunkName: "someModule" */ + 'someModule' + )`, + options: pickyCommentOptions, + parser: typescriptParser, + }, + { + code: `import( + /* webpackChunkName: 'someModule' */ + 'test' + )`, + options, + parser: typescriptParser, + }, + { + code: `import( + /* webpackChunkName: "[request]" */ + 'someModule' + )`, + options, + parser: typescriptParser, + }, + { + code: `import( + /* webpackChunkName: "my-chunk-[request]-custom" */ + 'someModule' + )`, + options, + parser: typescriptParser, + }, + { + code: `import( + /* webpackChunkName: '[index]' */ + 'someModule' + )`, + options, + parser: typescriptParser, + }, + { + code: `import( + /* webpackChunkName: 'my-chunk.[index].with-index' */ + 'someModule' + )`, + options, + parser: typescriptParser, + }, + { + code: `import( + /* webpackChunkName: "someModule" */ + /* webpackInclude: /\\.json$/ */ + 'someModule' + )`, + options, + parser: typescriptParser, + }, + { + code: `import( + /* webpackChunkName: "someModule", webpackInclude: /\\.json$/ */ + 'someModule' + )`, + options, + parser: typescriptParser, + }, + { + code: `import( + /* webpackChunkName: "someModule" */ + /* webpackExclude: /\\.json$/ */ + 'someModule' + )`, + options, + parser: typescriptParser, + }, + { + code: `import( + /* webpackChunkName: "someModule", webpackExclude: /\\.json$/ */ + 'someModule' + )`, + options, + parser: typescriptParser, + }, + { + code: `import( + /* webpackChunkName: "someModule" */ + /* webpackPreload: true */ + 'someModule' )`, options, parser: typescriptParser, }, { code: `import( - /* webpackChunkName: "Some_Other_Module" */ - "test" + /* webpackChunkName: "someModule", webpackPreload: false */ + 'someModule' )`, options, parser: typescriptParser, }, { code: `import( - /* webpackChunkName: "SomeModule123" */ - "test" + /* webpackChunkName: "someModule" */ + /* webpackIgnore: false */ + 'someModule' )`, options, parser: typescriptParser, }, { code: `import( - /* webpackChunkName: "someModule", webpackPrefetch: true */ - 'test' + /* webpackChunkName: "someModule", webpackIgnore: true */ + 'someModule' )`, options, parser: typescriptParser, }, { code: `import( - /* webpackChunkName: "someModule", webpackPrefetch: true, */ - 'test' + /* webpackChunkName: "someModule" */ + /* webpackMode: "lazy" */ + 'someModule' )`, options, parser: typescriptParser, }, { code: `import( - /* webpackPrefetch: true, webpackChunkName: "someModule" */ - 'test' + /* webpackChunkName: 'someModule', webpackMode: 'lazy' */ + 'someModule' )`, options, parser: typescriptParser, }, { code: `import( - /* webpackPrefetch: true, webpackChunkName: "someModule", */ - 'test' + /* webpackChunkName: "someModule" */ + /* webpackMode: "lazy-once" */ + 'someModule' )`, options, parser: typescriptParser, }, { code: `import( - /* webpackPrefetch: true */ /* webpackChunkName: "someModule" */ - 'test' + /* webpackMode: "eager" */ + 'someModule' )`, options, parser: typescriptParser, @@ -561,8 +1221,8 @@ context('TypeScript', () => { { code: `import( /* webpackChunkName: "someModule" */ - /* webpackPrefetch: true */ - 'test' + /* webpackMode: "weak" */ + 'someModule' )`, options, parser: typescriptParser, @@ -570,19 +1230,48 @@ context('TypeScript', () => { { code: `import( /* webpackChunkName: "someModule" */ + /* webpackExports: "default" */ 'someModule' )`, - options: pickyCommentOptions, + options, parser: typescriptParser, - errors: [{ - message: pickyCommentFormatError, - type: nodeType, - }], }, { code: `import( - /* webpackChunkName: 'someModule' */ - 'test' + /* webpackChunkName: "someModule", webpackExports: "named" */ + 'someModule' + )`, + options, + parser: typescriptParser, + }, + { + code: `import( + /* webpackChunkName: "someModule" */ + /* webpackExports: ["default", "named"] */ + 'someModule' + )`, + options, + parser: typescriptParser, + }, + { + code: `import( + /* webpackChunkName: 'someModule', webpackExports: ['default', 'named'] */ + 'someModule' + )`, + options, + parser: typescriptParser, + }, + { + code: `import( + /* webpackChunkName: "someModule" */ + /* webpackInclude: /\\.json$/ */ + /* webpackExclude: /\\.json$/ */ + /* webpackPrefetch: true */ + /* webpackPreload: true */ + /* webpackIgnore: false */ + /* webpackMode: "eager" */ + /* webpackExports: ["default", "named"] */ + 'someModule' )`, options, parser: typescriptParser, @@ -793,6 +1482,54 @@ context('TypeScript', () => { type: nodeType, }], }, + { + code: `import( + /* webpackChunkName: true */ + 'someModule' + )`, + options, + parser: typescriptParser, + output: `import( + /* webpackChunkName: true */ + 'someModule' + )`, + errors: [{ + message: chunkNameFormatError, + type: nodeType, + }], + }, + { + code: `import( + /* webpackChunkName: "my-module-[id]" */ + 'someModule' + )`, + options, + parser: typescriptParser, + output: `import( + /* webpackChunkName: "my-module-[id]" */ + 'someModule' + )`, + errors: [{ + message: chunkNameFormatError, + type: nodeType, + }], + }, + { + code: `import( + /* webpackChunkName: ["request"] */ + 'someModule' + )`, + options, + parser: typescriptParser, + output: `import( + /* webpackChunkName: ["request"] */ + 'someModule' + )`, + errors: [{ + message: chunkNameFormatError, + type: nodeType, + }], + }, { code: `import( /* webpackChunkName: "someModule123" */ @@ -805,7 +1542,183 @@ context('TypeScript', () => { 'someModule' )`, errors: [{ - message: pickyCommentFormatError, + message: pickyChunkNameFormatError, + type: nodeType, + }], + }, + { + code: `import( + /* webpackPrefetch: "module", webpackChunkName: "someModule" */ + 'someModule' + )`, + options, + parser: typescriptParser, + output: `import( + /* webpackPrefetch: "module", webpackChunkName: "someModule" */ + 'someModule' + )`, + errors: [{ + message: commentFormatError, + type: nodeType, + }], + }, + { + code: `import( + /* webpackPreload: "module", webpackChunkName: "someModule" */ + 'someModule' + )`, + options, + parser: typescriptParser, + output: `import( + /* webpackPreload: "module", webpackChunkName: "someModule" */ + 'someModule' + )`, + errors: [{ + message: commentFormatError, + type: nodeType, + }], + }, + { + code: `import( + /* webpackIgnore: "no", webpackChunkName: "someModule" */ + 'someModule' + )`, + options, + parser: typescriptParser, + output: `import( + /* webpackIgnore: "no", webpackChunkName: "someModule" */ + 'someModule' + )`, + errors: [{ + message: commentFormatError, + type: nodeType, + }], + }, + { + code: `import( + /* webpackInclude: "someModule", webpackChunkName: "someModule" */ + 'someModule' + )`, + options, + parser: typescriptParser, + output: `import( + /* webpackInclude: "someModule", webpackChunkName: "someModule" */ + 'someModule' + )`, + errors: [{ + message: commentFormatError, + type: nodeType, + }], + }, + { + code: `import( + /* webpackInclude: true, webpackChunkName: "someModule" */ + 'someModule' + )`, + options, + parser: typescriptParser, + output: `import( + /* webpackInclude: true, webpackChunkName: "someModule" */ + 'someModule' + )`, + errors: [{ + message: commentFormatError, + type: nodeType, + }], + }, + { + code: `import( + /* webpackExclude: "someModule", webpackChunkName: "someModule" */ + 'someModule' + )`, + options, + parser: typescriptParser, + output: `import( + /* webpackExclude: "someModule", webpackChunkName: "someModule" */ + 'someModule' + )`, + errors: [{ + message: commentFormatError, + type: nodeType, + }], + }, + { + code: `import( + /* webpackExclude: true, webpackChunkName: "someModule" */ + 'someModule' + )`, + options, + parser: typescriptParser, + output: `import( + /* webpackExclude: true, webpackChunkName: "someModule" */ + 'someModule' + )`, + errors: [{ + message: commentFormatError, + type: nodeType, + }], + }, + { + code: `import( + /* webpackMode: "fast", webpackChunkName: "someModule" */ + 'someModule' + )`, + options, + parser: typescriptParser, + output: `import( + /* webpackMode: "fast", webpackChunkName: "someModule" */ + 'someModule' + )`, + errors: [{ + message: commentFormatError, + type: nodeType, + }], + }, + { + code: `import( + /* webpackMode: true, webpackChunkName: "someModule" */ + 'someModule' + )`, + options, + parser: typescriptParser, + output: `import( + /* webpackMode: true, webpackChunkName: "someModule" */ + 'someModule' + )`, + errors: [{ + message: commentFormatError, + type: nodeType, + }], + }, + { + code: `import( + /* webpackExports: true, webpackChunkName: "someModule" */ + 'someModule' + )`, + options, + parser: typescriptParser, + output: `import( + /* webpackExports: true, webpackChunkName: "someModule" */ + 'someModule' + )`, + errors: [{ + message: commentFormatError, + type: nodeType, + }], + }, + { + code: `import( + /* webpackExports: /default/, webpackChunkName: "someModule" */ + 'someModule' + )`, + options, + parser: typescriptParser, + output: `import( + /* webpackExports: /default/, webpackChunkName: "someModule" */ + 'someModule' + )`, + errors: [{ + message: commentFormatError, type: nodeType, }], },