@@ -94,7 +94,6 @@ const slashedProtocol = {
94
94
'file' : true ,
95
95
'file:' : true
96
96
} ;
97
- const querystring = require ( 'querystring' ) ;
98
97
const {
99
98
CHAR_SPACE ,
100
99
CHAR_TAB ,
@@ -133,6 +132,9 @@ const {
133
132
CHAR_AT ,
134
133
} = require ( 'internal/constants' ) ;
135
134
135
+ // Lazy loaded for startup performance.
136
+ let querystring ;
137
+
136
138
function urlParse ( url , parseQueryString , slashesDenoteHost ) {
137
139
if ( url instanceof Url ) return url ;
138
140
@@ -233,6 +235,7 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) {
233
235
if ( simplePath [ 2 ] ) {
234
236
this . search = simplePath [ 2 ] ;
235
237
if ( parseQueryString ) {
238
+ if ( querystring === undefined ) querystring = require ( 'querystring' ) ;
236
239
this . query = querystring . parse ( this . search . slice ( 1 ) ) ;
237
240
} else {
238
241
this . query = this . search . slice ( 1 ) ;
@@ -422,6 +425,7 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) {
422
425
this . query = rest . slice ( questionIdx + 1 , hashIdx ) ;
423
426
}
424
427
if ( parseQueryString ) {
428
+ if ( querystring === undefined ) querystring = require ( 'querystring' ) ;
425
429
this . query = querystring . parse ( this . query ) ;
426
430
}
427
431
} else if ( parseQueryString ) {
@@ -584,8 +588,10 @@ Url.prototype.format = function format() {
584
588
}
585
589
}
586
590
587
- if ( this . query !== null && typeof this . query === 'object' )
591
+ if ( this . query !== null && typeof this . query === 'object' ) {
592
+ if ( querystring === undefined ) querystring = require ( 'querystring' ) ;
588
593
query = querystring . stringify ( this . query ) ;
594
+ }
589
595
590
596
var search = this . search || ( query && ( '?' + query ) ) || '' ;
591
597
0 commit comments