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

parse error on static blocks containing await accessor param #1106

Closed
jdalton opened this issue Feb 17, 2022 · 9 comments
Closed

parse error on static blocks containing await accessor param #1106

jdalton opened this issue Feb 17, 2022 · 9 comments

Comments

@jdalton
Copy link
Contributor

jdalton commented Feb 17, 2022

@rwaldron (who runs test262 for fun) found this bit of code that is technically valid (its function is beyond me) but found that acorn throws a parse error trying to process it. Reporting as a heads up:

    class C {
      static {
        ({set accessor(await) {}});
      }
    }
@cool-little-fish
Copy link
Contributor

see https://262.ecma-international.org/12.0/#prod-MethodDefinition, I believe it's invalide syntax.

@jdalton
Copy link
Contributor Author

jdalton commented Feb 17, 2022

It seems to parse in Chrome, Firefox, but not Safari:
https://jsbin.com/dunaqiz/1/edit?html,js,console,output

Update:

Here's the test262 test:
https://github.com/tc39/test262/blob/afe217b318df5f197e64b30a8b5a4b391c777359/test/language/expressions/object/method-definition/static-init-await-binding-accessor.js

Update:

Ah I see it's part of

"[Add tests for "Class Static Init. Blocks" proposal]

Looks like it's part of the static blocks proposal which hit stage 4 in August 2021 and is now supported by Chrome/Firefox:
tc39/proposal-class-static-block#48 (comment)

Spec link:
https://tc39.es/ecma262/#sec-classstaticblockdefinition-record-specification-type

@jdalton jdalton changed the title parse error on something technically valid. parse error on static blocks containing await accessor param Feb 17, 2022
@marijnh
Copy link
Member

marijnh commented Feb 17, 2022

I'm not actually seeing a parse error for this code in the current version of Acorn. How are you testing this?

@cool-little-fish
Copy link
Contributor

I used accorn v8.5.0 to reproduce this problem.

@marijnh
Copy link
Member

marijnh commented Feb 17, 2022

What did you set ecmaVersion to? Does the problem go away when you upgrade to 8.7.0?

@cool-little-fish
Copy link
Contributor

still can reproduce after upgrade to 8.7.0, with ecma 2022

@cool-little-fish
Copy link
Contributor

cool-little-fish commented Feb 17, 2022

let acorn = require("acorn");
const fs = require('fs');

// const tplToRead = fs.readFileSync('./src/acorn/parse-str.txt', { encoding: 'utf-8' });
const parseRes = acorn.parse(`
class C {
  static {
    ({set accessor(await) {}});
  }
}`, {ecmaVersion: 2022,  locations: true, sourceType: 'module' });

The error message: Uncaught SyntaxError: Cannot use keyword 'await' outside an async function (4:19)

@marijnh
Copy link
Member

marijnh commented Feb 17, 2022

Right, if you add sourceType: 'module' you can't use await as an identifier, but I'm pretty sure that's the appropriate behavior and I don't think the error has much to do with this specific code (just function foo(await){} also gives that parse error).

@jdalton
Copy link
Contributor Author

jdalton commented Feb 17, 2022

@marijnh Ah yes, as "module" it does error as expected.

module example:
https://jsbin.com/nemagif/1/edit?html,js,console,output

Thanks!

@jdalton jdalton closed this as completed Feb 17, 2022
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

No branches or pull requests

3 participants