diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index ff5baddbb70..0717ed68e83 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; } @@ -884,8 +884,16 @@ 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)); + 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); @@ -898,9 +906,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)); } } } diff --git a/src/services/services.ts b/src/services/services.ts index e3d9480e062..98f933c53dd 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4265,7 +4265,7 @@ namespace 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); } @@ -4917,10 +4917,10 @@ namespace 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 @@ -4955,7 +4955,7 @@ namespace ts { 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; } @@ -4965,8 +4965,9 @@ 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 quote - let declaredName = getDeclaredName(symbol, node); + // 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; // otherwise we'll need to search globally (i.e. include each file). @@ -5013,76 +5014,43 @@ namespace 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) { - // 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. - if (isImportOrExportSpecifierName(location)) { - return location.getText(); - } - - name = typeChecker.symbolToString(symbol); - - 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. + // 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(); } - // Special case for function expressions, whose names are solely local to their bodies. - let functionExpression = forEach(declarations, d => d.kind === SyntaxKind.FunctionExpression ? d : undefined); + // 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; - // 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); - } - - 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); } + /** + * 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, 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); @@ -6724,12 +6692,13 @@ namespace 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 73b88a3df26..0fd945caa7d 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -652,4 +652,34 @@ namespace ts { typechecker.getSymbolDisplayBuilder().buildSignatureDisplay(signature, writer, enclosingDeclaration, flags); }); } + + 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)) { + 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 diff --git a/tests/cases/fourslash/findAllRefsForDefaultExport01.ts b/tests/cases/fourslash/findAllRefsForDefaultExport01.ts new file mode 100644 index 00000000000..2f40af93c02 --- /dev/null +++ b/tests/cases/fourslash/findAllRefsForDefaultExport01.ts @@ -0,0 +1,18 @@ +/// + +////export default class [|DefaultExportedClass|] { +////} +//// +////var x: [|DefaultExportedClass|]; +//// +////var y = new [|DefaultExportedClass|]; + +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 diff --git a/tests/cases/fourslash/findAllRefsForDefaultExport02.ts b/tests/cases/fourslash/findAllRefsForDefaultExport02.ts new file mode 100644 index 00000000000..db773c74e3c --- /dev/null +++ b/tests/cases/fourslash/findAllRefsForDefaultExport02.ts @@ -0,0 +1,19 @@ +/// + +////export default function [|DefaultExportedFunction|]() { +//// return [|DefaultExportedFunction|] +////} +//// +////var x: typeof [|DefaultExportedFunction|]; +//// +////var y = [|DefaultExportedFunction|](); + +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 diff --git a/tests/cases/fourslash/findAllRefsForDefaultExport03.ts b/tests/cases/fourslash/findAllRefsForDefaultExport03.ts new file mode 100644 index 00000000000..f753d17de49 --- /dev/null +++ b/tests/cases/fourslash/findAllRefsForDefaultExport03.ts @@ -0,0 +1,25 @@ +/// + +////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); + + verify.referencesCountIs(ranges.length); + for (let expectedReference of ranges) { + verify.referencesAtPositionContains(expectedReference); + } +} \ No newline at end of file diff --git a/tests/cases/fourslash/findAllRefsForDefaultExport04.ts b/tests/cases/fourslash/findAllRefsForDefaultExport04.ts new file mode 100644 index 00000000000..45b008b55fe --- /dev/null +++ b/tests/cases/fourslash/findAllRefsForDefaultExport04.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/findAllRefsForDefaultExport05.ts b/tests/cases/fourslash/findAllRefsForDefaultExport05.ts new file mode 100644 index 00000000000..6655138da3b --- /dev/null +++ b/tests/cases/fourslash/findAllRefsForDefaultExport05.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/findAllRefsForDefaultExport06.ts b/tests/cases/fourslash/findAllRefsForDefaultExport06.ts new file mode 100644 index 00000000000..12c187b4b0c --- /dev/null +++ b/tests/cases/fourslash/findAllRefsForDefaultExport06.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/findAllRefsForDefaultExport07.ts b/tests/cases/fourslash/findAllRefsForDefaultExport07.ts new file mode 100644 index 00000000000..9534a671316 --- /dev/null +++ b/tests/cases/fourslash/findAllRefsForDefaultExport07.ts @@ -0,0 +1,18 @@ +/// + +////export default function DefaultExportedFunction() { +//// return DefaultExportedFunction +////} +//// +////var x: typeof DefaultExportedFunction; +//// +////var y = DefaultExportedFunction(); +//// +////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/findAllRefsForDefaultExport08.ts b/tests/cases/fourslash/findAllRefsForDefaultExport08.ts new file mode 100644 index 00000000000..80eabbe53f4 --- /dev/null +++ b/tests/cases/fourslash/findAllRefsForDefaultExport08.ts @@ -0,0 +1,17 @@ +/// + +////export default class DefaultExportedClass { +////} +//// +////var x: DefaultExportedClass; +//// +////var y = new DefaultExportedClass; +//// +////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/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 diff --git a/tests/cases/fourslash/renameForDefaultExport01.ts b/tests/cases/fourslash/renameForDefaultExport01.ts new file mode 100644 index 00000000000..809c127a727 --- /dev/null +++ b/tests/cases/fourslash/renameForDefaultExport01.ts @@ -0,0 +1,18 @@ +/// + +////export default class /*1*/[|DefaultExportedClass|] { +////} +/////* +//// * Commenting [|DefaultExportedClass|] +//// */ +//// +////var x: /*2*/[|DefaultExportedClass|]; +//// +////var y = new /*3*/[|DefaultExportedClass|]; + +let markers = test.markers() +for (let marker of markers) { + goTo.position(marker.position); + + verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ true); +} \ 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..ddf4b224023 --- /dev/null +++ b/tests/cases/fourslash/renameForDefaultExport02.ts @@ -0,0 +1,19 @@ +/// + +////export default function /*1*/[|DefaultExportedFunction|]() { +//// return /*2*/[|DefaultExportedFunction|] +////} +/////** +//// * Commenting [|DefaultExportedFunction|] +//// */ +//// +////var x: typeof /*3*/[|DefaultExportedFunction|]; +//// +////var y = /*4*/[|DefaultExportedFunction|](); + +let markers = test.markers() +for (let marker of markers) { + goTo.position(marker.position); + + verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ true); +} \ 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..6f82d96fe5e --- /dev/null +++ b/tests/cases/fourslash/renameForDefaultExport03.ts @@ -0,0 +1,25 @@ +/// + +////function /*1*/[|f|]() { +//// return 100; +////} +//// +////export default /*2*/[|f|]; +//// +////var x: typeof /*3*/[|f|]; +//// +////var y = /*4*/[|f|](); +//// +/////** +//// * Commenting [|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); +} \ 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..ba40374e262 --- /dev/null +++ b/tests/cases/fourslash/renameForDefaultExport04.ts @@ -0,0 +1,15 @@ +/// + +// @Filename: foo.ts +////export default class /**/[|DefaultExportedClass|] { +////} +/////* +//// * Commenting DefaultExportedClass +//// */ +//// +////var x: DefaultExportedClass; +//// +////var y = new DefaultExportedClass; + +goTo.marker(); +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 new file mode 100644 index 00000000000..099f878bda1 --- /dev/null +++ b/tests/cases/fourslash/renameForDefaultExport05.ts @@ -0,0 +1,15 @@ +/// + +// @Filename: foo.ts +////export default class DefaultExportedClass { +////} +/////* +//// * Commenting DefaultExportedClass +//// */ +//// +////var x: /**/[|DefaultExportedClass|]; +//// +////var y = new DefaultExportedClass; + +goTo.marker(); +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 new file mode 100644 index 00000000000..3ec067b7029 --- /dev/null +++ b/tests/cases/fourslash/renameForDefaultExport06.ts @@ -0,0 +1,15 @@ +/// + +// @Filename: foo.ts +////export default class DefaultExportedClass { +////} +/////* +//// * Commenting DefaultExportedClass +//// */ +//// +////var x: DefaultExportedClass; +//// +////var y = new /**/[|DefaultExportedClass|]; + +goTo.marker(); +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 new file mode 100644 index 00000000000..b65f348f2a0 --- /dev/null +++ b/tests/cases/fourslash/renameForDefaultExport07.ts @@ -0,0 +1,16 @@ +/// + +// @Filename: foo.ts +////export default function /**/[|DefaultExportedFunction|]() { +//// return DefaultExportedFunction +////} +/////** +//// * Commenting DefaultExportedFunction +//// */ +//// +////var x: typeof DefaultExportedFunction; +//// +////var y = DefaultExportedFunction(); + +goTo.marker(); +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 new file mode 100644 index 00000000000..9b3f23db2c1 --- /dev/null +++ b/tests/cases/fourslash/renameForDefaultExport08.ts @@ -0,0 +1,16 @@ +/// + +// @Filename: foo.ts +////export default function DefaultExportedFunction() { +//// return /**/[|DefaultExportedFunction|] +////} +/////** +//// * Commenting DefaultExportedFunction +//// */ +//// +////var x: typeof DefaultExportedFunction; +//// +////var y = DefaultExportedFunction(); + +goTo.marker(); +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 new file mode 100644 index 00000000000..bba2e57f49e --- /dev/null +++ b/tests/cases/fourslash/renameForDefaultExport09.ts @@ -0,0 +1,22 @@ +/// + +// @Filename: foo.ts +////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 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/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 new file mode 100644 index 00000000000..e884783d960 --- /dev/null +++ b/tests/cases/fourslash/renameLocationsForFunctionExpression01.ts @@ -0,0 +1,12 @@ +/// + +////var x = function [|f|](g: any, h: any) { +//// [|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 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