Skip to content
This repository has been archived by the owner on Sep 27, 2020. It is now read-only.

Should the loop expression of a ForStatement be an ExpressionStatement? #39

Open
fvictorio opened this issue Oct 21, 2018 · 1 comment

Comments

@fvictorio
Copy link
Contributor

The loop expression of the for statement gest the type ExpressionStatement added:

loopExpression: {
type: 'ExpressionStatement',
expression: this.visit(ctx.expression(1))
},

This is causing issues in prettier-solidity, where is difficult to know if an ExpressionStatement should have a semicolon or not (see prettier-solidity/prettier-plugin-solidity#46 and prettier-solidity/prettier-plugin-solidity#64 for the details). Since the loop expression of a for doesn't have a semicolon, calling it an ExpressionStatement feels wrong.

My question is if there's a good reason to do this, and if there's a chance of modifying it.

Thanks!

@federicobond
Copy link
Owner

Internally, the reference implementation of Solidity uses an ExpressionStatement, so I would approach this change carefully.

The definition of ExpressionStatement is an expression followed by a semicolon though. If it’s difficult to special case this in prettier then I’m open to accepting a pull request to update the parser. Make sure you include the change in the changelog too.

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

No branches or pull requests

2 participants