diff --git a/lib/ModuleFilenameHelpers.js b/lib/ModuleFilenameHelpers.js index afe3d345338..738bc442a2c 100644 --- a/lib/ModuleFilenameHelpers.js +++ b/lib/ModuleFilenameHelpers.js @@ -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 @@ -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 diff --git a/lib/wasm/EnableWasmLoadingPlugin.js b/lib/wasm/EnableWasmLoadingPlugin.js index 250dd0a2d71..4d4dace131b 100644 --- a/lib/wasm/EnableWasmLoadingPlugin.js +++ b/lib/wasm/EnableWasmLoadingPlugin.js @@ -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); } @@ -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); } diff --git a/test/helpers/supportsBlob.js b/test/helpers/supportsBlob.js index 4131935515a..8f6c80fb0ff 100644 --- a/test/helpers/supportsBlob.js +++ b/test/helpers/supportsBlob.js @@ -1,4 +1,4 @@ -module.exports = function supportsWebAssembly() { +module.exports = function supportsBlob() { try { return typeof Blob !== "undefined"; } catch (_err) { diff --git a/test/helpers/supportsResponse.js b/test/helpers/supportsResponse.js index bda3699eb85..0cc0bc2a328 100644 --- a/test/helpers/supportsResponse.js +++ b/test/helpers/supportsResponse.js @@ -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";