Merge pull request #3449 from Microsoft/typePredicateASI

Don't consume 'is' keyword if there is a preceding line terminator
This commit is contained in:
Jason Freeman 2015-06-09 11:27:04 -07:00
commit 6490d67509
5 changed files with 40 additions and 1 deletions

View file

@ -1903,7 +1903,7 @@ module ts {
function parseTypeReferenceOrTypePredicate(): TypeReferenceNode | TypePredicateNode {
let typeName = parseEntityName(/*allowReservedWords*/ false, Diagnostics.Type_expected);
if (typeName.kind === SyntaxKind.Identifier && token === SyntaxKind.IsKeyword) {
if (typeName.kind === SyntaxKind.Identifier && token === SyntaxKind.IsKeyword && !scanner.hasPrecedingLineBreak()) {
nextToken();
let node = <TypePredicateNode>createNode(SyntaxKind.TypePredicate, typeName.pos);
node.parameterName = <Identifier>typeName;

View file

@ -0,0 +1,7 @@
//// [typePredicateASI.ts]
interface I {
foo(callback: (a: any, b: any) => void): I
is(): boolean;
}
//// [typePredicateASI.js]

View file

@ -0,0 +1,14 @@
=== tests/cases/conformance/expressions/typeGuards/typePredicateASI.ts ===
interface I {
>I : Symbol(I, Decl(typePredicateASI.ts, 0, 0))
foo(callback: (a: any, b: any) => void): I
>foo : Symbol(foo, Decl(typePredicateASI.ts, 0, 13))
>callback : Symbol(callback, Decl(typePredicateASI.ts, 1, 8))
>a : Symbol(a, Decl(typePredicateASI.ts, 1, 19))
>b : Symbol(b, Decl(typePredicateASI.ts, 1, 26))
>I : Symbol(I, Decl(typePredicateASI.ts, 0, 0))
is(): boolean;
>is : Symbol(is, Decl(typePredicateASI.ts, 1, 46))
}

View file

@ -0,0 +1,14 @@
=== tests/cases/conformance/expressions/typeGuards/typePredicateASI.ts ===
interface I {
>I : I
foo(callback: (a: any, b: any) => void): I
>foo : (callback: (a: any, b: any) => void) => I
>callback : (a: any, b: any) => void
>a : any
>b : any
>I : I
is(): boolean;
>is : () => boolean
}

View file

@ -0,0 +1,4 @@
interface I {
foo(callback: (a: any, b: any) => void): I
is(): boolean;
}