diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 6c0489ff1dc..8161ea998c4 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -688,6 +688,21 @@ namespace ts { ch > CharacterCodes.maxAsciiCharacter && isUnicodeIdentifierPart(ch, languageVersion); } + /* @internal */ + export function isIdentifier(name: string, languageVersion: ScriptTarget): boolean { + if (!isIdentifierStart(name.charCodeAt(0), languageVersion)) { + return false; + } + + for (let i = 1, n = name.length; i < n; i++) { + if (!isIdentifierPart(name.charCodeAt(i), languageVersion)) { + return false; + } + } + + return true; + } + // Creates a scanner over a (possibly unspecified) range of a piece of text. export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean, diff --git a/src/services/services.ts b/src/services/services.ts index f2651163610..4efd87555a1 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2978,15 +2978,9 @@ namespace ts { // e.g "b a" is valid quoted name but when we strip off the quotes, it is invalid. // We, thus, need to check if whatever was inside the quotes is actually a valid identifier name. if (performCharacterChecks) { - if (!isIdentifierStart(name.charCodeAt(0), target)) { + if (!isIdentifier(name, target)) { return undefined; } - - for (let i = 1, n = name.length; i < n; i++) { - if (!isIdentifierPart(name.charCodeAt(i), target)) { - return undefined; - } - } } return name;