@@ -74,7 +74,7 @@ func (p *Parser) reparseUnhosted(tag *ast.Node, parent *ast.Node, jsDoc *ast.Nod
74
74
case ast .KindJSDocTypeExpression :
75
75
t = setHost (typeExpression , typeAlias )
76
76
case ast .KindJSDocTypeLiteral :
77
- t = p .reparseJSDocTypeLiteral (typeExpression , typeAlias )
77
+ t = p .reparseJSDocTypeLiteral (typeExpression )
78
78
default :
79
79
panic ("typedef tag type expression should be a name reference or a type expression" + typeExpression .Kind .String ())
80
80
}
@@ -148,9 +148,7 @@ func (p *Parser) reparseJSDocSignature(jsSignature *ast.Node, fun *ast.Node, jsD
148
148
jsparam := param .AsJSDocParameterOrPropertyTag ()
149
149
parameter = p .factory .NewParameterDeclaration (nil , nil , jsparam .Name (), p .makeQuestionIfOptional (jsparam ), nil , nil )
150
150
if jsparam .TypeExpression != nil {
151
- t := p .reparseJSDocTypeLiteral (jsparam .TypeExpression .Type (), parameter )
152
- setHost (jsparam .TypeExpression , parameter )
153
- parameter .AsParameterDeclaration ().Type = t
151
+ parameter .AsParameterDeclaration ().Type = p .reparseJSDocTypeLiteral (setHost (jsparam .TypeExpression , parameter ))
154
152
}
155
153
}
156
154
parameter .Loc = param .Loc
@@ -170,8 +168,12 @@ func (p *Parser) reparseJSDocSignature(jsSignature *ast.Node, fun *ast.Node, jsD
170
168
return signature
171
169
}
172
170
173
- func (p * Parser ) reparseJSDocTypeLiteral (t * ast.TypeNode , host * ast.Node ) * ast.Node {
174
- if t != nil && t .Kind == ast .KindJSDocTypeLiteral {
171
+ func (p * Parser ) reparseJSDocTypeLiteral (t * ast.TypeNode ) * ast.Node {
172
+ if t == nil {
173
+ return nil
174
+ }
175
+ if t .Kind == ast .KindJSDocTypeLiteral {
176
+ isArrayType := t .AsJSDocTypeLiteral ().IsArrayType
175
177
properties := p .nodeSlicePool .NewSlice (0 )
176
178
for _ , prop := range t .AsJSDocTypeLiteral ().JSDocPropertyTags {
177
179
jsprop := prop .AsJSDocParameterOrPropertyTag ()
@@ -180,7 +182,9 @@ func (p *Parser) reparseJSDocTypeLiteral(t *ast.TypeNode, host *ast.Node) *ast.N
180
182
name = name .AsQualifiedName ().Right
181
183
}
182
184
property := p .factory .NewPropertySignatureDeclaration (nil , name , p .makeQuestionIfOptional (jsprop ), nil , nil )
183
- property .AsPropertySignatureDeclaration ().Type = p .reparseJSDocTypeLiteral (jsprop .TypeExpression , property )
185
+ if jsprop .TypeExpression != nil {
186
+ property .AsPropertySignatureDeclaration ().Type = p .reparseJSDocTypeLiteral (jsprop .TypeExpression .Type ())
187
+ }
184
188
property .Loc = prop .Loc
185
189
property .Flags = p .contextFlags | ast .NodeFlagsReparsed
186
190
properties = append (properties , property )
@@ -189,6 +193,11 @@ func (p *Parser) reparseJSDocTypeLiteral(t *ast.TypeNode, host *ast.Node) *ast.N
189
193
t = p .factory .NewTypeLiteralNode (p .newNodeList (loc , properties ))
190
194
t .Loc = loc
191
195
t .Flags = p .contextFlags | ast .NodeFlagsReparsed
196
+ if isArrayType {
197
+ t = p .factory .NewArrayTypeNode (t )
198
+ t .Flags = p .contextFlags | ast .NodeFlagsReparsed
199
+ t .Loc = loc
200
+ }
192
201
}
193
202
return t
194
203
}
@@ -327,13 +336,13 @@ func (p *Parser) reparseHosted(tag *ast.Node, parent *ast.Node, jsDoc *ast.Node)
327
336
}
328
337
case ast .KindJSDocParameterTag :
329
338
if fun , ok := getFunctionLikeHost (parent ); ok {
330
- jsparam := tag .AsJSDocParameterOrPropertyTag ()
331
- if param , ok := findMatchingParameter (fun , jsparam ); ok {
339
+ parameterTag := tag .AsJSDocParameterOrPropertyTag ()
340
+ if param , ok := findMatchingParameter (fun , parameterTag , jsDoc ); ok {
332
341
if param .Type == nil {
333
- param .Type = setHost (jsparam . TypeExpression , param .AsNode ())
342
+ param .AsParameterDeclaration (). Type = p . reparseJSDocTypeLiteral ( setHost (p . reparseJSDocTypeLiteral ( parameterTag . TypeExpression ) , param .AsNode () ))
334
343
}
335
344
if param .QuestionToken == nil && param .Initializer == nil {
336
- if question := p .makeQuestionIfOptional (jsparam ); question != nil {
345
+ if question := p .makeQuestionIfOptional (parameterTag ); question != nil {
337
346
param .QuestionToken = question
338
347
}
339
348
}
@@ -461,11 +470,19 @@ func (p *Parser) makeQuestionIfOptional(parameter *ast.JSDocParameterTag) *ast.N
461
470
return questionToken
462
471
}
463
472
464
- func findMatchingParameter (fun * ast.Node , tag * ast.JSDocParameterTag ) (* ast.ParameterDeclaration , bool ) {
465
- for _ , parameter := range fun .Parameters () {
466
- if parameter .Name ().Kind == ast .KindIdentifier && tag .Name ().Kind == ast .KindIdentifier &&
467
- parameter .Name ().Text () == tag .Name ().Text () {
468
- return parameter .AsParameterDeclaration (), true
473
+ func findMatchingParameter (fun * ast.Node , tag * ast.JSDocParameterTag , jsDoc * ast.Node ) (* ast.ParameterDeclaration , bool ) {
474
+ tagIndex := core .FindIndex (jsDoc .AsJSDoc ().Tags .Nodes , func (n * ast.Node ) bool {
475
+ return n .Kind == ast .KindJSDocParameterTag && n .AsJSDocParameterOrPropertyTag () == tag
476
+ })
477
+ for parameterIndex , parameter := range fun .Parameters () {
478
+ if parameter .Name ().Kind == ast .KindIdentifier {
479
+ if tag .Name ().Kind == ast .KindIdentifier && parameter .Name ().Text () == tag .Name ().Text () {
480
+ return parameter .AsParameterDeclaration (), true
481
+ }
482
+ } else {
483
+ if parameterIndex == tagIndex {
484
+ return parameter .AsParameterDeclaration (), true
485
+ }
469
486
}
470
487
}
471
488
return nil , false
0 commit comments