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

Superfluous EmptyStatement created when parsing parenthized class or function expression in default export #379

Closed
zjmiller opened this issue Jan 25, 2016 · 1 comment

Comments

@zjmiller
Copy link

Acorn parses the semicolon in both export default (class{}); and export default (function(){}); as an EmptyStatement. Esprima doesn't. The same issue arises with named classes and functions, as in export default (class A{}); and export default (function a(){});. The ES6 spec seems to support Esprima's interpretation of these cases.

This appears to stem from a difference in how Acorn and Esprima treat anonymous classes and functions in default exports. Acorn treats them as expressions and Esprima treats them as declarations. See estree/estree#98 for a recent discussion of this.

So Acorn treats export default class{} as involving a class expression. Because a semicolon is not needed here, Acorn says that in default exports, any semicolon following a class expression is unnecessary (and therefore ends up getting parsed as an EmptyStatement). This works great in export default class{}, but overgeneralizes when dealing with export default (class{}); and export default (class A{});. This is what's happening with functions as well.

@marijnh marijnh closed this as completed in 0453696 Feb 5, 2016
@marijnh
Copy link
Member

marijnh commented Feb 5, 2016

Indeed. Attached patch should help.

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

2 participants