From 3318e7bb06f7b5b1006127335cca1dd805823e28 Mon Sep 17 00:00:00 2001 From: Max Burmagin Date: Sat, 18 Dec 2021 17:59:22 +0300 Subject: [PATCH] [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 | 1079 +++++++++++++++++-- 3 files changed, 1000 insertions(+), 88 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27c59ac032..5f9cfc0a1a 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 859e9fea46..2c59d35e59 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 2731084f04..814a5a6d1a 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" */ @@ -121,132 +150,583 @@ ruleTester.run('dynamic-import-chunkname', rule, { }, { code: `import( - /* webpackChunkName: "someModule" */ - /* webpackPrefetch: true */ - 'test' + /* webpackChunkName: "someModule" */ + /* webpackPrefetch: true */ + 'test' + )`, + options, + parser, + }, + { + code: `import( + /* webpackChunkName: "someModule" */ + /* webpackPrefetch: 12 */ + 'test' + )`, + options, + parser, + }, + { + code: `import( + /* webpackChunkName: "someModule" */ + /* webpackPrefetch: -30 */ + 'test' + )`, + options, + parser, + }, + { + code: `import( + /* webpackChunkName: 'someModule' */ + 'someModule' + )`, + options, + parser, + }, + { + code: `import( + /* webpackChunkName: "someModule" */ + 'someModule' + )`, + 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, + ], + + invalid: [ + { + code: `import( + // webpackChunkName: "someModule" + 'someModule' + )`, + options, + parser, + output: `import( + // webpackChunkName: "someModule" + 'someModule' + )`, + errors: [{ + message: nonBlockCommentError, + type: 'CallExpression', + }], + }, + { + code: 'import(\'test\')', + options, + parser, + output: 'import(\'test\')', + errors: [{ + message: noLeadingCommentError, + type: 'CallExpression', + }], + }, + { + code: `import( + /* webpackChunkName: someModule */ + 'someModule' + )`, + options, + parser, + output: `import( + /* webpackChunkName: someModule */ + 'someModule' + )`, + errors: [{ + message: invalidSyntaxCommentError, + type: 'CallExpression', + }], + }, + { + code: `import( + /* webpackChunkName: "someModule' */ + 'someModule' + )`, + options, + parser, + output: `import( + /* webpackChunkName: "someModule' */ + 'someModule' + )`, + errors: [{ + message: invalidSyntaxCommentError, + type: 'CallExpression', + }], + }, + { + code: `import( + /* webpackChunkName: 'someModule" */ + 'someModule' + )`, + options, + parser, + output: `import( + /* webpackChunkName: 'someModule" */ + 'someModule' + )`, + errors: [{ + message: invalidSyntaxCommentError, + type: 'CallExpression', + }], + }, + { + code: `import( + /* webpackChunkName "someModule" */ + 'someModule' + )`, + options, + parser, + output: `import( + /* webpackChunkName "someModule" */ + 'someModule' + )`, + errors: [{ + message: invalidSyntaxCommentError, + type: 'CallExpression', + }], + }, + { + code: `import( + /* webpackChunkName:"someModule" */ + 'someModule' + )`, + options, + parser, + output: `import( + /* webpackChunkName:"someModule" */ + 'someModule' + )`, + errors: [{ + message: commentFormatError, + type: 'CallExpression', + }], + }, + { + code: `import( + /* webpackChunkName: true */ + 'someModule' + )`, + options, + parser, + output: `import( + /* webpackChunkName: true */ + 'someModule' + )`, + errors: [{ + message: chunkNameFormatError, + type: 'CallExpression', + }], + }, + { + code: `import( + /* webpackChunkName: "my-module-[id]" */ + 'someModule' + )`, + options, + parser, + output: `import( + /* webpackChunkName: "my-module-[id]" */ + 'someModule' + )`, + errors: [{ + message: chunkNameFormatError, + type: 'CallExpression', + }], + }, + { + code: `import( + /* webpackChunkName: ["request"] */ + 'someModule' + )`, + options, + parser, + output: `import( + /* webpackChunkName: ["request"] */ + 'someModule' + )`, + errors: [{ + message: chunkNameFormatError, + type: 'CallExpression', + }], + }, + { + code: `import( + /*webpackChunkName: "someModule"*/ + 'someModule' + )`, + options, + parser, + output: `import( + /*webpackChunkName: "someModule"*/ + 'someModule' + )`, + errors: [{ + message: noPaddingCommentError, + type: 'CallExpression', + }], + }, + { + code: `import( + /* webpackChunkName : "someModule" */ + 'someModule' + )`, + options, + parser, + output: `import( + /* webpackChunkName : "someModule" */ + 'someModule' + )`, + errors: [{ + message: commentFormatError, + type: 'CallExpression', + }], + }, + { + code: `import( + /* webpackChunkName: "someModule" ; */ + 'someModule' )`, options, parser, + output: `import( + /* webpackChunkName: "someModule" ; */ + 'someModule' + )`, + errors: [{ + message: invalidSyntaxCommentError, + type: 'CallExpression', + }], }, { code: `import( - /* webpackChunkName: 'someModule' */ + /* totally not webpackChunkName: "someModule" */ 'someModule' )`, options, parser, - }, - { - code: `import( - /* webpackChunkName: "someModule" */ + output: `import( + /* totally not webpackChunkName: "someModule" */ 'someModule' )`, - options: pickyCommentOptions, - parser, }, - ...SYNTAX_CASES, - ], - - invalid: [ { code: `import( - // webpackChunkName: "someModule" + /* webpackPrefetch: true */ + /* webpackChunk: "someModule" */ 'someModule' )`, options, parser, output: `import( - // webpackChunkName: "someModule" + /* webpackPrefetch: true */ + /* webpackChunk: "someModule" */ 'someModule' )`, errors: [{ - message: nonBlockCommentError, + message: commentFormatError, type: 'CallExpression', }], }, { - code: 'import(\'test\')', + code: `import( + /* webpackPrefetch: true, webpackChunk: "someModule" */ + 'someModule' + )`, options, parser, - output: 'import(\'test\')', + output: `import( + /* webpackPrefetch: true, webpackChunk: "someModule" */ + 'someModule' + )`, errors: [{ - message: noLeadingCommentError, + message: commentFormatError, type: 'CallExpression', }], }, { code: `import( - /* webpackChunkName: someModule */ + /* webpackChunkName: "someModule123" */ 'someModule' )`, - options, + options: pickyCommentOptions, parser, output: `import( - /* webpackChunkName: someModule */ + /* webpackChunkName: "someModule123" */ 'someModule' )`, errors: [{ - message: invalidSyntaxCommentError, + message: pickyChunkNameFormatError, type: 'CallExpression', }], }, { code: `import( - /* webpackChunkName: "someModule' */ + /* webpackPrefetch: "module", webpackChunkName: "someModule" */ 'someModule' )`, options, parser, output: `import( - /* webpackChunkName: "someModule' */ + /* webpackPrefetch: "module", webpackChunkName: "someModule" */ 'someModule' )`, errors: [{ - message: invalidSyntaxCommentError, + message: commentFormatError, type: 'CallExpression', }], }, { code: `import( - /* webpackChunkName: 'someModule" */ + /* webpackPreload: "module", webpackChunkName: "someModule" */ 'someModule' )`, options, parser, output: `import( - /* webpackChunkName: 'someModule" */ + /* webpackPreload: "module", webpackChunkName: "someModule" */ 'someModule' )`, errors: [{ - message: invalidSyntaxCommentError, + message: commentFormatError, type: 'CallExpression', }], }, { code: `import( - /* webpackChunkName "someModule" */ + /* webpackIgnore: "no", webpackChunkName: "someModule" */ 'someModule' )`, options, parser, output: `import( - /* webpackChunkName "someModule" */ + /* webpackIgnore: "no", webpackChunkName: "someModule" */ 'someModule' )`, errors: [{ - message: invalidSyntaxCommentError, + message: commentFormatError, type: 'CallExpression', }], }, { code: `import( - /* webpackChunkName:"someModule" */ + /* webpackInclude: "someModule", webpackChunkName: "someModule" */ 'someModule' )`, options, parser, output: `import( - /* webpackChunkName:"someModule" */ + /* webpackInclude: "someModule", webpackChunkName: "someModule" */ 'someModule' )`, errors: [{ @@ -256,29 +736,29 @@ ruleTester.run('dynamic-import-chunkname', rule, { }, { code: `import( - /*webpackChunkName: "someModule"*/ + /* webpackInclude: true, webpackChunkName: "someModule" */ 'someModule' )`, options, parser, output: `import( - /*webpackChunkName: "someModule"*/ + /* webpackInclude: true, webpackChunkName: "someModule" */ 'someModule' )`, errors: [{ - message: noPaddingCommentError, + message: commentFormatError, type: 'CallExpression', }], }, { code: `import( - /* webpackChunkName : "someModule" */ + /* webpackExclude: "someModule", webpackChunkName: "someModule" */ 'someModule' )`, options, parser, output: `import( - /* webpackChunkName : "someModule" */ + /* webpackExclude: "someModule", webpackChunkName: "someModule" */ 'someModule' )`, errors: [{ @@ -288,47 +768,45 @@ ruleTester.run('dynamic-import-chunkname', rule, { }, { code: `import( - /* webpackChunkName: "someModule" ; */ + /* webpackExclude: true, webpackChunkName: "someModule" */ 'someModule' )`, options, parser, output: `import( - /* webpackChunkName: "someModule" ; */ + /* webpackExclude: true, webpackChunkName: "someModule" */ 'someModule' )`, errors: [{ - message: invalidSyntaxCommentError, + message: commentFormatError, type: 'CallExpression', }], }, { code: `import( - /* totally not webpackChunkName: "someModule" */ + /* webpackMode: "fast", webpackChunkName: "someModule" */ 'someModule' )`, options, parser, output: `import( - /* totally not webpackChunkName: "someModule" */ + /* webpackMode: "fast", webpackChunkName: "someModule" */ 'someModule' )`, errors: [{ - message: invalidSyntaxCommentError, + message: commentFormatError, type: 'CallExpression', }], }, { code: `import( - /* webpackPrefetch: true */ - /* webpackChunk: "someModule" */ + /* webpackMode: true, webpackChunkName: "someModule" */ 'someModule' )`, options, parser, output: `import( - /* webpackPrefetch: true */ - /* webpackChunk: "someModule" */ + /* webpackMode: true, webpackChunkName: "someModule" */ 'someModule' )`, errors: [{ @@ -338,13 +816,13 @@ ruleTester.run('dynamic-import-chunkname', rule, { }, { code: `import( - /* webpackPrefetch: true, webpackChunk: "someModule" */ + /* webpackExports: true, webpackChunkName: "someModule" */ 'someModule' )`, options, parser, output: `import( - /* webpackPrefetch: true, webpackChunk: "someModule" */ + /* webpackExports: true, webpackChunkName: "someModule" */ 'someModule' )`, errors: [{ @@ -354,17 +832,17 @@ ruleTester.run('dynamic-import-chunkname', rule, { }, { code: `import( - /* webpackChunkName: "someModule123" */ + /* webpackExports: /default/, webpackChunkName: "someModule" */ 'someModule' )`, - options: pickyCommentOptions, + options, parser, output: `import( - /* webpackChunkName: "someModule123" */ + /* webpackExports: /default/, webpackChunkName: "someModule" */ 'someModule' )`, errors: [{ - message: pickyCommentFormatError, + message: commentFormatError, type: 'CallExpression', }], }, @@ -478,7 +956,7 @@ ruleTester.run('dynamic-import-chunkname', rule, { 'someModule' )`, errors: [{ - message: pickyCommentFormatError, + message: pickyChunkNameFormatError, type: 'CallExpression', }], }, @@ -496,64 +974,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 +1217,8 @@ context('TypeScript', () => { { code: `import( /* webpackChunkName: "someModule" */ - /* webpackPrefetch: true */ - 'test' + /* webpackMode: "weak" */ + 'someModule' )`, options, parser: typescriptParser, @@ -570,19 +1226,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 +1478,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 +1538,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, }], },