Skip to content

Port ?? binary operator emit #1375

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

Merged
merged 2 commits into from
Jul 9, 2025
Merged

Conversation

weswigham
Copy link
Member

Which is to say, the smaller half of the es2020 transform. The other half being ?..

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR ports support for emitting the ?? (nullish coalescing) operator in the Go-based native transformer/printer. It introduces a new transformer for ??, updates the AST and factory to recognize and print long-form nullish checks, adjusts how parameters with default values/binding patterns are handled during emit, and brings baseline snapshots into alignment.

  • Added createNotNullCondition helper and a nullishCoalescingTransformer to handle ?? rewrites.
  • Updated NodeFactory and EmitContext to support strict equality, type checks, and hoisting defaults for parameters.
  • Regenerated many .js baselines to use the long-form x !== null && x !== void 0 ? x : y pattern.

Reviewed Changes

Copilot reviewed 101 out of 101 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/transformers/estransforms/utilities.go Added createNotNullCondition to build nullish check nodes
internal/transformers/estransforms/nullishcoalescing.go Implemented transformer for ?? to conditional expressions
internal/printer/factory.go Added NewStrictEqualityExpression and NewTypeCheck
internal/printer/emitcontext.go Enhanced parameter-scoped hoisting for default assignments
internal/ast/ast.go Updated token facts to mark ?? as SubtreeContainsNullishCoalescing
Comments suppressed due to low confidence (2)

internal/transformers/estransforms/nullishcoalescing.go:13

  • There are no unit tests for the new nullishCoalescingTransformer. Adding a minimal Go-level test for ?? emission would ensure future changes don’t regress this behavior.
func (ch *nullishCoalescingTransformer) visit(node *ast.Node) *ast.Node {

internal/transformers/estransforms/utilities.go:22

  • The invert parameter is never used (always called with false). Consider removing it or documenting its intended use to simplify this helper.
func createNotNullCondition(emitContext *printer.EmitContext, left *ast.Node, right *ast.Node, invert bool) *ast.Node {

@weswigham weswigham added this pull request to the merge queue Jul 9, 2025
Merged via the queue into microsoft:main with commit a076c17 Jul 9, 2025
22 checks passed
@weswigham weswigham deleted the nullishcoal branch July 9, 2025 20:35
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.

2 participants