Adjust isIdentifierText to skip multiple characters when a code point is multiple chars long (#32720)

* Adjust isIdentifierText to skip multiple characters when a code point is multiple chars long

* Add a few examples with mixed unicode characters

* for posterity, add some unicode cursive script characters

* Test some more planes more explicitly
This commit is contained in:
Wesley Wigham
2019-08-05 23:37:26 -07:00
committed by GitHub
parent 624d1cad93
commit 7adc175dfc
5 changed files with 278 additions and 10 deletions

View File

@@ -832,12 +832,13 @@ namespace ts {
/* @internal */
export function isIdentifierText(name: string, languageVersion: ScriptTarget | undefined): boolean {
if (!isIdentifierStart(name.charCodeAt(0), languageVersion)) {
let ch = codePointAt(name, 0);
if (!isIdentifierStart(ch, languageVersion)) {
return false;
}
for (let i = 1; i < name.length; i++) {
if (!isIdentifierPart(name.charCodeAt(i), languageVersion)) {
for (let i = charSize(ch); i < name.length; i += charSize(ch)) {
if (!isIdentifierPart(ch = codePointAt(name, i), languageVersion)) {
return false;
}
}
@@ -1870,13 +1871,6 @@ namespace ts {
}
}
function charSize(ch: number) {
if (ch > 0x10000) {
return 2;
}
return 1;
}
function reScanGreaterToken(): SyntaxKind {
if (token === SyntaxKind.GreaterThanToken) {
if (text.charCodeAt(pos) === CharacterCodes.greaterThan) {
@@ -2238,4 +2232,12 @@ namespace ts {
}
return first;
};
/* @internal */
function charSize(ch: number) {
if (ch > 0x10000) {
return 2;
}
return 1;
}
}