mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 01:04:49 -05:00
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user