Skip to content

Commit a228dae

Browse files
committed
magic comment regexp match update and statsCase test updated
plus minor renamings and snapshot update
1 parent 25ec7e4 commit a228dae

File tree

6 files changed

+17
-37
lines changed

6 files changed

+17
-37
lines changed

lib/Parser.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,8 @@ const defaultParserOptions = {
3131
}
3232
};
3333

34-
const webpackImportCommentOptions = [
35-
"webpackIgnore",
36-
"webpackChunkName",
37-
"webpackMode",
38-
"webpackPrefetch",
39-
"webpackPreload",
40-
"webpackInclude",
41-
"webpackExclude"
42-
];
43-
44-
const webpackCommentRegExp = new RegExp(webpackImportCommentOptions.join("|"));
34+
// regexp to match at lease one "magic comment"
35+
const webpackCommentRegExp = new RegExp(/(^|\W)webpack[A-Z]{1,}[A-Za-z]{1,}:/);
4536

4637
const EMPTY_COMMENT_OPTIONS = {
4738
options: null,

lib/dependencies/ImportParserPlugin.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ class ImportParserPlugin {
4141
for (const e of commentErrors) {
4242
const { comment } = e;
4343
parser.state.module.warnings.push(
44-
new ImportOptionsCompileWarning(
45-
`compilation error while processing: /*${comment.value}*/: ${
46-
e.message
47-
}`,
44+
new CommentCompilationWarning(
45+
`Compilation error while processing magic comment(-s): /*${
46+
comment.value
47+
}*/: ${e.message}`,
4848
parser.state.module,
4949
comment.loc
5050
)
@@ -250,11 +250,11 @@ class ImportParserPlugin {
250250
}
251251
}
252252

253-
class ImportOptionsCompileWarning extends WebpackError {
253+
class CommentCompilationWarning extends WebpackError {
254254
constructor(message, module, loc) {
255255
super();
256256

257-
this.name = "ImportOptionsCompileWarning";
257+
this.name = "CommentCompilationWarning";
258258
this.message = message;
259259

260260
this.origin = this.module = module;

test/__snapshots__/StatsTestCases.test.js.snap

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,29 +1008,16 @@ Entrypoint entry = entry.js
10081008
`;
10091009

10101010
exports[`StatsTestCases should print correct stats for import-with-invalid-options-comments 1`] = `
1011-
"Hash: 3933c30f2b0ad856b9f3
1012-
Time: Xms
1013-
Built at: Thu Jan 01 1970 00:00:00 GMT
1014-
Asset Size Chunks Chunk Names
1015-
chunk.js 1.16 KiB 0 [emitted] chunk
1016-
main.js 7.85 KiB 1 [emitted] main
1017-
2.js 154 bytes 2 [emitted]
1018-
goingToCompileChunkName-b.js 163 bytes 3 [emitted] goingToCompileChunkName-b
1019-
4.js 157 bytes 4 [emitted]
1020-
Entrypoint main = main.js
1021-
[0] ./chunk-a.js 27 bytes {2} [built]
1022-
[1] ./chunk-b.js 27 bytes {3} [built]
1023-
[2] ./chunk-c.js 27 bytes {4} [built]
1024-
[3] ./chunk.js 318 bytes {0} [built] [2 warnings]
1025-
[4] ./index.js 50 bytes {1} [built]
1011+
" 6 modules
1012+
1013+
WARNING in ./chunk.js
1014+
Compilation error while processing magic comment(-s): /* webpack Prefetch: 0, webpackChunkName: \\"notGoingToCompile-c\\" */: Unexpected identifier
10261015
10271016
WARNING in ./chunk.js
1028-
compilation error while processing: /* webpack Prefetch: 0, webpackChunkName: \\"notGoingToCompile-c\\" */: Unexpected identifier
1029-
@ ./index.js 4:11-77 1:0-49
1017+
Compilation error while processing magic comment(-s): /* webpackPrefetch: nope */: nope is not defined
10301018
10311019
WARNING in ./chunk.js
1032-
compilation error while processing: /* webpackPrefetch: true, webpackChunkName: notGoingToCompileChunkName */: notGoingToCompileChunkName is not defined
1033-
@ ./index.js 2:11-84 1:0-49"
1020+
Compilation error while processing magic comment(-s): /* webpackPrefetch: true, webpackChunkName: notGoingToCompileChunkName */: notGoingToCompileChunkName is not defined"
10341021
`;
10351022

10361023
exports[`StatsTestCases should print correct stats for limit-chunk-count-plugin 1`] = `
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "chunk-d";

test/statsCases/import-with-invalid-options-comments/chunk.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ export default function() {
22
import(/* webpackPrefetch: true, webpackChunkName: notGoingToCompileChunkName */ "./chunk-a");
33
import(/* webpackPrefetch: 0, webpackChunkName: "goingToCompileChunkName-b" */ "./chunk-b");
44
import(/* webpack Prefetch: 0, webpackChunkName: "notGoingToCompile-c" */ "./chunk-c");
5+
import(/* webpackPrefetch: nope */ /* webpackChunkName: "yep" */ "./chunk-d");
56
}

test/statsCases/import-with-invalid-options-comments/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ module.exports = {
44
output: {
55
chunkFilename: "[name].js"
66
},
7-
performance: false
7+
stats: "minimal"
88
};

0 commit comments

Comments
 (0)