Add new helper to check for valid identifiers
This commit is contained in:
parent
1e433bfb4f
commit
9b92697a61
2 changed files with 16 additions and 7 deletions
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue