refactor: hoist RegExps

This commit is contained in:
Nitin Kumar 2023-09-06 15:48:34 +05:30
parent 95f4a3d747
commit a602d8c2c4
1 changed files with 4 additions and 2 deletions

View File

@ -133,8 +133,9 @@ function fetchPathsFromFilesystem(
* @returns {void}
*/
function fetchFromURL(fs, context, url, skipReading, callback) {
const validProtocolPattern = /^[a-z][a-z0-9+.-]*:/i;
// 1. It's an absolute url and it is not `windows` path like `C:\dir\file`
if (/^[a-z][a-z0-9+.-]*:/i.test(url) && !path.win32.isAbsolute(url)) {
if (validProtocolPattern.test(url) && !path.win32.isAbsolute(url)) {
const { protocol } = new urlUtils.URL(url);
if (protocol === "data:") {
@ -159,7 +160,8 @@ function fetchFromURL(fs, context, url, skipReading, callback) {
}
// 2. It's a scheme-relative
if (/^\/\//.test(url)) {
const doubleSlashStartPattern = /^\/\//;
if (doubleSlashStartPattern.test(url)) {
return callback(
new Error(`Failed to parse source map: '${url}' URL is not supported`)
);