magic comment regexp match update and statsCase test updated

plus minor renamings and snapshot update
This commit is contained in:
Ronan Amsterdam 2018-05-30 09:24:36 +08:00
parent 25ec7e4102
commit a228daec58
6 changed files with 17 additions and 37 deletions

View File

@ -31,17 +31,8 @@ const defaultParserOptions = {
} }
}; };
const webpackImportCommentOptions = [ // regexp to match at lease one "magic comment"
"webpackIgnore", const webpackCommentRegExp = new RegExp(/(^|\W)webpack[A-Z]{1,}[A-Za-z]{1,}:/);
"webpackChunkName",
"webpackMode",
"webpackPrefetch",
"webpackPreload",
"webpackInclude",
"webpackExclude"
];
const webpackCommentRegExp = new RegExp(webpackImportCommentOptions.join("|"));
const EMPTY_COMMENT_OPTIONS = { const EMPTY_COMMENT_OPTIONS = {
options: null, options: null,

View File

@ -41,10 +41,10 @@ class ImportParserPlugin {
for (const e of commentErrors) { for (const e of commentErrors) {
const { comment } = e; const { comment } = e;
parser.state.module.warnings.push( parser.state.module.warnings.push(
new ImportOptionsCompileWarning( new CommentCompilationWarning(
`compilation error while processing: /*${comment.value}*/: ${ `Compilation error while processing magic comment(-s): /*${
e.message comment.value
}`, }*/: ${e.message}`,
parser.state.module, parser.state.module,
comment.loc comment.loc
) )
@ -250,11 +250,11 @@ class ImportParserPlugin {
} }
} }
class ImportOptionsCompileWarning extends WebpackError { class CommentCompilationWarning extends WebpackError {
constructor(message, module, loc) { constructor(message, module, loc) {
super(); super();
this.name = "ImportOptionsCompileWarning"; this.name = "CommentCompilationWarning";
this.message = message; this.message = message;
this.origin = this.module = module; this.origin = this.module = module;

View File

@ -1008,29 +1008,16 @@ Entrypoint entry = entry.js
`; `;
exports[`StatsTestCases should print correct stats for import-with-invalid-options-comments 1`] = ` exports[`StatsTestCases should print correct stats for import-with-invalid-options-comments 1`] = `
"Hash: 3933c30f2b0ad856b9f3 " 6 modules
Time: Xms
Built at: Thu Jan 01 1970 00:00:00 GMT
Asset Size Chunks Chunk Names
chunk.js 1.16 KiB 0 [emitted] chunk
main.js 7.85 KiB 1 [emitted] main
2.js 154 bytes 2 [emitted]
goingToCompileChunkName-b.js 163 bytes 3 [emitted] goingToCompileChunkName-b
4.js 157 bytes 4 [emitted]
Entrypoint main = main.js
[0] ./chunk-a.js 27 bytes {2} [built]
[1] ./chunk-b.js 27 bytes {3} [built]
[2] ./chunk-c.js 27 bytes {4} [built]
[3] ./chunk.js 318 bytes {0} [built] [2 warnings]
[4] ./index.js 50 bytes {1} [built]
WARNING in ./chunk.js WARNING in ./chunk.js
compilation error while processing: /* webpack Prefetch: 0, webpackChunkName: \\"notGoingToCompile-c\\" */: Unexpected identifier Compilation error while processing magic comment(-s): /* webpack Prefetch: 0, webpackChunkName: \\"notGoingToCompile-c\\" */: Unexpected identifier
@ ./index.js 4:11-77 1:0-49
WARNING in ./chunk.js WARNING in ./chunk.js
compilation error while processing: /* webpackPrefetch: true, webpackChunkName: notGoingToCompileChunkName */: notGoingToCompileChunkName is not defined Compilation error while processing magic comment(-s): /* webpackPrefetch: nope */: nope is not defined
@ ./index.js 2:11-84 1:0-49"
WARNING in ./chunk.js
Compilation error while processing magic comment(-s): /* webpackPrefetch: true, webpackChunkName: notGoingToCompileChunkName */: notGoingToCompileChunkName is not defined"
`; `;
exports[`StatsTestCases should print correct stats for limit-chunk-count-plugin 1`] = ` exports[`StatsTestCases should print correct stats for limit-chunk-count-plugin 1`] = `

View File

@ -0,0 +1 @@
module.exports = "chunk-d";

View File

@ -2,4 +2,5 @@ export default function() {
import(/* webpackPrefetch: true, webpackChunkName: notGoingToCompileChunkName */ "./chunk-a"); import(/* webpackPrefetch: true, webpackChunkName: notGoingToCompileChunkName */ "./chunk-a");
import(/* webpackPrefetch: 0, webpackChunkName: "goingToCompileChunkName-b" */ "./chunk-b"); import(/* webpackPrefetch: 0, webpackChunkName: "goingToCompileChunkName-b" */ "./chunk-b");
import(/* webpack Prefetch: 0, webpackChunkName: "notGoingToCompile-c" */ "./chunk-c"); import(/* webpack Prefetch: 0, webpackChunkName: "notGoingToCompile-c" */ "./chunk-c");
import(/* webpackPrefetch: nope */ /* webpackChunkName: "yep" */ "./chunk-d");
} }

View File

@ -4,5 +4,5 @@ module.exports = {
output: { output: {
chunkFilename: "[name].js" chunkFilename: "[name].js"
}, },
performance: false stats: "minimal"
}; };