-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
esm module import with data scheme has bug with ternary operator in object #42890
Comments
/cc @nodejs/modules It's not the first time an issue like this one is opened. Here's the annotated stack:
|
FWIW, Firefox and Safari do error with this snippet. I think this indeed already come up in another issue but I can't find it. From the top of my head, the gist of it was: the spec does not enforce a specific parsing algorithm for import specifiers, Chrome is the odd one out by using a more loose algorithm than others, Node.js is using the WHATWG import(`data:text/javascript,${encodeURIComponent(`
let a = {
b: function() { 1 == 1 ? "c" : "d"}
};
`)}`);
// or using Base64
import(`data:text/javascript;base64,${Buffer.from(`
let a = {
b: function() { 1 == 1 ? "c" : "d"}
};
`).toString('base64')}`); |
I assume you’re probably remembering #42504. Should we close this one too per the resolution there? Or perhaps the solution is to try to print a better error message (if that’s even possible, since this seems to error at a parsing level)? |
That would be nice, but I don't know if we can tell the difference between a real syntax error in the code and one introduced by URL encoding. |
node/lib/internal/modules/esm/get_source.js Lines 36 to 41 in ceadb47
We could try to detect a ternary (if there's a |
This not really works, because only
Under my test (at year 2023), Firefox and Safari do same with Chrome. |
Version
v16.15.0
Platform
Linux mojighahar 5.8.0-63-generic #71-Ubuntu SMP Tue Jul 13 15:59:12 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
No response
What steps will reproduce the bug?
Running the following codes causes a
SyntaxError: Unexpected end of input
:Or more complex:
But the following code works without error:
How often does it reproduce? Is there a required condition?
No response
What is the expected behavior?
No response
What do you see instead?
Additional information
No response
The text was updated successfully, but these errors were encountered: