Skip to content

Commit 4a92da1

Browse files
BridgeARMylesBorins
authored andcommitted
querystring: lazy loaded
PR-URL: #20567 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
1 parent 0ace8f9 commit 4a92da1

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

‎lib/internal/url.js‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ const {
2727
CHAR_LOWERCASE_A,
2828
CHAR_LOWERCASE_Z,
2929
}=require('internal/constants');
30-
constquerystring=require('querystring');
30+
31+
// Lazy loaded for startup performance.
32+
letquerystring;
3133

3234
const{ platform }=process;
3335
constisWindows=platform==='win32';
@@ -771,8 +773,10 @@ function parseParams(qs) {
771773
}elseif(encodeCheck>0){
772774
// eslint-disable-next-line no-extra-boolean-cast
773775
if(!!isHexTable[code]){
774-
if(++encodeCheck===3)
776+
if(++encodeCheck===3){
777+
querystring=require('querystring');
775778
encoded=true;
779+
}
776780
}else{
777781
encodeCheck=0;
778782
}

‎lib/url.js‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ const slashedProtocol = {
9494
'file': true,
9595
'file:': true
9696
};
97-
constquerystring=require('querystring');
9897
const{
9998
CHAR_SPACE,
10099
CHAR_TAB,
@@ -133,6 +132,9 @@ const {
133132
CHAR_AT,
134133
}=require('internal/constants');
135134

135+
// Lazy loaded for startup performance.
136+
letquerystring;
137+
136138
functionurlParse(url,parseQueryString,slashesDenoteHost){
137139
if(urlinstanceofUrl)returnurl;
138140

@@ -233,6 +235,7 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) {
233235
if(simplePath[2]){
234236
this.search=simplePath[2];
235237
if(parseQueryString){
238+
if(querystring===undefined)querystring=require('querystring');
236239
this.query=querystring.parse(this.search.slice(1));
237240
}else{
238241
this.query=this.search.slice(1);
@@ -422,6 +425,7 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) {
422425
this.query=rest.slice(questionIdx+1,hashIdx);
423426
}
424427
if(parseQueryString){
428+
if(querystring===undefined)querystring=require('querystring');
425429
this.query=querystring.parse(this.query);
426430
}
427431
}elseif(parseQueryString){
@@ -584,8 +588,10 @@ Url.prototype.format = function format() {
584588
}
585589
}
586590

587-
if(this.query!==null&&typeofthis.query==='object')
591+
if(this.query!==null&&typeofthis.query==='object'){
592+
if(querystring===undefined)querystring=require('querystring');
588593
query=querystring.stringify(this.query);
594+
}
589595

590596
varsearch=this.search||(query&&('?'+query))||'';
591597

0 commit comments

Comments
 (0)