-
Notifications
You must be signed in to change notification settings - Fork 96
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
Prevent invalid-regular expression syntax error in Safari < 16.4 #202
Conversation
Happy to consider caching the regexps if I'm missing use cases where the performance overhead of recompiling each time might become relevant. Shortly considered alternative ways to formulate the expressions without lookbehind, but couldn't think of anything that wouldn't make the code much more complex. |
I think this would be better to do, as it actually solves the underlying problem. |
PR flackr#177 added regular expressions to parse CSSNumericValue objects using lookbehind. Safari only supports lookbehind starting from version 16.4 [1]. In earlier versions loading the polyfill causes an error of the form: ``` SyntaxError: Invalid regular expression: invalid group specifier name ``` Compile RegExp on demand to ensure the polyfill can be loaded without errors. Since the relevant functions are only called initially when parsing options, the performance overhead appears limited. [1] https://caniuse.com/js-regexp-lookbehind
79c488f
to
153ed40
Compare
I agree that this would be the nicer solution, but the absence of unit tests makes the parsing logic rather scary to change. I played a bit with the current implementation and am still unsure which cases it is supposed to handle and if it does so correctly. |
I'm sorry for adding lookbehind without properly checking support. I needed an implementation of I agree that it would be better to add a proper implementation of (Note that these tests fail if the the build is run with terser so it's necessary to build with the --no-compress flag, see #200) Until we have a proper implementation, we could detect lookbehind-support and throw an error if a math-function is provided in parseCSSNumericValue: scroll-timeline/src/proxy-cssom.js Lines 177 to 184 in 147d187
|
The problem is that using lookbehind in a literal is a syntax error that cannot be caught in JS. This is why I proposed the workaround to use dynamically compiled expressions. |
I implemented tokenization and parsing for CSSNumericValue.parse() in #206 if we want to go that route. Looking forward to having parse() in all browsers so we don't have to reimplement it when polyfilling 😅. This will still leave one regexp in parseInset() where we need to consume a list of component values. |
I added a PR for a utility function |
All lookahead regexes have been replaced by proper parsing now. Is it ok to close this? |
When it comes to CSS, doing actual parsing indeed beats regexes. I think it’s fine to close this one indeed :) |
PR #177 added regular expressions to parse CSSNumericValue objects using lookbehind. Safari only supports lookbehind starting from version 16.4 [1]. In earlier versions loading the polyfill causes an error of the form:
Compile RegExp on demand to ensure the polyfill can be loaded without errors. Since the relevant functions are only called initially when parsing options, the performance overhead appears limited.
[1] https://caniuse.com/js-regexp-lookbehind