Skip to content
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

Replace hard-coded parser unicode identifier detection with RegExp #144

Open
brianmhunt opened this issue Jul 10, 2021 · 3 comments
Open

Comments

@brianmhunt
Copy link
Member

brianmhunt commented Jul 10, 2021

This may become our min browser: Chrome 50

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode

We can then get rid of the following 10kb:

https://github.com/knockout/tko/blob/4a0c9c0d03bb2ed53aa058672b5429d88bf92264/packages/utils.parser/src/identifierExpressions.js

@brianmhunt
Copy link
Member Author

Noting: https://mathiasbynens.be/notes/javascript-identifiers-es6

In ES2015, identifiers must start with $, _, or any symbol with the Unicode derived core property ID_Start.

The rest of the identifier can contain $, _, U+200C zero width non-joiner, U+200D zero width joiner, or any symbol with the Unicode derived core property ID_Continue.

@brianmhunt
Copy link
Member Author

Noting: https://github.com/tc39/proposal-regexp-unicode-property-escapes#other-examples

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;

@tscpp
Copy link

tscpp commented Sep 7, 2021

I have not worked with unicode ranges before, but shouldn't the regex be able to be generated runtime (maybe as a fallback)? The website used to generate the regex clearly does it runtime. The regex generation may be slow, but I think it's better as a fallback than nothing. Am I missing something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants