From dab0dbe6f04db3f8f70ffa4573e3cd4c7e7fe18f Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 7 Feb 2018 13:30:58 -0800 Subject: [PATCH] Avoid the class declaration not found assert when the new expression doesnt contain construct signature --- src/services/goToDefinition.ts | 2 +- .../goToDefinitionNewExpressionTargetNotClass.ts | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/services/goToDefinition.ts b/src/services/goToDefinition.ts index d46cd074869..fcad5eb10b0 100644 --- a/src/services/goToDefinition.ts +++ b/src/services/goToDefinition.ts @@ -191,7 +191,7 @@ namespace ts.GoToDefinition { function getConstructSignatureDefinition(): DefinitionInfo[] | undefined { // Applicable only if we are in a new expression, or we are on a constructor declaration // and in either case the symbol has a construct signature definition, i.e. class - if (isNewExpressionTarget(node) || node.kind === SyntaxKind.ConstructorKeyword && symbol.flags & SymbolFlags.Class) { + if (symbol.flags & SymbolFlags.Class && (isNewExpressionTarget(node) || node.kind === SyntaxKind.ConstructorKeyword)) { const cls = find(symbol.declarations, isClassLike) || Debug.fail("Expected declaration to have at least one class-like declaration"); return getSignatureDefinition(cls.members, /*selectConstructors*/ true); } diff --git a/tests/cases/fourslash/goToDefinitionNewExpressionTargetNotClass.ts b/tests/cases/fourslash/goToDefinitionNewExpressionTargetNotClass.ts index 6b03200760d..02a6dca9d52 100644 --- a/tests/cases/fourslash/goToDefinitionNewExpressionTargetNotClass.ts +++ b/tests/cases/fourslash/goToDefinitionNewExpressionTargetNotClass.ts @@ -5,6 +5,12 @@ ////let I: { //// /*constructSignature*/new(): C2; ////}; -////let C = new [|/*invokeExpression*/I|](); +////new [|/*invokeExpression1*/I|](); +////let /*symbolDeclaration*/I2: { +////}; +////new [|/*invokeExpression2*/I2|](); -verify.goToDefinition("invokeExpression", "constructSignature"); +verify.goToDefinition({ + invokeExpression1: "constructSignature", + invokeExpression2: "symbolDeclaration" +});