Skip to content

Commit 5d20c57

Browse files
author
Orta
authored
Merge pull request #34524 from orta/fix_32675
Does not add a duplicate completion when offering an export which was re-declared as a global
2 parents 43cf899 + 85010fa commit 5d20c57

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

src/services/completions.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,7 @@ namespace ts.Completions {
10001000
let completionKind = CompletionKind.None;
10011001
let isNewIdentifierLocation = false;
10021002
let keywordFilters = KeywordCompletionFilters.None;
1003+
// This also gets mutated in nested-functions after the return
10031004
let symbols: Symbol[] = [];
10041005
const symbolToOriginInfoMap: SymbolOriginInfoMap = [];
10051006
const symbolToSortTextMap: SymbolSortTextMap = [];
@@ -1464,7 +1465,7 @@ namespace ts.Completions {
14641465
}
14651466

14661467
/**
1467-
* Gathers symbols that can be imported from other files, deduplicating along the way. Symbols can be duplicates
1468+
* Gathers symbols that can be imported from other files, de-duplicating along the way. Symbols can be "duplicates"
14681469
* if re-exported from another module, e.g. `export { foo } from "./a"`. That syntax creates a fresh symbol, but
14691470
* it’s just an alias to the first, and both have the same name, so we generally want to filter those aliases out,
14701471
* if and only if the the first can be imported (it may be excluded due to package.json filtering in
@@ -1548,7 +1549,7 @@ namespace ts.Completions {
15481549
// Don't add another completion for `export =` of a symbol that's already global.
15491550
// So in `declare namespace foo {} declare module "foo" { export = foo; }`, there will just be the global completion for `foo`.
15501551
if (resolvedModuleSymbol !== moduleSymbol &&
1551-
every(resolvedModuleSymbol.declarations, d => !!d.getSourceFile().externalModuleIndicator)) {
1552+
every(resolvedModuleSymbol.declarations, d => !!d.getSourceFile().externalModuleIndicator && !findAncestor(d, isGlobalScopeAugmentation))) {
15521553
pushSymbol(resolvedModuleSymbol, moduleSymbol, /*skipFilter*/ true);
15531554
}
15541555

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// 32675 - if this fails there are two copies of assert in completions
4+
5+
// @esModuleInterop: true,
6+
// @target: esnext
7+
8+
// @Filename: /myAssert.d.ts
9+
////declare function assert(value:any, message?:string):void;
10+
////export = assert;
11+
////export as namespace assert;
12+
13+
// @Filename: /ambient.d.ts
14+
////import assert from './myAssert';
15+
////
16+
////type Assert = typeof assert;
17+
////
18+
////declare global {
19+
//// const assert: Assert;
20+
////}
21+
22+
// @Filename: /index.ts
23+
/////// <reference path="./ambient.d.ts" />
24+
////asser/**/;
25+
26+
verify.completions({
27+
marker: "",
28+
includes: [
29+
{
30+
name: "assert",
31+
sortText: completion.SortText.GlobalsOrKeywords
32+
}
33+
],
34+
preferences: { includeCompletionsForModuleExports: true, includeInsertTextCompletions: true }
35+
});

0 commit comments

Comments
 (0)