Skip to content

Finish implementing sourceFileMayBeEmitted, JSON emit #1245

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jakebailey
Copy link
Member

Fixes #660

I'm not happy with the emit change, but I don't know what the right fix is. Strada did parenthesizing completely differently.

@Copilot Copilot AI review requested due to automatic review settings June 20, 2025 06:42
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 implements changes to the emission logic for source files, with particular attention to JSON modules and their output paths. Key changes include:

  • Refining the handling of immediately invoked functions in JSON files (printer.go).
  • Renaming and updating the helper function for generating output file paths (outputpaths.go).
  • Introducing a new host interface and updating the logic for sourceFileMayBeEmitted (emitter.go).

Reviewed Changes

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

File Description
internal/printer/printer.go Adjusts expression emission for JSON files by checking the ScriptKind and avoiding parentheses for certain expressions.
internal/outputpaths/outputpaths.go Renames the helper function to follow Go naming conventions and updates its call site.
internal/compiler/emitter.go Refactors sourceFileMayBeEmitted by introducing a new host interface and adding conditions to decide file emission based on compiler options.

@@ -3175,7 +3175,10 @@ func (p *Printer) emitEmptyStatement(node *ast.EmptyStatement, isEmbeddedStateme
func (p *Printer) emitExpressionStatement(node *ast.ExpressionStatement) {
state := p.enterNode(node.AsNode())

if isImmediatelyInvokedFunctionExpressionOrArrowFunction(node.Expression) {
if p.currentSourceFile != nil && p.currentSourceFile.ScriptKind == core.ScriptKindJSON {
Copy link
Preview

Copilot AI Jun 20, 2025

Choose a reason for hiding this comment

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

The JSON-specific branch uses a hack comment referencing an undefined parenthesizerRule. Consider refactoring this block to either integrate a proper parenthesizing solution for JSON files or add a more descriptive comment on why the current approach is necessary.

Copilot uses AI. Check for mistakes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah yes, it's that simple

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.

JSON file includes do not change lowest common ancestor for outDir
1 participant