Skip to content

Commit 33836f8

Browse files
author
Andy
authored
Clean up getJavaScriptCompletionEntries (#16750)
* Clean up getJavaScriptCompletionEntries * Move each parameter to its own line
1 parent dbbf051 commit 33836f8

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

src/services/completions.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ namespace ts.Completions {
5757

5858
if (isSourceFileJavaScript(sourceFile)) {
5959
const uniqueNames = getCompletionEntriesFromSymbols(symbols, entries, location, /*performCharacterChecks*/ true, typeChecker, compilerOptions.target, log);
60-
addRange(entries, getJavaScriptCompletionEntries(sourceFile, location.pos, uniqueNames, compilerOptions.target));
60+
getJavaScriptCompletionEntries(sourceFile, location.pos, uniqueNames, compilerOptions.target, entries);
6161
}
6262
else {
6363
if ((!symbols || symbols.length === 0) && keywordFilters === KeywordCompletionFilters.None) {
@@ -79,33 +79,34 @@ namespace ts.Completions {
7979
return { isGlobalCompletion, isMemberCompletion, isNewIdentifierLocation, entries };
8080
}
8181

82-
function getJavaScriptCompletionEntries(sourceFile: SourceFile, position: number, uniqueNames: Map<true>, target: ScriptTarget): CompletionEntry[] {
83-
const entries: CompletionEntry[] = [];
84-
85-
const nameTable = getNameTable(sourceFile);
86-
nameTable.forEach((pos, name) => {
82+
function getJavaScriptCompletionEntries(
83+
sourceFile: SourceFile,
84+
position: number,
85+
uniqueNames: Map<true>,
86+
target: ScriptTarget,
87+
entries: Push<CompletionEntry>): void {
88+
getNameTable(sourceFile).forEach((pos, name) => {
8789
// Skip identifiers produced only from the current location
8890
if (pos === position) {
8991
return;
9092
}
9193
const realName = unescapeLeadingUnderscores(name);
9294

93-
if (!uniqueNames.get(realName)) {
94-
uniqueNames.set(realName, true);
95-
const displayName = getCompletionEntryDisplayName(realName, target, /*performCharacterChecks*/ true);
96-
if (displayName) {
97-
const entry = {
98-
name: displayName,
99-
kind: ScriptElementKind.warning,
100-
kindModifiers: "",
101-
sortText: "1"
102-
};
103-
entries.push(entry);
104-
}
95+
if (uniqueNames.has(realName)) {
96+
return;
10597
}
106-
});
10798

108-
return entries;
99+
uniqueNames.set(realName, true);
100+
const displayName = getCompletionEntryDisplayName(realName, target, /*performCharacterChecks*/ true);
101+
if (displayName) {
102+
entries.push({
103+
name: displayName,
104+
kind: ScriptElementKind.warning,
105+
kindModifiers: "",
106+
sortText: "1"
107+
});
108+
}
109+
});
109110
}
110111

111112
function createCompletionEntry(symbol: Symbol, location: Node, performCharacterChecks: boolean, typeChecker: TypeChecker, target: ScriptTarget): CompletionEntry {
@@ -141,7 +142,7 @@ namespace ts.Completions {
141142
const entry = createCompletionEntry(symbol, location, performCharacterChecks, typeChecker, target);
142143
if (entry) {
143144
const id = entry.name;
144-
if (!uniqueNames.get(id)) {
145+
if (!uniqueNames.has(id)) {
145146
entries.push(entry);
146147
uniqueNames.set(id, true);
147148
}

0 commit comments

Comments
 (0)