Skip to content
This repository was archived by the owner on May 12, 2025. It is now read-only.

Conversation

@arodionov
Copy link
Contributor

In a visitExpressionStatement TS parser method, if the expression is a Statement, it shouldn't be wrapped into ExpressionStatement.

Also, in a JavaScriptVisitor class, remove unwrapping ExpressionStatement into Statement if it is a Statement.

In a visitExpressionStatement parser method, if the expression is a Statement, it shouldn't be wrap into ExpressionStatement.

Also in a JavaScriptVisitor class remove unwrapping ExpressionStatement into Statement, if it is a Statement.
@arodionov arodionov self-assigned this Feb 24, 2025
import * as J from '../java'
import * as JS from "./tree";

export const statement_implementations_list: Array<{ new (...args: any[]): J.Statement }> = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we implement this as a type guard?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reimplemented the check as isStatement and isExpression methods

Unfortunately, there is no simple way in TS to require that the array contains only classes that implement the Statement/Expression interface.

J.Label,
J.Lambda,
J.MethodDeclaration,
J.MethodInvocation,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you also need something like an is_expression or how do we make sure that the types which are both expression and statement don't get wrapped? Also note the inverse wrapper (StatementExpression) which might show the same behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have removed unwrapping for the StatementExpression in a visitStatementExpression.
There is only one place in a parser where the StatementExpression is directly used.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I think it would be best if we could have this generated instead of maintaining it by hand, as now every time we add a new type to either J or JS, we need to make sure to check if we need to update these arrays.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am missing the following four types from J: DoWhileLoop, ForEachLoop, ForLoop, and WhileLoop. AFAIK we use all of these except for ForEachLoop in our parser.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am also missing the JS types ForOfLoop and ForInLoop.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thanks!
I've used a small util to generate the list of classes, but missed the Loop inheritors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I think it would be best if we could have this generated instead of maintaining it by hand, as now every time we add a new type to either J or JS, we need to make sure to check if we need to update these arrays.

Yes, it will be a more consistent way to keep lists up-to-date.

- remove unwrapping for visitStatementExpression
JS.Unary,
JS.Union,
JS.Void,
JS.Yield
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we here also have ExpressionStatement and StatementExpression?

@arodionov arodionov merged commit 2e15f7e into main Feb 25, 2025
1 check passed
@arodionov arodionov deleted the es-unwrapping branch February 25, 2025 12:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants