Skip to content

Does not add a duplicate completion when offering an export which was re-declared as a global #34524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/services/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,7 @@ namespace ts.Completions {
let completionKind = CompletionKind.None;
let isNewIdentifierLocation = false;
let keywordFilters = KeywordCompletionFilters.None;
// This also gets mutated in nested-functions after the return
let symbols: Symbol[] = [];
const symbolToOriginInfoMap: SymbolOriginInfoMap = [];
const symbolToSortTextMap: SymbolSortTextMap = [];
Expand Down Expand Up @@ -1464,7 +1465,7 @@ namespace ts.Completions {
}

/**
* Gathers symbols that can be imported from other files, deduplicating along the way. Symbols can be duplicates
* Gathers symbols that can be imported from other files, de-duplicating along the way. Symbols can be "duplicates"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷‍♂

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, I guess code-spell check doesn't have it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I make up a lot of words but this wasn’t one of them! 😛

* if re-exported from another module, e.g. `export { foo } from "./a"`. That syntax creates a fresh symbol, but
* it’s just an alias to the first, and both have the same name, so we generally want to filter those aliases out,
* if and only if the the first can be imported (it may be excluded due to package.json filtering in
Expand Down Expand Up @@ -1548,7 +1549,7 @@ namespace ts.Completions {
// Don't add another completion for `export =` of a symbol that's already global.
// So in `declare namespace foo {} declare module "foo" { export = foo; }`, there will just be the global completion for `foo`.
if (resolvedModuleSymbol !== moduleSymbol &&
every(resolvedModuleSymbol.declarations, d => !!d.getSourceFile().externalModuleIndicator)) {
every(resolvedModuleSymbol.declarations, d => !!d.getSourceFile().externalModuleIndicator && !findAncestor(d, isGlobalScopeAugmentation))) {
pushSymbol(resolvedModuleSymbol, moduleSymbol, /*skipFilter*/ true);
}

Expand Down
35 changes: 35 additions & 0 deletions tests/cases/fourslash/completionsRedeclareModuleAsGlobal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/// <reference path="fourslash.ts" />

// 32675 - if this fails there are two copies of assert in completions

// @esModuleInterop: true,
// @target: esnext

// @Filename: /myAssert.d.ts
////declare function assert(value:any, message?:string):void;
////export = assert;
////export as namespace assert;

// @Filename: /ambient.d.ts
////import assert from './myAssert';
////
////type Assert = typeof assert;
////
////declare global {
//// const assert: Assert;
////}

// @Filename: /index.ts
/////// <reference path="./ambient.d.ts" />
////asser/**/;

verify.completions({
marker: "",
includes: [
{
name: "assert",
sortText: completion.SortText.GlobalsOrKeywords
}
],
preferences: { includeCompletionsForModuleExports: true, includeInsertTextCompletions: true }
});