Skip to content

SyntaxError thrown on valid JS #633

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

Closed
p-bakker opened this issue Oct 28, 2024 · 2 comments · Fixed by #639
Closed

SyntaxError thrown on valid JS #633

p-bakker opened this issue Oct 28, 2024 · 2 comments · Fixed by #639
Labels
bug Something isn't working

Comments

@p-bakker
Copy link

p-bakker commented Oct 28, 2024

This snippet of code throws a SyntaxError: invalid lexical variable name:

        with (new Proxy({globalThis: {Infinity, NaN, undefined}}, {})) {
          const {Infinity,NaN,undefined} = this.globalThis;
        }

This sort of structure is used by SES in the Compartment polyfill

Besides this snippet being valid js and thus shouldn't be throwing a SyntaxError, if there would be a real syntax error, shouldn't the error include the invalid variable name?

@chqrlie
Copy link
Collaborator

chqrlie commented Oct 28, 2024

This snippet can be simplified as

{ const { undefined } = {} }

it throws:

SyntaxError: invalid lexical variable name
    at <evalScript>:1:8

Same problem without the destructuring:

{ const undefined = void 0; }

@chqrlie chqrlie added the bug Something isn't working label Oct 28, 2024
@chqrlie
Copy link
Collaborator

chqrlie commented Oct 28, 2024

Besides this snippet being valid js and thus shouldn't be throwing a SyntaxError, if there would be a real syntax error, shouldn't the error include the invalid variable name

I agree on both counts. Adding the identifier should be easy in this case because this is a parse error.

bnoordhuis added a commit to bnoordhuis/quickjs that referenced this issue Oct 29, 2024
Except at the global scope of a classic script because... who knows,
that's just how it is.

Fixes: quickjs-ng#633
bnoordhuis added a commit to bnoordhuis/quickjs that referenced this issue Oct 29, 2024
Except at the global scope of a classic script because... who knows,
that's just how it is.

Fixes: quickjs-ng#633
bluesky950520 pushed a commit to bluesky950520/quickjs that referenced this issue Mar 14, 2025
Except at the global scope of a classic script because... who knows,
that's just how it is.

Fixes: quickjs-ng/quickjs#633
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants