@@ -50,18 +50,28 @@ module ts {
50
50
* position >= start and (position < end or (position === end && token is keyword or identifier))
51
51
*/
52
52
export function getTouchingWord ( sourceFile : SourceFile , position : number ) : Node {
53
- return getTouchingToken ( sourceFile , position , /*allowPositionInLeadingTrivia*/ false , isWord ) ;
53
+ return getTouchingToken ( sourceFile , position , isWord ) ;
54
54
}
55
55
56
56
/* Gets the token whose text has range [start, end) and position >= start
57
57
* and (position < end or (position === end && token is keyword or identifier or numeric\string litera))
58
58
*/
59
59
export function getTouchingPropertyName ( sourceFile : SourceFile , position : number ) : Node {
60
- return getTouchingToken ( sourceFile , position , /*allowPositionInLeadingTrivia*/ false , isPropertyName ) ;
60
+ return getTouchingToken ( sourceFile , position , isPropertyName ) ;
61
+ }
62
+
63
+ /** Returns the token if position is in [start, end) or if position === end and includeItemAtEndPosition(token) === true */
64
+ export function getTouchingToken ( sourceFile : SourceFile , position : number , includeItemAtEndPosition ?: ( n : Node ) => boolean ) : Node {
65
+ return getTokenAtPositionWorker ( sourceFile , position , /*allowPositionInLeadingTrivia*/ false , includeItemAtEndPosition ) ;
66
+ }
67
+
68
+ /** Returns a token if position is in [start-of-leading-trivia, end) */
69
+ export function getTokenAtPosition ( sourceFile : SourceFile , position : number ) : Node {
70
+ return getTokenAtPositionWorker ( sourceFile , position , /*allowPositionInLeadingTrivia*/ true , /*includeItemAtEndPosition*/ undefined ) ;
61
71
}
62
72
63
73
/** Get the token whose text contains the position */
64
- export function getTouchingToken ( sourceFile : SourceFile , position : number , allowPositionInLeadingTrivia : boolean , includeItemAtEndPosition ? : ( n : Node ) => boolean ) : Node {
74
+ function getTokenAtPositionWorker ( sourceFile : SourceFile , position : number , allowPositionInLeadingTrivia : boolean , includeItemAtEndPosition : ( n : Node ) => boolean ) : Node {
65
75
var current : Node = sourceFile ;
66
76
outer: while ( true ) {
67
77
if ( isToken ( current ) ) {
@@ -101,7 +111,7 @@ module ts {
101
111
export function findTokenOnLeftOfPosition ( file : SourceFile , position : number ) : Node {
102
112
// Ideally, getTokenAtPosition should return a token. However, it is currently
103
113
// broken, so we do a check to make sure the result was indeed a token.
104
- var tokenAtPosition = getTouchingToken ( file , position , /*allowPositionInLeadingTrivia*/ true ) ;
114
+ var tokenAtPosition = getTokenAtPosition ( file , position ) ;
105
115
if ( isToken ( tokenAtPosition ) && position > tokenAtPosition . getStart ( file ) && position < tokenAtPosition . getEnd ( ) ) {
106
116
return tokenAtPosition ;
107
117
}
0 commit comments