Skip to content

Conversation

@jakebailey
Copy link
Member

@jakebailey jakebailey commented Nov 6, 2025

This fixes a massive number of diffs relating to prologues, including missing "use strict" or duplicating prologues/comments in general.

Before, "use strict" was added in the CJS transform. But this meant we were not adding it to non-CJS files that also needed it, e.g. scripts.

This PR splits the functionality out into a fine-grained transform which handles just adding "use strict", drops the code from CJS, then fixes related bugs in transforms/emit that were causing things to break with this fix in place.

After this PR, there are no missing "use strict" in any diffs, except for files which are missing entire files or are in general not being detected as ESM correctly. (only 9 diffs last I checked)

Copilot AI review requested due to automatic review settings November 6, 2025 17:30
Copy link
Contributor

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 pull request refactors how "use strict" directives are emitted by moving the logic from the CommonJS module transformer into a dedicated UseStrictTransformer. This fixes numerous baseline differences where "use strict" was previously missing or being duplicated in various compilation scenarios.

Key Changes

  • Created a new UseStrictTransformer that runs before module transformation
  • Removed "use strict" emission logic from the CommonJS module transformer
  • Fixed prologue splitting to correctly handle cases where all statements are prologue
  • Updated printer to emit only non-prologue statements when emitting function bodies

Reviewed Changes

Copilot reviewed 300 out of 1181 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
internal/transformers/estransforms/usestrict.go New transformer that adds "use strict" based on module type and compiler options
internal/transformers/moduletransforms/commonjsmodule.go Removed "use strict" logic that now belongs in the dedicated transformer
internal/compiler/emitter.go Added the new UseStrictTransformer to the transformation pipeline
internal/printer/factory.go Fixed SplitStandardPrologue to return all statements as prologue when applicable
internal/printer/printer.go Updated to use emitListRange to skip prologue statements in function bodies
testdata/baselines/reference/**/*.js Baseline updates showing "use strict" now correctly appears once at the start of files
testdata/baselines/reference/**/*.js.diff Diff files showing removal of duplicate "use strict" directives

@jakebailey
Copy link
Member Author

@sheetalkamat I don't really know how to handle this one; the test seems to be flaky. It seems to me like we are not correctly noting that strict/alwaysStrict are emit affecting (or even bind affecting!)

@jakebailey jakebailey enabled auto-merge November 7, 2025 21:00
@jakebailey jakebailey added this pull request to the merge queue Nov 7, 2025
Merged via the queue into main with commit ffa30a7 Nov 7, 2025
22 checks passed
@jakebailey jakebailey deleted the jabaile/use-strict branch November 7, 2025 21:15
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.

4 participants