Skip to content

Commit d851a61

Browse files
authored
@type tag correctly applies to multiple var decls (microsoft#832)
1 parent 4d22cfd commit d851a61

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

internal/parser/reparser.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ func (p *Parser) reparseTags(parent *ast.Node, jsDoc []*ast.Node) {
126126
for _, declaration := range parent.AsVariableStatement().DeclarationList.AsVariableDeclarationList().Declarations.Nodes {
127127
if declaration.AsVariableDeclaration().Type == nil {
128128
declaration.AsVariableDeclaration().Type = p.makeNewType(tag.AsJSDocTypeTag().TypeExpression, declaration)
129+
break
129130
}
130131
}
131132
} else if parent.Kind == ast.KindVariableDeclaration {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//// [tests/cases/conformance/typeTagForMultipleVariableDeclarations.ts] ////
2+
3+
=== typeTagForMultipleVariableDeclarations.js ===
4+
/** @type {number} */
5+
var x,y,z;
6+
>x : Symbol(x, Decl(typeTagForMultipleVariableDeclarations.js, 1, 3))
7+
>y : Symbol(y, Decl(typeTagForMultipleVariableDeclarations.js, 1, 6))
8+
>z : Symbol(z, Decl(typeTagForMultipleVariableDeclarations.js, 1, 8))
9+
10+
x
11+
>x : Symbol(x, Decl(typeTagForMultipleVariableDeclarations.js, 1, 3))
12+
13+
y
14+
>y : Symbol(y, Decl(typeTagForMultipleVariableDeclarations.js, 1, 6))
15+
16+
z
17+
>z : Symbol(z, Decl(typeTagForMultipleVariableDeclarations.js, 1, 8))
18+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//// [tests/cases/conformance/typeTagForMultipleVariableDeclarations.ts] ////
2+
3+
=== typeTagForMultipleVariableDeclarations.js ===
4+
/** @type {number} */
5+
var x,y,z;
6+
>x : number
7+
>y : any
8+
>z : any
9+
10+
x
11+
>x : number
12+
13+
y
14+
>y : any
15+
16+
z
17+
>z : any
18+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @checkJs: true
2+
// @filename: typeTagForMultipleVariableDeclarations.js
3+
// @allowJs: true
4+
/** @type {number} */
5+
var x,y,z;
6+
x
7+
y
8+
z

0 commit comments

Comments
 (0)