Skip to content

fix(parser): reject export as namespace inside a namespace body (TS1316)#22846

Merged
graphite-app[bot] merged 1 commit into
mainfrom
fix/namespace-export-as-namespace
May 30, 2026
Merged

fix(parser): reject export as namespace inside a namespace body (TS1316)#22846
graphite-app[bot] merged 1 commit into
mainfrom
fix/namespace-export-as-namespace

Conversation

@Boshen

@Boshen Boshen commented May 30, 2026

Copy link
Copy Markdown
Member

export as namespace X declares a UMD global export, which may only appear at the
top level of a module or a .d.ts file. Inside an internal namespace/module
body it is invalid:

namespace N { export as namespace N; }          // now TS1316
module M { export as namespace M; }             // now TS1316
declare namespace N { export as namespace N; }  // now TS1316

export as namespace Lib;                         // top level → still valid

This extends the namespace-body validation (check_namespace_body_statement) with
a TSNamespaceExportDeclaration arm emitting TS1316 ("Global module exports may
only appear at top level."), matching tsc and babel. The statement is already
checked inline as each direct child of the namespace body is parsed, so there is
no extra pass. External module declarations (declare module "x" {}) are left
unrestricted, consistent with the existing namespace-body checks.

parser_babel +1 negative-pass; positive/AST stay 100%.

@Boshen Boshen marked this pull request as ready for review May 30, 2026 03:52

Boshen commented May 30, 2026

Copy link
Copy Markdown
Member Author

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent changes, fast-track this PR to the front of 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.

@github-actions github-actions Bot added the A-parser Area - Parser label May 30, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3c86e2c9c3

ℹ️ 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".

Comment thread crates/oxc_parser/src/ts/statement.rs
@Boshen Boshen force-pushed the fix/namespace-export-as-namespace branch from 3c86e2c to a250445 Compare May 30, 2026 03:58
@codspeed-hq

codspeed-hq Bot commented May 30, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 57 untouched benchmarks


Comparing fix/namespace-export-as-namespace (a250445) with main (2eafea6)

Open in CodSpeed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a2504455f0

ℹ️ 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".

Comment thread crates/oxc_parser/src/ts/statement.rs
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label May 30, 2026

Boshen commented May 30, 2026

Copy link
Copy Markdown
Member Author

Merge activity

…1316) (#22846)

`export as namespace X` declares a UMD global export, which may only appear at the
top level of a module or a `.d.ts` file. Inside an internal `namespace`/`module`
body it is invalid:

    namespace N { export as namespace N; }          // now TS1316
    module M { export as namespace M; }             // now TS1316
    declare namespace N { export as namespace N; }  // now TS1316

    export as namespace Lib;                         // top level → still valid

This extends the namespace-body validation (`check_namespace_body_statement`) with
a `TSNamespaceExportDeclaration` arm emitting TS1316 ("Global module exports may
only appear at top level."), matching tsc and babel. The statement is already
checked inline as each direct child of the namespace body is parsed, so there is
no extra pass. External module declarations (`declare module "x" {}`) are left
unrestricted, consistent with the existing namespace-body checks.

parser_babel +1 negative-pass; positive/AST stay 100%.
@graphite-app graphite-app Bot force-pushed the fix/namespace-export-as-namespace branch from a250445 to 4f9afc5 Compare May 30, 2026 04:29
@graphite-app graphite-app Bot merged commit 4f9afc5 into main May 30, 2026
30 checks passed
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label May 30, 2026
@graphite-app graphite-app Bot deleted the fix/namespace-export-as-namespace branch May 30, 2026 04:33
camc314 pushed a commit that referenced this pull request Jun 1, 2026
### 🚀 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-parser Area - Parser

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant