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
fix(compiler): Generate backwards-compatible code to not crash on old browsers #383
Conversation
|
Do I understand right that you're compiling ICU MessageFormat strings in your client runtime, where this line is then throwing an error in really old browsers?
Have you considered using |
@@ -94,10 +94,10 @@ | |||
if (this.options.requireAllArguments && hasArgs) { | |||
this.setRuntimeFn('reqArgs'); | |||
const reqArgs = JSON.stringify(this.arguments); | |||
return `(d) => { reqArgs(${reqArgs}, d); return ${res}; }`; | |||
return `function (d) { reqArgs(${reqArgs}, d); return ${res}; }`; |
Check warning
Code scanning / CodeQL
Improper code sanitization
@@ -94,10 +94,10 @@ | |||
if (this.options.requireAllArguments && hasArgs) { | |||
this.setRuntimeFn('reqArgs'); | |||
const reqArgs = JSON.stringify(this.arguments); | |||
return `(d) => { reqArgs(${reqArgs}, d); return ${res}; }`; | |||
return `function (d) { reqArgs(${reqArgs}, d); return ${res}; }`; |
Check warning
Code scanning / CodeQL
Improper code sanitization
} | ||
|
||
return `(${hasArgs ? 'd' : ''}) => ${res}`; | ||
return `function (${hasArgs ? 'd' : ''}) { return ${res}; }`; |
Check warning
Code scanning / CodeQL
Improper code sanitization
I didn't do the implementation (just trying to fix things that broke afterwards ^_^), but yeah, we are. Seem to mostly be getting errors in the wild from "Samsung Internet" and old versions of Chrome. We do allow our volunteer translators to test their changes in-game, so do need the compiling to happen in the runtime (without access to source code / build pipeline), although in theory that could be in both the build pipeline and the runtime and the runtime stuff for translators could be limited to only new browsers.
I didn't know that was an option, but will pass the suggestion on to the engineer responsible, but that would likely be a more involved change. |
That's really the main recommended usage pattern for this library, tbh. Doing so would save you from needing to deploy the compiler at all in your client runtime. But yeah, I see how that would be a more involved change esp. if you need to figure out a different way for testing translations. Now, rather than effectively rolling back #309 and dropping the fat-arrow notation, I'd much prefer making this configurable. In other words, defaulting to the terser notation but allowing for a new option that would use Btw, the Node.js 19 test failures aren't your fault; those seem to be caused by an ICU 72 change in the whitespace used before the AM/PM marker. |
I'm not exactly sure where to start with that, but if you can point at some other code taking options I could take a poke at it. Alternatively, do we know if we're generating code at run-time (to pass to That being said, I just realized it actually would be pretty easy to just replace |
Probably something like the
If you're doing it at build time, you should either find calls to
Tbh, that sounds like a more intrusive option to me. But sure, it might work. |
Closing this as presumably solved by a user-space change. |
Since adopting @messageformat/core we've been running into various issues for some users on old browsers. For most of the issues the combination of Babel and polyfills handles it, but it appears this specific code is generating a string that contains an arrow function that's being passed to
eval()
, which of course Babel can't deal with. Trivial change, tested on Chrome 38 on our game (https://worlds.frvr.com, still have the old version live), mostly just had to change a bunch of test case outputs to match.