From 531f3aa0ac222d9ce50dfba8b6b8db5da205dbaa Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 7 May 2015 15:11:46 -0700 Subject: [PATCH 01/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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 f734055ee7522db7d3d1bced6f2ed9e68d483b80 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 25 Jun 2015 12:06:13 -0400 Subject: [PATCH 18/35] externam -> external --- ...nExternamModuleName.ts => goToDefinitionExternalModuleName.ts} | 0 ...xternamModuleName2.ts => goToDefinitionExternalModuleName2.ts} | 0 ...xternamModuleName3.ts => goToDefinitionExternalModuleName3.ts} | 0 ...xternamModuleName4.ts => goToDefinitionExternalModuleName4.ts} | 0 ...xternamModuleName5.ts => goToDefinitionExternalModuleName5.ts} | 0 ...xternamModuleName6.ts => goToDefinitionExternalModuleName6.ts} | 0 ...xternamModuleName7.ts => goToDefinitionExternalModuleName7.ts} | 0 ...xternamModuleName8.ts => goToDefinitionExternalModuleName8.ts} | 0 ...xternamModuleName9.ts => goToDefinitionExternalModuleName9.ts} | 0 9 files changed, 0 insertions(+), 0 deletions(-) rename tests/cases/fourslash/{goToDefinitionExternamModuleName.ts => goToDefinitionExternalModuleName.ts} (100%) rename tests/cases/fourslash/{goToDefinitionExternamModuleName2.ts => goToDefinitionExternalModuleName2.ts} (100%) rename tests/cases/fourslash/{goToDefinitionExternamModuleName3.ts => goToDefinitionExternalModuleName3.ts} (100%) rename tests/cases/fourslash/{goToDefinitionExternamModuleName4.ts => goToDefinitionExternalModuleName4.ts} (100%) rename tests/cases/fourslash/{goToDefinitionExternamModuleName5.ts => goToDefinitionExternalModuleName5.ts} (100%) rename tests/cases/fourslash/{goToDefinitionExternamModuleName6.ts => goToDefinitionExternalModuleName6.ts} (100%) rename tests/cases/fourslash/{goToDefinitionExternamModuleName7.ts => goToDefinitionExternalModuleName7.ts} (100%) rename tests/cases/fourslash/{goToDefinitionExternamModuleName8.ts => goToDefinitionExternalModuleName8.ts} (100%) rename tests/cases/fourslash/{goToDefinitionExternamModuleName9.ts => goToDefinitionExternalModuleName9.ts} (100%) diff --git a/tests/cases/fourslash/goToDefinitionExternamModuleName.ts b/tests/cases/fourslash/goToDefinitionExternalModuleName.ts similarity index 100% rename from tests/cases/fourslash/goToDefinitionExternamModuleName.ts rename to tests/cases/fourslash/goToDefinitionExternalModuleName.ts diff --git a/tests/cases/fourslash/goToDefinitionExternamModuleName2.ts b/tests/cases/fourslash/goToDefinitionExternalModuleName2.ts similarity index 100% rename from tests/cases/fourslash/goToDefinitionExternamModuleName2.ts rename to tests/cases/fourslash/goToDefinitionExternalModuleName2.ts diff --git a/tests/cases/fourslash/goToDefinitionExternamModuleName3.ts b/tests/cases/fourslash/goToDefinitionExternalModuleName3.ts similarity index 100% rename from tests/cases/fourslash/goToDefinitionExternamModuleName3.ts rename to tests/cases/fourslash/goToDefinitionExternalModuleName3.ts diff --git a/tests/cases/fourslash/goToDefinitionExternamModuleName4.ts b/tests/cases/fourslash/goToDefinitionExternalModuleName4.ts similarity index 100% rename from tests/cases/fourslash/goToDefinitionExternamModuleName4.ts rename to tests/cases/fourslash/goToDefinitionExternalModuleName4.ts diff --git a/tests/cases/fourslash/goToDefinitionExternamModuleName5.ts b/tests/cases/fourslash/goToDefinitionExternalModuleName5.ts similarity index 100% rename from tests/cases/fourslash/goToDefinitionExternamModuleName5.ts rename to tests/cases/fourslash/goToDefinitionExternalModuleName5.ts diff --git a/tests/cases/fourslash/goToDefinitionExternamModuleName6.ts b/tests/cases/fourslash/goToDefinitionExternalModuleName6.ts similarity index 100% rename from tests/cases/fourslash/goToDefinitionExternamModuleName6.ts rename to tests/cases/fourslash/goToDefinitionExternalModuleName6.ts diff --git a/tests/cases/fourslash/goToDefinitionExternamModuleName7.ts b/tests/cases/fourslash/goToDefinitionExternalModuleName7.ts similarity index 100% rename from tests/cases/fourslash/goToDefinitionExternamModuleName7.ts rename to tests/cases/fourslash/goToDefinitionExternalModuleName7.ts diff --git a/tests/cases/fourslash/goToDefinitionExternamModuleName8.ts b/tests/cases/fourslash/goToDefinitionExternalModuleName8.ts similarity index 100% rename from tests/cases/fourslash/goToDefinitionExternamModuleName8.ts rename to tests/cases/fourslash/goToDefinitionExternalModuleName8.ts diff --git a/tests/cases/fourslash/goToDefinitionExternamModuleName9.ts b/tests/cases/fourslash/goToDefinitionExternalModuleName9.ts similarity index 100% rename from tests/cases/fourslash/goToDefinitionExternamModuleName9.ts rename to tests/cases/fourslash/goToDefinitionExternalModuleName9.ts From 6732acaa325ee42322e5fa97e2bd260f358f580d Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 25 Jun 2015 12:10:09 -0400 Subject: [PATCH 19/35] Underscore typings. --- .../fourslash/{underscoreTypings1.ts => underscoreTypings01.ts} | 0 .../fourslash/{underscoreTyping1.ts => underscoreTypings02.ts} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename tests/cases/fourslash/{underscoreTypings1.ts => underscoreTypings01.ts} (100%) rename tests/cases/fourslash/{underscoreTyping1.ts => underscoreTypings02.ts} (100%) diff --git a/tests/cases/fourslash/underscoreTypings1.ts b/tests/cases/fourslash/underscoreTypings01.ts similarity index 100% rename from tests/cases/fourslash/underscoreTypings1.ts rename to tests/cases/fourslash/underscoreTypings01.ts diff --git a/tests/cases/fourslash/underscoreTyping1.ts b/tests/cases/fourslash/underscoreTypings02.ts similarity index 100% rename from tests/cases/fourslash/underscoreTyping1.ts rename to tests/cases/fourslash/underscoreTypings02.ts From 926c25e38b3f77c3b0a558e3ade537ef6ad35f88 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 25 Jun 2015 12:14:59 -0400 Subject: [PATCH 20/35] No more 'scriptLexicalStructure'. --- ...ureBindingPatterns.ts => navigationBarItemsBindingPatterns.ts} | 0 ...uctor.ts => navigationBarItemsBindingPatternsInConstructor.ts} | 0 ...mptyConstructors.ts => navigationBarItemsEmptyConstructors.ts} | 0 ...iptLexicalStructureExports.ts => navigationBarItemsExports.ts} | 0 ...exicalStructureFunctions.ts => navigationBarItemsFunctions.ts} | 0 ...ureFunctionsBroken.ts => navigationBarItemsFunctionsBroken.ts} | 0 ...eFunctionsBroken2.ts => navigationBarItemsFunctionsBroken2.ts} | 0 ...iptLexicalStructureImports.ts => navigationBarItemsImports.ts} | 0 ...{scriptLexicalStructureItems.ts => navigationBarItemsItems.ts} | 0 ...criptLexicalStructureItems2.ts => navigationBarItemsItems2.ts} | 0 ....ts => navigationBarItemsItemsContainsNoAnonymousFunctions.ts} | 0 ...ternalModules.ts => navigationBarItemsItemsExternalModules.ts} | 0 ...rnalModules2.ts => navigationBarItemsItemsExternalModules2.ts} | 0 ...rnalModules3.ts => navigationBarItemsItemsExternalModules3.ts} | 0 ...duleVariables.ts => navigationBarItemsItemsModuleVariables.ts} | 0 ...StructureMissingName1.ts => navigationBarItemsMissingName1.ts} | 0 ...StructureMissingName2.ts => navigationBarItemsMissingName2.ts} | 0 ...iptLexicalStructureModules.ts => navigationBarItemsModules.ts} | 0 ...tifiers.ts => navigationBarItemsMultilineStringIdentifiers.ts} | 0 ...rs.ts => navigationBarItemsPropertiesDefinedInConstructors.ts} | 0 ...tLexicalStructureSymbols1.ts => navigationBarItemsSymbols1.ts} | 0 ...tLexicalStructureSymbols2.ts => navigationBarItemsSymbols2.ts} | 0 ...tLexicalStructureSymbols3.ts => navigationBarItemsSymbols3.ts} | 0 23 files changed, 0 insertions(+), 0 deletions(-) rename tests/cases/fourslash/{scriptLexicalStructureBindingPatterns.ts => navigationBarItemsBindingPatterns.ts} (100%) rename tests/cases/fourslash/{scriptLexicalStructureBindingPatternsInConstructor.ts => navigationBarItemsBindingPatternsInConstructor.ts} (100%) rename tests/cases/fourslash/{scriptLexicalStructureEmptyConstructors.ts => navigationBarItemsEmptyConstructors.ts} (100%) rename tests/cases/fourslash/{scriptLexicalStructureExports.ts => navigationBarItemsExports.ts} (100%) rename tests/cases/fourslash/{scriptLexicalStructureFunctions.ts => navigationBarItemsFunctions.ts} (100%) rename tests/cases/fourslash/{scriptLexicalStructureFunctionsBroken.ts => navigationBarItemsFunctionsBroken.ts} (100%) rename tests/cases/fourslash/{scriptLexicalStructureFunctionsBroken2.ts => navigationBarItemsFunctionsBroken2.ts} (100%) rename tests/cases/fourslash/{scriptLexicalStructureImports.ts => navigationBarItemsImports.ts} (100%) rename tests/cases/fourslash/{scriptLexicalStructureItems.ts => navigationBarItemsItems.ts} (100%) rename tests/cases/fourslash/{scriptLexicalStructureItems2.ts => navigationBarItemsItems2.ts} (100%) rename tests/cases/fourslash/{scriptLexicalStructureItemsContainsNoAnonymousFunctions.ts => navigationBarItemsItemsContainsNoAnonymousFunctions.ts} (100%) rename tests/cases/fourslash/{scriptLexicalStructureItemsExternalModules.ts => navigationBarItemsItemsExternalModules.ts} (100%) rename tests/cases/fourslash/{scriptLexicalStructureItemsExternalModules2.ts => navigationBarItemsItemsExternalModules2.ts} (100%) rename tests/cases/fourslash/{scriptLexicalStructureItemsExternalModules3.ts => navigationBarItemsItemsExternalModules3.ts} (100%) rename tests/cases/fourslash/{scriptLexicalStructureItemsModuleVariables.ts => navigationBarItemsItemsModuleVariables.ts} (100%) rename tests/cases/fourslash/{scriptLexicalStructureMissingName1.ts => navigationBarItemsMissingName1.ts} (100%) rename tests/cases/fourslash/{scriptLexicalStructureMissingName2.ts => navigationBarItemsMissingName2.ts} (100%) rename tests/cases/fourslash/{scriptLexicalStructureModules.ts => navigationBarItemsModules.ts} (100%) rename tests/cases/fourslash/{scriptLexicalStructureMultilineStringIdentifiers.ts => navigationBarItemsMultilineStringIdentifiers.ts} (100%) rename tests/cases/fourslash/{scriptLexicalStructurePropertiesDefinedInConstructors.ts => navigationBarItemsPropertiesDefinedInConstructors.ts} (100%) rename tests/cases/fourslash/{scriptLexicalStructureSymbols1.ts => navigationBarItemsSymbols1.ts} (100%) rename tests/cases/fourslash/{scriptLexicalStructureSymbols2.ts => navigationBarItemsSymbols2.ts} (100%) rename tests/cases/fourslash/{scriptLexicalStructureSymbols3.ts => navigationBarItemsSymbols3.ts} (100%) diff --git a/tests/cases/fourslash/scriptLexicalStructureBindingPatterns.ts b/tests/cases/fourslash/navigationBarItemsBindingPatterns.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureBindingPatterns.ts rename to tests/cases/fourslash/navigationBarItemsBindingPatterns.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureBindingPatternsInConstructor.ts b/tests/cases/fourslash/navigationBarItemsBindingPatternsInConstructor.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureBindingPatternsInConstructor.ts rename to tests/cases/fourslash/navigationBarItemsBindingPatternsInConstructor.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureEmptyConstructors.ts b/tests/cases/fourslash/navigationBarItemsEmptyConstructors.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureEmptyConstructors.ts rename to tests/cases/fourslash/navigationBarItemsEmptyConstructors.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureExports.ts b/tests/cases/fourslash/navigationBarItemsExports.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureExports.ts rename to tests/cases/fourslash/navigationBarItemsExports.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureFunctions.ts b/tests/cases/fourslash/navigationBarItemsFunctions.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureFunctions.ts rename to tests/cases/fourslash/navigationBarItemsFunctions.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureFunctionsBroken.ts b/tests/cases/fourslash/navigationBarItemsFunctionsBroken.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureFunctionsBroken.ts rename to tests/cases/fourslash/navigationBarItemsFunctionsBroken.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureFunctionsBroken2.ts b/tests/cases/fourslash/navigationBarItemsFunctionsBroken2.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureFunctionsBroken2.ts rename to tests/cases/fourslash/navigationBarItemsFunctionsBroken2.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureImports.ts b/tests/cases/fourslash/navigationBarItemsImports.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureImports.ts rename to tests/cases/fourslash/navigationBarItemsImports.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureItems.ts b/tests/cases/fourslash/navigationBarItemsItems.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureItems.ts rename to tests/cases/fourslash/navigationBarItemsItems.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureItems2.ts b/tests/cases/fourslash/navigationBarItemsItems2.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureItems2.ts rename to tests/cases/fourslash/navigationBarItemsItems2.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureItemsContainsNoAnonymousFunctions.ts b/tests/cases/fourslash/navigationBarItemsItemsContainsNoAnonymousFunctions.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureItemsContainsNoAnonymousFunctions.ts rename to tests/cases/fourslash/navigationBarItemsItemsContainsNoAnonymousFunctions.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureItemsExternalModules.ts b/tests/cases/fourslash/navigationBarItemsItemsExternalModules.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureItemsExternalModules.ts rename to tests/cases/fourslash/navigationBarItemsItemsExternalModules.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureItemsExternalModules2.ts b/tests/cases/fourslash/navigationBarItemsItemsExternalModules2.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureItemsExternalModules2.ts rename to tests/cases/fourslash/navigationBarItemsItemsExternalModules2.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureItemsExternalModules3.ts b/tests/cases/fourslash/navigationBarItemsItemsExternalModules3.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureItemsExternalModules3.ts rename to tests/cases/fourslash/navigationBarItemsItemsExternalModules3.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureItemsModuleVariables.ts b/tests/cases/fourslash/navigationBarItemsItemsModuleVariables.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureItemsModuleVariables.ts rename to tests/cases/fourslash/navigationBarItemsItemsModuleVariables.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureMissingName1.ts b/tests/cases/fourslash/navigationBarItemsMissingName1.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureMissingName1.ts rename to tests/cases/fourslash/navigationBarItemsMissingName1.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureMissingName2.ts b/tests/cases/fourslash/navigationBarItemsMissingName2.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureMissingName2.ts rename to tests/cases/fourslash/navigationBarItemsMissingName2.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureModules.ts b/tests/cases/fourslash/navigationBarItemsModules.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureModules.ts rename to tests/cases/fourslash/navigationBarItemsModules.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureMultilineStringIdentifiers.ts b/tests/cases/fourslash/navigationBarItemsMultilineStringIdentifiers.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureMultilineStringIdentifiers.ts rename to tests/cases/fourslash/navigationBarItemsMultilineStringIdentifiers.ts diff --git a/tests/cases/fourslash/scriptLexicalStructurePropertiesDefinedInConstructors.ts b/tests/cases/fourslash/navigationBarItemsPropertiesDefinedInConstructors.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructurePropertiesDefinedInConstructors.ts rename to tests/cases/fourslash/navigationBarItemsPropertiesDefinedInConstructors.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureSymbols1.ts b/tests/cases/fourslash/navigationBarItemsSymbols1.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureSymbols1.ts rename to tests/cases/fourslash/navigationBarItemsSymbols1.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureSymbols2.ts b/tests/cases/fourslash/navigationBarItemsSymbols2.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureSymbols2.ts rename to tests/cases/fourslash/navigationBarItemsSymbols2.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureSymbols3.ts b/tests/cases/fourslash/navigationBarItemsSymbols3.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureSymbols3.ts rename to tests/cases/fourslash/navigationBarItemsSymbols3.ts From c04bc692d45f43ec6f428a2477122d98aae2efb7 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 25 Jun 2015 13:21:58 -0400 Subject: [PATCH 21/35] Fixed coment. --- tests/cases/compiler/numLit.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cases/compiler/numLit.ts b/tests/cases/compiler/numLit.ts index abe3505703d..23cd2ba45f8 100644 --- a/tests/cases/compiler/numLit.ts +++ b/tests/cases/compiler/numLit.ts @@ -6,7 +6,7 @@ // Preserve whitespace where important for JS compatibility var i: number = 1; var test1 = i.toString(); -var test2 = 2.toString(); // emitted as 2 .toString() +var test2 = 2.toString(); var test3 = 3 .toString(); var test4 = 3 .toString(); var test5 = 3 .toString(); From eda3956fa25d25444de843c83df46e9e143bec8f Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 25 Jun 2015 13:34:31 -0400 Subject: [PATCH 22/35] Accepted baselines. --- tests/baselines/reference/numLit.errors.txt | 2 +- tests/baselines/reference/numLit.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/baselines/reference/numLit.errors.txt b/tests/baselines/reference/numLit.errors.txt index 17392011fa6..603f655fe84 100644 --- a/tests/baselines/reference/numLit.errors.txt +++ b/tests/baselines/reference/numLit.errors.txt @@ -15,7 +15,7 @@ tests/cases/compiler/numLit.ts(9,24): error TS1109: Expression expected. // Preserve whitespace where important for JS compatibility var i: number = 1; var test1 = i.toString(); - var test2 = 2.toString(); // emitted as 2 .toString() + var test2 = 2.toString(); ~~~~~~~~ !!! error TS1005: ',' expected. ~ diff --git a/tests/baselines/reference/numLit.js b/tests/baselines/reference/numLit.js index c68d6925faa..add93ed0a6a 100644 --- a/tests/baselines/reference/numLit.js +++ b/tests/baselines/reference/numLit.js @@ -7,7 +7,7 @@ // Preserve whitespace where important for JS compatibility var i: number = 1; var test1 = i.toString(); -var test2 = 2.toString(); // emitted as 2 .toString() +var test2 = 2.toString(); var test3 = 3 .toString(); var test4 = 3 .toString(); var test5 = 3 .toString(); @@ -27,7 +27,7 @@ toString(); // Preserve whitespace where important for JS compatibility var i = 1; var test1 = i.toString(); -var test2 = 2., toString = (); // emitted as 2 .toString() +var test2 = 2., toString = (); var test3 = 3 .toString(); var test4 = 3 .toString(); var test5 = 3 .toString(); From ec2d5f3a0d9785d415bae02ba88ab1bb09e9ebf3 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 25 Jun 2015 13:38:42 -0400 Subject: [PATCH 23/35] Renamed test. --- ...ericLiteralsWithTrailingDecimalPoints01.errors.txt} | 10 +++++----- ...s => numericLiteralsWithTrailingDecimalPoints01.js} | 4 ++-- ...s => numericLiteralsWithTrailingDecimalPoints01.ts} | 0 3 files changed, 7 insertions(+), 7 deletions(-) rename tests/baselines/reference/{numLit.errors.txt => numericLiteralsWithTrailingDecimalPoints01.errors.txt} (56%) rename tests/baselines/reference/{numLit.js => numericLiteralsWithTrailingDecimalPoints01.js} (86%) rename tests/cases/compiler/{numLit.ts => numericLiteralsWithTrailingDecimalPoints01.ts} (100%) diff --git a/tests/baselines/reference/numLit.errors.txt b/tests/baselines/reference/numericLiteralsWithTrailingDecimalPoints01.errors.txt similarity index 56% rename from tests/baselines/reference/numLit.errors.txt rename to tests/baselines/reference/numericLiteralsWithTrailingDecimalPoints01.errors.txt index 603f655fe84..f08750ff0a6 100644 --- a/tests/baselines/reference/numLit.errors.txt +++ b/tests/baselines/reference/numericLiteralsWithTrailingDecimalPoints01.errors.txt @@ -1,10 +1,10 @@ -tests/cases/compiler/numLit.ts(3,3): error TS1005: ';' expected. -tests/cases/compiler/numLit.ts(9,15): error TS1005: ',' expected. -tests/cases/compiler/numLit.ts(9,23): error TS1005: '=' expected. -tests/cases/compiler/numLit.ts(9,24): error TS1109: Expression expected. +tests/cases/compiler/numericLiteralsWithTrailingDecimalPoints01.ts(3,3): error TS1005: ';' expected. +tests/cases/compiler/numericLiteralsWithTrailingDecimalPoints01.ts(9,15): error TS1005: ',' expected. +tests/cases/compiler/numericLiteralsWithTrailingDecimalPoints01.ts(9,23): error TS1005: '=' expected. +tests/cases/compiler/numericLiteralsWithTrailingDecimalPoints01.ts(9,24): error TS1109: Expression expected. -==== tests/cases/compiler/numLit.ts (4 errors) ==== +==== tests/cases/compiler/numericLiteralsWithTrailingDecimalPoints01.ts (4 errors) ==== 1..toString(); 1.0.toString(); 1.toString(); diff --git a/tests/baselines/reference/numLit.js b/tests/baselines/reference/numericLiteralsWithTrailingDecimalPoints01.js similarity index 86% rename from tests/baselines/reference/numLit.js rename to tests/baselines/reference/numericLiteralsWithTrailingDecimalPoints01.js index add93ed0a6a..0b1ce1f0736 100644 --- a/tests/baselines/reference/numLit.js +++ b/tests/baselines/reference/numericLiteralsWithTrailingDecimalPoints01.js @@ -1,4 +1,4 @@ -//// [numLit.ts] +//// [numericLiteralsWithTrailingDecimalPoints01.ts] 1..toString(); 1.0.toString(); 1.toString(); @@ -18,7 +18,7 @@ var test8 = new Number(4).toString(); var test9 = 3. + 3. -//// [numLit.js] +//// [numericLiteralsWithTrailingDecimalPoints01.js] 1..toString(); 1.0.toString(); 1.; diff --git a/tests/cases/compiler/numLit.ts b/tests/cases/compiler/numericLiteralsWithTrailingDecimalPoints01.ts similarity index 100% rename from tests/cases/compiler/numLit.ts rename to tests/cases/compiler/numericLiteralsWithTrailingDecimalPoints01.ts From 627ebc86eb497691109cca25e19b58c47ffe265f Mon Sep 17 00:00:00 2001 From: Dick van den Brink Date: Thu, 25 Jun 2015 20:47:40 +0200 Subject: [PATCH 24/35] Fixed formatting spaces on default keyword --- src/services/formatting/rules.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index 9897453e575..84d79be5c6e 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -318,7 +318,7 @@ namespace ts.formatting { this.NoSpaceAfterModuleImport = new Rule(RuleDescriptor.create2(Shared.TokenRange.FromTokens([SyntaxKind.ModuleKeyword, SyntaxKind.RequireKeyword]), SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete)); // Add a space around certain TypeScript keywords - this.SpaceAfterCertainTypeScriptKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.ClassKeyword, SyntaxKind.DeclareKeyword, SyntaxKind.EnumKeyword, SyntaxKind.ExportKeyword, SyntaxKind.ExtendsKeyword, SyntaxKind.GetKeyword, SyntaxKind.ImplementsKeyword, SyntaxKind.ImportKeyword, SyntaxKind.InterfaceKeyword, SyntaxKind.ModuleKeyword, SyntaxKind.NamespaceKeyword, SyntaxKind.PrivateKeyword, SyntaxKind.PublicKeyword, SyntaxKind.ProtectedKeyword, SyntaxKind.SetKeyword, SyntaxKind.StaticKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); + this.SpaceAfterCertainTypeScriptKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.ClassKeyword, SyntaxKind.DeclareKeyword, SyntaxKind.DefaultKeyword, SyntaxKind.EnumKeyword, SyntaxKind.ExportKeyword, SyntaxKind.ExtendsKeyword, SyntaxKind.GetKeyword, SyntaxKind.ImplementsKeyword, SyntaxKind.ImportKeyword, SyntaxKind.InterfaceKeyword, SyntaxKind.ModuleKeyword, SyntaxKind.NamespaceKeyword, SyntaxKind.PrivateKeyword, SyntaxKind.PublicKeyword, SyntaxKind.ProtectedKeyword, SyntaxKind.SetKeyword, SyntaxKind.StaticKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); this.SpaceBeforeCertainTypeScriptKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.Any, Shared.TokenRange.FromTokens([SyntaxKind.ExtendsKeyword, SyntaxKind.ImplementsKeyword])), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); // Treat string literals in module names as identifiers, and add a space between the literal and the opening Brace braces, e.g.: module "m2" { From de2d532b1f94a4c6980f8cded31516a028be5848 Mon Sep 17 00:00:00 2001 From: Dick van den Brink Date: Thu, 25 Jun 2015 20:49:25 +0200 Subject: [PATCH 25/35] Added test for formatting on default keyword --- tests/cases/fourslash/formattingOfExportDefault.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tests/cases/fourslash/formattingOfExportDefault.ts diff --git a/tests/cases/fourslash/formattingOfExportDefault.ts b/tests/cases/fourslash/formattingOfExportDefault.ts new file mode 100644 index 00000000000..ff69440b861 --- /dev/null +++ b/tests/cases/fourslash/formattingOfExportDefault.ts @@ -0,0 +1,12 @@ +/// + +////module Foo { +/////*1*/ export default class Test { } +////} +/////*2*/export default function bar() { } + +format.document(); +goTo.marker("1"); +verify.currentLineContentIs(" export default class Test { }") +goTo.marker("2"); +verify.currentLineContentIs("export default function bar() { }") From 408538fd43a72976f96a4af3d9c7affb30792eb8 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Thu, 25 Jun 2015 13:31:14 -0700 Subject: [PATCH 26/35] Remove unreferenced errors --- .../diagnosticInformationMap.generated.ts | 14 ----- src/compiler/diagnosticMessages.json | 56 ------------------- 2 files changed, 70 deletions(-) diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 8ccc9d890e2..5ca747e4b62 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -20,22 +20,16 @@ module ts { An_index_signature_must_have_a_type_annotation: { code: 1021, category: DiagnosticCategory.Error, key: "An index signature must have a type annotation." }, An_index_signature_parameter_must_have_a_type_annotation: { code: 1022, category: DiagnosticCategory.Error, key: "An index signature parameter must have a type annotation." }, An_index_signature_parameter_type_must_be_string_or_number: { code: 1023, category: DiagnosticCategory.Error, key: "An index signature parameter type must be 'string' or 'number'." }, - A_class_or_interface_declaration_can_only_have_one_extends_clause: { code: 1024, category: DiagnosticCategory.Error, key: "A class or interface declaration can only have one 'extends' clause." }, - An_extends_clause_must_precede_an_implements_clause: { code: 1025, category: DiagnosticCategory.Error, key: "An 'extends' clause must precede an 'implements' clause." }, - A_class_can_only_extend_a_single_class: { code: 1026, category: DiagnosticCategory.Error, key: "A class can only extend a single class." }, - A_class_declaration_can_only_have_one_implements_clause: { code: 1027, category: DiagnosticCategory.Error, key: "A class declaration can only have one 'implements' clause." }, Accessibility_modifier_already_seen: { code: 1028, category: DiagnosticCategory.Error, key: "Accessibility modifier already seen." }, _0_modifier_must_precede_1_modifier: { code: 1029, category: DiagnosticCategory.Error, key: "'{0}' modifier must precede '{1}' modifier." }, _0_modifier_already_seen: { code: 1030, category: DiagnosticCategory.Error, key: "'{0}' modifier already seen." }, _0_modifier_cannot_appear_on_a_class_element: { code: 1031, category: DiagnosticCategory.Error, key: "'{0}' modifier cannot appear on a class element." }, - An_interface_declaration_cannot_have_an_implements_clause: { code: 1032, category: DiagnosticCategory.Error, key: "An interface declaration cannot have an 'implements' clause." }, super_must_be_followed_by_an_argument_list_or_member_access: { code: 1034, category: DiagnosticCategory.Error, key: "'super' must be followed by an argument list or member access." }, Only_ambient_modules_can_use_quoted_names: { code: 1035, category: DiagnosticCategory.Error, key: "Only ambient modules can use quoted names." }, Statements_are_not_allowed_in_ambient_contexts: { code: 1036, category: DiagnosticCategory.Error, key: "Statements are not allowed in ambient contexts." }, A_declare_modifier_cannot_be_used_in_an_already_ambient_context: { code: 1038, category: DiagnosticCategory.Error, key: "A 'declare' modifier cannot be used in an already ambient context." }, Initializers_are_not_allowed_in_ambient_contexts: { code: 1039, category: DiagnosticCategory.Error, key: "Initializers are not allowed in ambient contexts." }, _0_modifier_cannot_appear_on_a_module_element: { code: 1044, category: DiagnosticCategory.Error, key: "'{0}' modifier cannot appear on a module element." }, - A_declare_modifier_cannot_be_used_with_an_interface_declaration: { code: 1045, category: DiagnosticCategory.Error, key: "A 'declare' modifier cannot be used with an interface declaration." }, A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file: { code: 1046, category: DiagnosticCategory.Error, key: "A 'declare' modifier is required for a top level declaration in a .d.ts file." }, A_rest_parameter_cannot_be_optional: { code: 1047, category: DiagnosticCategory.Error, key: "A rest parameter cannot be optional." }, A_rest_parameter_cannot_have_an_initializer: { code: 1048, category: DiagnosticCategory.Error, key: "A rest parameter cannot have an initializer." }, @@ -94,7 +88,6 @@ module ts { case_or_default_expected: { code: 1130, category: DiagnosticCategory.Error, key: "'case' or 'default' expected." }, Property_or_signature_expected: { code: 1131, category: DiagnosticCategory.Error, key: "Property or signature expected." }, Enum_member_expected: { code: 1132, category: DiagnosticCategory.Error, key: "Enum member expected." }, - Type_reference_expected: { code: 1133, category: DiagnosticCategory.Error, key: "Type reference expected." }, Variable_declaration_expected: { code: 1134, category: DiagnosticCategory.Error, key: "Variable declaration expected." }, Argument_expression_expected: { code: 1135, category: DiagnosticCategory.Error, key: "Argument expression expected." }, Property_assignment_expected: { code: 1136, category: DiagnosticCategory.Error, key: "Property assignment expected." }, @@ -111,9 +104,6 @@ module ts { Cannot_compile_modules_unless_the_module_flag_is_provided: { code: 1148, category: DiagnosticCategory.Error, key: "Cannot compile modules unless the '--module' flag is provided." }, File_name_0_differs_from_already_included_file_name_1_only_in_casing: { code: 1149, category: DiagnosticCategory.Error, key: "File name '{0}' differs from already included file name '{1}' only in casing" }, new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: DiagnosticCategory.Error, key: "'new T[]' cannot be used to create an array. Use 'new Array()' instead." }, - var_let_or_const_expected: { code: 1152, category: DiagnosticCategory.Error, key: "'var', 'let' or 'const' expected." }, - let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1153, category: DiagnosticCategory.Error, key: "'let' declarations are only available when targeting ECMAScript 6 and higher." }, - const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1154, category: DiagnosticCategory.Error, key: "'const' declarations are only available when targeting ECMAScript 6 and higher." }, const_declarations_must_be_initialized: { code: 1155, category: DiagnosticCategory.Error, key: "'const' declarations must be initialized" }, const_declarations_can_only_be_declared_inside_a_block: { code: 1156, category: DiagnosticCategory.Error, key: "'const' declarations can only be declared inside a block." }, let_declarations_can_only_be_declared_inside_a_block: { code: 1157, category: DiagnosticCategory.Error, key: "'let' declarations can only be declared inside a block." }, @@ -124,7 +114,6 @@ module ts { Computed_property_names_are_not_allowed_in_enums: { code: 1164, category: DiagnosticCategory.Error, key: "Computed property names are not allowed in enums." }, A_computed_property_name_in_an_ambient_context_must_directly_refer_to_a_built_in_symbol: { code: 1165, category: DiagnosticCategory.Error, key: "A computed property name in an ambient context must directly refer to a built-in symbol." }, A_computed_property_name_in_a_class_property_declaration_must_directly_refer_to_a_built_in_symbol: { code: 1166, category: DiagnosticCategory.Error, key: "A computed property name in a class property declaration must directly refer to a built-in symbol." }, - Computed_property_names_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1167, category: DiagnosticCategory.Error, key: "Computed property names are only available when targeting ECMAScript 6 and higher." }, A_computed_property_name_in_a_method_overload_must_directly_refer_to_a_built_in_symbol: { code: 1168, category: DiagnosticCategory.Error, key: "A computed property name in a method overload must directly refer to a built-in symbol." }, A_computed_property_name_in_an_interface_must_directly_refer_to_a_built_in_symbol: { code: 1169, category: DiagnosticCategory.Error, key: "A computed property name in an interface must directly refer to a built-in symbol." }, A_computed_property_name_in_a_type_literal_must_directly_refer_to_a_built_in_symbol: { code: 1170, category: DiagnosticCategory.Error, key: "A computed property name in a type literal must directly refer to a built-in symbol." }, @@ -140,7 +129,6 @@ module ts { Property_destructuring_pattern_expected: { code: 1180, category: DiagnosticCategory.Error, key: "Property destructuring pattern expected." }, Array_element_destructuring_pattern_expected: { code: 1181, category: DiagnosticCategory.Error, key: "Array element destructuring pattern expected." }, A_destructuring_declaration_must_have_an_initializer: { code: 1182, category: DiagnosticCategory.Error, key: "A destructuring declaration must have an initializer." }, - Destructuring_declarations_are_not_allowed_in_ambient_contexts: { code: 1183, category: DiagnosticCategory.Error, key: "Destructuring declarations are not allowed in ambient contexts." }, An_implementation_cannot_be_declared_in_ambient_contexts: { code: 1184, category: DiagnosticCategory.Error, key: "An implementation cannot be declared in ambient contexts." }, Modifiers_cannot_appear_here: { code: 1184, category: DiagnosticCategory.Error, key: "Modifiers cannot appear here." }, Merge_conflict_marker_encountered: { code: 1185, category: DiagnosticCategory.Error, key: "Merge conflict marker encountered." }, @@ -187,7 +175,6 @@ module ts { Module_0_has_no_exported_member_1: { code: 2305, category: DiagnosticCategory.Error, key: "Module '{0}' has no exported member '{1}'." }, File_0_is_not_a_module: { code: 2306, category: DiagnosticCategory.Error, key: "File '{0}' is not a module." }, Cannot_find_module_0: { code: 2307, category: DiagnosticCategory.Error, key: "Cannot find module '{0}'." }, - A_module_cannot_have_more_than_one_export_assignment: { code: 2308, category: DiagnosticCategory.Error, key: "A module cannot have more than one export assignment." }, An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements: { code: 2309, category: DiagnosticCategory.Error, key: "An export assignment cannot be used in a module with other exported elements." }, Type_0_recursively_references_itself_as_a_base_type: { code: 2310, category: DiagnosticCategory.Error, key: "Type '{0}' recursively references itself as a base type." }, A_class_may_only_extend_another_class: { code: 2311, category: DiagnosticCategory.Error, key: "A class may only extend another class." }, @@ -508,7 +495,6 @@ module ts { File_0_has_unsupported_extension_The_only_supported_extensions_are_1: { code: 6054, category: DiagnosticCategory.Error, key: "File '{0}' has unsupported extension. The only supported extensions are {1}." }, Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: { code: 6055, category: DiagnosticCategory.Message, key: "Suppress noImplicitAny errors for indexing objects lacking index signatures." }, Do_not_emit_declarations_for_code_that_has_an_internal_annotation: { code: 6056, category: DiagnosticCategory.Message, key: "Do not emit declarations for code that has an '@internal' annotation." }, - Preserve_new_lines_when_emitting_code: { code: 6057, category: DiagnosticCategory.Message, key: "Preserve new-lines when emitting code." }, Specifies_the_root_directory_of_input_files_Use_to_control_the_output_directory_structure_with_outDir: { code: 6058, category: DiagnosticCategory.Message, key: "Specifies the root directory of input files. Use to control the output directory structure with --outDir." }, File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files: { code: 6059, category: DiagnosticCategory.Error, key: "File '{0}' is not under 'rootDir' '{1}'. 'rootDir' is expected to contain all source files." }, Specifies_the_end_of_line_sequence_to_be_used_when_emitting_files_Colon_CRLF_dos_or_LF_unix: { code: 6060, category: DiagnosticCategory.Message, key: "Specifies the end of line sequence to be used when emitting files: 'CRLF' (dos) or 'LF' (unix)." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index fb246955f73..4610f699a16 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -67,22 +67,6 @@ "category": "Error", "code": 1023 }, - "A class or interface declaration can only have one 'extends' clause.": { - "category": "Error", - "code": 1024 - }, - "An 'extends' clause must precede an 'implements' clause.": { - "category": "Error", - "code": 1025 - }, - "A class can only extend a single class.": { - "category": "Error", - "code": 1026 - }, - "A class declaration can only have one 'implements' clause.": { - "category": "Error", - "code": 1027 - }, "Accessibility modifier already seen.": { "category": "Error", "code": 1028 @@ -99,10 +83,6 @@ "category": "Error", "code": 1031 }, - "An interface declaration cannot have an 'implements' clause.": { - "category": "Error", - "code": 1032 - }, "'super' must be followed by an argument list or member access.": { "category": "Error", "code": 1034 @@ -127,10 +107,6 @@ "category": "Error", "code": 1044 }, - "A 'declare' modifier cannot be used with an interface declaration.": { - "category": "Error", - "code": 1045 - }, "A 'declare' modifier is required for a top level declaration in a .d.ts file.": { "category": "Error", "code": 1046 @@ -363,10 +339,6 @@ "category": "Error", "code": 1132 }, - "Type reference expected.": { - "category": "Error", - "code": 1133 - }, "Variable declaration expected.": { "category": "Error", "code": 1134 @@ -431,18 +403,6 @@ "category": "Error", "code": 1150 }, - "'var', 'let' or 'const' expected.": { - "category": "Error", - "code": 1152 - }, - "'let' declarations are only available when targeting ECMAScript 6 and higher.": { - "category": "Error", - "code": 1153 - }, - "'const' declarations are only available when targeting ECMAScript 6 and higher.": { - "category": "Error", - "code": 1154 - }, "'const' declarations must be initialized": { "category": "Error", "code": 1155 @@ -483,10 +443,6 @@ "category": "Error", "code": 1166 }, - "Computed property names are only available when targeting ECMAScript 6 and higher.": { - "category": "Error", - "code": 1167 - }, "A computed property name in a method overload must directly refer to a built-in symbol.": { "category": "Error", "code": 1168 @@ -547,10 +503,6 @@ "category": "Error", "code": 1182 }, - "Destructuring declarations are not allowed in ambient contexts.": { - "category": "Error", - "code": 1183 - }, "An implementation cannot be declared in ambient contexts.": { "category": "Error", "code": 1184 @@ -736,10 +688,6 @@ "category": "Error", "code": 2307 }, - "A module cannot have more than one export assignment.": { - "category": "Error", - "code": 2308 - }, "An export assignment cannot be used in a module with other exported elements.": { "category": "Error", "code": 2309 @@ -2022,10 +1970,6 @@ "category": "Message", "code": 6056 }, - "Preserve new-lines when emitting code.": { - "category": "Message", - "code": 6057 - }, "Specifies the root directory of input files. Use to control the output directory structure with --outDir.": { "category": "Message", "code": 6058 From b4b2a41bc079c9b25ae833d77102e747206a7dcc Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Thu, 25 Jun 2015 13:34:42 -0700 Subject: [PATCH 27/35] Error check script --- scripts/errorCheck.ts | 83 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 scripts/errorCheck.ts diff --git a/scripts/errorCheck.ts b/scripts/errorCheck.ts new file mode 100644 index 00000000000..d2eb5a9632e --- /dev/null +++ b/scripts/errorCheck.ts @@ -0,0 +1,83 @@ +declare var require: any; +let fs = require('fs'); +let async = require('async'); +let glob = require('glob'); + +fs.readFile('src/compiler/diagnosticMessages.json', 'utf-8', (err, data) => { + let messages = JSON.parse(data); + if (err) throw err; + let keys = Object.keys(messages); + console.log('Loaded ' + keys.length + ' errors'); + + for(let k of keys) { + messages[k]['seen'] = false; + } + + let errRegex = /\(\d+,\d+\): error TS([^:]+):/g; + + let baseDir = 'tests/baselines/reference/'; + fs.readdir(baseDir, (err, files) => { + files = files.filter(f => f.indexOf('.errors.txt') > 0); + console.log('Read ' + files.length + ' baselines'); + let tasks: Array<(callback: () => void) => void> = []; + files.forEach(f => tasks.push(done => { + fs.readFile(baseDir + f, 'utf-8', (err, baseline) => { + if (err) throw err; + + let g: string[]; + while(g = errRegex.exec(baseline)) { + var errCode = +g[1]; + let msg = keys.filter(k => messages[k].code === errCode)[0]; + messages[msg]['seen'] = true; + } + + done(); + }); + })); + + async.parallelLimit(tasks, 25, done => { + console.log('== List of errors not present in baselines =='); + let count = 0; + for(let k of keys) { + if(messages[k]['seen'] !== true) { + console.log(k); + count++; + } + } + console.log(count + ' of ' + keys.length + ' errors are not in baselines'); + }); + }); +}); + +fs.readFile('src/compiler/diagnosticInformationMap.generated.ts', 'utf-8', (err, data) => { + let errorRegexp = /\s(\w+): \{ code/g; + let errorNames: string[] = []; + let errMatch: string[]; + while(errMatch = errorRegexp.exec(data)) { + errorNames.push(errMatch[1]); + } + + let allSrc: string = ''; + glob('./src/**/*.ts', {}, (err, files) => { + console.log('Reading ' + files.length + ' source files'); + files.forEach(file => { + if (file.indexOf('diagnosticInformationMap.generated.ts') > 0) return; + + let src = fs.readFileSync(file, 'utf-8'); + allSrc = allSrc + src; + }); + + console.log('Consumed ' + allSrc.length + ' characters of source'); + + let count = 0; + console.log('== List of errors not used in source ==') + errorNames.forEach(errName => { + if(allSrc.indexOf(errName) < 0) { + console.log(errName); + count++; + } + }); + console.log(count + ' of ' + errorNames.length + ' errors are not used in source'); + }); +}); + From aa59753fe4103778ea5514da48f89cf84336eed1 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Thu, 25 Jun 2015 14:02:30 -0700 Subject: [PATCH 28/35] CR feedback --- scripts/errorCheck.ts | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/scripts/errorCheck.ts b/scripts/errorCheck.ts index d2eb5a9632e..77892cb8f0c 100644 --- a/scripts/errorCheck.ts +++ b/scripts/errorCheck.ts @@ -4,12 +4,15 @@ let async = require('async'); let glob = require('glob'); fs.readFile('src/compiler/diagnosticMessages.json', 'utf-8', (err, data) => { - let messages = JSON.parse(data); - if (err) throw err; + if (err) { + throw err; + } + + let messages = JSON.parse(data); let keys = Object.keys(messages); console.log('Loaded ' + keys.length + ' errors'); - for(let k of keys) { + for (let k of keys) { messages[k]['seen'] = false; } @@ -18,14 +21,13 @@ fs.readFile('src/compiler/diagnosticMessages.json', 'utf-8', (err, data) => { let baseDir = 'tests/baselines/reference/'; fs.readdir(baseDir, (err, files) => { files = files.filter(f => f.indexOf('.errors.txt') > 0); - console.log('Read ' + files.length + ' baselines'); let tasks: Array<(callback: () => void) => void> = []; files.forEach(f => tasks.push(done => { fs.readFile(baseDir + f, 'utf-8', (err, baseline) => { if (err) throw err; let g: string[]; - while(g = errRegex.exec(baseline)) { + while (g = errRegex.exec(baseline)) { var errCode = +g[1]; let msg = keys.filter(k => messages[k].code === errCode)[0]; messages[msg]['seen'] = true; @@ -38,8 +40,8 @@ fs.readFile('src/compiler/diagnosticMessages.json', 'utf-8', (err, data) => { async.parallelLimit(tasks, 25, done => { console.log('== List of errors not present in baselines =='); let count = 0; - for(let k of keys) { - if(messages[k]['seen'] !== true) { + for (let k of keys) { + if (messages[k]['seen'] !== true) { console.log(k); count++; } @@ -53,30 +55,32 @@ fs.readFile('src/compiler/diagnosticInformationMap.generated.ts', 'utf-8', (err, let errorRegexp = /\s(\w+): \{ code/g; let errorNames: string[] = []; let errMatch: string[]; - while(errMatch = errorRegexp.exec(data)) { + while (errMatch = errorRegexp.exec(data)) { errorNames.push(errMatch[1]); } let allSrc: string = ''; glob('./src/**/*.ts', {}, (err, files) => { console.log('Reading ' + files.length + ' source files'); - files.forEach(file => { - if (file.indexOf('diagnosticInformationMap.generated.ts') > 0) return; + for(let file of files) { + if (file.indexOf('diagnosticInformationMap.generated.ts') > 0) { + continue; + } let src = fs.readFileSync(file, 'utf-8'); allSrc = allSrc + src; - }); + } console.log('Consumed ' + allSrc.length + ' characters of source'); let count = 0; console.log('== List of errors not used in source ==') - errorNames.forEach(errName => { - if(allSrc.indexOf(errName) < 0) { + for(let errName of errorNames) { + if (allSrc.indexOf(errName) < 0) { console.log(errName); count++; } - }); + } console.log(count + ' of ' + errorNames.length + ' errors are not used in source'); }); }); From c3af662e324e34d29794f30a81d7e12b8b0a645d Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 25 Jun 2015 18:39:29 -0700 Subject: [PATCH 29/35] Change var -> let and use destructuring --- src/services/services.ts | 46 ++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index e11fb32c73b..e3d9480e062 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1797,7 +1797,7 @@ namespace ts { let outputText: string; // Create a compilerHost object to allow the compiler to read and write files - var compilerHost: CompilerHost = { + let compilerHost: CompilerHost = { getSourceFile: (fileName, target) => fileName === inputFileName ? sourceFile : undefined, writeFile: (name, text, writeByteOrderMark) => { Debug.assert(outputText === undefined, "Unexpected multiple outputs for the file: " + name); @@ -1810,7 +1810,7 @@ namespace ts { getNewLine: () => newLine }; - var program = createProgram([inputFileName], options, compilerHost); + let program = createProgram([inputFileName], options, compilerHost); addRange(/*to*/ diagnostics, /*from*/ program.getSyntacticDiagnostics(sourceFile)); addRange(/*to*/ diagnostics, /*from*/ program.getOptionsDiagnostics()); @@ -3084,7 +3084,7 @@ namespace ts { * accurately aggregate locals from the closest containing scope. */ function getScopeNode(initialToken: Node, position: number, sourceFile: SourceFile) { - var scope = initialToken; + let scope = initialToken; while (scope && !positionBelongsToNode(scope, position, sourceFile)) { scope = scope.parent; } @@ -3485,10 +3485,10 @@ namespace ts { function getCompletionEntriesFromSymbols(symbols: Symbol[]): CompletionEntry[] { let start = new Date().getTime(); - var entries: CompletionEntry[] = []; + let entries: CompletionEntry[] = []; if (symbols) { - var nameToSymbol: Map = {}; + let nameToSymbol: Map = {}; for (let symbol of symbols) { let entry = createCompletionEntry(symbol, location); if (entry) { @@ -3522,13 +3522,13 @@ namespace ts { let symbol = forEach(symbols, s => getCompletionEntryDisplayNameForSymbol(s, target, /*performCharacterChecks:*/ false) === entryName ? s : undefined); if (symbol) { - let displayPartsDocumentationsAndSymbolKind = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, getValidSourceFile(fileName), location, location, SemanticMeaning.All); + let { displayParts, documentation, symbolKind } = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, getValidSourceFile(fileName), location, location, SemanticMeaning.All); return { name: entryName, - kind: displayPartsDocumentationsAndSymbolKind.symbolKind, kindModifiers: getSymbolModifiers(symbol), - displayParts: displayPartsDocumentationsAndSymbolKind.displayParts, - documentation: displayPartsDocumentationsAndSymbolKind.documentation + kind: symbolKind, + displayParts, + documentation }; } } @@ -4203,7 +4203,7 @@ namespace ts { } if (type.flags & TypeFlags.Union) { - var result: DefinitionInfo[] = []; + let result: DefinitionInfo[] = []; forEach((type).types, t => { if (t.symbol) { addRange(/*to*/ result, /*from*/ getDefinitionFromSymbol(t.symbol, node)); @@ -4303,7 +4303,7 @@ namespace ts { function getSyntacticDocumentHighlights(node: Node): DocumentHighlights[] { let fileName = sourceFile.fileName; - var highlightSpans = getHighlightSpans(node); + let highlightSpans = getHighlightSpans(node); if (!highlightSpans || highlightSpans.length === 0) { return undefined; } @@ -4881,17 +4881,17 @@ namespace ts { } function findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): RenameLocation[] { - var referencedSymbols = findReferencedSymbols(fileName, position, findInStrings, findInComments); + let referencedSymbols = findReferencedSymbols(fileName, position, findInStrings, findInComments); return convertReferences(referencedSymbols); } function getReferencesAtPosition(fileName: string, position: number): ReferenceEntry[] { - var referencedSymbols = findReferencedSymbols(fileName, position, /*findInStrings:*/ false, /*findInComments:*/ false); + let referencedSymbols = findReferencedSymbols(fileName, position, /*findInStrings:*/ false, /*findInComments:*/ false); return convertReferences(referencedSymbols); } function findReferences(fileName: string, position: number): ReferencedSymbol[]{ - var referencedSymbols = findReferencedSymbols(fileName, position, /*findInStrings:*/ false, /*findInComments:*/ false); + let referencedSymbols = findReferencedSymbols(fileName, position, /*findInStrings:*/ false, /*findInComments:*/ false); // Only include referenced symbols that have a valid definition. return filter(referencedSymbols, rs => !!rs.definition); @@ -5190,7 +5190,7 @@ namespace ts { } }); - var definition: DefinitionInfo = { + let definition: DefinitionInfo = { containerKind: "", containerName: "", fileName: targetLabel.getSourceFile().fileName, @@ -5286,10 +5286,10 @@ namespace ts { if (referenceSymbol) { let referenceSymbolDeclaration = referenceSymbol.valueDeclaration; let shorthandValueSymbol = typeChecker.getShorthandAssignmentValueSymbol(referenceSymbolDeclaration); - var relatedSymbol = getRelatedSymbol(searchSymbols, referenceSymbol, referenceLocation); + let relatedSymbol = getRelatedSymbol(searchSymbols, referenceSymbol, referenceLocation); if (relatedSymbol) { - var referencedSymbol = getReferencedSymbol(relatedSymbol); + let referencedSymbol = getReferencedSymbol(relatedSymbol); referencedSymbol.references.push(getReferenceEntryFromNode(referenceLocation)); } /* Because in short-hand property assignment, an identifier which stored as name of the short-hand property assignment @@ -5299,7 +5299,7 @@ namespace ts { * position of property accessing, the referenceEntry of such position will be handled in the first case. */ else if (!(referenceSymbol.flags & SymbolFlags.Transient) && searchSymbols.indexOf(shorthandValueSymbol) >= 0) { - var referencedSymbol = getReferencedSymbol(shorthandValueSymbol); + let referencedSymbol = getReferencedSymbol(shorthandValueSymbol); referencedSymbol.references.push(getReferenceEntryFromNode(referenceSymbolDeclaration.name)); } } @@ -5309,8 +5309,8 @@ namespace ts { return; function getReferencedSymbol(symbol: Symbol): ReferencedSymbol { - var symbolId = getSymbolId(symbol); - var index = symbolToIndex[symbolId]; + let symbolId = getSymbolId(symbol); + let index = symbolToIndex[symbolId]; if (index === undefined) { index = result.length; symbolToIndex[symbolId] = index; @@ -5397,7 +5397,7 @@ namespace ts { } }); - var definition = getDefinition(searchSpaceNode.symbol); + let definition = getDefinition(searchSpaceNode.symbol); return [{ definition, references }]; } @@ -5592,7 +5592,7 @@ namespace ts { // If the reference symbol is an alias, check if what it is aliasing is one of the search // symbols. if (isImportOrExportSpecifierImportSymbol(referenceSymbol)) { - var aliasedSymbol = typeChecker.getAliasedSymbol(referenceSymbol); + let aliasedSymbol = typeChecker.getAliasedSymbol(referenceSymbol); if (searchSymbols.indexOf(aliasedSymbol) >= 0) { return aliasedSymbol; } @@ -6908,7 +6908,7 @@ namespace ts { } function convertClassifications(classifications: Classifications, text: string): ClassificationResult { - var entries: ClassificationInfo[] = []; + let entries: ClassificationInfo[] = []; let dense = classifications.spans; let lastEnd = 0; From 133a86a3773868178d0aa6c53981f8b68087d7a1 Mon Sep 17 00:00:00 2001 From: mihailik Date: Fri, 26 Jun 2015 09:22:55 +0100 Subject: [PATCH 30/35] Conflict with Object.prototype.watch in FireFox/Gecko In Gecko engine `commandLine.options.watch` evaluates to a truthy value (a function). Adding an extra check to work around. [Definition of CompilerOptions.watch in compiler/types](https://github.com/Microsoft/TypeScript/blob/master/src/compiler/types.ts#L1860) ``` typescript export interface CompilerOptions { // . . . watch?: boolean; ``` [Object.prototype.watch on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/watch) > Warning: Generally you should avoid using watch() and unwatch() when possible. These two methods are > implemented only in Gecko, and they're intended primarily for debugging use. In addition, using watchpoints > has a serious negative impact on performance, which is especially true when used on global objects, such > as window. You can usually use setters and getters or proxies instead. See Browser compatibility for details. > Also, do not confuse Object.watch with Object.observe. --- src/compiler/tsc.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 2903c3a31f4..eada189d642 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -191,7 +191,7 @@ namespace ts { return sys.exit(ExitStatus.Success); } - if (commandLine.options.watch) { + if (commandLine.options.watch && commandLine.options.hasOwnProperty('watch')) { // FireFox has Object.prototype.watch if (!sys.watchFile) { reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--watch")); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); From e7e020e958bb4e9ec7942227be32092624a4ee99 Mon Sep 17 00:00:00 2001 From: mihailik Date: Fri, 26 Jun 2015 14:38:25 +0100 Subject: [PATCH 31/35] PR feedback - comments and whitespace adjustments --- src/compiler/tsc.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index eada189d642..1851e516abd 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -191,7 +191,8 @@ namespace ts { return sys.exit(ExitStatus.Success); } - if (commandLine.options.watch && commandLine.options.hasOwnProperty('watch')) { // FireFox has Object.prototype.watch + // Firefox has Object.prototype.watch + if (commandLine.options.watch && commandLine.options.hasOwnProperty('watch')) { if (!sys.watchFile) { reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--watch")); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); From 72050073bc9d6448dc4c7114b53c4e7fcb9b6ed5 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 26 Jun 2015 10:25:58 -0700 Subject: [PATCH 32/35] use double quotes --- src/compiler/tsc.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 1851e516abd..2a01774fbca 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -192,7 +192,7 @@ namespace ts { } // Firefox has Object.prototype.watch - if (commandLine.options.watch && commandLine.options.hasOwnProperty('watch')) { + if (commandLine.options.watch && commandLine.options.hasOwnProperty("watch")) { if (!sys.watchFile) { reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--watch")); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); From 83163697864611d81c74f98115e4f03b5641865c Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 29 Jun 2015 09:46:41 -0400 Subject: [PATCH 33/35] 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 34/35] 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 35/35] 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; ////}