Skip to content

Commit

Permalink
feat(perf): hoist final regexp
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLarkInn committed Jul 1, 2017
1 parent 5806d15 commit 987a9f3
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/RequestShortener.js
Expand Up @@ -9,6 +9,7 @@ const NORMALIZE_SLASH_DIRECTION_REGEXP = /\\/g;
const PATH_CHARS_REGEXP = /[-[\]{}()*+?.,\\^$|#\s]/g;
const SEPERATOR_REGEXP = /[\/\\]$/;
const FRONT_OR_BACK_BANG_REGEXP = /^!|!$/g;
const INDEX_JS_REGEXP = /\/index.js(!|\?|\(query\))/g;

const normalizeBackSlashDirection = (request) => {
return request.replace(NORMALIZE_SLASH_DIRECTION_REGEXP, "/");
Expand Down Expand Up @@ -41,8 +42,6 @@ class RequestShortener {
this.buildinsAsModule = buildinsAsModule;
this.buildinsRegExp = createRegExpForPath(buildins);
}

this.indexJsRegExp = /\/index.js(!|\?|\(query\))/g;
}

shorten(request) {
Expand All @@ -56,7 +55,7 @@ class RequestShortener {
request = request.replace(this.parentDirectoryRegExp, "!..");
if(!this.buildinsAsModule && this.buildinsRegExp)
request = request.replace(this.buildinsRegExp, "!(webpack)");
request = request.replace(this.indexJsRegExp, "$1");
request = request.replace(INDEX_JS_REGEXP, "$1");
return request.replace(FRONT_OR_BACK_BANG_REGEXP, "");
}
}
Expand Down

0 comments on commit 987a9f3

Please sign in to comment.