From 2902aa2ba330c56e18ef418695b18c814dc9019b Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 18 Mar 2015 14:21:17 -0700 Subject: [PATCH 1/4] Added tests. --- ...dProperty.ts => goToDefinitionShorthandProperty01.ts} | 0 .../cases/fourslash/goToDefinitionShorthandProperty02.ts | 9 +++++++++ .../cases/fourslash/goToDefinitionShorthandProperty03.ts | 9 +++++++++ 3 files changed, 18 insertions(+) rename tests/cases/fourslash/{goToDefinitionShorthandProperty.ts => goToDefinitionShorthandProperty01.ts} (100%) create mode 100644 tests/cases/fourslash/goToDefinitionShorthandProperty02.ts create mode 100644 tests/cases/fourslash/goToDefinitionShorthandProperty03.ts diff --git a/tests/cases/fourslash/goToDefinitionShorthandProperty.ts b/tests/cases/fourslash/goToDefinitionShorthandProperty01.ts similarity index 100% rename from tests/cases/fourslash/goToDefinitionShorthandProperty.ts rename to tests/cases/fourslash/goToDefinitionShorthandProperty01.ts diff --git a/tests/cases/fourslash/goToDefinitionShorthandProperty02.ts b/tests/cases/fourslash/goToDefinitionShorthandProperty02.ts new file mode 100644 index 00000000000..033cb1d6bab --- /dev/null +++ b/tests/cases/fourslash/goToDefinitionShorthandProperty02.ts @@ -0,0 +1,9 @@ +/// + +////let x = { +//// f/*1*/oo +////} + +goTo.marker("1"); +goTo.definition(); +verify.not.definitionLocationExists(); \ No newline at end of file diff --git a/tests/cases/fourslash/goToDefinitionShorthandProperty03.ts b/tests/cases/fourslash/goToDefinitionShorthandProperty03.ts new file mode 100644 index 00000000000..5e61c19c7cc --- /dev/null +++ b/tests/cases/fourslash/goToDefinitionShorthandProperty03.ts @@ -0,0 +1,9 @@ +/// + +////let /*def*/x = { +//// /*prop*/x +////} + +goTo.marker("prop"); +goTo.definition(); +verify.caretAtMarker("def"); \ No newline at end of file From 773530c699d6716e0bb7c09e868709d0e19efe3c Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 18 Mar 2015 14:35:36 -0700 Subject: [PATCH 2/4] Fixed test. --- tests/cases/fourslash/goToDefinitionShorthandProperty02.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/cases/fourslash/goToDefinitionShorthandProperty02.ts b/tests/cases/fourslash/goToDefinitionShorthandProperty02.ts index 033cb1d6bab..1f8fe466277 100644 --- a/tests/cases/fourslash/goToDefinitionShorthandProperty02.ts +++ b/tests/cases/fourslash/goToDefinitionShorthandProperty02.ts @@ -5,5 +5,4 @@ ////} goTo.marker("1"); -goTo.definition(); verify.not.definitionLocationExists(); \ No newline at end of file From acd0fdfba5e6ca693e8999dc4c97aab7dc7edddf Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 18 Mar 2015 14:41:45 -0700 Subject: [PATCH 3/4] Fixed issue where goToDef on a shorthand property of an undefined entity would crash. --- src/services/services.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 067e4580991..98ad85ab612 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3492,7 +3492,6 @@ module ts { } } - let result: DefinitionInfo[] = []; // Because name in short-hand property assignment has two different meanings: property name and property value, // using go-to-definition at such position should go to the variable declaration of the property value rather than @@ -3501,16 +3500,19 @@ module ts { // assignment. This case and others are handled by the following code. if (node.parent.kind === SyntaxKind.ShorthandPropertyAssignment) { let shorthandSymbol = typeInfoResolver.getShorthandAssignmentValueSymbol(symbol.valueDeclaration); + if (!shorthandSymbol) { + return []; + } + let shorthandDeclarations = shorthandSymbol.getDeclarations(); let shorthandSymbolKind = getSymbolKind(shorthandSymbol, typeInfoResolver, node); let shorthandSymbolName = typeInfoResolver.symbolToString(shorthandSymbol); let shorthandContainerName = typeInfoResolver.symbolToString(symbol.parent, node); - forEach(shorthandDeclarations, declaration => { - result.push(getDefinitionInfo(declaration, shorthandSymbolKind, shorthandSymbolName, shorthandContainerName)); - }); - return result + return map(shorthandDeclarations, + declaration => getDefinitionInfo(declaration, shorthandSymbolKind, shorthandSymbolName, shorthandContainerName)); } + let result: DefinitionInfo[] = []; let declarations = symbol.getDeclarations(); let symbolName = typeInfoResolver.symbolToString(symbol); // Do not get scoped name, just the name of the symbol let symbolKind = getSymbolKind(symbol, typeInfoResolver, node); From 3b453e68c8b6c7a15b18ea8f917e532989f13123 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 18 Mar 2015 16:03:33 -0700 Subject: [PATCH 4/4] Extended test. --- .../goToDefinitionShorthandProperty03.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/cases/fourslash/goToDefinitionShorthandProperty03.ts b/tests/cases/fourslash/goToDefinitionShorthandProperty03.ts index 5e61c19c7cc..eb21b159f5a 100644 --- a/tests/cases/fourslash/goToDefinitionShorthandProperty03.ts +++ b/tests/cases/fourslash/goToDefinitionShorthandProperty03.ts @@ -1,9 +1,16 @@ /// -////let /*def*/x = { -//// /*prop*/x +////var /*varDef*/x = { +//// /*varProp*/x +////} +////let /*letDef*/y = { +//// /*letProp*/y ////} -goTo.marker("prop"); +goTo.marker("varProp"); goTo.definition(); -verify.caretAtMarker("def"); \ No newline at end of file +verify.caretAtMarker("varDef"); + +goTo.marker("letProp"); +goTo.definition(); +verify.caretAtMarker("letDef"); \ No newline at end of file