From 13e1ccdd01d611e57e7d1791424d3e8ff12841bc Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 27 Aug 2019 16:22:22 -0700 Subject: [PATCH] goto-def should treat constructor functions as functions (#33109) * goto-def:special handling for constructor functions * Just treat constructor functions like functions * Even simpler fallback --- src/services/goToDefinition.ts | 2 +- .../gotoDefinitionConstructorFunction.ts | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/gotoDefinitionConstructorFunction.ts diff --git a/src/services/goToDefinition.ts b/src/services/goToDefinition.ts index e514ca01e79..22d28efd2f4 100644 --- a/src/services/goToDefinition.ts +++ b/src/services/goToDefinition.ts @@ -241,7 +241,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 (symbol.flags & SymbolFlags.Class && (isNewExpressionTarget(node) || node.kind === SyntaxKind.ConstructorKeyword)) { + if (symbol.flags & SymbolFlags.Class && !(symbol.flags & SymbolFlags.Function) && (isNewExpressionTarget(node) || node.kind === SyntaxKind.ConstructorKeyword)) { const cls = find(filteredDeclarations, 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/gotoDefinitionConstructorFunction.ts b/tests/cases/fourslash/gotoDefinitionConstructorFunction.ts new file mode 100644 index 00000000000..aa149e70d7d --- /dev/null +++ b/tests/cases/fourslash/gotoDefinitionConstructorFunction.ts @@ -0,0 +1,15 @@ +/// +// @allowJs: true +// @checkJs: true +// @noEmit: true +// @filename: gotoDefinitionConstructorFunction.js +//// function /*end*/StringStreamm() { +//// } +//// StringStreamm.prototype = { +//// }; +//// +//// function runMode () { +//// new [|/*start*/StringStreamm|]() +//// }; + +verify.goToDefinition('start', 'end')