Skip to content

fix: honor --use-strict for CommonJS scripts - #65248

Open
SomSamantray wants to merge 1 commit into
nodejs:mainfrom
SomSamantray:fix/30039-use-strict
Open

fix: honor --use-strict for CommonJS scripts#65248
SomSamantray wants to merge 1 commit into
nodejs:mainfrom
SomSamantray:fix/30039-use-strict

Conversation

@SomSamantray

@SomSamantray SomSamantray commented Aug 12, 2026

Copy link
Copy Markdown

deps: honor --use-strict for wrapped CommonJS scripts

node --use-strict script.js did not apply strict mode to CommonJS
scripts. Parser::ParseWrapped(), used to parse the function V8
synthesizes for CommonJS module wrapping, hardcoded
LanguageMode::kSloppy instead of consulting the language mode already
configured on the ParseInfo. As a result the --use-strict CLI flag
had no effect on ordinary script execution, even though it worked
correctly from the REPL.

Pass info->language_mode() through to ParseFunctionLiteral() so the
wrapped function honors the language mode Node.js configured for the
parse, matching V8's behavior for other entry points.

Add regression coverage in test/parallel/test-cli-eval.js that runs a
script assigning to an undeclared variable with and without
--use-strict, asserting the ReferenceError is only thrown in the
latter case.

Fixes: #30039
Signed-off-by: Som Samantray 92726151+SomSamantray@users.noreply.github.com

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/security-wg
  • @nodejs/v8-update

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. v8 engine Issues and PRs related to the V8 dependency. labels Aug 12, 2026
@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.31%. Comparing base (00f0f8c) to head (293b936).
⚠️ Report is 17 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main   #65248    +/-   ##
========================================
  Coverage   90.31%   90.31%            
========================================
  Files         760      760            
  Lines      248637   249130   +493     
  Branches    46942    47055   +113     
========================================
+ Hits       224556   225009   +453     
- Misses      15475    15525    +50     
+ Partials     8606     8596    -10     

see 39 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread test/parallel/test-cli-eval.js Outdated
`node --use-strict script.js` did not apply strict mode to CommonJS
scripts. Parser::ParseWrapped(), used to parse the function V8
synthesizes for CommonJS module wrapping, hardcoded
LanguageMode::kSloppy instead of consulting the language mode already
configured on the ParseInfo. As a result the `--use-strict` CLI flag
had no effect on ordinary script execution, even though it worked
correctly from the REPL.

Pass `info->language_mode()` through to ParseFunctionLiteral() so the
wrapped function honors the language mode Node.js configured for the
parse, matching V8's behavior for other entry points.

Add regression coverage in test/parallel/test-cli-eval.js that runs a
script assigning to an undeclared variable with and without
`--use-strict`, asserting the ReferenceError is only thrown in the
latter case.

Fixes: nodejs#30039
Signed-off-by: Som Samantray <92726151+SomSamantray@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. v8 engine Issues and PRs related to the V8 dependency.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--use-strict flag doesn't apply strict mode to script

3 participants