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

Codegen does not wrap ChainExpression in parentheses when it's left side of AssignmentExpression #6385

Closed
overlookmotel opened this issue Oct 9, 2024 · 0 comments · Fixed by #6430
Assignees
Labels
A-codegen Area - Code Generation C-bug Category - Bug

Comments

@overlookmotel
Copy link
Contributor

Source:

(foo?.bar).qux = 1;

Output from codegen:

foo?.bar.qux = 1;

Playground

This output is not legal. "SyntaxError: Invalid left-hand side in assignment"

Same problem with (foo?.()).bar = 1.

@overlookmotel overlookmotel added C-bug Category - Bug A-codegen Area - Code Generation labels Oct 9, 2024
@Dunqing Dunqing self-assigned this Oct 10, 2024
Boshen pushed a commit that referenced this issue Oct 13, 2024
close: #6385

The fixing way was referenced from `esbuild`, it is according to these [states](https://github.com/evanw/esbuild/blob/332727499e62315cff4ecaff9fa8b86336555e46/internal/js_ast/js_ast.go#L590-L604
)(determined in the parser) to determine whether to print parenthesis

Due to differences in implementation details, we are unable to record certain information like `esbuild` does in its parser. But fortunately, The `ParenthesisExpression` AST is actually like what `esbuild` stored states.
@Dunqing Dunqing closed this as completed Oct 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area - Code Generation C-bug Category - Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants