Support import completions for a re-export with a different name from the original (#28055)

This commit is contained in:
Andy
2018-10-22 11:16:39 -07:00
committed by GitHub
parent 778f438a7f
commit 8e0142d709
2 changed files with 17 additions and 4 deletions

View File

@@ -1410,7 +1410,7 @@ namespace ts.Completions {
// If `symbol.parent !== ...`, this comes from an `export * from "foo"` re-export. Those don't create new symbols.
// If `some(...)`, this comes from an `export { foo } from "foo"` re-export, which creates a new symbol (thus isn't caught by the first check).
if (typeChecker.getMergedSymbol(symbol.parent!) !== resolvedModuleSymbol
|| some(symbol.declarations, d => isExportSpecifier(d) && !!d.parent.parent.moduleSpecifier)) {
|| some(symbol.declarations, d => isExportSpecifier(d) && !d.propertyName && !!d.parent.parent.moduleSpecifier)) {
continue;
}

View File

@@ -12,9 +12,13 @@
/////**/
goTo.marker("");
verify.completionListContains({ name: "x", source: "/a" }, "const x: 0", "", "const", /*spanIndex*/ undefined, /*hasAction*/ true, {
includeCompletionsForModuleExports: true,
sourceDisplay: "./a",
verify.completions({
marker: "",
includes: [
{ name: "x", source: "/a", sourceDisplay: "./a", text: "const x: 0", hasAction: true },
{ name: "y", source: "/index", sourceDisplay: ".", text: "(alias) const y: 0\nexport y", hasAction: true },
],
preferences: { includeCompletionsForModuleExports: true },
});
verify.applyCodeActionFromCompletion("", {
@@ -25,3 +29,12 @@ verify.applyCodeActionFromCompletion("", {
`,
});
verify.applyCodeActionFromCompletion("", {
name: "y",
source: "/index",
description: `Import 'y' from module "."`,
newFileContent: `import { x } from "./a";
import { y } from ".";
`,
});