From 9b92697a61fc65867689364af7bfbc53fefc58e0 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 7 Jan 2016 14:56:05 -0800 Subject: [PATCH] Add new helper to check for valid identifiers --- src/compiler/scanner.ts | 15 +++++++++++++++ src/services/services.ts | 8 +------- 2 files changed, 16 insertions(+), 7 deletions(-) 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;