diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index e990c0f675c32..0aff5e56b34c1 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -6565,8 +6565,8 @@ namespace ts { return finishNode(node); } - function parseNamespaceExport(): NamespaceExport { - const node = createNode(SyntaxKind.NamespaceExport); + function parseNamespaceExport(pos: number): NamespaceExport { + const node = createNode(SyntaxKind.NamespaceExport, pos); node.name = parseIdentifier(); return finishNode(node); } @@ -6574,9 +6574,10 @@ namespace ts { function parseExportDeclaration(node: ExportDeclaration): ExportDeclaration { node.kind = SyntaxKind.ExportDeclaration; node.isTypeOnly = parseOptional(SyntaxKind.TypeKeyword); + const namespaceExportPos = scanner.getStartPos(); if (parseOptional(SyntaxKind.AsteriskToken)) { if (parseOptional(SyntaxKind.AsKeyword)) { - node.exportClause = parseNamespaceExport(); + node.exportClause = parseNamespaceExport(namespaceExportPos); } parseExpected(SyntaxKind.FromKeyword); node.moduleSpecifier = parseModuleSpecifier(); diff --git a/src/harness/fourslashImpl.ts b/src/harness/fourslashImpl.ts index 6dc821fad6c08..3be657d4cd02b 100644 --- a/src/harness/fourslashImpl.ts +++ b/src/harness/fourslashImpl.ts @@ -1319,6 +1319,37 @@ namespace FourSlash { } } + public baselineRename(marker: string, options: FourSlashInterface.RenameOptions) { + const position = this.getMarkerByName(marker).position; + const locations = this.languageService.findRenameLocations( + this.activeFile.fileName, + position, + options.findInStrings ?? false, + options.findInComments ?? false, + options.providePrefixAndSuffixTextForRename); + + if (!locations) { + this.raiseError(`baselineRename failed. Could not rename at the provided position.`); + } + + const renamesByFile = ts.group(locations, l => l.fileName); + const baselineContent = renamesByFile.map(renames => { + const { fileName } = renames[0]; + const sortedRenames = ts.sort(renames, (a, b) => b.textSpan.start - a.textSpan.start); + let baselineFileContent = this.getFileContent(fileName); + for (const { textSpan } of sortedRenames) { + const isOriginalSpan = fileName === this.activeFile.fileName && ts.textSpanIntersectsWithPosition(textSpan, position); + baselineFileContent = + baselineFileContent.slice(0, textSpan.start) + + (isOriginalSpan ? "[|RENAME|]" : "RENAME") + + baselineFileContent.slice(textSpan.start + textSpan.length); + } + return `/*====== ${fileName} ======*/\n\n${baselineFileContent}`; + }).join("\n\n") + "\n"; + + Harness.Baseline.runBaseline(this.getBaselineFileNameForContainingTestFile(), baselineContent); + } + public verifyQuickInfoExists(negative: boolean) { const actualQuickInfo = this.languageService.getQuickInfoAtPosition(this.activeFile.fileName, this.currentCaretPosition); if (negative) { diff --git a/src/harness/fourslashInterfaceImpl.ts b/src/harness/fourslashInterfaceImpl.ts index a74785b8271ab..c5daf133cef32 100644 --- a/src/harness/fourslashInterfaceImpl.ts +++ b/src/harness/fourslashInterfaceImpl.ts @@ -516,6 +516,10 @@ namespace FourSlashInterface { this.state.verifyRenameLocations(startRanges, options); } + public baselineRename(marker: string, options: RenameOptions) { + this.state.baselineRename(marker, options); + } + public verifyQuickInfoDisplayParts(kind: string, kindModifiers: string, textSpan: FourSlash.TextSpan, displayParts: ts.SymbolDisplayPart[], documentation: ts.SymbolDisplayPart[], tags: ts.JSDocTagInfo[]) { this.state.verifyQuickInfoDisplayParts(kind, kindModifiers, textSpan, displayParts, documentation, tags); @@ -1623,4 +1627,9 @@ namespace FourSlashInterface { template: string }; export type RenameLocationOptions = FourSlash.Range | { readonly range: FourSlash.Range, readonly prefixText?: string, readonly suffixText?: string }; + export interface RenameOptions { + readonly findInStrings?: boolean; + readonly findInComments?: boolean; + readonly providePrefixAndSuffixTextForRename?: boolean; + }; } diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index 920d2dcc573ea..85886777eeb0d 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -1927,10 +1927,12 @@ namespace ts.FindAllReferences { } const exportSpecifier = getDeclarationOfKind(symbol, SyntaxKind.ExportSpecifier); - const localSymbol = exportSpecifier && checker.getExportSpecifierLocalTargetSymbol(exportSpecifier); - if (localSymbol) { - const res = cbSymbol(localSymbol, /*rootSymbol*/ undefined, /*baseSymbol*/ undefined, EntryKind.Node); - if (res) return res; + if (!isForRenamePopulateSearchSymbolSet || exportSpecifier && !exportSpecifier.propertyName) { + const localSymbol = exportSpecifier && checker.getExportSpecifierLocalTargetSymbol(exportSpecifier); + if (localSymbol) { + const res = cbSymbol(localSymbol, /*rootSymbol*/ undefined, /*baseSymbol*/ undefined, EntryKind.Node); + if (res) return res; + } } // symbolAtLocation for a binding element is the local symbol. See if the search symbol is the property. diff --git a/tests/baselines/reference/exportAsNamespace1(module=amd).symbols b/tests/baselines/reference/exportAsNamespace1(module=amd).symbols index 3c6b7529361ba..2ac5cba812883 100644 --- a/tests/baselines/reference/exportAsNamespace1(module=amd).symbols +++ b/tests/baselines/reference/exportAsNamespace1(module=amd).symbols @@ -7,7 +7,7 @@ export const b = 2; === tests/cases/conformance/es2020/modules/1.ts === export * as ns from './0'; ->ns : Symbol(ns, Decl(1.ts, 0, 11)) +>ns : Symbol(ns, Decl(1.ts, 0, 6)) ns.a; ns.b; @@ -18,15 +18,15 @@ import * as foo from './1' foo.ns.a; >foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) foo.ns.b; >foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) diff --git a/tests/baselines/reference/exportAsNamespace1(module=commonjs).symbols b/tests/baselines/reference/exportAsNamespace1(module=commonjs).symbols index 3c6b7529361ba..2ac5cba812883 100644 --- a/tests/baselines/reference/exportAsNamespace1(module=commonjs).symbols +++ b/tests/baselines/reference/exportAsNamespace1(module=commonjs).symbols @@ -7,7 +7,7 @@ export const b = 2; === tests/cases/conformance/es2020/modules/1.ts === export * as ns from './0'; ->ns : Symbol(ns, Decl(1.ts, 0, 11)) +>ns : Symbol(ns, Decl(1.ts, 0, 6)) ns.a; ns.b; @@ -18,15 +18,15 @@ import * as foo from './1' foo.ns.a; >foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) foo.ns.b; >foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) diff --git a/tests/baselines/reference/exportAsNamespace1(module=es2015).symbols b/tests/baselines/reference/exportAsNamespace1(module=es2015).symbols index 3c6b7529361ba..2ac5cba812883 100644 --- a/tests/baselines/reference/exportAsNamespace1(module=es2015).symbols +++ b/tests/baselines/reference/exportAsNamespace1(module=es2015).symbols @@ -7,7 +7,7 @@ export const b = 2; === tests/cases/conformance/es2020/modules/1.ts === export * as ns from './0'; ->ns : Symbol(ns, Decl(1.ts, 0, 11)) +>ns : Symbol(ns, Decl(1.ts, 0, 6)) ns.a; ns.b; @@ -18,15 +18,15 @@ import * as foo from './1' foo.ns.a; >foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) foo.ns.b; >foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) diff --git a/tests/baselines/reference/exportAsNamespace1(module=esnext).symbols b/tests/baselines/reference/exportAsNamespace1(module=esnext).symbols index 3c6b7529361ba..2ac5cba812883 100644 --- a/tests/baselines/reference/exportAsNamespace1(module=esnext).symbols +++ b/tests/baselines/reference/exportAsNamespace1(module=esnext).symbols @@ -7,7 +7,7 @@ export const b = 2; === tests/cases/conformance/es2020/modules/1.ts === export * as ns from './0'; ->ns : Symbol(ns, Decl(1.ts, 0, 11)) +>ns : Symbol(ns, Decl(1.ts, 0, 6)) ns.a; ns.b; @@ -18,15 +18,15 @@ import * as foo from './1' foo.ns.a; >foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) foo.ns.b; >foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) diff --git a/tests/baselines/reference/exportAsNamespace1(module=system).symbols b/tests/baselines/reference/exportAsNamespace1(module=system).symbols index 3c6b7529361ba..2ac5cba812883 100644 --- a/tests/baselines/reference/exportAsNamespace1(module=system).symbols +++ b/tests/baselines/reference/exportAsNamespace1(module=system).symbols @@ -7,7 +7,7 @@ export const b = 2; === tests/cases/conformance/es2020/modules/1.ts === export * as ns from './0'; ->ns : Symbol(ns, Decl(1.ts, 0, 11)) +>ns : Symbol(ns, Decl(1.ts, 0, 6)) ns.a; ns.b; @@ -18,15 +18,15 @@ import * as foo from './1' foo.ns.a; >foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) foo.ns.b; >foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) diff --git a/tests/baselines/reference/exportAsNamespace1(module=umd).symbols b/tests/baselines/reference/exportAsNamespace1(module=umd).symbols index 3c6b7529361ba..2ac5cba812883 100644 --- a/tests/baselines/reference/exportAsNamespace1(module=umd).symbols +++ b/tests/baselines/reference/exportAsNamespace1(module=umd).symbols @@ -7,7 +7,7 @@ export const b = 2; === tests/cases/conformance/es2020/modules/1.ts === export * as ns from './0'; ->ns : Symbol(ns, Decl(1.ts, 0, 11)) +>ns : Symbol(ns, Decl(1.ts, 0, 6)) ns.a; ns.b; @@ -18,15 +18,15 @@ import * as foo from './1' foo.ns.a; >foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) foo.ns.b; >foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) diff --git a/tests/baselines/reference/exportAsNamespace2(module=amd).symbols b/tests/baselines/reference/exportAsNamespace2(module=amd).symbols index 3c6b7529361ba..2ac5cba812883 100644 --- a/tests/baselines/reference/exportAsNamespace2(module=amd).symbols +++ b/tests/baselines/reference/exportAsNamespace2(module=amd).symbols @@ -7,7 +7,7 @@ export const b = 2; === tests/cases/conformance/es2020/modules/1.ts === export * as ns from './0'; ->ns : Symbol(ns, Decl(1.ts, 0, 11)) +>ns : Symbol(ns, Decl(1.ts, 0, 6)) ns.a; ns.b; @@ -18,15 +18,15 @@ import * as foo from './1' foo.ns.a; >foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) foo.ns.b; >foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) diff --git a/tests/baselines/reference/exportAsNamespace2(module=commonjs).symbols b/tests/baselines/reference/exportAsNamespace2(module=commonjs).symbols index 3c6b7529361ba..2ac5cba812883 100644 --- a/tests/baselines/reference/exportAsNamespace2(module=commonjs).symbols +++ b/tests/baselines/reference/exportAsNamespace2(module=commonjs).symbols @@ -7,7 +7,7 @@ export const b = 2; === tests/cases/conformance/es2020/modules/1.ts === export * as ns from './0'; ->ns : Symbol(ns, Decl(1.ts, 0, 11)) +>ns : Symbol(ns, Decl(1.ts, 0, 6)) ns.a; ns.b; @@ -18,15 +18,15 @@ import * as foo from './1' foo.ns.a; >foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) foo.ns.b; >foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) diff --git a/tests/baselines/reference/exportAsNamespace2(module=es2015).symbols b/tests/baselines/reference/exportAsNamespace2(module=es2015).symbols index 3c6b7529361ba..2ac5cba812883 100644 --- a/tests/baselines/reference/exportAsNamespace2(module=es2015).symbols +++ b/tests/baselines/reference/exportAsNamespace2(module=es2015).symbols @@ -7,7 +7,7 @@ export const b = 2; === tests/cases/conformance/es2020/modules/1.ts === export * as ns from './0'; ->ns : Symbol(ns, Decl(1.ts, 0, 11)) +>ns : Symbol(ns, Decl(1.ts, 0, 6)) ns.a; ns.b; @@ -18,15 +18,15 @@ import * as foo from './1' foo.ns.a; >foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) foo.ns.b; >foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) diff --git a/tests/baselines/reference/exportAsNamespace2(module=esnext).symbols b/tests/baselines/reference/exportAsNamespace2(module=esnext).symbols index 3c6b7529361ba..2ac5cba812883 100644 --- a/tests/baselines/reference/exportAsNamespace2(module=esnext).symbols +++ b/tests/baselines/reference/exportAsNamespace2(module=esnext).symbols @@ -7,7 +7,7 @@ export const b = 2; === tests/cases/conformance/es2020/modules/1.ts === export * as ns from './0'; ->ns : Symbol(ns, Decl(1.ts, 0, 11)) +>ns : Symbol(ns, Decl(1.ts, 0, 6)) ns.a; ns.b; @@ -18,15 +18,15 @@ import * as foo from './1' foo.ns.a; >foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) foo.ns.b; >foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) diff --git a/tests/baselines/reference/exportAsNamespace2(module=system).symbols b/tests/baselines/reference/exportAsNamespace2(module=system).symbols index 3c6b7529361ba..2ac5cba812883 100644 --- a/tests/baselines/reference/exportAsNamespace2(module=system).symbols +++ b/tests/baselines/reference/exportAsNamespace2(module=system).symbols @@ -7,7 +7,7 @@ export const b = 2; === tests/cases/conformance/es2020/modules/1.ts === export * as ns from './0'; ->ns : Symbol(ns, Decl(1.ts, 0, 11)) +>ns : Symbol(ns, Decl(1.ts, 0, 6)) ns.a; ns.b; @@ -18,15 +18,15 @@ import * as foo from './1' foo.ns.a; >foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) foo.ns.b; >foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) diff --git a/tests/baselines/reference/exportAsNamespace2(module=umd).symbols b/tests/baselines/reference/exportAsNamespace2(module=umd).symbols index 3c6b7529361ba..2ac5cba812883 100644 --- a/tests/baselines/reference/exportAsNamespace2(module=umd).symbols +++ b/tests/baselines/reference/exportAsNamespace2(module=umd).symbols @@ -7,7 +7,7 @@ export const b = 2; === tests/cases/conformance/es2020/modules/1.ts === export * as ns from './0'; ->ns : Symbol(ns, Decl(1.ts, 0, 11)) +>ns : Symbol(ns, Decl(1.ts, 0, 6)) ns.a; ns.b; @@ -18,15 +18,15 @@ import * as foo from './1' foo.ns.a; >foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) foo.ns.b; >foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) diff --git a/tests/baselines/reference/exportAsNamespace3(module=amd).symbols b/tests/baselines/reference/exportAsNamespace3(module=amd).symbols index 0414e93a36357..b66876b8cb602 100644 --- a/tests/baselines/reference/exportAsNamespace3(module=amd).symbols +++ b/tests/baselines/reference/exportAsNamespace3(module=amd).symbols @@ -7,7 +7,7 @@ export const b = 2; === tests/cases/conformance/es2020/modules/1.ts === export * as ns from './0'; ->ns : Symbol(ns, Decl(1.ts, 0, 11)) +>ns : Symbol(ns, Decl(1.ts, 0, 6)) ns.a; >ns.a : Symbol(a, Decl(1.ts, 3, 10)) @@ -40,15 +40,15 @@ import * as foo from './1' foo.ns.a; >foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) foo.ns.b; >foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) diff --git a/tests/baselines/reference/exportAsNamespace3(module=commonjs).symbols b/tests/baselines/reference/exportAsNamespace3(module=commonjs).symbols index 0414e93a36357..b66876b8cb602 100644 --- a/tests/baselines/reference/exportAsNamespace3(module=commonjs).symbols +++ b/tests/baselines/reference/exportAsNamespace3(module=commonjs).symbols @@ -7,7 +7,7 @@ export const b = 2; === tests/cases/conformance/es2020/modules/1.ts === export * as ns from './0'; ->ns : Symbol(ns, Decl(1.ts, 0, 11)) +>ns : Symbol(ns, Decl(1.ts, 0, 6)) ns.a; >ns.a : Symbol(a, Decl(1.ts, 3, 10)) @@ -40,15 +40,15 @@ import * as foo from './1' foo.ns.a; >foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) foo.ns.b; >foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) diff --git a/tests/baselines/reference/exportAsNamespace3(module=es2015).symbols b/tests/baselines/reference/exportAsNamespace3(module=es2015).symbols index 0414e93a36357..b66876b8cb602 100644 --- a/tests/baselines/reference/exportAsNamespace3(module=es2015).symbols +++ b/tests/baselines/reference/exportAsNamespace3(module=es2015).symbols @@ -7,7 +7,7 @@ export const b = 2; === tests/cases/conformance/es2020/modules/1.ts === export * as ns from './0'; ->ns : Symbol(ns, Decl(1.ts, 0, 11)) +>ns : Symbol(ns, Decl(1.ts, 0, 6)) ns.a; >ns.a : Symbol(a, Decl(1.ts, 3, 10)) @@ -40,15 +40,15 @@ import * as foo from './1' foo.ns.a; >foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) foo.ns.b; >foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) diff --git a/tests/baselines/reference/exportAsNamespace3(module=esnext).symbols b/tests/baselines/reference/exportAsNamespace3(module=esnext).symbols index 0414e93a36357..b66876b8cb602 100644 --- a/tests/baselines/reference/exportAsNamespace3(module=esnext).symbols +++ b/tests/baselines/reference/exportAsNamespace3(module=esnext).symbols @@ -7,7 +7,7 @@ export const b = 2; === tests/cases/conformance/es2020/modules/1.ts === export * as ns from './0'; ->ns : Symbol(ns, Decl(1.ts, 0, 11)) +>ns : Symbol(ns, Decl(1.ts, 0, 6)) ns.a; >ns.a : Symbol(a, Decl(1.ts, 3, 10)) @@ -40,15 +40,15 @@ import * as foo from './1' foo.ns.a; >foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) foo.ns.b; >foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) diff --git a/tests/baselines/reference/exportAsNamespace3(module=system).symbols b/tests/baselines/reference/exportAsNamespace3(module=system).symbols index 0414e93a36357..b66876b8cb602 100644 --- a/tests/baselines/reference/exportAsNamespace3(module=system).symbols +++ b/tests/baselines/reference/exportAsNamespace3(module=system).symbols @@ -7,7 +7,7 @@ export const b = 2; === tests/cases/conformance/es2020/modules/1.ts === export * as ns from './0'; ->ns : Symbol(ns, Decl(1.ts, 0, 11)) +>ns : Symbol(ns, Decl(1.ts, 0, 6)) ns.a; >ns.a : Symbol(a, Decl(1.ts, 3, 10)) @@ -40,15 +40,15 @@ import * as foo from './1' foo.ns.a; >foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) foo.ns.b; >foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) diff --git a/tests/baselines/reference/exportAsNamespace3(module=umd).symbols b/tests/baselines/reference/exportAsNamespace3(module=umd).symbols index 0414e93a36357..b66876b8cb602 100644 --- a/tests/baselines/reference/exportAsNamespace3(module=umd).symbols +++ b/tests/baselines/reference/exportAsNamespace3(module=umd).symbols @@ -7,7 +7,7 @@ export const b = 2; === tests/cases/conformance/es2020/modules/1.ts === export * as ns from './0'; ->ns : Symbol(ns, Decl(1.ts, 0, 11)) +>ns : Symbol(ns, Decl(1.ts, 0, 6)) ns.a; >ns.a : Symbol(a, Decl(1.ts, 3, 10)) @@ -40,15 +40,15 @@ import * as foo from './1' foo.ns.a; >foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) foo.ns.b; >foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) ->foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >foo : Symbol(foo, Decl(2.ts, 0, 6)) ->ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 6)) >b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) diff --git a/tests/baselines/reference/exportNamespace2.symbols b/tests/baselines/reference/exportNamespace2.symbols index ec764627a8209..4e0cbd9f48435 100644 --- a/tests/baselines/reference/exportNamespace2.symbols +++ b/tests/baselines/reference/exportNamespace2.symbols @@ -4,7 +4,7 @@ export class A {} === tests/cases/conformance/externalModules/typeOnly/b.ts === export * as a from './a'; ->a : Symbol(a, Decl(b.ts, 0, 11)) +>a : Symbol(a, Decl(b.ts, 0, 6)) === tests/cases/conformance/externalModules/typeOnly/c.ts === import type { a } from './b'; diff --git a/tests/baselines/reference/exportNamespace3.symbols b/tests/baselines/reference/exportNamespace3.symbols index a108ab6647bb3..6bf10e589b339 100644 --- a/tests/baselines/reference/exportNamespace3.symbols +++ b/tests/baselines/reference/exportNamespace3.symbols @@ -8,7 +8,7 @@ export type { A } from './a'; === tests/cases/conformance/externalModules/typeOnly/c.ts === export * as a from './b'; ->a : Symbol(a, Decl(c.ts, 0, 11)) +>a : Symbol(a, Decl(c.ts, 0, 6)) === tests/cases/conformance/externalModules/typeOnly/d.ts === import { a } from './c'; diff --git a/tests/baselines/reference/renameExportSpecifier.baseline b/tests/baselines/reference/renameExportSpecifier.baseline new file mode 100644 index 0000000000000..f0a3a28f3c94a --- /dev/null +++ b/tests/baselines/reference/renameExportSpecifier.baseline @@ -0,0 +1,9 @@ +/*====== /tests/cases/fourslash/a.ts ======*/ + +const name = {}; +export { name as [|RENAME|] }; + +/*====== /tests/cases/fourslash/b.ts ======*/ + +import { RENAME } from './a'; +const x = RENAME.toString(); diff --git a/tests/baselines/reference/renameExportSpecifier2.baseline b/tests/baselines/reference/renameExportSpecifier2.baseline new file mode 100644 index 0000000000000..9f20320696f35 --- /dev/null +++ b/tests/baselines/reference/renameExportSpecifier2.baseline @@ -0,0 +1,9 @@ +/*====== /tests/cases/fourslash/a.ts ======*/ + +const RENAME = {}; +export { [|RENAME|] }; + +/*====== /tests/cases/fourslash/b.ts ======*/ + +import { RENAME } from './a'; +const x = RENAME.toString(); diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index f7c2932511a7a..d44148972fbf9 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -359,6 +359,7 @@ declare namespace FourSlashInterface { renameInfoSucceeded(displayName?: string, fullDisplayName?: string, kind?: string, kindModifiers?: string, fileToRename?: string, range?: Range, allowRenameOfImportPath?: boolean): void; renameInfoFailed(message?: string, allowRenameOfImportPath?: boolean): void; renameLocations(startRanges: ArrayOrSingle, options: RenameLocationsOptions): void; + baselineRename(marker: string, options: RenameOptions): void; /** Verify the quick info available at the current marker. */ quickInfoIs(expectedText: string, expectedDocumentation?: string): void; @@ -723,6 +724,8 @@ declare namespace FourSlashInterface { readonly ranges: ReadonlyArray; readonly providePrefixAndSuffixTextForRename?: boolean; }; + + type RenameOptions = { readonly findInStrings?: boolean, readonly findInComments?: boolean, readonly providePrefixAndSuffixTextForRename?: boolean }; type RenameLocationOptions = Range | { readonly range: Range, readonly prefixText?: string, readonly suffixText?: string }; type DiagnosticIgnoredInterpolations = { template: string } } diff --git a/tests/cases/fourslash/referencesForStatementKeywords.ts b/tests/cases/fourslash/referencesForStatementKeywords.ts index 5d04fc5e6be99..e5a171f0d9f10 100644 --- a/tests/cases/fourslash/referencesForStatementKeywords.ts +++ b/tests/cases/fourslash/referencesForStatementKeywords.ts @@ -17,7 +17,7 @@ //// ////// export ... from ... ////[|{| "id": "exportDecl1" |}[|export|] [|type|] * [|from|] "[|{| "isWriteAccess": false, "isDefinition": false, "contextRangeId": "exportDecl1" |}./g|]";|] -////[|{| "id": "exportDecl2" |}[|export|] [|type|] * [|as|] [|{| "isWriteAccess": true, "isDefinition": true |}H|] [|from|] "[|{| "isWriteAccess": false, "isDefinition": false, "contextRangeId": "exportDecl2" |}./h|]";|] +////[|{| "id": "exportDecl2" |}[|export|] [|type|] [|{| "id": "exportDecl2_namespaceExport" |}* [|as|] [|{| "isWriteAccess": true, "isDefinition": true, "contextRangeId": "exportDecl2_namespaceExport" |}H|]|] [|from|] "[|{| "isWriteAccess": false, "isDefinition": false, "contextRangeId": "exportDecl2" |}./h|]";|] ////[|{| "id": "exportDecl3" |}[|export|] [|type|] { [|{| "isWriteAccess": true, "isDefinition": true, "contextRangeId": "exportDecl3" |}I|] } [|from|] "[|{| "isWriteAccess": false, "isDefinition": false, "contextRangeId": "exportDecl3" |}./i|]";|] ////[|{| "id": "exportDecl4" |}[|export|] [|type|] { j1, j2 [|as|] [|{| "isWriteAccess": true, "isDefinition": true, "contextRangeId": "exportDecl4" |}j3|] } [|from|] "[|{| "isWriteAccess": false, "isDefinition": false, "contextRangeId": "exportDecl4" |}./j|]";|] ////[|{| "id": "typeDecl1" |}type [|{| "isWriteAccess": true, "isDefinition": true, "contextRangeId": "typeDecl1" |}Z1|] = 1;|] @@ -125,6 +125,7 @@ const [ exportDecl2, exportDecl2_exportKeyword, exportDecl2_typeKeyword, + exportDecl2_namespaceExport, exportDecl2_asKeyword, exportDecl2_name, exportDecl2_fromKeyword, diff --git a/tests/cases/fourslash/renameExportSpecifier.ts b/tests/cases/fourslash/renameExportSpecifier.ts new file mode 100644 index 0000000000000..2ad344ee50b73 --- /dev/null +++ b/tests/cases/fourslash/renameExportSpecifier.ts @@ -0,0 +1,11 @@ +/// + +// @Filename: a.ts +////const name = {}; +////export { name as name/**/ }; + +// @Filename: b.ts +////import { name } from './a'; +////const x = name.toString(); + +verify.baselineRename("", { providePrefixAndSuffixTextForRename: false }); diff --git a/tests/cases/fourslash/renameExportSpecifier2.ts b/tests/cases/fourslash/renameExportSpecifier2.ts new file mode 100644 index 0000000000000..deafa466225e0 --- /dev/null +++ b/tests/cases/fourslash/renameExportSpecifier2.ts @@ -0,0 +1,11 @@ +/// + +// @Filename: a.ts +////const name = {}; +////export { name/**/ }; + +// @Filename: b.ts +////import { name } from './a'; +////const x = name.toString(); + +verify.baselineRename("", { providePrefixAndSuffixTextForRename: false });