@@ -489,114 +489,161 @@ DataFlow::SourceNode moduleMember(string path, string m) {
489489 * });
490490 * ```
491491 */
492- class ClassNode extends DataFlow:: SourceNode , DataFlow:: ValueNode {
493- ClassNode ( ) {
494- astNode instanceof ClassDefinition
495- or
496- astNode instanceof Function and
497- exists ( getAPropertyReference ( "prototype" ) )
498- }
492+ class ClassNode extends DataFlow:: SourceNode {
493+ ClassNode:: Range impl ;
494+
495+ ClassNode ( ) { this = impl }
499496
500497 /**
501498 * Gets the name of the class, if it has one.
502499 */
503- string getName ( ) {
504- result = astNode .( ClassDefinition ) .getName ( )
505- or
506- result = astNode .( Function ) .getName ( )
507- }
500+ string getName ( ) { result = impl .getName ( ) }
508501
509502 /**
510503 * Gets a description of the class.
511504 */
512- string describe ( ) {
513- result = astNode .( ClassDefinition ) .describe ( )
514- or
515- result = astNode .( Function ) .describe ( )
516- }
505+ string desribe ( ) { result = impl .describe ( ) }
517506
518507 /**
519508 * Gets the constructor function of this class.
520509 */
521- FunctionNode getConstructor ( ) {
522- result = astNode .( ClassDefinition ) .getConstructor ( ) .getBody ( ) .flow ( )
523- or
524- result = this
525- }
510+ FunctionNode getConstructor ( ) { result = impl .getConstructor ( ) }
526511
527512 /**
528513 * Gets an instance method with the given name, if any.
529514 */
530- FunctionNode getInstanceMethod ( string name ) {
531- exists ( MethodDeclaration method |
532- method = astNode .( ClassDefinition ) .getMethod ( name ) and
533- not method .isStatic ( ) and
534- not method .isAmbient ( ) and
535- not method instanceof ConstructorDeclaration and
536- result = method .getBody ( ) .flow ( )
537- )
538- or
539- result = getAPrototypeReference ( ) .getAPropertyWrite ( name ) .getRhs ( ) .getALocalSource ( )
540- }
515+ FunctionNode getInstanceMethod ( string name ) { result = impl .getInstanceMethod ( name ) }
541516
542517 /**
543518 * Gets an instance method of this class.
544519 *
545520 * The constructor is not considered an instance method.
546521 */
547- FunctionNode getAnInstanceMethod ( ) {
548- exists ( MethodDeclaration method |
549- method = astNode .( ClassDefinition ) .getAMethod ( ) and
550- not method .isStatic ( ) and
551- not method .isAmbient ( ) and
552- not method instanceof ConstructorDeclaration and
553- result = method .getBody ( ) .flow ( )
554- )
555- or
556- result = getAPrototypeReference ( ) .getAPropertyWrite ( ) .getRhs ( ) .getALocalSource ( )
557- }
522+ FunctionNode getAnInstanceMethod ( ) { result = impl .getAnInstanceMethod ( ) }
558523
559524 /**
560525 * Gets the static method of this class with the given name.
561526 */
562- FunctionNode getStaticMethod ( string name ) {
563- exists ( MethodDeclaration method |
564- method = astNode .( ClassDefinition ) .getMethod ( name ) and
565- method .isStatic ( ) and
566- not method .isAmbient ( ) and
567- result = method .getBody ( ) .flow ( )
568- )
569- or
570- result = getAPropertyWrite ( name ) .getRhs ( ) .getALocalSource ( )
571- }
527+ FunctionNode getStaticMethod ( string name ) { result = impl .getStaticMethod ( name ) }
572528
573529 /**
574530 * Gets a static method of this class.
575531 *
576532 * The constructor is not considered a static method.
577533 */
578- FunctionNode getAStaticMethod ( ) {
579- exists ( MethodDeclaration method |
580- method = astNode .( ClassDefinition ) .getAMethod ( ) and
581- method .isStatic ( ) and
582- not method .isAmbient ( ) and
583- result = method .getBody ( ) .flow ( )
584- )
585- or
586- result = getAPropertyWrite ( ) .getRhs ( ) .getALocalSource ( )
587- }
534+ FunctionNode getAStaticMethod ( ) { result = impl .getAStaticMethod ( ) }
535+ }
588536
589- /**
590- * Gets a reference to the prototype of this class.
591- */
592- private DataFlow:: SourceNode getAPrototypeReference ( ) {
593- result = getAPropertyRead ( "prototype" )
594- or
595- result = getAPropertySource ( "prototype" )
596- or
597- exists ( ExtendCall call |
598- call .getDestinationOperand ( ) = getAPropertyRead ( "prototype" ) and
599- result = call .getASourceOperand ( )
600- )
537+ module ClassNode {
538+ class Range extends DataFlow:: SourceNode , DataFlow:: ValueNode {
539+ Range ( ) {
540+ astNode instanceof ClassDefinition
541+ or
542+ astNode instanceof Function and
543+ exists ( getAPropertyReference ( "prototype" ) )
544+ }
545+
546+ /**
547+ * Gets the name of the class, if it has one.
548+ */
549+ string getName ( ) {
550+ result = astNode .( ClassDefinition ) .getName ( )
551+ or
552+ result = astNode .( Function ) .getName ( )
553+ }
554+
555+ /**
556+ * Gets a description of the class.
557+ */
558+ string describe ( ) {
559+ result = astNode .( ClassDefinition ) .describe ( )
560+ or
561+ result = astNode .( Function ) .describe ( )
562+ }
563+
564+ /**
565+ * Gets the constructor function of this class.
566+ */
567+ FunctionNode getConstructor ( ) {
568+ result = astNode .( ClassDefinition ) .getConstructor ( ) .getBody ( ) .flow ( )
569+ or
570+ result = this
571+ }
572+
573+ /**
574+ * Gets an instance method with the given name, if any.
575+ */
576+ FunctionNode getInstanceMethod ( string name ) {
577+ exists ( MethodDeclaration method |
578+ method = astNode .( ClassDefinition ) .getMethod ( name ) and
579+ not method .isStatic ( ) and
580+ not method .isAmbient ( ) and
581+ not method instanceof ConstructorDeclaration and
582+ result = method .getBody ( ) .flow ( )
583+ )
584+ or
585+ result = getAPrototypeReference ( ) .getAPropertyWrite ( name ) .getRhs ( ) .getALocalSource ( )
586+ }
587+
588+ /**
589+ * Gets an instance method of this class.
590+ *
591+ * The constructor is not considered an instance method.
592+ */
593+ FunctionNode getAnInstanceMethod ( ) {
594+ exists ( MethodDeclaration method |
595+ method = astNode .( ClassDefinition ) .getAMethod ( ) and
596+ not method .isStatic ( ) and
597+ not method .isAmbient ( ) and
598+ not method instanceof ConstructorDeclaration and
599+ result = method .getBody ( ) .flow ( )
600+ )
601+ or
602+ result = getAPrototypeReference ( ) .getAPropertyWrite ( ) .getRhs ( ) .getALocalSource ( )
603+ }
604+
605+ /**
606+ * Gets the static method of this class with the given name.
607+ */
608+ FunctionNode getStaticMethod ( string name ) {
609+ exists ( MethodDeclaration method |
610+ method = astNode .( ClassDefinition ) .getMethod ( name ) and
611+ method .isStatic ( ) and
612+ not method .isAmbient ( ) and
613+ result = method .getBody ( ) .flow ( )
614+ )
615+ or
616+ result = getAPropertyWrite ( name ) .getRhs ( ) .getALocalSource ( )
617+ }
618+
619+ /**
620+ * Gets a static method of this class.
621+ *
622+ * The constructor is not considered a static method.
623+ */
624+ FunctionNode getAStaticMethod ( ) {
625+ exists ( MethodDeclaration method |
626+ method = astNode .( ClassDefinition ) .getAMethod ( ) and
627+ method .isStatic ( ) and
628+ not method .isAmbient ( ) and
629+ result = method .getBody ( ) .flow ( )
630+ )
631+ or
632+ result = getAPropertyWrite ( ) .getRhs ( ) .getALocalSource ( )
633+ }
634+
635+ /**
636+ * Gets a reference to the prototype of this class.
637+ */
638+ private DataFlow:: SourceNode getAPrototypeReference ( ) {
639+ result = getAPropertyRead ( "prototype" )
640+ or
641+ result = getAPropertySource ( "prototype" )
642+ or
643+ exists ( ExtendCall call |
644+ call .getDestinationOperand ( ) = getAPropertyRead ( "prototype" ) and
645+ result = call .getASourceOperand ( )
646+ )
647+ }
601648 }
602649}
0 commit comments