Skip to content

Commit a31ce78

Browse files
committed
Remove escaped names of well known symbols from string completions
1 parent ceba507 commit a31ce78

3 files changed

Lines changed: 30 additions & 8 deletions

File tree

src/compiler/utilities.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,12 @@ namespace ts {
385385
return (identifier.length >= 2 && identifier.charCodeAt(0) === CharacterCodes._ && identifier.charCodeAt(1) === CharacterCodes._ ? "_" + identifier : identifier) as __String;
386386
}
387387

388+
export function isEscapedNameOfWellKnownSymbol(escapedName: __String) {
389+
return (escapedName as string).charCodeAt(0) === CharacterCodes._ &&
390+
(escapedName as string).charCodeAt(1) === CharacterCodes._ &&
391+
(escapedName as string).charCodeAt(2) === CharacterCodes.at;
392+
}
393+
388394
/**
389395
* @deprecated Use `id.escapedText` to get the escaped text of an Identifier.
390396
* @param identifier The identifier to escape

src/services/completions.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,17 @@ namespace ts.Completions {
167167
const uniqueNames = createMap<true>();
168168
if (symbols) {
169169
for (const symbol of symbols) {
170-
const entry = createCompletionEntry(symbol, location, performCharacterChecks, typeChecker, target, allowStringLiteral);
171-
if (entry) {
172-
const id = entry.name;
173-
if (!uniqueNames.has(id)) {
174-
if (symbolToOriginInfoMap && symbolToOriginInfoMap[getUniqueSymbolId(symbol, typeChecker)]) {
175-
entry.hasAction = true;
170+
if (!isEscapedNameOfWellKnownSymbol(symbol.escapedName)) {
171+
const entry = createCompletionEntry(symbol, location, performCharacterChecks, typeChecker, target, allowStringLiteral);
172+
if (entry) {
173+
const id = entry.name;
174+
if (!uniqueNames.has(id)) {
175+
if (symbolToOriginInfoMap && symbolToOriginInfoMap[getUniqueSymbolId(symbol, typeChecker)]) {
176+
entry.hasAction = true;
177+
}
178+
entries.push(entry);
179+
uniqueNames.set(id, true);
176180
}
177-
entries.push(entry);
178-
uniqueNames.set(id, true);
179181
}
180182
}
181183
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
////interface SymbolConstructor {
4+
//// readonly species: symbol;
5+
////}
6+
////var Symbol: SymbolConstructor;
7+
////interface PromiseConstructor {
8+
//// [Symbol.species]: PromiseConstructor;
9+
////}
10+
////var Promise: PromiseConstructor;
11+
////Promise["/*1*/"];
12+
13+
goTo.marker('1');
14+
verify.not.completionListContains("__@species");

0 commit comments

Comments
 (0)