(j *ast.Node, typedefOrCallback bool)
| 291 | } |
| 292 | |
| 293 | func (p *Parser) gatherTypeParameters(j *ast.Node, typedefOrCallback bool) *ast.NodeList { |
| 294 | var typeParameters []*ast.Node |
| 295 | pos := -1 |
| 296 | endPos := -1 |
| 297 | firstTemplate := true |
| 298 | for _, tag := range j.AsJSDoc().Tags.Nodes { |
| 299 | // When a JSDoc comment contains an `@typedef` or `@callback` tag, `@template` type parameter |
| 300 | // declarations apply to the type being defined. |
| 301 | if !typedefOrCallback && (ast.IsJSDocTypedefTag(tag) || ast.IsJSDocCallbackTag(tag)) { |
| 302 | return nil |
| 303 | } |
| 304 | if !ast.IsJSDocTemplateTag(tag) { |
| 305 | continue |
| 306 | } |
| 307 | if firstTemplate { |
| 308 | pos = tag.Pos() |
| 309 | firstTemplate = false |
| 310 | } |
| 311 | endPos = tag.End() |
| 312 | constraint := tag.AsJSDocTemplateTag().Constraint |
| 313 | firstTypeParameter := true |
| 314 | for _, tp := range tag.TypeParameters() { |
| 315 | var reparse *ast.Node |
| 316 | if constraint != nil && firstTypeParameter { |
| 317 | reparse = p.factory.NewTypeParameterDeclaration( |
| 318 | p.factory.DeepCloneReparseModifiers(tp.Modifiers()), |
| 319 | p.addDeepCloneReparse(p.checkNonIdentifierName(tp.Name())), |
| 320 | p.addDeepCloneReparse(constraint.Type()), |
| 321 | nil, // expression |
| 322 | p.addDeepCloneReparse(tp.AsTypeParameterDeclaration().DefaultType), |
| 323 | ) |
| 324 | p.finishReparsedNode(reparse, tp) |
| 325 | } else { |
| 326 | reparse = p.addDeepCloneReparse(tp) |
| 327 | } |
| 328 | if typeParameters == nil { |
| 329 | typeParameters = p.nodeSliceArena.NewSlice(0) |
| 330 | } |
| 331 | typeParameters = append(typeParameters, reparse) |
| 332 | firstTypeParameter = false |
| 333 | } |
| 334 | } |
| 335 | if len(typeParameters) == 0 { |
| 336 | return nil |
| 337 | } else { |
| 338 | return p.newNodeList(core.NewTextRange(pos, endPos), typeParameters) |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | func (p *Parser) reparseHosted(tag *ast.Node, parent *ast.Node, jsDoc *ast.Node) { |
| 343 | switch tag.Kind { |
no test coverage detected