mirror of https://github.com/webpack/webpack.git
Merge pull request #11471 from Adityaperiwal/bugfix/ContextModuleRegex
refactor regex
This commit is contained in:
commit
7412e71ba5
|
|
@ -144,7 +144,9 @@ class ContextModule extends Module {
|
|||
prettyRegExp(regexString) {
|
||||
// remove the "/" at the front and the beginning
|
||||
// "/foo/" -> "foo"
|
||||
return regexString.substring(1, regexString.length - 1);
|
||||
return regexString
|
||||
.substring(1, regexString.length - 1)
|
||||
.replace(/!/g, "%21");
|
||||
}
|
||||
|
||||
_createIdentifier() {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
expect.extend({
|
||||
toBeValidModuleId(received, moduleIdString) {
|
||||
const pass = typeof received === "number" || received === moduleIdString;
|
||||
if (pass) {
|
||||
return {
|
||||
message: () => `expected ${received} not to be a valid module id`,
|
||||
pass: true
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
message: () => `expected ${received} to be a valid module id`,
|
||||
pass: false
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it("should replace ! with %21 in the module id string of the context module", function () {
|
||||
const moduleId = require.context("./folder", true, /^(?!file1\.js$).*$/i, "lazy").id;
|
||||
expect(moduleId).toBeValidModuleId("./context/issue-10969/folder lazy recursive ^(?%21file1\\.js$).*$/");
|
||||
});
|
||||
Loading…
Reference in New Issue