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
Identifiers & unquoted property names #554
Conversation
@jskrzypek some tests and a README entry would be great, thanks. |
@chriso Of course, happy to do both (I wouldn't expect the PR to be accepted without them!) For the tests, should just add them as |
@jskrzypek great 😄 Adding tests to the end of that test suite will be fine. |
👍 I'll get on this today, just have to finish up some changes on one of our projects. |
Okay I wrote tests for everything I wrote (feel free to double check me) I'll ad a readme tomorrow |
23670cc
to
7e8b087
Compare
2ad0795
to
c75b6ec
Compare
Thanks, I can't see any issues with the code after a quick pass. I can't merge this in its currently state though unfortunately, as the client-side version of the library is now 3x larger (17.5 KB => 54.5 KB) and IMO it's already bloated enough as it is. Something like #531 would help by allowing users to pick and choose the validators they need in their front-end build. I'll leave this PR open in the mean time. |
_Yikes!_ Wow, I did not look at the minified version until now. I'm actually kind of impressed with how unoptimized that is... 😆 Ok I'll see if I can can somehow replace the regex with something equivalent in how it evaluates unicode... hopefully that will be cleaner... ... the longest regex is 14654 characters 😮 |
So after a bunch of research it looks like the only clean way to do this without obscenely long regexes will be to either wait until this tc39 proposal for unicode properties in RegExp lands (seems like it will, but not sure when) to do something like the following for the ES5/6 matching: /^(?:\p{ID_Start}|\$|_|\\u[a-zA-Z0-9]{4}|\\u\{[a-zA-Z0-9]{1,}\})(?:\p{ID_Continue}|\$|_|\\u[a-zA-Z0-9]{4}|\\u\{[a-zA-Z0-9]{1,}\}|\u200C|\u200D)*/ All of the other solutions ultimately fall back on including the obscenely long regexes for backwards compatibility. I also realized that estools/esutils already includes the equivalent of my I think I'll do 2 things. First I'll break off the numeric property name validation part of |
That tc39 proposal looks very useful, but it unfortunately won't reduce the size of the minified front-end version where we still need to support the lowest common denominator browsers. I'd be happy to accept this PR once we have a build system in place like lodash, and happy to accept a smaller PR in the mean time. Thanks again 😄 |
I think that for now the current numeric validators suffice for validating if property names are numeric. We can circle back to this more integrated solution when the build system lands. In the meantime I'm going to be using the esutils validator in my project. |
Closing this out due to conflicts. We can revisit if/when custom builds are supported (#531). |
@chriso Can you look over this and tell me what I should add/fix? Where should I add the tests?