@@ -415,20 +415,51 @@ module ClientRequest {
415415 }
416416
417417 /**
418- * Gets a reference to an instance of the `got` library, including instances
419- * created through chained `extend` calls.
418+ * Represents an instance of the `got` HTTP client library.
420419 */
421- private API:: Node getAGotInstance ( ) {
422- result = [ API:: moduleImport ( "got" ) , getAGotInstance ( ) .getMember ( "extend" ) .getReturn ( ) ]
420+ abstract private class GotInstance extends API:: Node {
421+ /**
422+ * Gets the options object associated with this instance of `got`.
423+ */
424+ API:: Node getOptions ( ) { none ( ) }
425+ }
426+
427+ /**
428+ * Represents the root `got` module import.
429+ * For example: `const got = require('got')`.
430+ */
431+ private class RootGotInstance extends GotInstance {
432+ RootGotInstance ( ) { this = API:: moduleImport ( "got" ) }
433+ }
434+
435+ /**
436+ * Represents an instance of `got` created by calling the `extend()` method.
437+ * It may also be chained with multiple calls to `extend()`.
438+ *
439+ * For example: `const client = got.extend({ prefixUrl: 'https://example.com' })`.
440+ */
441+ private class ExtendGotInstance extends GotInstance {
442+ private GotInstance base ;
443+ private API:: CallNode extendCall ;
444+
445+ ExtendGotInstance ( ) {
446+ extendCall = base .getMember ( "extend" ) .getACall ( ) and
447+ this = extendCall .getReturn ( )
448+ }
449+
450+ override API:: Node getOptions ( ) {
451+ result = extendCall .getParameter ( 0 ) or result = base .getOptions ( )
452+ }
423453 }
424454
425455 /**
426456 * A model of a URL request made using the `got` library.
427457 */
428458 class GotUrlRequest extends ClientRequest:: Range {
459+ GotInstance got ;
460+
429461 GotUrlRequest ( ) {
430- exists ( API:: Node callee , API:: Node got | this = callee .getACall ( ) |
431- got = getAGotInstance ( ) and
462+ exists ( API:: Node callee | this = callee .getACall ( ) |
432463 callee =
433464 [
434465 got ,
@@ -442,11 +473,8 @@ module ClientRequest {
442473 not exists ( this .getOptionArgument ( 1 , "baseUrl" ) )
443474 or
444475 // Handle URL from options passed to extend()
445- exists ( API:: CallNode extendCall |
446- extendCall = API:: moduleImport ( "got" ) .getMember ( "extend" ) .getACall ( ) and
447- result = extendCall .getParameter ( 0 ) .getMember ( "url" ) .asSink ( ) and
448- not exists ( this .getArgument ( 0 ) )
449- )
476+ result = got .getOptions ( ) .getMember ( "url" ) .asSink ( ) and
477+ not exists ( this .getArgument ( 0 ) )
450478 or
451479 // Handle URL from options passed as third argument when first arg is undefined/missing
452480 exists ( API:: InvokeNode optionsCall |
0 commit comments