Skip to content

Commit 987a9f3

Browse files
committed
feat(perf): hoist final regexp
1 parent 5806d15 commit 987a9f3

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

‎lib/RequestShortener.js‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const NORMALIZE_SLASH_DIRECTION_REGEXP = /\\/g;
99
const PATH_CHARS_REGEXP = /[-[\]{}()*+?.,\\^$|#\s]/g;
1010
const SEPERATOR_REGEXP = /[\/\\]$/;
1111
const FRONT_OR_BACK_BANG_REGEXP = /^!|!$/g;
12+
const INDEX_JS_REGEXP = /\/index.js(!|\?|\(query\))/g;
1213

1314
const normalizeBackSlashDirection = (request) => {
1415
return request.replace(NORMALIZE_SLASH_DIRECTION_REGEXP, "/");
@@ -41,8 +42,6 @@ class RequestShortener {
4142
this.buildinsAsModule = buildinsAsModule;
4243
this.buildinsRegExp = createRegExpForPath(buildins);
4344
}
44-
45-
this.indexJsRegExp = /\/index.js(!|\?|\(query\))/g;
4645
}
4746

4847
shorten(request) {
@@ -56,7 +55,7 @@ class RequestShortener {
5655
request = request.replace(this.parentDirectoryRegExp, "!..");
5756
if(!this.buildinsAsModule && this.buildinsRegExp)
5857
request = request.replace(this.buildinsRegExp, "!(webpack)");
59-
request = request.replace(this.indexJsRegExp, "$1");
58+
request = request.replace(INDEX_JS_REGEXP, "$1");
6059
return request.replace(FRONT_OR_BACK_BANG_REGEXP, "");
6160
}
6261
}

0 commit comments

Comments
 (0)