-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Use ES2018 RegExp lookbehind assertions when available #1708
Comments
Sorry, but this feature is so new that not even FireFox (64.0.2) supports it at this point in time. It will probably take a few years until the majority of browsers support this feature. Also, I don't think that a polyfill is possible for this as the underlying Regex-engine itself has to be changed for this. |
I don’t mean implement a polyfill, I mean keep using the current code path for browsers which don’t support lookbehind, but add a new code path for browsers which do support this, which would convert the first |
I was actually also thinking that this might be a good idea at some point. "The browser (and Node) can optimize way better than we ever could and everything would be so much nicer", I was thinking. But unfortunately, we can't do this because Prism's lookbehinds are not real lookbehinds; they behave differently. To illustrate this, suppose the following pattern:
The real lookbehind obviously behaves correct but the point is that some patterns actually use this 'incorrect' behavior of Prism's lookbehinds, so we might get different highlighting results depending on the browser (version). Another problem is that real lookbehinds can even access parts of the string before I do think that we should totally go for real Regex lookbehinds as soon as they become available on a majority of browsers. We can then remove the fake Prism lookbehinds and live happily ever after. To be clear: |
We have #1578 to track when we can drop IE11 support. We can't use new RegEx features until we've decided that we're going to abandon IE11. |
@mAAdhaTTah We can't even use it IF we were to abandon IE11. This Regex feature is so new that not even the latest release of FF supports it. Only V8 implements this at the moment. |
AFAIK Safari is the major hold out now on support for look-behind. We don't plan to support it in Highlight.js until Safari has added proper support so that we have the same behavior across all modern browsers. |
Interesting. Right now, about 75% use a browser that supports lookbehinds. If all Safari browsers added support for them now, we could be at >=90% in maybe a year. Well, that's a big if, so Prism will likely not use lookbehinds for another two years or so. Also, Prism has to be conservative about this because we heavily use RegExp literals. Browsers that don't support lookbehinds in RegExp literals will throw a |
ECMAScript 2018 adds built‑in support for lookbehind assertions to regular expressions, which can be a lot faster than the current pseudo‑lookbehind implemented in Prism.
Also, it’d be nice to use the official syntax and only use the pre‑ES2018 implementation when necessary.
The text was updated successfully, but these errors were encountered: