take token kind from the tree in case if token kind from scanner is different

This commit is contained in:
Vladimir Matveev 2014-12-01 13:29:49 -08:00
parent 9f0e85cb8e
commit 7358b0f7d3
2 changed files with 22 additions and 2 deletions

View File

@ -146,7 +146,7 @@ module ts.formatting {
if (lastTokenInfo && expectedScanAction === lastScanAction) {
// readTokenInfo was called before with the same expected scan action.
// No need to re-scan text, return existing 'lastTokenInfo'
return lastTokenInfo;
return fixTokenKind(lastTokenInfo, n);
}
if (scanner.getStartPos() !== savedPos) {
@ -207,11 +207,13 @@ module ts.formatting {
}
}
return lastTokenInfo = {
lastTokenInfo = {
leadingTrivia: leadingTrivia,
trailingTrivia: trailingTrivia,
token: token
}
return fixTokenKind(lastTokenInfo, n);
}
function isOnToken(): boolean {
@ -219,5 +221,16 @@ module ts.formatting {
var startPos = (lastTokenInfo && lastTokenInfo.token.pos) || scanner.getStartPos();
return startPos < endPos && current !== SyntaxKind.EndOfFileToken && !isTrivia(current);
}
// when containing node in the tree is token
// but its kind differs from the kind that was returned by the scanner,
// then kind needs to be fixed. This might happen in cases
// when parser interprets token differently, i.e keyword treated as identifier
function fixTokenKind(tokenInfo: TokenInfo, container: Node): TokenInfo {
if (isToken(container) && tokenInfo.token.kind !== container.kind) {
tokenInfo.token.kind = container.kind;
}
return tokenInfo;
}
}
}

View File

@ -0,0 +1,7 @@
/// <reference path='fourslash.ts'/>
////declare var module/*1*/
goTo.marker("1");
edit.insert(";");
verify.currentLineContentIs("declare var module;");