Skip to content

Commit

Permalink
Cherry-pick release bugs (#36804)
Browse files Browse the repository at this point in the history
* Fix renaming an ExportSpecifier name when propertyName is present (#36790)

* Fix renaming exportSpecifier name when propertyName is present

* Add baseline test for name without propertyName too

* Set correct pos for NamespaceExport (#36794)

* Set correct pos for NamespaceExport

* Update tests
andrewbranch authored Feb 14, 2020
1 parent e7fec6d commit 5a2fa49
Showing 30 changed files with 187 additions and 100 deletions.
7 changes: 4 additions & 3 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
@@ -6565,18 +6565,19 @@ namespace ts {
return finishNode(node);
}

function parseNamespaceExport(): NamespaceExport {
const node = <NamespaceExport>createNode(SyntaxKind.NamespaceExport);
function parseNamespaceExport(pos: number): NamespaceExport {
const node = <NamespaceExport>createNode(SyntaxKind.NamespaceExport, pos);
node.name = parseIdentifier();
return finishNode(node);
}

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();
31 changes: 31 additions & 0 deletions src/harness/fourslashImpl.ts
Original file line number Diff line number Diff line change
@@ -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) {
9 changes: 9 additions & 0 deletions src/harness/fourslashInterfaceImpl.ts
Original file line number Diff line number Diff line change
@@ -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;
};
}
10 changes: 6 additions & 4 deletions src/services/findAllReferences.ts
Original file line number Diff line number Diff line change
@@ -1927,10 +1927,12 @@ namespace ts.FindAllReferences {
}

const exportSpecifier = getDeclarationOfKind<ExportSpecifier>(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.
10 changes: 5 additions & 5 deletions tests/baselines/reference/exportAsNamespace1(module=amd).symbols
Original file line number Diff line number Diff line change
@@ -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))

Original file line number Diff line number Diff line change
@@ -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))

Original file line number Diff line number Diff line change
@@ -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))

Original file line number Diff line number Diff line change
@@ -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))

Original file line number Diff line number Diff line change
@@ -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))

10 changes: 5 additions & 5 deletions tests/baselines/reference/exportAsNamespace1(module=umd).symbols
Original file line number Diff line number Diff line change
@@ -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))

10 changes: 5 additions & 5 deletions tests/baselines/reference/exportAsNamespace2(module=amd).symbols
Original file line number Diff line number Diff line change
@@ -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))

Original file line number Diff line number Diff line change
@@ -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))

Original file line number Diff line number Diff line change
@@ -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))

Original file line number Diff line number Diff line change
@@ -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))

Loading

0 comments on commit 5a2fa49

Please sign in to comment.