Skip to content

fix(biome_js_semantic): fix incorrect semantic resolution of arguments object#7671

Closed
qraqras wants to merge 1 commit intobiomejs:mainfrom
qraqras:dev/7628
Closed

fix(biome_js_semantic): fix incorrect semantic resolution of arguments object#7671
qraqras wants to merge 1 commit intobiomejs:mainfrom
qraqras:dev/7628

Conversation

@qraqras
Copy link
Contributor

@qraqras qraqras commented Oct 3, 2025

Summary

Closes #7628

The arguments object was incorrectly resolved to outer scope declarations, even though it implicitly exists within functions.
This PR ensures that the arguments object is resolved only within the function.
As a result, #7628 will be resolved.

Before:

let arguments = 0;
function func() {
    return arguments[0];  // Incorrectly resolved to outer `arguments` variable
}

After:

let arguments = 0;
function func() {
    return arguments[0];  // Correctly unresolved
}

Please feel free to give feedback if tests are lacking or hard to read.

Test Plan

  • existing tests (js_analyze, js_semantic)
  • new tests (js_analyze, js_semantic)
    • Update semantic test logic to support script mode parsing

Docs

  • changeset
  • rustdoc

@changeset-bot
Copy link

changeset-bot bot commented Oct 3, 2025

🦋 Changeset detected

Latest commit: a35d661

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages labels Oct 3, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 3, 2025

Walkthrough

This PR updates scope tracking and reference binding in the semantic layer to carry scope range and kind, changes push/pop scope signatures, and adds logic to correctly bind/promote references to the built-in arguments across function scopes. Scope-ended events now emit the stored range. Test infrastructure can parse as script when prefixed with // @script. New tests cover arguments resolution across function forms and nesting, plus updated noArguments valid/invalid samples. A changeset records a patch for @biomejs/biome documenting the fix to noArguments scoping of arguments.

Possibly related PRs

Suggested labels

A-Core, A-Linter, A-Parser, L-JavaScript

Suggested reviewers

  • ematipico
  • Conaclos

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title Check ✅ Passed The title precisely summarises the primary change of fixing the incorrect semantic resolution of the arguments object in the biome_js_semantic crate without unnecessary detail, making it clear and specific.
Linked Issues Check ✅ Passed The PR implements the semantic binding logic to resolve arguments only within function scopes and adds noArguments lint tests for both valid and invalid shadowing cases, directly fulfilling the primary objective of issue #7628. It also introduces script mode parsing support in test logic to satisfy the playground source type requirement, and includes minimal reproducible examples that match those described in the issue.
Out of Scope Changes Check ✅ Passed All code changes focus exclusively on fixing argument binding semantics, updating the noArguments lint tests, and adding script-mode parsing support as specified in issue #7628, with no unrelated modifications.
Description Check ✅ Passed The description directly addresses the linked issue by illustrating the before and after behaviour, summarising the fix, and outlining the test plan and documentation updates, all of which are relevant and on-topic.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 459a6ac and a35d661.

⛔ Files ignored due to path filters (2)
  • crates/biome_js_analyze/tests/specs/complexity/noArguments/invalid.cjs.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/complexity/noArguments/valid.cjs.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (6)
  • .changeset/every-baths-dream.md (1 hunks)
  • crates/biome_js_analyze/tests/specs/complexity/noArguments/invalid.cjs (2 hunks)
  • crates/biome_js_analyze/tests/specs/complexity/noArguments/valid.cjs (1 hunks)
  • crates/biome_js_semantic/src/events.rs (21 hunks)
  • crates/biome_js_semantic/src/tests/assertions.rs (2 hunks)
  • crates/biome_js_semantic/src/tests/references.rs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
crates/biome_*_{syntax,parser,formatter,analyze,factory,semantic}/**

📄 CodeRabbit inference engine (CLAUDE.md)

Maintain the per-language crate structure: biome_{lang}_{syntax,parser,formatter,analyze,factory,semantic}

Files:

  • crates/biome_js_semantic/src/tests/assertions.rs
  • crates/biome_js_semantic/src/tests/references.rs
  • crates/biome_js_analyze/tests/specs/complexity/noArguments/valid.cjs
  • crates/biome_js_semantic/src/events.rs
  • crates/biome_js_analyze/tests/specs/complexity/noArguments/invalid.cjs
crates/biome_*/**

📄 CodeRabbit inference engine (CLAUDE.md)

Place core crates under /crates/biome_*/

Files:

  • crates/biome_js_semantic/src/tests/assertions.rs
  • crates/biome_js_semantic/src/tests/references.rs
  • crates/biome_js_analyze/tests/specs/complexity/noArguments/valid.cjs
  • crates/biome_js_semantic/src/events.rs
  • crates/biome_js_analyze/tests/specs/complexity/noArguments/invalid.cjs
**/tests/**

📄 CodeRabbit inference engine (CLAUDE.md)

Place test files under a tests/ directory in each crate

Files:

  • crates/biome_js_semantic/src/tests/assertions.rs
  • crates/biome_js_semantic/src/tests/references.rs
  • crates/biome_js_analyze/tests/specs/complexity/noArguments/valid.cjs
  • crates/biome_js_analyze/tests/specs/complexity/noArguments/invalid.cjs
**/*.{rs,toml}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Before committing, format Rust and TOML files (e.g., via just f/just format)

Files:

  • crates/biome_js_semantic/src/tests/assertions.rs
  • crates/biome_js_semantic/src/tests/references.rs
  • crates/biome_js_semantic/src/events.rs
**/*.rs

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Document rules, assists, and options via inline rustdoc in Rust source

Files:

  • crates/biome_js_semantic/src/tests/assertions.rs
  • crates/biome_js_semantic/src/tests/references.rs
  • crates/biome_js_semantic/src/events.rs
.changeset/**/*.md

📄 CodeRabbit inference engine (CONTRIBUTING.md)

.changeset/**/*.md: Create changesets using the just new-changeset command; do not author them manually
In changeset markdown, only use headers #### or #####
Changeset descriptions must end every sentence with a full stop (.)
For bug fixes, start the changeset description with a linked issue reference like “Fixed #1234
Prefer past tense for what was done and present tense for current behavior in changesets

Files:

  • .changeset/every-baths-dream.md
🧬 Code graph analysis (4)
crates/biome_js_semantic/src/tests/assertions.rs (2)
packages/@biomejs/backend-jsonrpc/src/workspace.ts (1)
  • JsFileSource (9361-9370)
crates/biome_js_factory/src/generated/node_factory.rs (1)
  • js_script (3122-3134)
crates/biome_js_analyze/tests/specs/complexity/noArguments/valid.cjs (1)
crates/biome_js_analyze/tests/specs/complexity/noArguments/invalid.cjs (2)
  • arguments (1-1)
  • arguments (14-14)
crates/biome_js_semantic/src/events.rs (1)
packages/@biomejs/backend-jsonrpc/src/workspace.ts (1)
  • TextRange (9205-9205)
crates/biome_js_analyze/tests/specs/complexity/noArguments/invalid.cjs (1)
crates/biome_js_analyze/tests/specs/complexity/noArguments/valid.cjs (1)
  • arguments (3-3)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (13)
  • GitHub Check: Parser conformance
  • GitHub Check: Bench (biome_js_analyze)
  • GitHub Check: Bench (biome_js_parser)
  • GitHub Check: Bench (biome_js_formatter)
  • GitHub Check: Test Node.js API
  • GitHub Check: Documentation
  • GitHub Check: End-to-end tests
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Check Dependencies
  • GitHub Check: autofix
🔇 Additional comments (4)
crates/biome_js_semantic/src/tests/references.rs (4)

205-212: LGTM! Test correctly verifies arguments scoping in function declarations.

The test properly demonstrates that arguments within a function declaration should remain unresolved (not bind to outer scope), whilst foo correctly resolves to the outer binding.


213-220: LGTM! Validates arguments scoping for function expressions.

Correctly parallels the function declaration test, confirming that function expressions also treat arguments as implicitly scoped.


221-226: LGTM! Correctly validates arrow function semantics.

Arrow functions do not bind arguments, so the reference correctly resolves to the outer scope. Nice distinction from regular functions.


227-243: LGTM! Comprehensive test for nested function scoping.

The test thoroughly validates that arguments in nested functions remains unresolved (implicitly scoped per function), whilst local arguments variables are correctly resolved when referenced. Excellent coverage of the shadowing scenario.

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 3, 2025

CodSpeed Performance Report

Merging #7671 will not alter performance

Comparing qraqras:dev/7628 (a35d661) with main (29e4229)1

Summary

✅ 53 untouched
⏩ 85 skipped2

Footnotes

  1. No successful run was found on main (459a6ac) during the generation of this report, so 29e4229 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 85 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@qraqras qraqras closed this Oct 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Linter Area: linter L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

💅 noArguments reports false negatives when arguments is shadowed

1 participant