Skip to content
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

Some parser bugs #835

Closed
bakkot opened this issue Feb 18, 2021 · 1 comment
Closed

Some parser bugs #835

bakkot opened this issue Feb 18, 2021 · 1 comment

Comments

@bakkot
Copy link

bakkot commented Feb 18, 2021

I ran a fuzzer for a bit and found a few cases where esbuild incorrectly rejects valid programs.

If you'd prefer I not file issues found with a fuzzer, let me know.


// code a human might actually write 
for (let x = `${a in b ? '0' : '1'}`; false; );

// minimal repro
for(`${0 in 0}`;;);

Here the in grammar flag should get reset when entering template literals.


// code a human might actually write 
function makeClass() {
  return class {
    [arguments.length === 0 ? 'default' : arguments[0]](){}
  };
};

// minimal repro
(class { [arguments](){} });

arguments can be referred to in computed property names in classes; it's inherited from the surrounding context.


// code a human might actually write 
[[...a, fallback].prop] = c;

// minimal repro
[[...0,0]._]=0

I assume that when [ is encountered in the LHS of an assignment it is assumed to be an ArrayAssignmentPattern, and hence forbidden from having any elements after the ... one, but that assumption is not necessarily true: [ can also begin an array which is the object of a member assignment, as here. My first line here assigns the value of the first element in c to the prop field in the first element of a, if there are any such, or otherwise to the prop field of fallback.


class C extends S {
  constructor(_=super()) {
  }
}

It is technically legal to call super() in the parameters of the constructor in a derived class, not just the body. This example is a fun (if inscrutable) way to make a class which throws if you try to new it with any arguments.


new async()._ = 0

This one I doubt would ever actually come up. It only happens with new, and the binding is named async, and when assigning to a property. But I'm including it for completeness. I assume it's an issue with the parsing of the hideous cover grammar for async arrow expressions.

@evanw
Copy link
Owner

evanw commented Feb 18, 2021

Thanks for these reports. Issues found with a fuzzer are very welcome. I'll work on fixing these.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants