Skip to content

Commit cfcf2ff

Browse files
committed
inline regex for magic comments
1 parent e127b32 commit cfcf2ff

File tree

1 file changed

+2
-19
lines changed

1 file changed

+2
-19
lines changed

Diff for: src/rules/dynamic-import-chunkname.js

+2-19
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
import vm from 'vm';
22
import docsUrl from '../docsUrl';
33

4-
function generateRegexForMagicComments(magicComments) {
5-
const preparedComments = magicComments.map(([comment, value]) => {
6-
return `(${comment}: ${value})`;
7-
});
8-
9-
return new RegExp(`^( (${preparedComments.join('|')}),?)+ $`);
10-
}
11-
124
module.exports = {
135
meta: {
146
type: 'suggestion',
@@ -36,18 +28,9 @@ module.exports = {
3628
const config = context.options[0];
3729
const { importFunctions = [] } = config || {};
3830
const { webpackChunknameFormat = '([0-9a-zA-Z-_/.]|\\[(request|index)\\])+' } = config || {};
39-
const webpackMagicComments = [
40-
['webpackChunkName', `["']${webpackChunknameFormat}["']`],
41-
['webpackPrefetch', '(true|false|-?[0-9]+)'],
42-
['webpackPreload', '(true|false|-?[0-9]+)'],
43-
['webpackIgnore', '(true|false)'],
44-
['webpackInclude', '\\/.*\\/'],
45-
['webpackExclude', '\\/.*\\/'],
46-
['webpackMode', `["'](lazy|lazy-once|eager|weak)["']`],
47-
['webpackExports', `(['"]\\w+['"]|\\[(['"]\\w+['"], *)+(['"]\\w+['"]*)\\])`],
48-
];
31+
4932
const paddedCommentRegex = /^ (\S[\s\S]+\S) $/;
50-
const commentStyleRegex = generateRegexForMagicComments(webpackMagicComments);
33+
const commentStyleRegex = /^( ((webpackChunkName: ["']([0-9a-zA-Z-_/.]|\[(request|index)\])+["'])|((webpackPrefetch|webpackPreload): (true|false|-?[0-9]+))|(webpackIgnore: (true|false))|((webpackInclude|webpackExclude): \/.*\/)|(webpackMode: ["'](lazy|lazy-once|eager|weak)["'])|(webpackExports: (['"]\w+['"]|\[(['"]\w+['"], *)+(['"]\w+['"]*)\]))),?)+ $/;
5134
const chunkSubstrFormat = ` webpackChunkName: ["']${webpackChunknameFormat}["'],? `;
5235
const chunkSubstrRegex = new RegExp(chunkSubstrFormat);
5336

0 commit comments

Comments
 (0)