Skip to content

Commit 73868c8

Browse files
authored
Fix grammar checking for in and out modifiers in @template tags (#4100)
1 parent 804eb7a commit 73868c8

3 files changed

Lines changed: 2 additions & 66 deletions

File tree

internal/checker/grammarchecks.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,7 @@ func (c *Checker) checkGrammarModifiers(node *ast.Node /*Union[HasModifiers, Has
301301
if node.Kind != ast.KindEnumDeclaration && node.Kind != ast.KindTypeParameter {
302302
return c.grammarErrorOnNode(node, diagnostics.A_class_member_cannot_have_the_0_keyword, scanner.TokenToString(ast.KindConstKeyword))
303303
}
304-
305-
// !!!
306-
// parent := (isJSDocTemplateTag(node.Parent) && getEffectiveJSDocHost(node.Parent)) || node.Parent
307304
parent := node.Parent
308-
309305
if node.Kind == ast.KindTypeParameter {
310306
if !(ast.IsFunctionLikeDeclaration(parent) || ast.IsClassLike(parent) ||
311307
ast.IsFunctionTypeNode(parent) || ast.IsConstructorTypeNode(parent) ||
@@ -532,10 +528,8 @@ func (c *Checker) checkGrammarModifiers(node *ast.Node /*Union[HasModifiers, Has
532528
} else {
533529
inOutText = "out"
534530
}
535-
// !!!
536-
// parent := isJSDocTemplateTag(node.Parent) && (getEffectiveJSDocHost(node.Parent) || core.Find(getJSDocRoot(node.Parent). /* ? */ tags, isJSDocTypedefTag)) || node.Parent
537531
parent := node.Parent
538-
if node.Kind != ast.KindTypeParameter || parent != nil && !(ast.IsInterfaceDeclaration(parent) || ast.IsClassLike(parent) || ast.IsTypeAliasDeclaration(parent) || isJSDocTypedefTag(parent)) {
532+
if node.Kind != ast.KindTypeParameter || parent != nil && !(ast.IsInterfaceDeclaration(parent) || ast.IsClassLike(parent) || ast.IsTypeOrJSTypeAliasDeclaration(parent)) {
539533
return c.grammarErrorOnNode(modifier, diagnostics.X_0_modifier_can_only_appear_on_a_type_parameter_of_a_class_interface_or_type_alias, inOutText)
540534
}
541535
if flags&inOutFlag != 0 {
@@ -573,11 +567,6 @@ func (c *Checker) checkGrammarModifiers(node *ast.Node /*Union[HasModifiers, Has
573567
return false
574568
}
575569

576-
func isJSDocTypedefTag(_ *ast.Node) bool {
577-
// !!!
578-
return false
579-
}
580-
581570
func (c *Checker) reportObviousModifierErrors(node *ast.Node) bool {
582571
modifier := c.findFirstIllegalModifier(node)
583572
if modifier == nil {

testdata/baselines/reference/submodule/conformance/jsdocTemplateTag8.errors.txt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
a.js(2,14): error TS1274: 'out' modifier can only appear on a type parameter of a class, interface or type alias
21
a.js(18,1): error TS2322: Type 'Covariant<unknown>' is not assignable to type 'Covariant<string>'.
32
Type 'unknown' is not assignable to type 'string'.
4-
a.js(21,14): error TS1274: 'in' modifier can only appear on a type parameter of a class, interface or type alias
53
a.js(36,1): error TS2322: Type 'Contravariant<string>' is not assignable to type 'Contravariant<unknown>'.
64
Type 'unknown' is not assignable to type 'string'.
7-
a.js(40,14): error TS1274: 'in' modifier can only appear on a type parameter of a class, interface or type alias
85
a.js(55,1): error TS2322: Type 'Invariant<string>' is not assignable to type 'Invariant<unknown>'.
96
Types of property 'f' are incompatible.
107
Type '(x: string) => string' is not assignable to type '(x: unknown) => unknown'.
@@ -16,11 +13,9 @@ a.js(56,1): error TS2322: Type 'Invariant<unknown>' is not assignable to type 'I
1613
a.js(59,14): error TS1274: 'in' modifier can only appear on a type parameter of a class, interface or type alias
1714

1815

19-
==== a.js (8 errors) ====
16+
==== a.js (5 errors) ====
2017
/**
2118
* @template out T
22-
~~~
23-
!!! error TS1274: 'out' modifier can only appear on a type parameter of a class, interface or type alias
2419
* @typedef {Object} Covariant
2520
* @property {T} x
2621
*/
@@ -43,8 +38,6 @@ a.js(59,14): error TS1274: 'in' modifier can only appear on a type parameter of
4338

4439
/**
4540
* @template in T
46-
~~
47-
!!! error TS1274: 'in' modifier can only appear on a type parameter of a class, interface or type alias
4841
* @typedef {Object} Contravariant
4942
* @property {(x: T) => void} f
5043
*/
@@ -67,8 +60,6 @@ a.js(59,14): error TS1274: 'in' modifier can only appear on a type parameter of
6760

6861
/**
6962
* @template in out T
70-
~~
71-
!!! error TS1274: 'in' modifier can only appear on a type parameter of a class, interface or type alias
7263
* @typedef {Object} Invariant
7364
* @property {(x: T) => T} f
7465
*/

testdata/baselines/reference/submodule/conformance/jsdocTemplateTag8.errors.txt.diff

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)