import { ParseTreeWalker } from '../analyzer/parseTreeWalker' ; import { fail } from '../common/debug' ; import { TextRange } from '../common/textRange' ; import { NameNode , ParseNode , ParseNodeArray , ParseNodeType } from '../parser/parseNodes' ; import { TypeEvaluator } from './typeEvaluatorTypes' ; export class TestWalker extends ParseTreeWalker { constructor ( ) { super ( ) ; } override visitNode ( node ) { const children = super . visitNode ( node ) ; this . _verifyParentChildLinks ( node , children ) ; this . _verifyChildRanges ( node , children ) ; return children ; } private _verifyParentChildLinks ( node , children ) { children . forEach ( ( child ) => { if ( child ) { if ( child . parent !== node ) { fail ( `Child node ${ child . nodeType } does not ` + `contain a reference to its parent ${ node . nodeType }` ) ; } } } ) ; } private _verifyChildRanges ( node , children ) { let prevNode ; children . forEach ( ( child ) => { if ( child ) { let skipCheck = false ; if ( node . nodeType === ParseNodeType . Assignment ) { if ( child === node . typeAnnotationComment ) { skipCheck = true ; } } if ( node . nodeType === ParseNodeType . StringList ) { if ( child === node . typeAnnotation ) { skipCheck = true ; } } if ( ! skipCheck ) { if ( child . start < node . start || TextRange . getEnd ( child ) > TextRange . getEnd ( node ) ) { fail ( `Child node ${ child . nodeType } is not contained within its parent ${ node . nodeType }` ) ; } if ( prevNode ) { if ( child . start < TextRange . getEnd ( prevNode ) ) { if ( prevNode . nodeType !== ParseNodeType . FunctionAnnotation ) { fail ( `Child node is not after previous child node` ) ; } } } prevNode = child ; } } } ) ; } } export class NameTypeWalker extends ParseTreeWalker { constructor ( private _evaluator ) { super ( ) ; } override visitName ( node ) { if ( node . parent ?. nodeType !== ParseNodeType . ImportFromAs && node . parent ?. nodeType !== ParseNodeType . ImportAs ) { if ( this . _evaluator . isNodeReachable ( node , undefined ) ) { this . _evaluator . getType ( node ) ; } } return true ; } }