From 531f3aa0ac222d9ce50dfba8b6b8db5da205dbaa Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 7 May 2015 15:11:46 -0700 Subject: [PATCH 01/20] Nodes -> Node --- src/services/services.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 400bf754a00..52ffc75efe4 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4227,7 +4227,7 @@ module ts { isLiteralNameOfPropertyDeclarationOrIndexAccess(node) || isNameOfExternalModuleImportOrDeclaration(node)) { - let referencedSymbols = getReferencedSymbolsForNodes(node, sourceFilesToSearch, /*findInStrings:*/ false, /*findInComments:*/ false); + let referencedSymbols = getReferencedSymbolsForNode(node, sourceFilesToSearch, /*findInStrings:*/ false, /*findInComments:*/ false); return convertReferencedSymbols(referencedSymbols); } @@ -4879,10 +4879,10 @@ module ts { } Debug.assert(node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.NumericLiteral || node.kind === SyntaxKind.StringLiteral); - return getReferencedSymbolsForNodes(node, program.getSourceFiles(), findInStrings, findInComments); + return getReferencedSymbolsForNode(node, program.getSourceFiles(), findInStrings, findInComments); } - function getReferencedSymbolsForNodes(node: Node, sourceFiles: SourceFile[], findInStrings: boolean, findInComments: boolean): ReferencedSymbol[] { + function getReferencedSymbolsForNode(node: Node, sourceFiles: SourceFile[], findInStrings: boolean, findInComments: boolean): ReferencedSymbol[] { let typeChecker = program.getTypeChecker(); // Labels From 1a17aba26ae0baf681327415d1be2cc55948f7d2 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 15 May 2015 17:00:13 -0700 Subject: [PATCH 02/20] Added tests. --- .../findAllRefsForDefaultExport01.ts | 21 ++++++++++++++++ .../findAllRefsForDefaultExport02.ts | 22 +++++++++++++++++ .../findAllRefsForDefaultExport03.ts | 24 +++++++++++++++++++ .../findAllRefsForDefaultExportNegative01.ts | 14 +++++++++++ .../findAllRefsForDefaultExportNegative02.ts | 15 ++++++++++++ .../findAllRefsForDefaultExportNegative03.ts | 17 +++++++++++++ 6 files changed, 113 insertions(+) create mode 100644 tests/cases/fourslash/findAllRefsForDefaultExport01.ts create mode 100644 tests/cases/fourslash/findAllRefsForDefaultExport02.ts create mode 100644 tests/cases/fourslash/findAllRefsForDefaultExport03.ts create mode 100644 tests/cases/fourslash/findAllRefsForDefaultExportNegative01.ts create mode 100644 tests/cases/fourslash/findAllRefsForDefaultExportNegative02.ts create mode 100644 tests/cases/fourslash/findAllRefsForDefaultExportNegative03.ts diff --git a/tests/cases/fourslash/findAllRefsForDefaultExport01.ts b/tests/cases/fourslash/findAllRefsForDefaultExport01.ts new file mode 100644 index 00000000000..87c439bd9ef --- /dev/null +++ b/tests/cases/fourslash/findAllRefsForDefaultExport01.ts @@ -0,0 +1,21 @@ +/// + +////export default class [|DefaultExportedClass|] { +////} +//// +////var x: [|DefaultExportedClass|]; +//// +////var y = new [|DefaultExportedClass|]; +//// +////namespace [|DefaultExportedClass|] { +//// var local = 100; +////} + +let ranges = test.ranges() +for (let range of ranges) { + goTo.position(range.start); + + for (let expectedReference of ranges) { + verify.referencesAtPositionContains(expectedReference); + } +} \ No newline at end of file diff --git a/tests/cases/fourslash/findAllRefsForDefaultExport02.ts b/tests/cases/fourslash/findAllRefsForDefaultExport02.ts new file mode 100644 index 00000000000..3000b7de92d --- /dev/null +++ b/tests/cases/fourslash/findAllRefsForDefaultExport02.ts @@ -0,0 +1,22 @@ +/// + +////export default function [|DefaultExportedFunction|]() { +//// return [|DefaultExportedFunction|] +////} +//// +////var x: typeof [|DefaultExportedFunction|]; +//// +////var y = [|DefaultExportedFunction|](); +//// +////namespace [|DefaultExportedFunction|] { +//// var local = 100; +////} + +let ranges = test.ranges() +for (let range of ranges) { + goTo.position(range.start); + + for (let expectedReference of ranges) { + verify.referencesAtPositionContains(expectedReference); + } +} \ No newline at end of file diff --git a/tests/cases/fourslash/findAllRefsForDefaultExport03.ts b/tests/cases/fourslash/findAllRefsForDefaultExport03.ts new file mode 100644 index 00000000000..89027879ff1 --- /dev/null +++ b/tests/cases/fourslash/findAllRefsForDefaultExport03.ts @@ -0,0 +1,24 @@ +/// + +////function [|f|]() { +//// return 100; +////} +//// +////export default [|f|]; +//// +////var x: typeof [|f|]; +//// +////var y = [|f|](); +//// +////namespace [|f|] { +//// var local = 100; +////} + +let ranges = test.ranges() +for (let range of ranges) { + goTo.position(range.start); + + for (let expectedReference of ranges) { + verify.referencesAtPositionContains(expectedReference); + } +} \ No newline at end of file diff --git a/tests/cases/fourslash/findAllRefsForDefaultExportNegative01.ts b/tests/cases/fourslash/findAllRefsForDefaultExportNegative01.ts new file mode 100644 index 00000000000..b44ab76b292 --- /dev/null +++ b/tests/cases/fourslash/findAllRefsForDefaultExportNegative01.ts @@ -0,0 +1,14 @@ +/// + +////export default class DefaultExportedClass { +////} +//// +////var x: DefaultExportedClass; +//// +////var y = new DefaultExportedClass; +//// +////namespace /**/DefaultExportedClass { +////} + +goTo.marker(); +verify.referencesCountIs(1); diff --git a/tests/cases/fourslash/findAllRefsForDefaultExportNegative02.ts b/tests/cases/fourslash/findAllRefsForDefaultExportNegative02.ts new file mode 100644 index 00000000000..901cc3ffe0f --- /dev/null +++ b/tests/cases/fourslash/findAllRefsForDefaultExportNegative02.ts @@ -0,0 +1,15 @@ +/// + +////export default function DefaultExportedFunction() { +//// return DefaultExportedFunction +////} +//// +////var x: typeof DefaultExportedFunction; +//// +////var y = DefaultExportedFunction(); +//// +////namespace /**/DefaultExportedFunction { +////} + +goTo.marker(); +verify.referencesCountIs(1); diff --git a/tests/cases/fourslash/findAllRefsForDefaultExportNegative03.ts b/tests/cases/fourslash/findAllRefsForDefaultExportNegative03.ts new file mode 100644 index 00000000000..d9364b2193e --- /dev/null +++ b/tests/cases/fourslash/findAllRefsForDefaultExportNegative03.ts @@ -0,0 +1,17 @@ +/// + +////function f() { +//// return 100; +////} +//// +////export default f; +//// +////var x: typeof f; +//// +////var y = f(); +//// +////namespace /**/f { +////} + +goTo.marker(); +verify.referencesCountIs(1); From 9907d62f3b4f4995b9d3831b52248039357ae533 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 19 May 2015 12:43:58 -0700 Subject: [PATCH 03/20] Added rename tests. --- .../fourslash/renameForDefaultExport01.ts | 23 ++++++++++++++++ .../fourslash/renameForDefaultExport02.ts | 24 +++++++++++++++++ .../fourslash/renameForDefaultExport03.ts | 26 +++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 tests/cases/fourslash/renameForDefaultExport01.ts create mode 100644 tests/cases/fourslash/renameForDefaultExport02.ts create mode 100644 tests/cases/fourslash/renameForDefaultExport03.ts diff --git a/tests/cases/fourslash/renameForDefaultExport01.ts b/tests/cases/fourslash/renameForDefaultExport01.ts new file mode 100644 index 00000000000..ec9c3900a5e --- /dev/null +++ b/tests/cases/fourslash/renameForDefaultExport01.ts @@ -0,0 +1,23 @@ +/// + +/////** +//// * Commenting [|DefaultExportedClass|] +//// */ +////export default class /*1*/[|DefaultExportedClass|] { +////} +//// +////var x: /*2*/[|DefaultExportedClass|]; +//// +////var y = new /*3*/[|DefaultExportedClass|]; +//// +////namespace /*4*/[|DefaultExportedClass|] { +//// var local = 100; +////} + +let markers = test.markers() +for (let marker of markers) { + goTo.position(marker.position); + + verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ true); + verify.renameInfoSucceeded("DefaultExportedClass"); +} \ No newline at end of file diff --git a/tests/cases/fourslash/renameForDefaultExport02.ts b/tests/cases/fourslash/renameForDefaultExport02.ts new file mode 100644 index 00000000000..eea63282f5f --- /dev/null +++ b/tests/cases/fourslash/renameForDefaultExport02.ts @@ -0,0 +1,24 @@ +/// + +/////** +//// * Commenting [|DefaultExportedFunction|] +//// */ +////export default function /*1*/[|DefaultExportedFunction|]() { +//// return /*2*/[|DefaultExportedFunction|] +////} +//// +////var x: typeof /*3*/[|DefaultExportedFunction|]; +//// +////var y = /*4*/[|DefaultExportedFunction|](); +//// +////namespace /*5*/[|DefaultExportedFunction|] { +//// var local = 100; +////} + +let markers = test.markers() +for (let marker of markers) { + goTo.position(marker.position); + + verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ true); + verify.renameInfoSucceeded("DefaultExportedFunction"); +} \ No newline at end of file diff --git a/tests/cases/fourslash/renameForDefaultExport03.ts b/tests/cases/fourslash/renameForDefaultExport03.ts new file mode 100644 index 00000000000..b36b04768ab --- /dev/null +++ b/tests/cases/fourslash/renameForDefaultExport03.ts @@ -0,0 +1,26 @@ +/// + +/////** +//// * Commenting [|f|] +//// */ +////function /*1*/[|f|]() { +//// return 100; +////} +//// +////export default /*2*/[|f|]; +//// +////var x: typeof /*3*/[|f|]; +//// +////var y = /*4*/[|f|](); +//// +////namespace /*5*/[|f|] { +//// var local = 100; +////} + +let markers = test.markers() +for (let marker of markers) { + goTo.position(marker.position); + + verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ true); + verify.renameInfoSucceeded("f"); +} \ No newline at end of file From 693c587b86fdcaac2e6e82955adc21a4e3974d66 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 19 May 2015 15:53:16 -0700 Subject: [PATCH 04/20] Removed unused code, use valueDeclaration for symbol. --- src/compiler/checker.ts | 3 ++- src/services/services.ts | 22 +++++++--------------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index aa2207d5431..a6d95fd3d42 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11833,7 +11833,8 @@ module ts { if (languageVersion === ScriptTarget.ES3) { defaultKeyword = "[\"default\"]"; - } else { + } + else { defaultKeyword = ".default"; } return getGeneratedNameForNode(node.parent) + defaultKeyword; diff --git a/src/services/services.ts b/src/services/services.ts index 52ffc75efe4..1b5ba6752de 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4988,19 +4988,6 @@ module ts { } function getDeclaredName(symbol: Symbol, location: Node) { - // Special case for function expressions, whose names are solely local to their bodies. - let functionExpression = forEach(symbol.declarations, d => d.kind === SyntaxKind.FunctionExpression ? d : undefined); - - // When a name gets interned into a SourceFile's 'identifiers' Map, - // its name is escaped and stored in the same way its symbol name/identifier - // name should be stored. Function expressions, however, are a special case, - // because despite sometimes having a name, the binder unconditionally binds them - // to a symbol with the name "__function". - let name: string; - if (functionExpression && functionExpression.name) { - name = functionExpression.name.text; - } - // If this is an export or import specifier it could have been renamed using the as syntax. // if so we want to search for whatever under the cursor, the symbol is pointing to the alias (name) // so check for the propertyName. @@ -5008,7 +4995,7 @@ module ts { return location.getText(); } - name = typeChecker.symbolToString(symbol); + let name = typeChecker.symbolToString(symbol); return stripQuotes(name); } @@ -5022,7 +5009,12 @@ module ts { } // Special case for function expressions, whose names are solely local to their bodies. - let functionExpression = forEach(declarations, d => d.kind === SyntaxKind.FunctionExpression ? d : undefined); + // TODO (drosen): Why would we have to lookup the interned name for a function expression? + // Shouldn't we have found a scope? Consider a 'Debug.fail()'. + let functionExpression: FunctionExpression; + if (symbol.valueDeclaration && symbol.valueDeclaration.kind === SyntaxKind.FunctionExpression) { + functionExpression = symbol.valueDeclaration; + } // When a name gets interned into a SourceFile's 'identifiers' Map, // its name is escaped and stored in the same way its symbol name/identifier From 24c504415e0e8896980f4a9cad8cc031f86af064 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 19 May 2015 16:15:51 -0700 Subject: [PATCH 05/20] Error smarter. --- src/harness/fourslash.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 8d313c9a1a6..6867863a941 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -882,6 +882,14 @@ module FourSlash { this.activeFile.fileName, this.currentCaretPosition, findInStrings, findInComments); var ranges = this.getRanges(); + + if (!references) { + if (ranges.length !== 0) { + this.raiseError(`Expected ${ranges.length} rename locations; got none.`); + } + return; + } + if (ranges.length !== references.length) { this.raiseError(this.assertionMessage("Rename locations", references.length, ranges.length)); } From 70911a31b656c020558702c8618f7623c5a04c45 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 20 May 2015 14:58:55 -0700 Subject: [PATCH 06/20] Adjust tests. --- .../fourslash/findAllRefsForDefault04.ts | 28 +++++++++++++++++++ .../fourslash/findAllRefsForDefault05.ts | 28 +++++++++++++++++++ .../fourslash/findAllRefsForDefault06.ts | 28 +++++++++++++++++++ ...gative02.ts => findAllRefsForDefault07.ts} | 3 ++ ...gative01.ts => findAllRefsForDefault08.ts} | 3 ++ .../findAllRefsForDefaultExportNegative03.ts | 17 ----------- 6 files changed, 90 insertions(+), 17 deletions(-) create mode 100644 tests/cases/fourslash/findAllRefsForDefault04.ts create mode 100644 tests/cases/fourslash/findAllRefsForDefault05.ts create mode 100644 tests/cases/fourslash/findAllRefsForDefault06.ts rename tests/cases/fourslash/{findAllRefsForDefaultExportNegative02.ts => findAllRefsForDefault07.ts} (76%) rename tests/cases/fourslash/{findAllRefsForDefaultExportNegative01.ts => findAllRefsForDefault08.ts} (72%) delete mode 100644 tests/cases/fourslash/findAllRefsForDefaultExportNegative03.ts diff --git a/tests/cases/fourslash/findAllRefsForDefault04.ts b/tests/cases/fourslash/findAllRefsForDefault04.ts new file mode 100644 index 00000000000..45b008b55fe --- /dev/null +++ b/tests/cases/fourslash/findAllRefsForDefault04.ts @@ -0,0 +1,28 @@ +/// + +////function f() { +//// return 100; +////} +//// +////export default [|f|]; +//// +////var x: typeof f; +//// +////var y = f(); +//// +////namespace /**/[|f|] { +////} + +// The function 'f' and the namespace 'f' don't get merged, +// but the 'export default' site, includes both meanings. + +// Here we are testing whether the 'export default' +// site is included in the references to the namespace. + +goTo.marker(); +let ranges = test.ranges(); +verify.referencesCountIs(ranges.length); + +for (let expectedReference of ranges) { + verify.referencesAtPositionContains(expectedReference); +} diff --git a/tests/cases/fourslash/findAllRefsForDefault05.ts b/tests/cases/fourslash/findAllRefsForDefault05.ts new file mode 100644 index 00000000000..6655138da3b --- /dev/null +++ b/tests/cases/fourslash/findAllRefsForDefault05.ts @@ -0,0 +1,28 @@ +/// + +////function /**/[|f|]() { +//// return 100; +////} +//// +////export default [|f|]; +//// +////var x: typeof [|f|]; +//// +////var y = [|f|](); +//// +////namespace f { +////} + +// The function 'f' and the namespace 'f' don't get merged, +// but the 'export default' site, includes both meanings. + +// Here we are testing whether the 'export default' site +// and all value-uses of 'f' are included in the references to the function. + +goTo.marker(); +let ranges = test.ranges(); +verify.referencesCountIs(ranges.length); + +for (let expectedReference of ranges) { + verify.referencesAtPositionContains(expectedReference); +} diff --git a/tests/cases/fourslash/findAllRefsForDefault06.ts b/tests/cases/fourslash/findAllRefsForDefault06.ts new file mode 100644 index 00000000000..12c187b4b0c --- /dev/null +++ b/tests/cases/fourslash/findAllRefsForDefault06.ts @@ -0,0 +1,28 @@ +/// + +////function [|f|]() { +//// return 100; +////} +//// +////export default /**/[|f|]; +//// +////var x: typeof [|f|]; +//// +////var y = [|f|](); +//// +////namespace [|f|] { +////} + +// The function 'f' and the namespace 'f' don't get merged, +// but the 'export default' site, includes both meanings. + +// Here we are testing whether the 'export default' site +// and all value-uses of 'f' are included in the references to the function. + +goTo.marker(); +let ranges = test.ranges(); +verify.referencesCountIs(ranges.length); + +for (let expectedReference of ranges) { + verify.referencesAtPositionContains(expectedReference); +} diff --git a/tests/cases/fourslash/findAllRefsForDefaultExportNegative02.ts b/tests/cases/fourslash/findAllRefsForDefault07.ts similarity index 76% rename from tests/cases/fourslash/findAllRefsForDefaultExportNegative02.ts rename to tests/cases/fourslash/findAllRefsForDefault07.ts index 901cc3ffe0f..9534a671316 100644 --- a/tests/cases/fourslash/findAllRefsForDefaultExportNegative02.ts +++ b/tests/cases/fourslash/findAllRefsForDefault07.ts @@ -11,5 +11,8 @@ ////namespace /**/DefaultExportedFunction { ////} +// The namespace and function do not merge, +// so the namespace should be all alone. + goTo.marker(); verify.referencesCountIs(1); diff --git a/tests/cases/fourslash/findAllRefsForDefaultExportNegative01.ts b/tests/cases/fourslash/findAllRefsForDefault08.ts similarity index 72% rename from tests/cases/fourslash/findAllRefsForDefaultExportNegative01.ts rename to tests/cases/fourslash/findAllRefsForDefault08.ts index b44ab76b292..80eabbe53f4 100644 --- a/tests/cases/fourslash/findAllRefsForDefaultExportNegative01.ts +++ b/tests/cases/fourslash/findAllRefsForDefault08.ts @@ -10,5 +10,8 @@ ////namespace /**/DefaultExportedClass { ////} +// The namespace and class do not merge, +// so the namespace should be all alone. + goTo.marker(); verify.referencesCountIs(1); diff --git a/tests/cases/fourslash/findAllRefsForDefaultExportNegative03.ts b/tests/cases/fourslash/findAllRefsForDefaultExportNegative03.ts deleted file mode 100644 index d9364b2193e..00000000000 --- a/tests/cases/fourslash/findAllRefsForDefaultExportNegative03.ts +++ /dev/null @@ -1,17 +0,0 @@ -/// - -////function f() { -//// return 100; -////} -//// -////export default f; -//// -////var x: typeof f; -//// -////var y = f(); -//// -////namespace /**/f { -////} - -goTo.marker(); -verify.referencesCountIs(1); From cf193a4dc4f203c7ff5fa64e69a1f890a37b2e1b Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 20 May 2015 15:34:31 -0700 Subject: [PATCH 07/20] Renamed tests. --- ...indAllRefsForDefault04.ts => findAllRefsForDefaultExport04.ts} | 0 ...indAllRefsForDefault05.ts => findAllRefsForDefaultExport05.ts} | 0 ...indAllRefsForDefault06.ts => findAllRefsForDefaultExport06.ts} | 0 ...indAllRefsForDefault07.ts => findAllRefsForDefaultExport07.ts} | 0 ...indAllRefsForDefault08.ts => findAllRefsForDefaultExport08.ts} | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename tests/cases/fourslash/{findAllRefsForDefault04.ts => findAllRefsForDefaultExport04.ts} (100%) rename tests/cases/fourslash/{findAllRefsForDefault05.ts => findAllRefsForDefaultExport05.ts} (100%) rename tests/cases/fourslash/{findAllRefsForDefault06.ts => findAllRefsForDefaultExport06.ts} (100%) rename tests/cases/fourslash/{findAllRefsForDefault07.ts => findAllRefsForDefaultExport07.ts} (100%) rename tests/cases/fourslash/{findAllRefsForDefault08.ts => findAllRefsForDefaultExport08.ts} (100%) diff --git a/tests/cases/fourslash/findAllRefsForDefault04.ts b/tests/cases/fourslash/findAllRefsForDefaultExport04.ts similarity index 100% rename from tests/cases/fourslash/findAllRefsForDefault04.ts rename to tests/cases/fourslash/findAllRefsForDefaultExport04.ts diff --git a/tests/cases/fourslash/findAllRefsForDefault05.ts b/tests/cases/fourslash/findAllRefsForDefaultExport05.ts similarity index 100% rename from tests/cases/fourslash/findAllRefsForDefault05.ts rename to tests/cases/fourslash/findAllRefsForDefaultExport05.ts diff --git a/tests/cases/fourslash/findAllRefsForDefault06.ts b/tests/cases/fourslash/findAllRefsForDefaultExport06.ts similarity index 100% rename from tests/cases/fourslash/findAllRefsForDefault06.ts rename to tests/cases/fourslash/findAllRefsForDefaultExport06.ts diff --git a/tests/cases/fourslash/findAllRefsForDefault07.ts b/tests/cases/fourslash/findAllRefsForDefaultExport07.ts similarity index 100% rename from tests/cases/fourslash/findAllRefsForDefault07.ts rename to tests/cases/fourslash/findAllRefsForDefaultExport07.ts diff --git a/tests/cases/fourslash/findAllRefsForDefault08.ts b/tests/cases/fourslash/findAllRefsForDefaultExport08.ts similarity index 100% rename from tests/cases/fourslash/findAllRefsForDefault08.ts rename to tests/cases/fourslash/findAllRefsForDefaultExport08.ts From 2539ebe29faba45accc9ca023231108e2d5dcd39 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 20 May 2015 15:39:35 -0700 Subject: [PATCH 08/20] Verify references count. --- tests/cases/fourslash/findAllRefsForDefaultExport01.ts | 1 + tests/cases/fourslash/findAllRefsForDefaultExport02.ts | 1 + tests/cases/fourslash/findAllRefsForDefaultExport03.ts | 1 + 3 files changed, 3 insertions(+) diff --git a/tests/cases/fourslash/findAllRefsForDefaultExport01.ts b/tests/cases/fourslash/findAllRefsForDefaultExport01.ts index 87c439bd9ef..ca2f982302c 100644 --- a/tests/cases/fourslash/findAllRefsForDefaultExport01.ts +++ b/tests/cases/fourslash/findAllRefsForDefaultExport01.ts @@ -15,6 +15,7 @@ let ranges = test.ranges() for (let range of ranges) { goTo.position(range.start); + verify.referencesCountIs(ranges.length); for (let expectedReference of ranges) { verify.referencesAtPositionContains(expectedReference); } diff --git a/tests/cases/fourslash/findAllRefsForDefaultExport02.ts b/tests/cases/fourslash/findAllRefsForDefaultExport02.ts index 3000b7de92d..1a0a92241f4 100644 --- a/tests/cases/fourslash/findAllRefsForDefaultExport02.ts +++ b/tests/cases/fourslash/findAllRefsForDefaultExport02.ts @@ -16,6 +16,7 @@ let ranges = test.ranges() for (let range of ranges) { goTo.position(range.start); + verify.referencesCountIs(ranges.length); for (let expectedReference of ranges) { verify.referencesAtPositionContains(expectedReference); } diff --git a/tests/cases/fourslash/findAllRefsForDefaultExport03.ts b/tests/cases/fourslash/findAllRefsForDefaultExport03.ts index 89027879ff1..f753d17de49 100644 --- a/tests/cases/fourslash/findAllRefsForDefaultExport03.ts +++ b/tests/cases/fourslash/findAllRefsForDefaultExport03.ts @@ -18,6 +18,7 @@ let ranges = test.ranges() for (let range of ranges) { goTo.position(range.start); + verify.referencesCountIs(ranges.length); for (let expectedReference of ranges) { verify.referencesAtPositionContains(expectedReference); } From b9ddfcc0824c0fc6498f1245c092bc634be9c47a Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 21 May 2015 12:26:41 -0700 Subject: [PATCH 09/20] Spit out JSON when expected =/= actual. --- src/harness/fourslash.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 6867863a941..938e486fee1 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -891,7 +891,7 @@ module FourSlash { } if (ranges.length !== references.length) { - this.raiseError(this.assertionMessage("Rename locations", references.length, ranges.length)); + this.raiseError("Rename location count does not match result.\n\nExpected: " + JSON.stringify(ranges) + "\n\nActual:" + JSON.stringify(references)); } ranges = ranges.sort((r1, r2) => r1.start - r2.start); @@ -904,9 +904,7 @@ module FourSlash { if (reference.textSpan.start !== range.start || ts.textSpanEnd(reference.textSpan) !== range.end) { - this.raiseError(this.assertionMessage("Rename location", - "[" + reference.textSpan.start + "," + ts.textSpanEnd(reference.textSpan) + ")", - "[" + range.start + "," + range.end + ")")); + this.raiseError("Rename location results do not match.\n\nExpected: " + JSON.stringify(ranges) + "\n\nActual:" + JSON.stringify(references)); } } } From ddb67e461a6a19f0bcbf03d2dc89091775488b5b Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 21 May 2015 12:28:02 -0700 Subject: [PATCH 10/20] Fixed tests. --- .../findAllRefsForDefaultExport01.ts | 4 ---- .../findAllRefsForDefaultExport02.ts | 4 ---- .../fourslash/renameForDefaultExport01.ts | 11 +++------- .../fourslash/renameForDefaultExport02.ts | 11 +++------- .../fourslash/renameForDefaultExport03.ts | 7 +++---- .../fourslash/renameForDefaultExport04.ts | 14 +++++++++++++ .../fourslash/renameForDefaultExport05.ts | 14 +++++++++++++ .../fourslash/renameForDefaultExport06.ts | 14 +++++++++++++ .../fourslash/renameForDefaultExport07.ts | 15 +++++++++++++ .../fourslash/renameForDefaultExport08.ts | 15 +++++++++++++ .../fourslash/renameForDefaultExport09.ts | 21 +++++++++++++++++++ 11 files changed, 102 insertions(+), 28 deletions(-) create mode 100644 tests/cases/fourslash/renameForDefaultExport04.ts create mode 100644 tests/cases/fourslash/renameForDefaultExport05.ts create mode 100644 tests/cases/fourslash/renameForDefaultExport06.ts create mode 100644 tests/cases/fourslash/renameForDefaultExport07.ts create mode 100644 tests/cases/fourslash/renameForDefaultExport08.ts create mode 100644 tests/cases/fourslash/renameForDefaultExport09.ts diff --git a/tests/cases/fourslash/findAllRefsForDefaultExport01.ts b/tests/cases/fourslash/findAllRefsForDefaultExport01.ts index ca2f982302c..2f40af93c02 100644 --- a/tests/cases/fourslash/findAllRefsForDefaultExport01.ts +++ b/tests/cases/fourslash/findAllRefsForDefaultExport01.ts @@ -6,10 +6,6 @@ ////var x: [|DefaultExportedClass|]; //// ////var y = new [|DefaultExportedClass|]; -//// -////namespace [|DefaultExportedClass|] { -//// var local = 100; -////} let ranges = test.ranges() for (let range of ranges) { diff --git a/tests/cases/fourslash/findAllRefsForDefaultExport02.ts b/tests/cases/fourslash/findAllRefsForDefaultExport02.ts index 1a0a92241f4..db773c74e3c 100644 --- a/tests/cases/fourslash/findAllRefsForDefaultExport02.ts +++ b/tests/cases/fourslash/findAllRefsForDefaultExport02.ts @@ -7,10 +7,6 @@ ////var x: typeof [|DefaultExportedFunction|]; //// ////var y = [|DefaultExportedFunction|](); -//// -////namespace [|DefaultExportedFunction|] { -//// var local = 100; -////} let ranges = test.ranges() for (let range of ranges) { diff --git a/tests/cases/fourslash/renameForDefaultExport01.ts b/tests/cases/fourslash/renameForDefaultExport01.ts index ec9c3900a5e..809c127a727 100644 --- a/tests/cases/fourslash/renameForDefaultExport01.ts +++ b/tests/cases/fourslash/renameForDefaultExport01.ts @@ -1,23 +1,18 @@ /// -/////** -//// * Commenting [|DefaultExportedClass|] -//// */ ////export default class /*1*/[|DefaultExportedClass|] { ////} +/////* +//// * Commenting [|DefaultExportedClass|] +//// */ //// ////var x: /*2*/[|DefaultExportedClass|]; //// ////var y = new /*3*/[|DefaultExportedClass|]; -//// -////namespace /*4*/[|DefaultExportedClass|] { -//// var local = 100; -////} let markers = test.markers() for (let marker of markers) { goTo.position(marker.position); verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ true); - verify.renameInfoSucceeded("DefaultExportedClass"); } \ No newline at end of file diff --git a/tests/cases/fourslash/renameForDefaultExport02.ts b/tests/cases/fourslash/renameForDefaultExport02.ts index eea63282f5f..ddf4b224023 100644 --- a/tests/cases/fourslash/renameForDefaultExport02.ts +++ b/tests/cases/fourslash/renameForDefaultExport02.ts @@ -1,24 +1,19 @@ /// -/////** -//// * Commenting [|DefaultExportedFunction|] -//// */ ////export default function /*1*/[|DefaultExportedFunction|]() { //// return /*2*/[|DefaultExportedFunction|] ////} +/////** +//// * Commenting [|DefaultExportedFunction|] +//// */ //// ////var x: typeof /*3*/[|DefaultExportedFunction|]; //// ////var y = /*4*/[|DefaultExportedFunction|](); -//// -////namespace /*5*/[|DefaultExportedFunction|] { -//// var local = 100; -////} let markers = test.markers() for (let marker of markers) { goTo.position(marker.position); verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ true); - verify.renameInfoSucceeded("DefaultExportedFunction"); } \ No newline at end of file diff --git a/tests/cases/fourslash/renameForDefaultExport03.ts b/tests/cases/fourslash/renameForDefaultExport03.ts index b36b04768ab..6f82d96fe5e 100644 --- a/tests/cases/fourslash/renameForDefaultExport03.ts +++ b/tests/cases/fourslash/renameForDefaultExport03.ts @@ -1,8 +1,5 @@ /// -/////** -//// * Commenting [|f|] -//// */ ////function /*1*/[|f|]() { //// return 100; ////} @@ -13,6 +10,9 @@ //// ////var y = /*4*/[|f|](); //// +/////** +//// * Commenting [|f|] +//// */ ////namespace /*5*/[|f|] { //// var local = 100; ////} @@ -22,5 +22,4 @@ for (let marker of markers) { goTo.position(marker.position); verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ true); - verify.renameInfoSucceeded("f"); } \ No newline at end of file diff --git a/tests/cases/fourslash/renameForDefaultExport04.ts b/tests/cases/fourslash/renameForDefaultExport04.ts new file mode 100644 index 00000000000..44dd764682f --- /dev/null +++ b/tests/cases/fourslash/renameForDefaultExport04.ts @@ -0,0 +1,14 @@ +/// + +////export default class /**/[|DefaultExportedClass|] { +////} +/////* +//// * Commenting DefaultExportedClass +//// */ +//// +////var x: DefaultExportedClass; +//// +////var y = new DefaultExportedClass; + +goTo.marker(); +verify.renameInfoSucceeded("DefaultExportedClass", "DefaultExportedClass"); \ No newline at end of file diff --git a/tests/cases/fourslash/renameForDefaultExport05.ts b/tests/cases/fourslash/renameForDefaultExport05.ts new file mode 100644 index 00000000000..926fa5dd6fd --- /dev/null +++ b/tests/cases/fourslash/renameForDefaultExport05.ts @@ -0,0 +1,14 @@ +/// + +////export default class DefaultExportedClass { +////} +/////* +//// * Commenting DefaultExportedClass +//// */ +//// +////var x: /**/[|DefaultExportedClass|]; +//// +////var y = new DefaultExportedClass; + +goTo.marker(); +verify.renameInfoSucceeded("DefaultExportedClass", "DefaultExportedClass"); \ No newline at end of file diff --git a/tests/cases/fourslash/renameForDefaultExport06.ts b/tests/cases/fourslash/renameForDefaultExport06.ts new file mode 100644 index 00000000000..da3ca8d92a4 --- /dev/null +++ b/tests/cases/fourslash/renameForDefaultExport06.ts @@ -0,0 +1,14 @@ +/// + +////export default class DefaultExportedClass { +////} +/////* +//// * Commenting DefaultExportedClass +//// */ +//// +////var x: DefaultExportedClass; +//// +////var y = new /**/[|DefaultExportedClass|]; + +goTo.marker(); +verify.renameInfoSucceeded("DefaultExportedClass", "DefaultExportedClass"); \ No newline at end of file diff --git a/tests/cases/fourslash/renameForDefaultExport07.ts b/tests/cases/fourslash/renameForDefaultExport07.ts new file mode 100644 index 00000000000..9b1010580bf --- /dev/null +++ b/tests/cases/fourslash/renameForDefaultExport07.ts @@ -0,0 +1,15 @@ +/// + +////export default function /**/[|DefaultExportedFunction|]() { +//// return DefaultExportedFunction +////} +/////** +//// * Commenting DefaultExportedFunction +//// */ +//// +////var x: typeof DefaultExportedFunction; +//// +////var y = DefaultExportedFunction(); + +goTo.marker(); +verify.renameInfoSucceeded("DefaultExportedFunction", "DefaultExportedFunction"); \ No newline at end of file diff --git a/tests/cases/fourslash/renameForDefaultExport08.ts b/tests/cases/fourslash/renameForDefaultExport08.ts new file mode 100644 index 00000000000..033b20516be --- /dev/null +++ b/tests/cases/fourslash/renameForDefaultExport08.ts @@ -0,0 +1,15 @@ +/// + +////export default function DefaultExportedFunction() { +//// return /**/[|DefaultExportedFunction|] +////} +/////** +//// * Commenting DefaultExportedFunction +//// */ +//// +////var x: typeof DefaultExportedFunction; +//// +////var y = DefaultExportedFunction(); + +goTo.marker(); +verify.renameInfoSucceeded("DefaultExportedFunction", "DefaultExportedFunction"); \ No newline at end of file diff --git a/tests/cases/fourslash/renameForDefaultExport09.ts b/tests/cases/fourslash/renameForDefaultExport09.ts new file mode 100644 index 00000000000..568eb18a84e --- /dev/null +++ b/tests/cases/fourslash/renameForDefaultExport09.ts @@ -0,0 +1,21 @@ +/// + +////function /**/[|f|]() { +//// return 100; +////} +//// +////export default f; +//// +////var x: typeof f; +//// +////var y = f(); +//// +/////** +//// * Commenting f +//// */ +////namespace f { +//// var local = 100; +////} + +goTo.marker(); +verify.renameInfoSucceeded("f", "f"); \ No newline at end of file From 2c4bb5717c8e4a8a0868281465b9cff62c6966ef Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 21 May 2015 12:29:09 -0700 Subject: [PATCH 11/20] Find the references themselves. --- src/services/services.ts | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 1b5ba6752de..d99f3bacfc8 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4915,20 +4915,25 @@ module ts { return undefined; } + let declarations = symbol.declarations; - // The symbol was an internal symbol and does not have a declaration e.g.undefined symbol + // The symbol was an internal symbol and does not have a declaration e.g. undefined symbol if (!declarations || !declarations.length) { return undefined; } + // Try to get the local symbol if we're dealing with an 'export default' + // since that symbol has the "true" name and we need to account for other declarations. + let localExportDefaultSymbol = getLocalSymbolForExportDefault(symbol); + let result: ReferencedSymbol[]; // Compute the meaning from the location and the symbol it references let searchMeaning = getIntersectingMeaningFromDeclarations(getMeaningFromLocation(node), declarations); - // Get the text to search for, we need to normalize it as external module names will have quote - let declaredName = getDeclaredName(symbol, node); + // Get the text to search for, we need to normalize it as external module names will have quotes + let declaredName = getDeclaredName(localExportDefaultSymbol || symbol, node); // Try to get the smallest valid scope that we can limit our search to; // otherwise we'll need to search globally (i.e. include each file). @@ -4942,7 +4947,7 @@ module ts { getReferencesInNode(scope, symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result, symbolToIndex); } else { - let internedName = getInternedName(symbol, node, declarations) + let internedName = getInternedName(localExportDefaultSymbol || symbol, node, declarations) for (let sourceFile of sourceFiles) { cancellationToken.throwIfCancellationRequested(); @@ -4988,9 +4993,8 @@ module ts { } function getDeclaredName(symbol: Symbol, location: Node) { - // If this is an export or import specifier it could have been renamed using the as syntax. - // if so we want to search for whatever under the cursor, the symbol is pointing to the alias (name) - // so check for the propertyName. + // If this is an export or import specifier it could have been renamed using the 'as' syntax. + // If so we want to search for whatever is under the cursor. if (isImportOrExportSpecifierName(location)) { return location.getText(); } @@ -5000,10 +5004,9 @@ module ts { return stripQuotes(name); } - function getInternedName(symbol: Symbol, location: Node, declarations: Declaration[]): string { - // If this is an export or import specifier it could have been renamed using the as syntax. - // if so we want to search for whatever under the cursor, the symbol is pointing to the alias (name) - // so check for the propertyName. + function getInternedName(symbol: Symbol, location: Node, declarations: Declaration[]) { + // If this is an export or import specifier it could have been renamed using the 'as' syntax. + // If so we want to search for whatever under the cursor. if (isImportOrExportSpecifierName(location)) { return location.getText(); } @@ -5014,18 +5017,13 @@ module ts { let functionExpression: FunctionExpression; if (symbol.valueDeclaration && symbol.valueDeclaration.kind === SyntaxKind.FunctionExpression) { functionExpression = symbol.valueDeclaration; + + if (functionExpression.name) { + return functionExpression.name.text; + } } - // When a name gets interned into a SourceFile's 'identifiers' Map, - // its name is escaped and stored in the same way its symbol name/identifier - // name should be stored. Function expressions, however, are a special case, - // because despite sometimes having a name, the binder unconditionally binds them - // to a symbol with the name "__function". - let name = functionExpression && functionExpression.name - ? functionExpression.name.text - : symbol.name; - - return stripQuotes(name); + return stripQuotes(symbol.name); } function stripQuotes(name: string) { From 33693e87ddf037fbbdfcfb56bb204d1c0a5ae895 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 21 May 2015 12:43:58 -0700 Subject: [PATCH 12/20] Adjust expectations. --- tests/cases/fourslash/renameForDefaultExport04.ts | 2 +- tests/cases/fourslash/renameForDefaultExport05.ts | 2 +- tests/cases/fourslash/renameForDefaultExport06.ts | 2 +- tests/cases/fourslash/renameForDefaultExport07.ts | 2 +- tests/cases/fourslash/renameForDefaultExport08.ts | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/cases/fourslash/renameForDefaultExport04.ts b/tests/cases/fourslash/renameForDefaultExport04.ts index 44dd764682f..8c4e2733e33 100644 --- a/tests/cases/fourslash/renameForDefaultExport04.ts +++ b/tests/cases/fourslash/renameForDefaultExport04.ts @@ -11,4 +11,4 @@ ////var y = new DefaultExportedClass; goTo.marker(); -verify.renameInfoSucceeded("DefaultExportedClass", "DefaultExportedClass"); \ No newline at end of file +verify.renameInfoSucceeded("DefaultExportedClass"); \ No newline at end of file diff --git a/tests/cases/fourslash/renameForDefaultExport05.ts b/tests/cases/fourslash/renameForDefaultExport05.ts index 926fa5dd6fd..f6c87d936da 100644 --- a/tests/cases/fourslash/renameForDefaultExport05.ts +++ b/tests/cases/fourslash/renameForDefaultExport05.ts @@ -11,4 +11,4 @@ ////var y = new DefaultExportedClass; goTo.marker(); -verify.renameInfoSucceeded("DefaultExportedClass", "DefaultExportedClass"); \ No newline at end of file +verify.renameInfoSucceeded("DefaultExportedClass"); \ No newline at end of file diff --git a/tests/cases/fourslash/renameForDefaultExport06.ts b/tests/cases/fourslash/renameForDefaultExport06.ts index da3ca8d92a4..083fd29054a 100644 --- a/tests/cases/fourslash/renameForDefaultExport06.ts +++ b/tests/cases/fourslash/renameForDefaultExport06.ts @@ -11,4 +11,4 @@ ////var y = new /**/[|DefaultExportedClass|]; goTo.marker(); -verify.renameInfoSucceeded("DefaultExportedClass", "DefaultExportedClass"); \ No newline at end of file +verify.renameInfoSucceeded("DefaultExportedClass"); \ No newline at end of file diff --git a/tests/cases/fourslash/renameForDefaultExport07.ts b/tests/cases/fourslash/renameForDefaultExport07.ts index 9b1010580bf..2c718a1202b 100644 --- a/tests/cases/fourslash/renameForDefaultExport07.ts +++ b/tests/cases/fourslash/renameForDefaultExport07.ts @@ -12,4 +12,4 @@ ////var y = DefaultExportedFunction(); goTo.marker(); -verify.renameInfoSucceeded("DefaultExportedFunction", "DefaultExportedFunction"); \ No newline at end of file +verify.renameInfoSucceeded("DefaultExportedFunction"); \ No newline at end of file diff --git a/tests/cases/fourslash/renameForDefaultExport08.ts b/tests/cases/fourslash/renameForDefaultExport08.ts index 033b20516be..29064180d58 100644 --- a/tests/cases/fourslash/renameForDefaultExport08.ts +++ b/tests/cases/fourslash/renameForDefaultExport08.ts @@ -12,4 +12,4 @@ ////var y = DefaultExportedFunction(); goTo.marker(); -verify.renameInfoSucceeded("DefaultExportedFunction", "DefaultExportedFunction"); \ No newline at end of file +verify.renameInfoSucceeded("DefaultExportedFunction"); \ No newline at end of file From 6f925acacbf50c491fc55b81dff7aa177852a2f2 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 21 May 2015 12:50:22 -0700 Subject: [PATCH 13/20] Add rename tests for function expressions. --- .../fourslash/renameInfoForFunctionExpression01.ts | 8 ++++++++ .../renameLocationsForFunctionExpression01.ts | 12 ++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 tests/cases/fourslash/renameInfoForFunctionExpression01.ts create mode 100644 tests/cases/fourslash/renameLocationsForFunctionExpression01.ts diff --git a/tests/cases/fourslash/renameInfoForFunctionExpression01.ts b/tests/cases/fourslash/renameInfoForFunctionExpression01.ts new file mode 100644 index 00000000000..807c4541f3f --- /dev/null +++ b/tests/cases/fourslash/renameInfoForFunctionExpression01.ts @@ -0,0 +1,8 @@ +/// + +////var x = function /**/[|f|](g: any, h: any) { +//// f(f, g); +////} + +goTo.marker(); +verify.renameInfoSucceeded("f"); \ No newline at end of file diff --git a/tests/cases/fourslash/renameLocationsForFunctionExpression01.ts b/tests/cases/fourslash/renameLocationsForFunctionExpression01.ts new file mode 100644 index 00000000000..b2f54853c7b --- /dev/null +++ b/tests/cases/fourslash/renameLocationsForFunctionExpression01.ts @@ -0,0 +1,12 @@ +/// + +////var x = function /*1*/[|f|](g: any, h: any) { +//// /*2*/[|f|](/*3*/[|f|], g); +////} + +let markers = test.markers() +for (let marker of markers) { + goTo.position(marker.position); + + verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); +} \ No newline at end of file From 934a3bfc6d53b986ca8434fbb2001a3bfc4fffaf Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 21 May 2015 12:52:00 -0700 Subject: [PATCH 14/20] Fixed 'displayName'. --- src/services/services.ts | 43 ++++++++------------------------------- src/services/utilities.ts | 30 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 34 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index d99f3bacfc8..0865c68db64 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4915,7 +4915,6 @@ module ts { return undefined; } - let declarations = symbol.declarations; // The symbol was an internal symbol and does not have a declaration e.g. undefined symbol @@ -4923,17 +4922,13 @@ module ts { return undefined; } - // Try to get the local symbol if we're dealing with an 'export default' - // since that symbol has the "true" name and we need to account for other declarations. - let localExportDefaultSymbol = getLocalSymbolForExportDefault(symbol); - let result: ReferencedSymbol[]; // Compute the meaning from the location and the symbol it references let searchMeaning = getIntersectingMeaningFromDeclarations(getMeaningFromLocation(node), declarations); // Get the text to search for, we need to normalize it as external module names will have quotes - let declaredName = getDeclaredName(localExportDefaultSymbol || symbol, node); + let declaredName = getDeclaredName(typeChecker, symbol, node); // Try to get the smallest valid scope that we can limit our search to; // otherwise we'll need to search globally (i.e. include each file). @@ -4947,7 +4942,7 @@ module ts { getReferencesInNode(scope, symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result, symbolToIndex); } else { - let internedName = getInternedName(localExportDefaultSymbol || symbol, node, declarations) + let internedName = getInternedName(symbol, node, declarations) for (let sourceFile of sourceFiles) { cancellationToken.throwIfCancellationRequested(); @@ -4980,30 +4975,12 @@ module ts { }; } - function isImportOrExportSpecifierName(location: Node): boolean { - return location.parent && - (location.parent.kind === SyntaxKind.ImportSpecifier || location.parent.kind === SyntaxKind.ExportSpecifier) && - (location.parent).propertyName === location; - } - function isImportOrExportSpecifierImportSymbol(symbol: Symbol) { return (symbol.flags & SymbolFlags.Alias) && forEach(symbol.declarations, declaration => { return declaration.kind === SyntaxKind.ImportSpecifier || declaration.kind === SyntaxKind.ExportSpecifier; }); } - function getDeclaredName(symbol: Symbol, location: Node) { - // If this is an export or import specifier it could have been renamed using the 'as' syntax. - // If so we want to search for whatever is under the cursor. - if (isImportOrExportSpecifierName(location)) { - return location.getText(); - } - - let name = typeChecker.symbolToString(symbol); - - return stripQuotes(name); - } - function getInternedName(symbol: Symbol, location: Node, declarations: Declaration[]) { // If this is an export or import specifier it could have been renamed using the 'as' syntax. // If so we want to search for whatever under the cursor. @@ -5023,15 +5000,12 @@ module ts { } } - return stripQuotes(symbol.name); - } + // Try to get the local symbol if we're dealing with an 'export default' + // since that symbol has the "true" name. + let localExportDefaultSymbol = getLocalSymbolForExportDefault(symbol); + symbol = localExportDefaultSymbol || symbol; - function stripQuotes(name: string) { - let length = name.length; - if (length >= 2 && name.charCodeAt(0) === CharacterCodes.doubleQuote && name.charCodeAt(length - 1) === CharacterCodes.doubleQuote) { - return name.substring(1, length - 1); - }; - return name; + return stripQuotes(symbol.name); } function getSymbolScope(symbol: Symbol): Node { @@ -6647,12 +6621,13 @@ module ts { } } + let displayName = getDeclaredName(typeChecker, symbol, node); let kind = getSymbolKind(symbol, node); if (kind) { return { canRename: true, localizedErrorMessage: undefined, - displayName: symbol.name, + displayName, fullDisplayName: typeChecker.getFullyQualifiedName(symbol), kind: kind, kindModifiers: getSymbolModifiers(symbol), diff --git a/src/services/utilities.ts b/src/services/utilities.ts index da0a0aa96c1..e1cbf609c86 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -652,4 +652,34 @@ module ts { typechecker.getSymbolDisplayBuilder().buildSignatureDisplay(signature, writer, enclosingDeclaration, flags); }); } + + export function getDeclaredName(typeChecker: TypeChecker, symbol: Symbol, location: Node) { + // If this is an export or import specifier it could have been renamed using the 'as' syntax. + // If so we want to search for whatever is under the cursor. + if (isImportOrExportSpecifierName(location)) { + return location.getText(); + } + + // Try to get the local symbol if we're dealing with an 'export default' + // since that symbol has the "true" name. + let localExportDefaultSymbol = getLocalSymbolForExportDefault(symbol); + + let name = typeChecker.symbolToString(localExportDefaultSymbol || symbol); + + return stripQuotes(name); + } + + export function isImportOrExportSpecifierName(location: Node): boolean { + return location.parent && + (location.parent.kind === SyntaxKind.ImportSpecifier || location.parent.kind === SyntaxKind.ExportSpecifier) && + (location.parent).propertyName === location; + } + + export function stripQuotes(name: string) { + let length = name.length; + if (length >= 2 && name.charCodeAt(0) === CharacterCodes.doubleQuote && name.charCodeAt(length - 1) === CharacterCodes.doubleQuote) { + return name.substring(1, length - 1); + }; + return name; + } } \ No newline at end of file From 035962bee16a68876acb5ba0e9df65dc6d428ffc Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 28 May 2015 11:47:12 -0700 Subject: [PATCH 15/20] Added test for find all refs of function expressions. --- .../findAllRefsForFunctionExpression01.ts | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/cases/fourslash/findAllRefsForFunctionExpression01.ts diff --git a/tests/cases/fourslash/findAllRefsForFunctionExpression01.ts b/tests/cases/fourslash/findAllRefsForFunctionExpression01.ts new file mode 100644 index 00000000000..a312a277ebb --- /dev/null +++ b/tests/cases/fourslash/findAllRefsForFunctionExpression01.ts @@ -0,0 +1,21 @@ +/// + +// @Filename: file1.ts +////var foo = function [|foo|](a = [|foo|](), b = () => [|foo|]) { +//// [|foo|]([|foo|], [|foo|]); +////} + +// @Filename: file2.ts +/////// +////foo(); + + +let ranges = test.ranges() +for (let range of ranges) { + goTo.position(range.start); + + verify.referencesCountIs(ranges.length); + for (let expectedReference of ranges) { + verify.referencesAtPositionContains(expectedReference); + } +} \ No newline at end of file From bca3d014fd65703db6d2ec094d9a81a45534c979 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 28 May 2015 12:10:18 -0700 Subject: [PATCH 16/20] Limit scope of function expressions to themselves. --- src/compiler/types.ts | 4 ++-- src/services/services.ts | 25 +++++++++++++------------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 296e75c4b76..0fda2989e1a 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1582,10 +1582,10 @@ module ts { Tuple = 0x00002000, // Tuple Union = 0x00004000, // Union Anonymous = 0x00008000, // Anonymous - /* @internal */ + /* @internal */ FromSignature = 0x00010000, // Created for signature assignment check ObjectLiteral = 0x00020000, // Originates in an object literal - /* @internal */ + /* @internal */ ContainsUndefinedOrNull = 0x00040000, // Type is or contains Undefined or Null type /* @internal */ ContainsObjectLiteral = 0x00080000, // Type is or contains object literal type diff --git a/src/services/services.ts b/src/services/services.ts index 0865c68db64..691aebf6cc3 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4988,18 +4988,6 @@ module ts { return location.getText(); } - // Special case for function expressions, whose names are solely local to their bodies. - // TODO (drosen): Why would we have to lookup the interned name for a function expression? - // Shouldn't we have found a scope? Consider a 'Debug.fail()'. - let functionExpression: FunctionExpression; - if (symbol.valueDeclaration && symbol.valueDeclaration.kind === SyntaxKind.FunctionExpression) { - functionExpression = symbol.valueDeclaration; - - if (functionExpression.name) { - return functionExpression.name.text; - } - } - // Try to get the local symbol if we're dealing with an 'export default' // since that symbol has the "true" name. let localExportDefaultSymbol = getLocalSymbolForExportDefault(symbol); @@ -5008,7 +4996,20 @@ module ts { return stripQuotes(symbol.name); } + /** + * Determines the smallest scope in which a symbol may have named references. + * + * Returns undefined if the scope cannot be determined, often implying that + * a reference to a symbol can occur anywhere. + */ function getSymbolScope(symbol: Symbol): Node { + // If this is the symbol of a function expression, then named references + // are limited to its own scope. + let valueDeclaration = symbol.valueDeclaration; + if (valueDeclaration && valueDeclaration.kind === SyntaxKind.FunctionExpression) { + return valueDeclaration; + } + // If this is private property or method, the scope is the containing class if (symbol.flags & (SymbolFlags.Property | SymbolFlags.Method)) { let privateDeclaration = forEach(symbol.getDeclarations(), d => (d.flags & NodeFlags.Private) ? d : undefined); From 6a7ce44aadff783151d3e8a12b1cf95a1a61077f Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 29 May 2015 14:37:51 -0700 Subject: [PATCH 17/20] a deer, a female deer -> does --- src/harness/fourslash.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 938e486fee1..cbbd1d37e63 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -743,7 +743,7 @@ module FourSlash { var reference = references[i]; if (reference && reference.fileName === fileName && reference.textSpan.start === start && ts.textSpanEnd(reference.textSpan) === end) { if (typeof isWriteAccess !== "undefined" && reference.isWriteAccess !== isWriteAccess) { - this.raiseError('verifyReferencesAtPositionListContains failed - item isWriteAccess value doe not match, actual: ' + reference.isWriteAccess + ', expected: ' + isWriteAccess + '.'); + this.raiseError('verifyReferencesAtPositionListContains failed - item isWriteAccess value does not match, actual: ' + reference.isWriteAccess + ', expected: ' + isWriteAccess + '.'); } return; } From 83163697864611d81c74f98115e4f03b5641865c Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 29 Jun 2015 09:46:41 -0400 Subject: [PATCH 18/20] Added tests. --- .../renameLocationsForClassExpression01.ts | 34 +++++++++++++++++++ .../renameLocationsForFunctionExpression01.ts | 10 +++--- .../renameLocationsForFunctionExpression02.ts | 18 ++++++++++ 3 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 tests/cases/fourslash/renameLocationsForClassExpression01.ts create mode 100644 tests/cases/fourslash/renameLocationsForFunctionExpression02.ts diff --git a/tests/cases/fourslash/renameLocationsForClassExpression01.ts b/tests/cases/fourslash/renameLocationsForClassExpression01.ts new file mode 100644 index 00000000000..a1174d503ed --- /dev/null +++ b/tests/cases/fourslash/renameLocationsForClassExpression01.ts @@ -0,0 +1,34 @@ +/// + +////class Foo { +////} +//// +////var x = class /**/Foo { +//// doIt() { +//// return Foo; +//// } +//// +//// static doItStatically() { +//// return Foo; +//// } +////} +//// +////var y = class { +//// getSomeName() { +//// return Foo +//// } +////} + + +// TODO (yuit): Fix up this test when class expressions are supported. +// Just uncomment the below, remove the marker, and add the +// appropriate ranges in the test itself. +goTo.marker(); +verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); + +////let ranges = test.ranges() +////for (let range of ranges) { +//// goTo.position(range.start); +//// +//// verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); +////} \ No newline at end of file diff --git a/tests/cases/fourslash/renameLocationsForFunctionExpression01.ts b/tests/cases/fourslash/renameLocationsForFunctionExpression01.ts index b2f54853c7b..e884783d960 100644 --- a/tests/cases/fourslash/renameLocationsForFunctionExpression01.ts +++ b/tests/cases/fourslash/renameLocationsForFunctionExpression01.ts @@ -1,12 +1,12 @@ /// -////var x = function /*1*/[|f|](g: any, h: any) { -//// /*2*/[|f|](/*3*/[|f|], g); +////var x = function [|f|](g: any, h: any) { +//// [|f|]([|f|], g); ////} -let markers = test.markers() -for (let marker of markers) { - goTo.position(marker.position); +let ranges = test.ranges() +for (let range of ranges) { + goTo.position(range.start); verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); } \ No newline at end of file diff --git a/tests/cases/fourslash/renameLocationsForFunctionExpression02.ts b/tests/cases/fourslash/renameLocationsForFunctionExpression02.ts new file mode 100644 index 00000000000..8186611cb64 --- /dev/null +++ b/tests/cases/fourslash/renameLocationsForFunctionExpression02.ts @@ -0,0 +1,18 @@ +/// + +////function f() { +//// +////} +////var x = function [|f|](g: any, h: any) { +//// +//// let helper = function f(): any { f(); } +//// +//// let foo = () => [|f|]([|f|], g); +////} + +let ranges = test.ranges() +for (let range of ranges) { + goTo.position(range.start); + + verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); +} \ No newline at end of file From 4143d1df7fc36410cd9323200765bc27a3f065b5 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 29 Jun 2015 10:29:23 -0400 Subject: [PATCH 19/20] Addressed CR feedback. --- src/services/services.ts | 9 ++++++--- src/services/utilities.ts | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 21537f0fa14..b0bf52291c0 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4965,7 +4965,8 @@ namespace ts { // Compute the meaning from the location and the symbol it references let searchMeaning = getIntersectingMeaningFromDeclarations(getMeaningFromLocation(node), declarations); - // Get the text to search for, we need to normalize it as external module names will have quotes + // Get the text to search for. + // Note: if this is an external module symbol, the name doesn't include quotes. let declaredName = getDeclaredName(typeChecker, symbol, node); // Try to get the smallest valid scope that we can limit our search to; @@ -5019,7 +5020,7 @@ namespace ts { }); } - function getInternedName(symbol: Symbol, location: Node, declarations: Declaration[]) { + function getInternedName(symbol: Symbol, location: Node, declarations: Declaration[]): string { // If this is an export or import specifier it could have been renamed using the 'as' syntax. // If so we want to search for whatever under the cursor. if (isImportOrExportSpecifierName(location)) { @@ -5036,8 +5037,10 @@ namespace ts { /** * Determines the smallest scope in which a symbol may have named references. + * Note that not every construct has been accounted for. This function can + * probably be improved. * - * Returns undefined if the scope cannot be determined, often implying that + * @returns undefined if the scope cannot be determined, implying that * a reference to a symbol can occur anywhere. */ function getSymbolScope(symbol: Symbol): Node { diff --git a/src/services/utilities.ts b/src/services/utilities.ts index a6834e1230d..0fd945caa7d 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -653,7 +653,7 @@ namespace ts { }); } - export function getDeclaredName(typeChecker: TypeChecker, symbol: Symbol, location: Node) { + export function getDeclaredName(typeChecker: TypeChecker, symbol: Symbol, location: Node): string { // If this is an export or import specifier it could have been renamed using the 'as' syntax. // If so we want to search for whatever is under the cursor. if (isImportOrExportSpecifierName(location)) { From cdc8c3b5fb10ae6cb9fa43045b4717b9b8593ad4 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 29 Jun 2015 11:09:40 -0400 Subject: [PATCH 20/20] Use full display name in tests. This is a modified revert of 33693e8 --- tests/cases/fourslash/renameForDefaultExport04.ts | 3 ++- tests/cases/fourslash/renameForDefaultExport05.ts | 3 ++- tests/cases/fourslash/renameForDefaultExport06.ts | 3 ++- tests/cases/fourslash/renameForDefaultExport07.ts | 3 ++- tests/cases/fourslash/renameForDefaultExport08.ts | 3 ++- tests/cases/fourslash/renameForDefaultExport09.ts | 1 + 6 files changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/cases/fourslash/renameForDefaultExport04.ts b/tests/cases/fourslash/renameForDefaultExport04.ts index 8c4e2733e33..ba40374e262 100644 --- a/tests/cases/fourslash/renameForDefaultExport04.ts +++ b/tests/cases/fourslash/renameForDefaultExport04.ts @@ -1,5 +1,6 @@ /// +// @Filename: foo.ts ////export default class /**/[|DefaultExportedClass|] { ////} /////* @@ -11,4 +12,4 @@ ////var y = new DefaultExportedClass; goTo.marker(); -verify.renameInfoSucceeded("DefaultExportedClass"); \ No newline at end of file +verify.renameInfoSucceeded("DefaultExportedClass", '"tests/cases/fourslash/foo".DefaultExportedClass'); \ No newline at end of file diff --git a/tests/cases/fourslash/renameForDefaultExport05.ts b/tests/cases/fourslash/renameForDefaultExport05.ts index f6c87d936da..099f878bda1 100644 --- a/tests/cases/fourslash/renameForDefaultExport05.ts +++ b/tests/cases/fourslash/renameForDefaultExport05.ts @@ -1,5 +1,6 @@ /// +// @Filename: foo.ts ////export default class DefaultExportedClass { ////} /////* @@ -11,4 +12,4 @@ ////var y = new DefaultExportedClass; goTo.marker(); -verify.renameInfoSucceeded("DefaultExportedClass"); \ No newline at end of file +verify.renameInfoSucceeded("DefaultExportedClass", '"tests/cases/fourslash/foo".DefaultExportedClass'); \ No newline at end of file diff --git a/tests/cases/fourslash/renameForDefaultExport06.ts b/tests/cases/fourslash/renameForDefaultExport06.ts index 083fd29054a..3ec067b7029 100644 --- a/tests/cases/fourslash/renameForDefaultExport06.ts +++ b/tests/cases/fourslash/renameForDefaultExport06.ts @@ -1,5 +1,6 @@ /// +// @Filename: foo.ts ////export default class DefaultExportedClass { ////} /////* @@ -11,4 +12,4 @@ ////var y = new /**/[|DefaultExportedClass|]; goTo.marker(); -verify.renameInfoSucceeded("DefaultExportedClass"); \ No newline at end of file +verify.renameInfoSucceeded("DefaultExportedClass", '"tests/cases/fourslash/foo".DefaultExportedClass'); \ No newline at end of file diff --git a/tests/cases/fourslash/renameForDefaultExport07.ts b/tests/cases/fourslash/renameForDefaultExport07.ts index 2c718a1202b..b65f348f2a0 100644 --- a/tests/cases/fourslash/renameForDefaultExport07.ts +++ b/tests/cases/fourslash/renameForDefaultExport07.ts @@ -1,5 +1,6 @@ /// +// @Filename: foo.ts ////export default function /**/[|DefaultExportedFunction|]() { //// return DefaultExportedFunction ////} @@ -12,4 +13,4 @@ ////var y = DefaultExportedFunction(); goTo.marker(); -verify.renameInfoSucceeded("DefaultExportedFunction"); \ No newline at end of file +verify.renameInfoSucceeded("DefaultExportedFunction", '"tests/cases/fourslash/foo".DefaultExportedFunction'); \ No newline at end of file diff --git a/tests/cases/fourslash/renameForDefaultExport08.ts b/tests/cases/fourslash/renameForDefaultExport08.ts index 29064180d58..9b3f23db2c1 100644 --- a/tests/cases/fourslash/renameForDefaultExport08.ts +++ b/tests/cases/fourslash/renameForDefaultExport08.ts @@ -1,5 +1,6 @@ /// +// @Filename: foo.ts ////export default function DefaultExportedFunction() { //// return /**/[|DefaultExportedFunction|] ////} @@ -12,4 +13,4 @@ ////var y = DefaultExportedFunction(); goTo.marker(); -verify.renameInfoSucceeded("DefaultExportedFunction"); \ No newline at end of file +verify.renameInfoSucceeded("DefaultExportedFunction", '"tests/cases/fourslash/foo".DefaultExportedFunction'); \ No newline at end of file diff --git a/tests/cases/fourslash/renameForDefaultExport09.ts b/tests/cases/fourslash/renameForDefaultExport09.ts index 568eb18a84e..bba2e57f49e 100644 --- a/tests/cases/fourslash/renameForDefaultExport09.ts +++ b/tests/cases/fourslash/renameForDefaultExport09.ts @@ -1,5 +1,6 @@ /// +// @Filename: foo.ts ////function /**/[|f|]() { //// return 100; ////}