Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 8 additions & 26 deletions lib/ModuleFilenameHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,28 +87,6 @@ const getHash =
return digest.slice(0, 4);
};

/**
* Returns a function that returns the string with the token replaced with the replacement
* @param {string|RegExp} test A regular expression string or Regular Expression object
* @returns {RegExp} A regular expression object
* @example
* ```js
* const test = asRegExp("test");
* test.test("test"); // true
*
* const test2 = asRegExp(/test/);
* test2.test("test"); // true
* ```
*/
const asRegExp = test => {
if (typeof test === "string") {
// Escape special characters in the string to prevent them from being interpreted as special characters in a regular expression. Do this by
// adding a backslash before each special character
test = new RegExp(`^${test.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&")}`);
}
return test;
};

/**
* @template T
* Returns a lazy object. The object is lazy in the sense that the properties are
Expand Down Expand Up @@ -335,15 +313,19 @@ ModuleFilenameHelpers.replaceDuplicates = (array, fn, comparator) => {
* ModuleFilenameHelpers.matchPart("foo.js", [/^baz/, /^bar/]); // false
* ```
*/
ModuleFilenameHelpers.matchPart = (str, test) => {
const matchPart = (str, test) => {
if (!test) return true;

if (Array.isArray(test)) {
return test.map(asRegExp).some(regExp => regExp.test(str));
return test.some(test => matchPart(str, test));
}
return asRegExp(test).test(str);
if (typeof test === "string") {
return str.startsWith(test);
}
return test.test(str);
};

ModuleFilenameHelpers.matchPart = matchPart;

/**
* Tests if a string matches a match object. The match object can have the following properties:
* - `test`: a RegExp or an array of RegExp
Expand Down
4 changes: 2 additions & 2 deletions lib/wasm/EnableWasmLoadingPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class EnableWasmLoadingPlugin {
new ReadFileCompileWasmPlugin({
mangleImports: compiler.options.optimization.mangleWasmImports,
import:
compiler.options.output.environment.module &&
compiler.options.output.module &&
compiler.options.output.environment.dynamicImport
}).apply(compiler);
}
Expand All @@ -108,7 +108,7 @@ class EnableWasmLoadingPlugin {
const ReadFileCompileAsyncWasmPlugin = require("../node/ReadFileCompileAsyncWasmPlugin");
new ReadFileCompileAsyncWasmPlugin({
import:
compiler.options.output.environment.module &&
compiler.options.output.module &&
compiler.options.output.environment.dynamicImport
}).apply(compiler);
}
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/supportsBlob.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function supportsWebAssembly() {
module.exports = function supportsBlob() {
try {
return typeof Blob !== "undefined";
} catch (_err) {
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/supportsResponse.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function supportsWebAssembly() {
module.exports = function supportsResponse() {
try {
// eslint-disable-next-line n/no-unsupported-features/node-builtins
return typeof Response !== "undefined";
Expand Down
Loading