parser: Reject TypeScript-only syntax in JavaScript export declarations#13206
Closed
parser: Reject TypeScript-only syntax in JavaScript export declarations#13206
Conversation
Contributor
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. |
…port declarations Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Add checks for TypeScript-only syntax when used in export declarations in JavaScript files:
- export enum A {}
- export type B = {}
- export interface C {}
- export module D {}
- export namespace E {}
These now properly error with TypeScript-specific diagnostic messages.
Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] parser:
parser: Reject TypeScript-only syntax in JavaScript export declarations
Aug 19, 2025
export enum a {} is not rejected for lang=js
Boshen
reviewed
Aug 19, 2025
Member
There was a problem hiding this comment.
hmmm I should git ignore but cache this in CI.
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.
This PR fixes an issue where TypeScript-only syntax like
export enum a {}was not being rejected when parsing JavaScript files (lang=js).Problem
The parser correctly rejected standalone TypeScript syntax in JavaScript files:
However, when the same syntax was exported, it was incorrectly accepted:
Root Cause
The issue occurred in the export declaration parsing path. When parsing
export <declaration>, the code callsparse_declarationints/statement.rs, which directly parsed TypeScript-only constructs without checking if the parser was in TypeScript mode (is_ts).Solution
Added TypeScript mode checks in
parse_declarationfor the following constructs:enumdeclarations → TS8003: "'enum' can only be used in TypeScript files."typealias declarations → TS8004: "'type' alias can only be used in TypeScript files."interfacedeclarations → TS8005: "'interface' can only be used in TypeScript files."moduledeclarations → TS8006: "'module' can only be used in TypeScript files."namespacedeclarations → TS8007: "'namespace' can only be used in TypeScript files."The parser still constructs a complete AST (for tooling compatibility) but emits appropriate TypeScript-specific diagnostic messages when these constructs are used in JavaScript files.
Verification
After the fix:
Fixes #13205.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.