@@ -94,7 +94,6 @@ const slashedProtocol = {
9494 'file' : true ,
9595 'file:' : true
9696} ;
97- const querystring = require ( 'querystring' ) ;
9897const {
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+ let querystring ;
137+
136138function urlParse ( url , parseQueryString , slashesDenoteHost ) {
137139 if ( url instanceof Url ) return url ;
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 } else if ( parseQueryString ) {
@@ -584,8 +588,10 @@ Url.prototype.format = function format() {
584588 }
585589 }
586590
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' ) ;
588593 query = querystring . stringify ( this . query ) ;
594+ }
589595
590596 var search = this . search || ( query && ( '?' + query ) ) || '' ;
591597
0 commit comments