Inject "use strict" directive based on tsconfig alwaysStrict setting#8266
Draft
Inject "use strict" directive based on tsconfig alwaysStrict setting#8266
Conversation
✅ Deploy Preview for rolldown-rs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
… strict" injection logic Co-authored-by: shulaoda <[email protected]>
Co-authored-by: shulaoda <[email protected]>
Copilot
AI
changed the title
[WIP] Add 'use strict' injection for CJS builds
Inject "use strict" directive based on tsconfig alwaysStrict setting
Feb 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When bundling for non-ESM formats with
tsconfigenabled andalwaysStrict: true(orstrict: true), the output should include"use strict";at the top of the bundle.Changes
Core Infrastructure
tsconfigfield toNormalizedBundlerOptionsto track tsconfig configuration through the pipelineresolvertoGenerateContextandGenerateStageto enable tsconfig resolution during code generationDirective Injection Logic
Implemented
should_inject_use_strict()helper that:alwaysStrictorstrictcompiler optionsModified directive collection in
ecma_generator.rsto prepend"use strict";when appropriate, avoiding duplicatesTest Coverage
Created test fixtures for:
alwaysStrict: true✓alwaysStrict: false✓strict: true(implies alwaysStrict) ✓alwaysStrict: true✓alwaysStrict: true(should not emit) ✓Known Issue
Format detection bug:
ctx.options.formatreturns the global bundle format (ESM by default) rather than the per-output format. This causes the ESM format check to always trigger, blocking injection even for CJS/IIFE outputs. Need to identify where the per-chunk output format is stored and use that instead.Debug output confirms:
Even when output config specifies
format: 'cjs'and the generated code containsexportsobject.Original prompt
"use strict"is not injected for CJS builds #5865💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.