fix(parser): reject generators in ambient contexts and overload signatures (TS1221/TS1222)#22848
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: 0f5040b36a
ℹ️ 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".
0f5040b to
f685a21
Compare
Merge activity
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f685a21eec
ℹ️ 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".
…tures (TS1221/TS1222) (#22848) A generator (`function*` / `*method`) is not allowed in an ambient context (TS1221), and a generator overload signature with no body is not allowed (TS1222). Mirrors tsc's `checkGrammarForGenerator`: declare function* f(): any; // now TS1221 declare namespace N { function* g(); } // now TS1221 declare class C { *m(); } // now TS1221 function* f(): any; // overload → now TS1222 function* f() { yield 1; } function* f() { yield 1; } // normal generator → still valid The check lives in `parse_function` next to the TS1183 implementation-in-ambient check and keys off `ctx.has_ambient()` / `body.is_none()`. Class methods are covered too (`class.rs` does not check generators, so there is no duplicate diagnostic). Also fixes a latent bug: `parse_ts_declare_function` hard-coded `generator: false` and never consumed the `*`, so `declare function* f()` silently dropped the generator flag. It now eats the `*` and threads the flag through (which is what lets TS1221 fire there). parser_typescript +7 negative-pass (generatorInAmbientContext1-4, generatorOverloads1-3); positive/AST stay 100%.
f685a21 to
5d7fa1a
Compare
8ee95fc to
93ac8fb
Compare
…tures (TS1221/TS1222) (#22848) A generator (`function*` / `*method`) is not allowed in an ambient context (TS1221), and a generator overload signature with no body is not allowed (TS1222). Mirrors tsc's `checkGrammarForGenerator`: declare function* f(): any; // now TS1221 declare namespace N { function* g(); } // now TS1221 declare class C { *m(); } // now TS1221 function* f(): any; // overload → now TS1222 function* f() { yield 1; } function* f() { yield 1; } // normal generator → still valid The check lives in `parse_function` next to the TS1183 implementation-in-ambient check and keys off `ctx.has_ambient()` / `body.is_none()`. Class methods are covered too (`class.rs` does not check generators, so there is no duplicate diagnostic). Also fixes a latent bug: `parse_ts_declare_function` hard-coded `generator: false` and never consumed the `*`, so `declare function* f()` silently dropped the generator flag. It now eats the `*` and threads the flag through (which is what lets TS1221 fire there). parser_typescript +7 negative-pass (generatorInAmbientContext1-4, generatorOverloads1-3); positive/AST stay 100%.
93ac8fb to
c360fb6
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)

A generator (
function*/*method) is not allowed in an ambient context(TS1221), and a generator overload signature with no body is not allowed
(TS1222). Mirrors tsc's
checkGrammarForGenerator:The check lives in
parse_functionnext to the TS1183 implementation-in-ambientcheck and keys off
ctx.has_ambient()/body.is_none(). Class methods arecovered too (
class.rsdoes not check generators, so there is no duplicatediagnostic).
Also fixes a latent bug:
parse_ts_declare_functionhard-codedgenerator: falseand never consumed the
*, sodeclare function* f()silently dropped thegenerator flag. It now eats the
*and threads the flag through (which is whatlets TS1221 fire there).
parser_typescript +7 negative-pass (generatorInAmbientContext1-4, generatorOverloads1-3);
positive/AST stay 100%.