diff --git a/examples/build-common.js b/examples/build-common.js index da2af185a..70be096e9 100644 --- a/examples/build-common.js +++ b/examples/build-common.js @@ -125,7 +125,7 @@ const doCompileAndReplace = (args, prefix, callback) => { stdout .replace(/[\r?\n]*$/, "") .replace( - /\d\d\d\d-(0[1-9]|1[0-2])-(0[1-9]|[1-2]\d|3[0-1])/g, + /\d\d\d\d-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])/g, "XXXX-XX-XX" ) .replace(/([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]/g, "XXXX:XX:XX") diff --git a/examples/template-common.js b/examples/template-common.js index 5e557424d..56b520aae 100644 --- a/examples/template-common.js +++ b/examples/template-common.js @@ -14,7 +14,7 @@ const path = require("path"); function lessStrict(regExpStr) { regExpStr = regExpStr .replace(/node_modules/g, "(node_modules|~)") - .replace(/(\\\/|\\\\)/g, "[\\/\\\\]"); + .replace(/\\\/|\\\\/g, "[\\/\\\\]"); return regExpStr; } diff --git a/lib/CleanPlugin.js b/lib/CleanPlugin.js index c5b1d78e9..6a90a582c 100644 --- a/lib/CleanPlugin.js +++ b/lib/CleanPlugin.js @@ -416,7 +416,7 @@ class CleanPlugin { const currentAssets = new Map(); const now = Date.now(); for (const asset of Object.keys(compilation.assets)) { - if (/^[A-Za-z]:\\|^\/|^\\\\/.test(asset)) continue; + if (/^[a-z]:\\|^\/|^\\\\/i.test(asset)) continue; let normalizedAsset; let newNormalizedAsset = asset.replace(/\\/g, "/"); do { diff --git a/lib/ContextModule.js b/lib/ContextModule.js index e2ea38c1c..337db0935 100644 --- a/lib/ContextModule.js +++ b/lib/ContextModule.js @@ -509,7 +509,7 @@ class ContextModule extends Module { for (const dep of dependencies) { let chunkName = this.options.chunkName; if (chunkName) { - if (!/\[(index|request)\]/.test(chunkName)) { + if (!/\[(?:index|request)\]/.test(chunkName)) { chunkName += "[index]"; } chunkName = chunkName.replace(/\[index\]/g, `${index++}`); diff --git a/lib/ContextModuleFactory.js b/lib/ContextModuleFactory.js index 3e3e01d61..46b3fa267 100644 --- a/lib/ContextModuleFactory.js +++ b/lib/ContextModuleFactory.js @@ -165,7 +165,7 @@ class ContextModuleFactory extends ModuleFactory { loadersRequest = loadersRequest .slice(i) .replace(/!+$/, "") - .replace(/!!+/g, "!"); + .replace(/!{2,}/g, "!"); loaders = loadersRequest === "" ? [] : loadersRequest.split("!"); resource = request.slice(idx + 1); } else { diff --git a/lib/DotenvPlugin.js b/lib/DotenvPlugin.js index 4a0151aca..37a678cd4 100644 --- a/lib/DotenvPlugin.js +++ b/lib/DotenvPlugin.js @@ -25,9 +25,9 @@ const DEFAULT_OPTIONS = { }; // Regex for parsing .env files -// ported from https://github.com/motdotla/dotenv/blob/master/lib/main.js#L32 +// ported from https://github.com/motdotla/dotenv/blob/master/lib/main.js#L49 const LINE = - /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm; + /^\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?$/gm; const PLUGIN_NAME = "DotenvPlugin"; @@ -60,7 +60,7 @@ function parse(src) { let lines = src.toString(); // Convert line breaks to same format - lines = lines.replace(/\r\n?/gm, "\n"); + lines = lines.replace(/\r\n?/g, "\n"); let match; while ((match = LINE.exec(lines)) !== null) { @@ -112,7 +112,7 @@ function _resolveEscapeSequences(value) { function expandValue(value, processEnv, runningParsed) { const env = { ...runningParsed, ...processEnv }; // process.env wins - const regex = /(? { const split = replaced.split("."); const last = split.pop(); if (!last) return ""; - return last && /^(gz|br|map)$/i.test(last) ? `${split.pop()}.${last}` : last; + return last && /^(?:gz|br|map)$/i.test(last) + ? `${split.pop()}.${last}` + : last; }; class ManifestPlugin { diff --git a/lib/ModuleFilenameHelpers.js b/lib/ModuleFilenameHelpers.js index 638d821ff..1be1cb4f8 100644 --- a/lib/ModuleFilenameHelpers.js +++ b/lib/ModuleFilenameHelpers.js @@ -115,7 +115,7 @@ const lazyObject = (obj) => { return newObj; }; -const SQUARE_BRACKET_TAG_REGEXP = /\[\\*([\w-]+)\\*\]/gi; +const SQUARE_BRACKET_TAG_REGEXP = /\[\\*([\w-]+)\\*\]/g; /** * @typedef {object} ModuleFilenameTemplateContext * @property {string} identifier the identifier of the module diff --git a/lib/NormalModule.js b/lib/NormalModule.js index 02164f6b0..ab8650f24 100644 --- a/lib/NormalModule.js +++ b/lib/NormalModule.js @@ -123,7 +123,7 @@ const getExtractSourceMap = memoize(() => require("./util/extractSourceMap")); const getValidate = memoize(() => require("schema-utils").validate); -const ABSOLUTE_PATH_REGEX = /^([a-zA-Z]:\\|\\\\|\/)/; +const ABSOLUTE_PATH_REGEX = /^(?:[a-z]:\\|\\\\|\/)/i; /** * @typedef {object} LoaderItem @@ -360,7 +360,7 @@ class NormalModule extends Module { /** @type {NormalModuleCreateData['rawRequest']} */ this.rawRequest = rawRequest; /** @type {boolean} */ - this.binary = /^(asset|webassembly)\b/.test(type); + this.binary = /^(?:asset|webassembly)\b/.test(type); /** @type {NormalModuleCreateData['parser'] | undefined} */ this.parser = parser; /** @type {NormalModuleCreateData['parserOptions']} */ diff --git a/lib/NormalModuleFactory.js b/lib/NormalModuleFactory.js index 97d4532a7..9b16f0c42 100644 --- a/lib/NormalModuleFactory.js +++ b/lib/NormalModuleFactory.js @@ -853,7 +853,7 @@ class NormalModuleFactory extends ModuleFactory { * @param {string} context context */ const defaultResolve = (context) => { - if (/^($|\?)/.test(unresolvedResource)) { + if (/^(?:$|\?)/.test(unresolvedResource)) { resourceData = { ...cacheParseResource(unresolvedResource), resource: unresolvedResource, @@ -1185,7 +1185,7 @@ Add the extension to the request.` (err, resolvedResource) => { if (!err && resolvedResource) { let hint = ""; - const match = /(\.[^.]+)(\?|$)/.exec(unresolvedResource); + const match = /\.[^.]+(?:\?|$)/.exec(unresolvedResource); if (match) { const fixedRequest = unresolvedResource.replace( /(\.[^.]+)(\?|$)/, diff --git a/lib/RuntimePlugin.js b/lib/RuntimePlugin.js index ca2b3afeb..0f30ad19b 100644 --- a/lib/RuntimePlugin.js +++ b/lib/RuntimePlugin.js @@ -111,6 +111,8 @@ const TREE_DEPENDENCIES = { [RuntimeGlobals.shareScopeMap]: [RuntimeGlobals.hasOwnProperty] }; +const FULLHASH_REGEXP = /\[(?:full)?hash(?::\d+)?\]/; + const PLUGIN_NAME = "RuntimePlugin"; class RuntimePlugin { @@ -266,7 +268,7 @@ class RuntimePlugin { if ( typeof publicPath !== "string" || - /\[(full)?hash\]/.test(publicPath) + /\[(?:full)?hash\]/.test(publicPath) ) { module.fullHash = true; } @@ -314,9 +316,7 @@ class RuntimePlugin { .tap(PLUGIN_NAME, (chunk, set, { chunkGraph }) => { if ( typeof compilation.outputOptions.chunkFilename === "string" && - /\[(full)?hash(:\d+)?\]/.test( - compilation.outputOptions.chunkFilename - ) + FULLHASH_REGEXP.test(compilation.outputOptions.chunkFilename) ) { set.add(RuntimeGlobals.getFullHash); } @@ -342,9 +342,7 @@ class RuntimePlugin { .tap(PLUGIN_NAME, (chunk, set, { chunkGraph }) => { if ( typeof compilation.outputOptions.cssChunkFilename === "string" && - /\[(full)?hash(:\d+)?\]/.test( - compilation.outputOptions.cssChunkFilename - ) + FULLHASH_REGEXP.test(compilation.outputOptions.cssChunkFilename) ) { set.add(RuntimeGlobals.getFullHash); } @@ -374,7 +372,7 @@ class RuntimePlugin { .for(RuntimeGlobals.getChunkUpdateScriptFilename) .tap(PLUGIN_NAME, (chunk, set) => { if ( - /\[(full)?hash(:\d+)?\]/.test( + FULLHASH_REGEXP.test( compilation.outputOptions.hotUpdateChunkFilename ) ) { @@ -396,7 +394,7 @@ class RuntimePlugin { .for(RuntimeGlobals.getUpdateManifestFilename) .tap(PLUGIN_NAME, (chunk, set) => { if ( - /\[(full)?hash(:\d+)?\]/.test( + FULLHASH_REGEXP.test( compilation.outputOptions.hotUpdateMainFilename ) ) { diff --git a/lib/RuntimeTemplate.js b/lib/RuntimeTemplate.js index b6ab8c94c..295057033 100644 --- a/lib/RuntimeTemplate.js +++ b/lib/RuntimeTemplate.js @@ -84,7 +84,7 @@ function getGlobalObject(definition) { // iife // call expression // expression in parentheses - /^([_\p{L}][_0-9\p{L}]*)?\(.*\)$/iu.test(trimmed) + /^(?:[_\p{L}][_0-9\p{L}]*)?\(.*\)$/iu.test(trimmed) ) { return trimmed; } diff --git a/lib/SourceMapDevToolPlugin.js b/lib/SourceMapDevToolPlugin.js index f6a1779c8..53c4983c9 100644 --- a/lib/SourceMapDevToolPlugin.js +++ b/lib/SourceMapDevToolPlugin.js @@ -51,9 +51,9 @@ const validate = createSchemaValidation( */ const METACHARACTERS_REGEXP = /[-[\]\\/{}()*+?.^$|]/g; -const CONTENT_HASH_DETECT_REGEXP = /\[contenthash(:\w+)?\]/; +const CONTENT_HASH_DETECT_REGEXP = /\[contenthash(?::\w+)?\]/; const CSS_AND_JS_MODULE_EXTENSIONS_REGEXP = /\.((c|m)?js|css)($|\?)/i; -const CSS_EXTENSION_DETECT_REGEXP = /\.css($|\?)/i; +const CSS_EXTENSION_DETECT_REGEXP = /\.css(?:$|\?)/i; const MAP_URL_COMMENT_REGEXP = /\[map\]/g; const URL_COMMENT_REGEXP = /\[url\]/g; const URL_FORMATTING_REGEXP = /^\n\/\/(.*)$/; @@ -310,7 +310,7 @@ class SourceMapDevToolPlugin { if ( typeof module === "string" && - /^(data|https?):/.test(module) + /^(?:data|https?):/.test(module) ) { moduleToSourceNameMapping.set(module, module); continue; diff --git a/lib/Template.js b/lib/Template.js index 229880fa3..b9d60717c 100644 --- a/lib/Template.js +++ b/lib/Template.js @@ -36,10 +36,10 @@ const NUMBER_OF_IDENTIFIER_CONTINUATION_CHARS = const FUNCTION_CONTENT_REGEX = /^function\s?\(\)\s?\{\r?\n?|\r?\n?\}$/g; const INDENT_MULTILINE_REGEX = /^\t/gm; const LINE_SEPARATOR_REGEX = /\r?\n/g; -const IDENTIFIER_NAME_REPLACE_REGEX = /^([^a-zA-Z$_])/; -const IDENTIFIER_ALPHA_NUMERIC_NAME_REPLACE_REGEX = /[^a-zA-Z0-9$]+/g; +const IDENTIFIER_NAME_REPLACE_REGEX = /^([^a-z$_])/i; +const IDENTIFIER_ALPHA_NUMERIC_NAME_REPLACE_REGEX = /[^a-z0-9$]+/gi; const COMMENT_END_REGEX = /\*\//g; -const PATH_NAME_NORMALIZE_REPLACE_REGEX = /[^a-zA-Z0-9_!§$()=\-^°]+/g; +const PATH_NAME_NORMALIZE_REPLACE_REGEX = /[^a-z0-9_!§$()=\-^°]+/gi; const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g; /** diff --git a/lib/TemplatedPathPlugin.js b/lib/TemplatedPathPlugin.js index ccbc817e4..2f515e0b9 100644 --- a/lib/TemplatedPathPlugin.js +++ b/lib/TemplatedPathPlugin.js @@ -18,7 +18,7 @@ const { parseResource } = require("./util/identifier"); /** @typedef {import("./Compilation").PathData} PathData */ /** @typedef {import("./Compiler")} Compiler */ -const REGEXP = /\[\\*([\w:]+)\\*\]/gi; +const REGEXP = /\[\\*([\w:]+)\\*\]/g; /** @type {PathData["prepareId"]} */ const prepareId = (id) => { @@ -32,7 +32,7 @@ const prepareId = (id) => { } + "").replace(/(^[.-]|[^a-zA-Z0-9_-])+/g, "_") + "`; } - return id.replace(/(^[.-]|[^a-zA-Z0-9_-])+/g, "_"); + return id.replace(/(^[.-]|[^a-z0-9_-])+/gi, "_"); }; /** diff --git a/lib/WebpackOptionsApply.js b/lib/WebpackOptionsApply.js index f584574ba..f090e8527 100644 --- a/lib/WebpackOptionsApply.js +++ b/lib/WebpackOptionsApply.js @@ -129,8 +129,8 @@ class WebpackOptionsApply extends OptionsApply { "module", ({ request, dependencyType, contextInfo }, callback) => { if ( - /\.css(\?|$)/.test(contextInfo.issuer) && - /^(\/\/|https?:\/\/|#)/.test(request) + /\.css(?:\?|$)/.test(contextInfo.issuer) && + /^(?:\/\/|https?:\/\/|#)/.test(request) ) { if (dependencyType === "url") { return callback(null, `asset ${request}`); @@ -156,7 +156,7 @@ class WebpackOptionsApply extends OptionsApply { const ExternalsPlugin = require("./ExternalsPlugin"); new ExternalsPlugin(type, ({ request, dependencyType }, callback) => { - if (/^(\/\/|https?:\/\/|#|std:|jsr:|npm:)/.test(request)) { + if (/^(?:\/\/|https?:\/\/|#|std:|jsr:|npm:)/.test(request)) { if (dependencyType === "url") { return callback(null, `asset ${request}`); } else if ( @@ -166,7 +166,7 @@ class WebpackOptionsApply extends OptionsApply { options.experiments.css ) { return callback(null, `css-import ${request}`); - } else if (/^(\/\/|https?:\/\/|std:|jsr:|npm:)/.test(request)) { + } else if (/^(?:\/\/|https?:\/\/|std:|jsr:|npm:)/.test(request)) { return callback(null, `${type} ${request}`); } } diff --git a/lib/cli.js b/lib/cli.js index e12184e64..4cc5e1ca8 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -621,7 +621,7 @@ const parseValueForArgumentConfig = (argConfig, value) => { break; case "number": if (typeof value === "number") return value; - if (typeof value === "string" && /^[+-]?\d*(\.\d*)[eE]\d+$/) { + if (typeof value === "string" && /^[+-]?\d*(\.\d*)e\d+$/i) { const n = Number(value); if (!Number.isNaN(n)) return n; } diff --git a/lib/config/defaults.js b/lib/config/defaults.js index 6ae9a40e1..9538d59f8 100644 --- a/lib/config/defaults.js +++ b/lib/config/defaults.js @@ -1588,7 +1588,7 @@ const applyOutputDefaults = ( "policyName", () => /** @type {NonNullable} */ - (output.uniqueName).replace(/[^a-zA-Z0-9\-#=_/@.%]+/g, "_") || "webpack" + (output.uniqueName).replace(/[^a-z0-9\-#=_/@.%]+/gi, "_") || "webpack" ); D(trustedTypes, "onPolicyCreationFailure", "stop"); } diff --git a/lib/css/CssParser.js b/lib/css/CssParser.js index 9486002e3..cca2a1b6b 100644 --- a/lib/css/CssParser.js +++ b/lib/css/CssParser.js @@ -56,11 +56,11 @@ const CC_EQUAL = "=".charCodeAt(0); const STRING_MULTILINE = /\\[\n\r\f]/g; // https://www.w3.org/TR/css-syntax-3/#whitespace const TRIM_WHITE_SPACES = /(^[ \t\n\r\f]*|[ \t\n\r\f]*$)/g; -const UNESCAPE = /\\([0-9a-fA-F]{1,6}[ \t\n\r\f]?|[\s\S])/g; -const IMAGE_SET_FUNCTION = /^(-\w+-)?image-set$/i; -const OPTIONALLY_VENDOR_PREFIXED_KEYFRAMES_AT_RULE = /^@(-\w+-)?keyframes$/; -const COMPOSES_PROPERTY = /^(composes|compose-with)$/i; -const IS_MODULES = /\.module(s)?\.[^.]+$/i; +const UNESCAPE = /\\([0-9a-f]{1,6}[ \t\n\r\f]?|[\s\S])/gi; +const IMAGE_SET_FUNCTION = /^(?:-\w+-)?image-set$/i; +const OPTIONALLY_VENDOR_PREFIXED_KEYFRAMES_AT_RULE = /^@(?:-\w+-)?keyframes$/; +const COMPOSES_PROPERTY = /^(?:composes|compose-with)$/i; +const IS_MODULES = /\.modules?\.[^.]+$/i; const CSS_COMMENT = /\/\*((?!\*\/).*?)\*\//g; /** @@ -123,8 +123,7 @@ const normalizeUrl = (str, isString) => { return str; }; -// eslint-disable-next-line no-useless-escape -const regexSingleEscape = /[ -,.\/:-@[\]\^`{-~]/; +const regexSingleEscape = /[ -,./:-@[\]^`{-~]/; const regexExcessiveSpaces = /(^|\\+)?(\\[A-F0-9]{1,6})\u0020(?![a-fA-F0-9\u0020])/g; @@ -141,8 +140,7 @@ const escapeIdentifier = (str) => { let value; - // eslint-disable-next-line no-control-regex - if (/[\t\n\f\r\u000B]/.test(character)) { + if (/[\t\n\f\r\v]/.test(character)) { const codePoint = character.charCodeAt(0); value = `\\${codePoint.toString(16).toUpperCase()} `; diff --git a/lib/dependencies/CssIcssExportDependency.js b/lib/dependencies/CssIcssExportDependency.js index 5b7f6a944..197f3cca0 100644 --- a/lib/dependencies/CssIcssExportDependency.js +++ b/lib/dependencies/CssIcssExportDependency.js @@ -60,7 +60,7 @@ const getLocalIdent = (local, module, chunkGraph, runtimeTemplate) => { let localIdentHash = ""; - if (/\[(fullhash|hash)\]/.test(localIdentName)) { + if (/\[(?:fullhash|hash)\]/.test(localIdentName)) { const hashSalt = generator.options.localIdentHashSalt; const hashDigest = /** @type {string} */ @@ -113,8 +113,8 @@ const getLocalIdent = (local, module, chunkGraph, runtimeTemplate) => { if (typeof id !== "string") return id; return id - .replace(/^([.-]|[^a-zA-Z0-9_-])+/, "") - .replace(/[^a-zA-Z0-9_-]+/g, "_"); + .replace(/^([.-]|[^a-z0-9_-])+/i, "") + .replace(/[^a-z0-9_-]+/gi, "_"); }, filename: relativeResourcePath, hash: localIdentHash, @@ -135,7 +135,7 @@ const getLocalIdent = (local, module, chunkGraph, runtimeTemplate) => { } // Protect the first character from unsupported values - return localIdent.replace(/^((-?[0-9])|--)/, "_$1"); + return localIdent.replace(/^((-?\d)|--)/, "_$1"); }; // 0 - replace, 1 - replace, 2 - append, 2 - once diff --git a/lib/ids/IdHelpers.js b/lib/ids/IdHelpers.js index 44b471753..504d885f2 100644 --- a/lib/ids/IdHelpers.js +++ b/lib/ids/IdHelpers.js @@ -56,7 +56,7 @@ const avoidNumber = (str) => { * @returns {string} id representation */ const requestToId = (request) => - request.replace(/^(\.\.?\/)+/, "").replace(/(^[.-]|[^a-zA-Z0-9_-])+/g, "_"); + request.replace(/^(\.\.?\/)+/, "").replace(/(^[.-]|[^a-z0-9_-])+/gi, "_"); /** * @param {string} string the string diff --git a/lib/javascript/JavascriptParser.js b/lib/javascript/JavascriptParser.js index 088d6eda4..61f49e21c 100644 --- a/lib/javascript/JavascriptParser.js +++ b/lib/javascript/JavascriptParser.js @@ -4891,7 +4891,7 @@ class JavascriptParser extends Parser { ]).some( (comment) => comment.type === "Block" && - /^\s*(#|@)__PURE__\s*$/.test(comment.value) + /^\s*(?:#|@)__PURE__\s*$/.test(comment.value) ); if (!pureFlag) return false; commentsStartPos = /** @type {Range} */ (expr.callee.range)[1]; diff --git a/lib/library/AssignLibraryPlugin.js b/lib/library/AssignLibraryPlugin.js index f8f00df18..63ed17292 100644 --- a/lib/library/AssignLibraryPlugin.js +++ b/lib/library/AssignLibraryPlugin.js @@ -33,7 +33,7 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin"); */ const KEYWORD_REGEX = - /^(await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|finally|for|function|if|implements|import|in|instanceof|interface|let|new|null|package|private|protected|public|return|super|switch|static|this|throw|try|true|typeof|var|void|while|with|yield)$/; + /^(?:await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|finally|for|function|if|implements|import|in|instanceof|interface|let|new|null|package|private|protected|public|return|super|switch|static|this|throw|try|true|typeof|var|void|while|with|yield)$/; const IDENTIFIER_REGEX = /^[\p{L}\p{Nl}$_][\p{L}\p{Nl}$\p{Mn}\p{Mc}\p{Nd}\p{Pc}]*$/iu; diff --git a/lib/optimize/MangleExportsPlugin.js b/lib/optimize/MangleExportsPlugin.js index 39383da8f..711067223 100644 --- a/lib/optimize/MangleExportsPlugin.js +++ b/lib/optimize/MangleExportsPlugin.js @@ -69,11 +69,11 @@ const mangleExportsInfo = (deterministic, exportsInfo, isNamespace) => { // Can the export be mangled? exportInfo.canMangle !== true || // Never rename 1 char exports - (name.length === 1 && /^[a-zA-Z0-9_$]/.test(name)) || + (name.length === 1 && /^[a-z0-9_$]/i.test(name)) || // Don't rename 2 char exports in deterministic mode (deterministic && name.length === 2 && - /^[a-zA-Z_$][a-zA-Z0-9_$]|^[1-9][0-9]/.test(name)) || + /^[a-z_$][a-z0-9_$]|^[1-9][0-9]/i.test(name)) || // Don't rename exports that are not provided (avoidMangleNonProvided && exportInfo.provided !== true) ) { diff --git a/lib/schemes/HttpUriPlugin.js b/lib/schemes/HttpUriPlugin.js index 90705cdee..265b9c7fb 100644 --- a/lib/schemes/HttpUriPlugin.js +++ b/lib/schemes/HttpUriPlugin.js @@ -104,9 +104,7 @@ const validate = createSchemaValidation( * @returns {string} safe path */ const toSafePath = (str) => - str - .replace(/^[^a-zA-Z0-9]+|[^a-zA-Z0-9]+$/g, "") - .replace(/[^a-zA-Z0-9._-]+/g, "_"); + str.replace(/^[^a-z0-9]+|[^a-z0-9]+$/gi, "").replace(/[^a-z0-9._-]+/gi, "_"); /** * @param {Buffer} content content diff --git a/lib/sharing/ConsumeSharedPlugin.js b/lib/sharing/ConsumeSharedPlugin.js index e261e316d..ce3a31186 100644 --- a/lib/sharing/ConsumeSharedPlugin.js +++ b/lib/sharing/ConsumeSharedPlugin.js @@ -159,7 +159,7 @@ class ConsumeSharedPlugin { }; const directFallback = config.import && - /^(\.\.?(\/|$)|\/|[A-Za-z]:|\\\\)/.test(config.import); + /^(?:\.\.?(?:\/|$)|\/|[A-Z]:|\\\\)/i.test(config.import); return Promise.all([ new Promise( /** @@ -215,13 +215,13 @@ class ConsumeSharedPlugin { } let packageName = config.packageName; if (packageName === undefined) { - if (/^(\/|[A-Za-z]:|\\\\)/.test(request)) { + if (/^(?:\/|[A-Z]:|\\\\)/i.test(request)) { // For relative or absolute requests we don't automatically use a packageName. // If wished one can specify one with the packageName option. resolve(); return; } - const match = /^((?:@[^\\/]+[\\/])?[^\\/]+)/.exec(request); + const match = /^(?:@[^\\/]+[\\/])?[^\\/]+/.exec(request); if (!match) { requiredVersionWarning( "Unable to extract the package name from request." diff --git a/lib/sharing/ProvideSharedPlugin.js b/lib/sharing/ProvideSharedPlugin.js index 5ad4c3d08..8ba29b801 100644 --- a/lib/sharing/ProvideSharedPlugin.js +++ b/lib/sharing/ProvideSharedPlugin.js @@ -95,13 +95,13 @@ class ProvideSharedPlugin { /** @type {Map} */ const prefixMatchProvides = new Map(); for (const [request, config] of this._provides) { - if (/^(\/|[A-Za-z]:\\|\\\\|\.\.?(\/|$))/.test(request)) { + if (/^(?:\/|[A-Z]:\\|\\\\|\.\.?(?:\/|$))/i.test(request)) { // relative request resolvedProvideMap.set(request, { config, version: config.version }); - } else if (/^(\/|[A-Za-z]:\\|\\\\)/.test(request)) { + } else if (/^(?:\/|[A-Z]:\\|\\\\)/i.test(request)) { // absolute path resolvedProvideMap.set(request, { config, diff --git a/lib/sharing/resolveMatchedConfigs.js b/lib/sharing/resolveMatchedConfigs.js index 3611d605d..a1eec87f4 100644 --- a/lib/sharing/resolveMatchedConfigs.js +++ b/lib/sharing/resolveMatchedConfigs.js @@ -54,7 +54,7 @@ module.exports.resolveMatchedConfigs = (compilation, configs) => { return Promise.all( // eslint-disable-next-line array-callback-return configs.map(([request, config]) => { - if (/^\.\.?(\/|$)/.test(request)) { + if (/^\.\.?(?:\/|$)/.test(request)) { // relative request return new Promise((resolve) => { resolver.resolve( @@ -77,7 +77,7 @@ module.exports.resolveMatchedConfigs = (compilation, configs) => { } ); }); - } else if (/^(\/|[A-Za-z]:\\|\\\\)/.test(request)) { + } else if (/^(?:\/|[a-z]:\\|\\\\)/i.test(request)) { // absolute path resolved.set(request, config); } else if (request.endsWith("/")) { diff --git a/lib/sharing/utils.js b/lib/sharing/utils.js index 26e731ae5..689baa309 100644 --- a/lib/sharing/utils.js +++ b/lib/sharing/utils.js @@ -15,30 +15,30 @@ const { dirname, join, readJson } = require("../util/fs"); const RE_URL_GITHUB_EXTREME_SHORT = /^[^/@:.\s][^/@:\s]*\/[^@:\s]*[^/@:\s]#\S+/; // Short url with specific protocol. eg: github:foo/bar -const RE_GIT_URL_SHORT = /^(github|gitlab|bitbucket|gist):\/?[^/.]+\/?/i; +const RE_GIT_URL_SHORT = /^(?:github|gitlab|bitbucket|gist):\/?[^/.]+\/?/i; // Currently supported protocols const RE_PROTOCOL = - /^((git\+)?(ssh|https?|file)|git|github|gitlab|bitbucket|gist):$/i; + /^(?:(?:git\+)?(?:ssh|https?|file)|git|github|gitlab|bitbucket|gist):$/i; // Has custom protocol -const RE_CUSTOM_PROTOCOL = /^((git\+)?(ssh|https?|file)|git):\/\//i; +const RE_CUSTOM_PROTOCOL = /^(?:(?:git\+)?(?:ssh|https?|file)|git):\/\//i; // Valid hash format for npm / yarn ... const RE_URL_HASH_VERSION = /#(?:semver:)?(.+)/; // Simple hostname validate -const RE_HOSTNAME = /^(?:[^/.]+(\.[^/]+)+|localhost)$/; +const RE_HOSTNAME = /^(?:[^/.]+(?:\.[^/]+)+|localhost)$/; // For hostname with colon. eg: ssh://user@github.com:foo/bar const RE_HOSTNAME_WITH_COLON = /([^/@#:.]+(?:\.[^/@#:.]+)+|localhost):([^#/0-9]+)/; // Reg for url without protocol -const RE_NO_PROTOCOL = /^([^/@#:.]+(?:\.[^/@#:.]+)+)/; +const RE_NO_PROTOCOL = /^[^/@#:.]+(?:\.[^/@#:.]+)+/; // RegExp for version string -const VERSION_PATTERN_REGEXP = /^([\d^=v<>~]|[*xX]$)/; +const VERSION_PATTERN_REGEXP = /^(?:[\d^=v<>~]|[*xX]$)/; // Specific protocol for short url without normal hostname const PROTOCOLS_FOR_SHORT = [ diff --git a/lib/stats/DefaultStatsPrinterPlugin.js b/lib/stats/DefaultStatsPrinterPlugin.js index 83bd6a316..5c515c70f 100644 --- a/lib/stats/DefaultStatsPrinterPlugin.js +++ b/lib/stats/DefaultStatsPrinterPlugin.js @@ -799,7 +799,7 @@ const ERROR_PRINTERS = { "error.file": (file, { bold }) => bold(file), "error.moduleName": (moduleName, { bold }) => moduleName.includes("!") - ? `${bold(moduleName.replace(/^(\s|\S)*!/, ""))} (${moduleName})` + ? `${bold(moduleName.replace(/^([\s\S])*!/, ""))} (${moduleName})` : `${bold(moduleName)}`, "error.loc": (loc, { green }) => green(loc), "error.message": (message, { bold, formatError }) => diff --git a/lib/util/concatenate.js b/lib/util/concatenate.js index 5f2f5abbd..1c0cccff5 100644 --- a/lib/util/concatenate.js +++ b/lib/util/concatenate.js @@ -110,7 +110,7 @@ function findNewName(oldName, usedNamed1, usedNamed2, extraInfo) { // Remove uncool stuff extraInfo = extraInfo.replace( - /\.+\/|(\/index)?\.([a-zA-Z0-9]{1,4})($|\s|\?)|\s*\+\s*\d+\s*modules/g, + /\.+\/|(?:\/index)?\.[a-zA-Z0-9]{1,4}(?:$|\s|\?)|\s*\+\s*\d+\s*modules/g, "" ); diff --git a/lib/util/conventions.js b/lib/util/conventions.js index f60517870..b10410ecf 100644 --- a/lib/util/conventions.js +++ b/lib/util/conventions.js @@ -20,7 +20,7 @@ const preserveCamelCase = (string) => { for (let i = 0; i < result.length; i++) { const character = result[i]; - if (isLastCharLower && /[\p{Lu}]/u.test(character)) { + if (isLastCharLower && /\p{Lu}/u.test(character)) { result = `${result.slice(0, i)}-${result.slice(i)}`; isLastCharLower = false; isLastLastCharUpper = isLastCharUpper; @@ -29,7 +29,7 @@ const preserveCamelCase = (string) => { } else if ( isLastCharUpper && isLastLastCharUpper && - /[\p{Ll}]/u.test(character) + /\p{Ll}/u.test(character) ) { result = `${result.slice(0, i - 1)}-${result.slice(i - 1)}`; isLastLastCharUpper = isLastCharUpper; diff --git a/lib/util/identifier.js b/lib/util/identifier.js index 149292faf..851372d3d 100644 --- a/lib/util/identifier.js +++ b/lib/util/identifier.js @@ -6,7 +6,7 @@ const path = require("path"); -const WINDOWS_ABS_PATH_REGEXP = /^[a-zA-Z]:[\\/]/; +const WINDOWS_ABS_PATH_REGEXP = /^[a-z]:[\\/]/i; const SEGMENTS_SPLIT_REGEXP = /([|!])/; const WINDOWS_PATH_SEPARATOR_REGEXP = /\\/g; diff --git a/lib/util/magicComment.js b/lib/util/magicComment.js index 173dfe53f..de03604a0 100644 --- a/lib/util/magicComment.js +++ b/lib/util/magicComment.js @@ -16,7 +16,7 @@ module.exports.createMagicCommentContext = () => codeGeneration: { strings: false, wasm: false } }); module.exports.webpackCommentRegExp = new RegExp( - /(^|\W)webpack[A-Z]{1,}[A-Za-z]{1,}:/ + /(^|\W)webpack[A-Z][A-Za-z]+:/ ); // regexp to match at least one "magic comment" diff --git a/lib/util/propertyName.js b/lib/util/propertyName.js index b2d8a8f72..c31e21d38 100644 --- a/lib/util/propertyName.js +++ b/lib/util/propertyName.js @@ -5,7 +5,7 @@ "use strict"; -const SAFE_IDENTIFIER = /^[_a-zA-Z$][_a-zA-Z$0-9]*$/; +const SAFE_IDENTIFIER = /^[_a-z$][_a-z$0-9]*$/i; const RESERVED_IDENTIFIER = new Set([ "break", "case", diff --git a/setup/setup.js b/setup/setup.js index 0a67a2b28..d92c60bbb 100644 --- a/setup/setup.js +++ b/setup/setup.js @@ -61,7 +61,7 @@ function checkSymlinkExistsAsync() { */ async function ensureYarnInstalledAsync() { const semverPattern = - /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(\+[0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*)?$/; + /^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:0|[1-9]\d*|\d*[a-z-][0-9a-z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-z-][0-9a-z-]*))*)?(?:\+[0-9a-z-]+(?:\.[0-9a-z-]+)*)?$/i; let hasYarn = false; try { const stdout = await execGetOutput("yarn", ["-v"], "Check yarn version"); diff --git a/test/BenchmarkTestCases.benchmark.mjs b/test/BenchmarkTestCases.benchmark.mjs index 9756cec6d..556208cb4 100644 --- a/test/BenchmarkTestCases.benchmark.mjs +++ b/test/BenchmarkTestCases.benchmark.mjs @@ -277,7 +277,7 @@ function buildConfiguration( ? path.resolve( testDirectory, config.entry - ? /\.(c|m)?js$/.test(config.entry) + ? /\.(?:c|m)?js$/.test(config.entry) ? config.entry : `${config.entry}.js` : "./index.js" diff --git a/test/BuildDependencies.longtest.js b/test/BuildDependencies.longtest.js index 7deb97f74..eb3923c12 100644 --- a/test/BuildDependencies.longtest.js +++ b/test/BuildDependencies.longtest.js @@ -45,7 +45,7 @@ const exec = (n, options = {}) => const rawStdout = chunks.join(""); const stdout = rawStdout.replace( // This warning is expected - /<([ew])> \[.+\n(?:<([ew])> [^[].+\n)*/g, + /<([ew])> \[.+\n(?:<[ew]> [^[].+\n)*/g, (message, type) => { (type === "e" ? errors : warnings).push(message); return ""; diff --git a/test/Errors.test.js b/test/Errors.test.js index 91e4d91af..d81ee5eb0 100644 --- a/test/Errors.test.js +++ b/test/Errors.test.js @@ -8,7 +8,7 @@ const prettyFormat = require("pretty-format").default; const webpack = require(".."); const CWD_PATTERN = new RegExp(process.cwd().replace(/\\/g, "/"), "gm"); -const ERROR_STACK_PATTERN = /(?:\n\s+at\s.*)+/gm; +const ERROR_STACK_PATTERN = /(?:\n\s+at\s.*)+/g; /** * @param {unknown} err an err @@ -51,9 +51,9 @@ const prettyFormatOptions = { }, print(val) { return `"${val - .replace(/\\/gm, "/") - .replace(/"/gm, '\\"') - .replace(/\r?\n/gm, "\\n")}"`; + .replace(/\\/g, "/") + .replace(/"/g, '\\"') + .replace(/\r?\n/g, "\\n")}"`; } } ] diff --git a/test/MemoryLimitTestCases.test.js b/test/MemoryLimitTestCases.test.js index 9e361207e..19a515df7 100644 --- a/test/MemoryLimitTestCases.test.js +++ b/test/MemoryLimitTestCases.test.js @@ -103,7 +103,7 @@ describe("MemoryLimitTestCases", () => { ...args, (err, result) => { if (err) return callback(err); - if (!/\.(js|json|txt)$/.test(args[0])) { + if (!/\.(?:js|json|txt)$/.test(args[0])) { return callback(null, result); } callback(null, result.toString("utf8").replace(/\r/g, "")); diff --git a/test/StatsTestCases.basictest.js b/test/StatsTestCases.basictest.js index 61a4df2d9..2d31c073c 100644 --- a/test/StatsTestCases.basictest.js +++ b/test/StatsTestCases.basictest.js @@ -111,7 +111,7 @@ describe("StatsTestCases", () => { ...args, (err, result) => { if (err) return callback(err); - if (!/\.(js|json|txt)$/.test(args[0])) { + if (!/\.(?:js|json|txt)$/.test(args[0])) { return callback(null, result); } callback(null, result.toString("utf8").replace(/\r/g, "")); @@ -215,7 +215,7 @@ describe("StatsTestCases", () => { .replace(/Unexpected identifier '.+?'/g, "Unexpected identifier") .replace(/[.0-9]+(\s?(bytes|KiB|MiB|GiB))/g, "X$1") .replace( - /ms\s\([0-9a-f]{6,32}\)|(?![0-9]+-)[0-9a-f-]{6,32}\./g, + /ms\s\([0-9a-f]{6,32}\)|(?!\d+-)[0-9a-f-]{6,32}\./g, (match) => `${match.replace(/[0-9a-f]/g, "X")}` ) // Normalize stack traces between Jest v27 and v30 diff --git a/test/configCases/externals/import-assertion/test.filter.js b/test/configCases/externals/import-assertion/test.filter.js index 8b36f73c4..85a1532d5 100644 --- a/test/configCases/externals/import-assertion/test.filter.js +++ b/test/configCases/externals/import-assertion/test.filter.js @@ -1,3 +1,3 @@ "use strict"; -module.exports = () => /^v(1[6-9]|21)/.test(process.version); +module.exports = () => /^v(?:1[6-9]|21)/.test(process.version); diff --git a/test/configCases/externals/import-attributes/test.filter.js b/test/configCases/externals/import-attributes/test.filter.js index c2a0580e7..172b8855c 100644 --- a/test/configCases/externals/import-attributes/test.filter.js +++ b/test/configCases/externals/import-attributes/test.filter.js @@ -1,3 +1,3 @@ "use strict"; -module.exports = () => /^v(2[2-9])/.test(process.version); +module.exports = () => /^v2[2-9]/.test(process.version); diff --git a/test/configCases/parsing/bom/test.config.js b/test/configCases/parsing/bom/test.config.js index 8c5911a01..80a6f7573 100644 --- a/test/configCases/parsing/bom/test.config.js +++ b/test/configCases/parsing/bom/test.config.js @@ -17,7 +17,7 @@ module.exports = { switch (file) { case "resource-with-bom.ext": { - if (!/[\uFEFF]/.test(source)) { + if (!/\uFEFF/.test(source)) { throw new Error(`Not found BOM in ${filename}.`); } break; diff --git a/test/configCases/process-assets/html-plugin/webpack.config.js b/test/configCases/process-assets/html-plugin/webpack.config.js index b8cb54806..c5cc32ca4 100644 --- a/test/configCases/process-assets/html-plugin/webpack.config.js +++ b/test/configCases/process-assets/html-plugin/webpack.config.js @@ -150,7 +150,7 @@ class HtmlInlinePlugin { /** @type {{ start: number, length: number, asset: Asset }[]} */ const matches = []; const regExp = - /<\/script>/g; + /<\/script>/g; let match = regExp.exec(content); while (match) { let url = match[1]; diff --git a/test/helpers/FakeDocument.js b/test/helpers/FakeDocument.js index 279b7e529..8ad36408d 100644 --- a/test/helpers/FakeDocument.js +++ b/test/helpers/FakeDocument.js @@ -264,7 +264,7 @@ class FakeSheet { css = css // Remove comments // @ts-expect-error we use es2018 for such tests - .replace(/\/\*.*?\*\//gms, "") + .replace(/\/\*.*?\*\//gs, "") .replace(/@import url\("([^"]+)"\);/g, (match, url) => { if (!/^https:\/\/test\.cases\/path\//.test(url)) { return url; @@ -376,7 +376,7 @@ class CSSStyleSheet { // Remove comments const cleanCss = cssText // @ts-expect-error we use es2018 for such tests - .replace(/\/\*.*?\*\//gms, ""); + .replace(/\/\*.*?\*\//gs, ""); let ruleStart = 0; diff --git a/tooling/generate-wasm-code.js b/tooling/generate-wasm-code.js index 3aa5c9639..31e6df931 100644 --- a/tooling/generate-wasm-code.js +++ b/tooling/generate-wasm-code.js @@ -21,7 +21,7 @@ const files = ["lib/util/hash/xxhash64.js", "lib/util/hash/md4.js"]; const content = fs.readFileSync(filePath, "utf8"); const regexp = - /\n\/\/[\s]*#region wasm code: (.+) \((.+)\)(.*)\n[\s\S]+?\/\/[\s+]*#endregion\n/g; + /\n\/\/\s*#region wasm code: (.+) \((.+)\)(.*)\n[\s\S]+?\/\/[\s+]*#endregion\n/g; const replaces = new Map();