Skip to content

[WIP] Port TypeScript PR #60304: More rigorous ASI prevention when emitting return/yield #1128

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

Closed
wants to merge 2 commits into from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 9, 2025

  • Analyze TypeScript PR #60304 which fixes ASI (Automatic Semicolon Insertion) issues when emitting return/yield statements
  • Identify the current equivalent function emitExpressionNoASI in the Go port's printer
  • Understand the problem: comments in parenthesized expressions can cause ASI issues when parentheses are removed
  • Map AST node kinds from TypeScript to Go equivalents
  • Enhance emitExpressionNoASI to match the new parenthesizeExpressionForNoAsi logic from TypeScript
  • Apply recursive ASI prevention to PropertyAccess, ElementAccess, Call, TaggedTemplate, PostfixUnary, Binary, Conditional, As, Satisfies, and NonNull expressions
  • Ensure existing printer tests continue to pass
  • Implement proper comment detection in willEmitLeadingNewLine function
  • Test the changes work correctly for the reported ASI issue
  • Update baselines if necessary

Enhanced the emitExpressionNoASI function to recursively process expression structures that could have ASI issues, matching the approach from TypeScript PR #60304. The main improvement is more rigorous parenthesization logic that walks into sub-expressions. However, the willEmitLeadingNewLine function still needs proper comment detection implementation to fully resolve the reported ASI issues.

Fixes #1123.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: andrewbranch <3277153+andrewbranch@users.noreply.github.com>
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

Successfully merging this pull request may close these issues.

Port TypeScript PR #60304: More rigorous ASI prevention when emitting return/yield
2 participants