feat(span)!: use ModuleKind::CommonJS for .cjs and .cts file extensions#18117
Merged
graphite-app[bot] merged 1 commit intomainfrom Jan 17, 2026
Merged
feat(span)!: use ModuleKind::CommonJS for .cjs and .cts file extensions#18117graphite-app[bot] merged 1 commit intomainfrom
ModuleKind::CommonJS for .cjs and .cts file extensions#18117graphite-app[bot] merged 1 commit intomainfrom
Conversation
ModuleKind::CommonJS for .cjs and .cts file extensionsModuleKind::CommonJS for .cjs and .cts file extensions
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request updates the handling of .cjs and .cts file extensions to properly treat them as CommonJS modules instead of plain scripts. The change enables CommonJS-specific semantics like top-level return and new.target, while also enforcing script-specific restrictions like preventing top-level using declarations.
Changes:
- Updates
SourceType::from_path()to map.cjs/.ctsfiles toModuleKind::CommonJSinstead ofModuleKind::Script - Fixes linter rules (
no_eval,no_redeclare) to properly handle both scripts and CommonJS by checking!is_module()instead ofis_script() - Adds semantic checker for
usingdeclarations to prevent them at the top level of scripts (while allowing them in CommonJS and modules)
Reviewed changes
Copilot reviewed 7 out of 17 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| crates/oxc_span/src/source_type.rs | Updates file extension mapping to return ModuleKind::CommonJS for .cjs/.cts files and adds comprehensive test assertions |
| crates/oxc_semantic/src/diagnostics.rs | Adds new diagnostic for invalid top-level using declarations in scripts |
| crates/oxc_semantic/src/checker/mod.rs | Registers the new variable declaration checker |
| crates/oxc_semantic/src/checker/javascript.rs | Implements check to prevent top-level using in scripts while allowing in modules and CommonJS |
| crates/oxc_linter/src/rules/eslint/no_redeclare.rs | Updates to run for both scripts and CommonJS (not just scripts) |
| crates/oxc_linter/src/rules/eslint/no_eval.rs | Updates to check !is_module() instead of is_script() with clarifying comment |
| crates/oxc_linter/src/loader/partial_loader/vue.rs | Updates test to use from_extension() to get correct CommonJS type |
| tasks/coverage/misc/pass/script-using-in-block.js | New test showing using is allowed in blocks within scripts |
| tasks/coverage/misc/fail/script-top-level-using.js | New test showing using is not allowed at top level of scripts |
| Multiple snapshot files | Updated test results showing CommonJS files now parse correctly and script-level using is properly rejected |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
0ed20a4 to
9becfb9
Compare
Member
Author
Merge activity
|
ModuleKind::CommonJS for .cjs and .cts file extensionsModuleKind::CommonJS for .cjs and .cts file extensions
562d2dd to
895a020
Compare
…tensions (#18117) ## Summary - Updates `SourceType::from_path()` to return `ModuleKind::CommonJS` for `.cjs`/`.cts` files (previously returned `ModuleKind::Script`) - Fixes `eslint/no-eval` to check `!is_module()` instead of `is_script()` to handle both scripts and CommonJS (matching ESLint's `sourceType: "commonjs"` behavior) - Fixes `eslint/no-redeclare` to run for both scripts and CommonJS files - Updates tests to use proper CommonJS assertions This follows up on #18089 which added `ModuleKind::CommonJS` support but didn't update the file extension mapping. ## Test plan - [x] `cargo test -p oxc_span` - [x] `cargo test -p oxc_linter` 🤖 Generated with [Claude Code](https://claude.com/claude-code)
895a020 to
ba9c750
Compare
This was referenced Jan 19, 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.
Summary
SourceType::from_path()to returnModuleKind::CommonJSfor.cjs/.ctsfiles (previously returnedModuleKind::Script)eslint/no-evalto check!is_module()instead ofis_script()to handle both scripts and CommonJS (matching ESLint'ssourceType: "commonjs"behavior)eslint/no-redeclareto run for both scripts and CommonJS filesThis follows up on #18089 which added
ModuleKind::CommonJSsupport but didn't update the file extension mapping.Test plan
cargo test -p oxc_spancargo test -p oxc_linter🤖 Generated with Claude Code