fix(parser): reject module-referencing imports/exports in a namespace body#22836
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7baf5d0e58
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Merge activity
|
… body (#22836) Inside an internal `namespace N {}` / `module N {}`, statements that reference a module are not permitted — this matches both babel and TypeScript: - `import ... from "m"` / `import x = require("m")` → TS1147 - `export ... from "m"` / `export * from "m"` → TS1194 - `export default ...` → TS1319 - `export = ...` → TS1063 Bare `export { x }` (re-export of locals, no module source) and `import x = A.B` (entity alias) stay valid, as do external modules (`declare module "x" {}`) where these forms are allowed — the check only runs for internal namespaces. Each statement is validated inline as the namespace body is parsed (no second pass). Also removes TS1147 from the coverage denylist (`NOT_SUPPORTED_ERROR_CODES`), since oxc now detects it. Conformance: parser_babel +8 and parser_typescript +9 negative-passes vs main, with positive/AST staying 100% across all parser suites (no regressions).
7baf5d0 to
276b78b
Compare
### 🚀 Features - 9c71f2e ast, codegen, formatter: Add `WithClauseKeyword::as_str` helper and use it (#22791) (camc314) ### 🐛 Bug Fixes - cf5769c parser: Reject TypeScript declarations in single-statement context (#22827) (Boshen) - c360fb6 parser: Reject generators in ambient contexts and overload signatures (TS1221/TS1222) (#22848) (Boshen) - cc60d8d parser: Reject invalid index signature parameter types (TS1268/TS1337) (#22852) (Boshen) - 3d13e29 parser: Reject `declare` in an already-ambient context (TS1038) (#22850) (Boshen) - 5152854 parser: Reject statements in ambient contexts (TS1036) (#22849) (Boshen) - 4f9afc5 parser: Reject `export as namespace` inside a namespace body (TS1316) (#22846) (Boshen) - 2eafea6 parser: Reject function implementations in ambient contexts (TS1183) (#22845) (Boshen) - c645615 parser: Reject incompatible class member modifiers (#22843) (Boshen) - 276b78b parser: Reject module-referencing imports/exports in a namespace body (#22836) (Boshen) - 842ed1c parser: Parse `class implements` with `implements` as the class name (#22801) (Boshen) ### ⚡ Performance - 7e3a567 parser: Reuse cached token kind in delimited-list loops (#22841) (Boshen) - 9e741c2 parser: Use peek_token instead of lookahead on the modifier path (#22842) (Boshen) - 9e496a7 semantic: Defer declare lookup for empty accessors (#22810) (camc314)

Inside an internal
namespace N {}/module N {}, statements that reference amodule are not permitted — this matches both babel and TypeScript:
import ... from "m"/import x = require("m")→ TS1147export ... from "m"/export * from "m"→ TS1194export default ...→ TS1319export = ...→ TS1063Bare
export { x }(re-export of locals, no module source) andimport x = A.B(entity alias) stay valid, as do external modules (
declare module "x" {}) wherethese forms are allowed — the check only runs for internal namespaces.
Each statement is validated inline as the namespace body is parsed (no second pass).
Also removes TS1147 from the coverage denylist (
NOT_SUPPORTED_ERROR_CODES), sinceoxc now detects it.
Conformance: parser_babel +8 and parser_typescript +9 negative-passes vs main, with
positive/AST staying 100% across all parser suites (no regressions).