-
-
Notifications
You must be signed in to change notification settings - Fork 669
Support supplementary CPs in Unicode identifiers #2522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
62e0f29
Add script to generate unicode identifier starts/parts
dcodeIO 5de629c
simplify
dcodeIO efa019d
handle max cp
dcodeIO dd32010
i -> cp
dcodeIO 727927d
generate comments
dcodeIO 3714970
install tables
dcodeIO dfdf900
clean
dcodeIO 163d014
fix
dcodeIO 5ceeb7c
compact
dcodeIO 1a6e09e
safe
dcodeIO 8a01c8a
indicate code point
dcodeIO 37a35b8
use i32
dcodeIO ce03268
simplify
dcodeIO 31eeb71
use a utility function for clarity
dcodeIO c0b4b8f
cache min/max in constant
dcodeIO a55b745
optimize for common case
dcodeIO eaa7346
add parser test
dcodeIO File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// see https://github.com/microsoft/TypeScript/blob/main/scripts/regenerate-unicode-identifier-parts.js | ||
|
||
const MAX_UNICODE_CODEPOINT = 0x10FFFF; | ||
const isStart = c => /[\p{ID_Start}\u{2118}\u{212E}\u{309B}\u{309C}]/u.test(c); // Other_ID_Start explicitly included for back compat - see http://www.unicode.org/reports/tr31/#Introduction | ||
const isPart = c => /[\p{ID_Continue}\u{00B7}\u{0387}\u{19DA}\u{1369}\u{136A}\u{136B}\u{136C}\u{136D}\u{136E}\u{136F}\u{1370}\u{1371}]/u.test(c) || isStart(c); // Likewise for Other_ID_Continue | ||
const parts = []; | ||
let partsActive = false; | ||
let startsActive = false; | ||
const starts = []; | ||
|
||
// Skip 0-9 (48..57), A-Z (65..90), a-z (97..122) - checked otherwise | ||
for (let cp = 123; cp <= MAX_UNICODE_CODEPOINT; cp++) { | ||
if (isStart(String.fromCodePoint(cp)) !== startsActive) { | ||
starts.push(cp - +startsActive); | ||
startsActive = !startsActive; | ||
} | ||
if (isPart(String.fromCodePoint(cp)) !== partsActive) { | ||
parts.push(cp - +partsActive); | ||
partsActive = !partsActive; | ||
} | ||
} | ||
if (startsActive) starts.push(MAX_UNICODE_CODEPOINT); | ||
if (partsActive) parts.push(MAX_UNICODE_CODEPOINT); | ||
|
||
function tablify(cps) { | ||
let sb = ["/*\n| from ... to | from ... to | from ... to | from ... to |*/"]; | ||
let i = 0; | ||
while (i < cps.length) { | ||
if (!(i % 8)) sb.push("\n "); | ||
sb.push(`${cps[i++].toString().padEnd(6)}, `); | ||
} | ||
return sb.join("") + "\n"; | ||
} | ||
|
||
console.log(`/** Unicode ${process.versions.unicode} ID_Start/Other_ID_Start ranges */`); | ||
console.log(`const unicodeIdentifierStart: i32[] = [${tablify(starts)}];`); | ||
console.log(`const unicodeIdentifierStartMin = ${starts[0]};`); | ||
console.log(`const unicodeIdentifierStartMax = ${starts[starts.length - 1]};\n`); | ||
console.log(`/** Unicode ${process.versions.unicode} ID_Continue/Other_ID_Continue + ID_Start/Other_ID_Start ranges*/`); | ||
console.log(`const unicodeIdentifierPart: i32[] = [${tablify(parts)}];`); | ||
console.log(`const unicodeIdentifierPartMin = ${parts[0]};`); | ||
console.log(`const unicodeIdentifierPartMax = ${parts[parts.length - 1]};\n`); | ||
dcodeIO marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using title case for
SomeEnum.SomeValue
seems fine, but justSomeValue
conflicts visually with classes, enums and interfaces. Not sure it's preferable?