microsoft / microsoft/TypeScript
Support Unicode RegExp property escapes
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
TypeScript currently doesn't transpile Unicode property escapes (of the form \p{ID_Start} or \P{ASCII}) in regular expressions.
It would be great if it did!
Search Terms
regexp, regular expression, Unicode, property escapes, ES2018
Suggestion
Support transpiling Unicode property escapes in regular expressions. Examples:
/\p{ID_Start}/u;
/\P{ASCII}/u;
/\p{Script_Extensions=Greek}/u;
Use Cases
One particular use case is matching identifier characters in JavaScript parsers. This is currently commonly implemented as a large script-generated regular expression pattern (like in Esprima) or as a magical-looking list of code point ranges (like in TypeScript itself). However, it would be much simpler to use property escapes.
const regexIdentifierStart = /[$_\p{ID_Start}]/u;
const regexIdentifierPart = /[$_\u200C\u200D\p{ID_Continue}]/u;
const regexIdentifierName = /^(?:[$_\p{ID_Start}])(?:[$_\u200C\u200D\p{ID_Continue}])*$/u;
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia riproducendo gli esempi elencati di escape delle proprietà Unicode nel TypeScript Playground collegato con la destinazione specificata. Esamina il percorso di transpilation delle espressioni regolari del compilatore e determina come dovrebbero essere emessi gli esempi per le destinazioni meno recenti. Il lavoro è completato quando gli esempi vengono transp ilati correttamente senza modificarne il comportamento a runtime.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, typescript
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100