Skip to content

Commit 2ff6fb5

Browse files
committed
fix(parser): include generator marker in overload diagnostic span (#27313)
Include the generator `*` in TS1222 diagnostic spans for class method overload signatures. Use the earlier of the function start and generator marker so function declaration spans retain their existing start.
1 parent 4359a66 commit 2ff6fb5

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

‎crates/oxc_parser/src/js/function.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,9 @@ impl<'a, C: Config> ParserImpl<'a, C> {
350350
if ctx.has_ambient() {
351351
self.error(diagnostics::generator_in_ambient_context(self.end_span(generator)));
352352
} else if body.is_none() {
353-
self.error(diagnostics::overload_signature_generator(self.end_span(start)));
353+
self.error(diagnostics::overload_signature_generator(
354+
self.end_span(start.min(generator)),
355+
));
354356
}
355357
}
356358
self.verify_modifiers(

‎tasks/coverage/snapshots/parser_typescript.snap‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21647,18 +21647,18 @@ Expect to Parse: tasks/coverage/typescript/tsc/testdata/tests/cases/conformance/
2164721647
╰────
2164821648

2164921649
× TS(1222): An overload signature cannot be declared as a generator.
21650-
╭─[typescript/tsc/testdata/tests/cases/conformance/es6/yieldExpressions/generatorOverloads3.ts:2:7]
21650+
╭─[typescript/tsc/testdata/tests/cases/conformance/es6/yieldExpressions/generatorOverloads3.ts:2:5]
2165121651
1 │ class C {
2165221652
2 │ *f(s: string): Iterable<any>;
21653-
· ───────────────────────────
21653+
· ─────────────────────────────
2165421654
3 │ *f(s: number): Iterable<any>;
2165521655
╰────
2165621656

2165721657
× TS(1222): An overload signature cannot be declared as a generator.
21658-
╭─[typescript/tsc/testdata/tests/cases/conformance/es6/yieldExpressions/generatorOverloads3.ts:3:7]
21658+
╭─[typescript/tsc/testdata/tests/cases/conformance/es6/yieldExpressions/generatorOverloads3.ts:3:5]
2165921659
2 │ *f(s: string): Iterable<any>;
2166021660
3 │ *f(s: number): Iterable<any>;
21661-
· ───────────────────────────
21661+
· ─────────────────────────────
2166221662
4 │ *f(s: any): Iterable<any> { }
2166321663
╰────
2166421664

0 commit comments

Comments
 (0)