@@ -70,75 +70,6 @@ module TypeScript.ASTHelpers {
7070 return true ;
7171 }
7272
73- ///
74- /// Return the ISyntaxElement containing "position"
75- ///
76- export function getAstAtPosition ( script : ISyntaxElement , pos : number , useTrailingTriviaAsLimChar : boolean = true , forceInclusive : boolean = false ) : ISyntaxElement {
77- var top : ISyntaxElement = null ;
78-
79- var pre = function ( cur : ISyntaxElement , walker : IAstWalker ) {
80- if ( ! isShared ( cur ) && isValidAstNode ( cur ) ) {
81- var isInvalid1 = cur . kind ( ) === SyntaxKind . ExpressionStatement && width ( cur ) === 0 ;
82-
83- if ( isInvalid1 ) {
84- walker . options . goChildren = false ;
85- }
86- else {
87- // Add "cur" to the stack if it contains our position
88- // For "identifier" nodes, we need a special case: A position equal to "limChar" is
89- // valid, since the position corresponds to a caret position (in between characters)
90- // For example:
91- // bar
92- // 0123
93- // If "position === 3", the caret is at the "right" of the "r" character, which should be considered valid
94- var inclusive =
95- forceInclusive ||
96- cur . kind ( ) === SyntaxKind . IdentifierName ||
97- cur . kind ( ) === SyntaxKind . MemberAccessExpression ||
98- cur . kind ( ) === SyntaxKind . QualifiedName ||
99- //cur.kind() === SyntaxKind.TypeRef ||
100- cur . kind ( ) === SyntaxKind . VariableDeclaration ||
101- cur . kind ( ) === SyntaxKind . VariableDeclarator ||
102- cur . kind ( ) === SyntaxKind . InvocationExpression ||
103- pos === end ( script ) + lastToken ( script ) . trailingTriviaWidth ( ) ; // Special "EOF" case
104-
105- var minChar = start ( cur ) ;
106- var limChar = end ( cur ) + ( useTrailingTriviaAsLimChar ? trailingTriviaWidth ( cur ) : 0 ) + ( inclusive ? 1 : 0 ) ;
107- if ( pos >= minChar && pos < limChar ) {
108-
109- // Ignore empty lists
110- if ( ( cur . kind ( ) !== SyntaxKind . List && cur . kind ( ) !== SyntaxKind . SeparatedList ) || end ( cur ) > start ( cur ) ) {
111- // TODO: Since ISyntaxElement is sometimes not correct wrt to position, only add "cur" if it's better
112- // than top of the stack.
113- if ( top === null ) {
114- top = cur ;
115- }
116- else if ( start ( cur ) >= start ( top ) &&
117- ( end ( cur ) + ( useTrailingTriviaAsLimChar ? trailingTriviaWidth ( cur ) : 0 ) ) <= ( end ( top ) + ( useTrailingTriviaAsLimChar ? trailingTriviaWidth ( top ) : 0 ) ) ) {
118- // this new node appears to be better than the one we're
119- // storing. Make this the new node.
120-
121- // However, If the current top is a missing identifier, we
122- // don't want to replace it with another missing identifier.
123- // We want to return the first missing identifier found in a
124- // depth first walk of the tree.
125- if ( width ( top ) !== 0 || width ( cur ) !== 0 ) {
126- top = cur ;
127- }
128- }
129- }
130- }
131-
132- // Don't go further down the tree if pos is outside of [minChar, limChar]
133- walker . options . goChildren = ( minChar <= pos && pos <= limChar ) ;
134- }
135- }
136- } ;
137-
138- getAstWalkerFactory ( ) . walk ( script , pre ) ;
139- return top ;
140- }
141-
14273 export function getExtendsHeritageClause ( clauses : HeritageClauseSyntax [ ] ) : HeritageClauseSyntax {
14374 return getHeritageClause ( clauses , SyntaxKind . ExtendsHeritageClause ) ;
14475 }
0 commit comments