(jsSignature *ast.Node, fun *ast.Node, jsDoc *ast.Node, tag *ast.Node, modifiers *ast.ModifierList)
| 140 | } |
| 141 | |
| 142 | func (p *Parser) reparseJSDocSignature(jsSignature *ast.Node, fun *ast.Node, jsDoc *ast.Node, tag *ast.Node, modifiers *ast.ModifierList) *ast.Node { |
| 143 | var signature *ast.Node |
| 144 | clonedModifiers := p.factory.DeepCloneReparseModifiers(modifiers) |
| 145 | switch fun.Kind { |
| 146 | case ast.KindFunctionDeclaration: |
| 147 | signature = p.factory.NewFunctionDeclaration(clonedModifiers, nil, p.factory.DeepCloneReparse(p.checkNonIdentifierName(fun.Name())), nil, nil, nil, nil, nil) |
| 148 | case ast.KindMethodDeclaration: |
| 149 | signature = p.factory.NewMethodDeclaration(clonedModifiers, nil, p.factory.DeepCloneReparse(p.checkNonIdentifierName(fun.Name())), nil, nil, nil, nil, nil, nil) |
| 150 | case ast.KindConstructor: |
| 151 | signature = p.factory.NewConstructorDeclaration(clonedModifiers, nil, nil, nil, nil, nil) |
| 152 | case ast.KindJSDocCallbackTag: |
| 153 | signature = p.factory.NewFunctionTypeNode(nil, nil, p.factory.NewKeywordTypeNode(ast.KindAnyKeyword)) |
| 154 | default: |
| 155 | panic("Unexpected kind " + fun.Kind.String()) |
| 156 | } |
| 157 | |
| 158 | if tag.Kind != ast.KindJSDocCallbackTag { |
| 159 | signature.FunctionLikeData().TypeParameters = p.gatherTypeParameters(jsDoc, false /*typedefOrCallback*/) |
| 160 | } |
| 161 | parameters := p.nodeSliceArena.NewSlice(0) |
| 162 | for pi, param := range jsSignature.Parameters() { |
| 163 | var parameter *ast.Node |
| 164 | if param.Kind == ast.KindJSDocThisTag { |
| 165 | thisTag := param.AsJSDocThisTag() |
| 166 | thisIdent := p.factory.NewIdentifier("this") |
| 167 | thisIdent.Loc = thisTag.Loc |
| 168 | thisIdent.Flags = p.contextFlags | ast.NodeFlagsReparsed |
| 169 | parameter = p.factory.NewParameterDeclaration(nil, nil, thisIdent, nil, nil, nil) |
| 170 | if thisTag.TypeExpression != nil { |
| 171 | parameter.AsParameterDeclaration().Type = p.addDeepCloneReparse(thisTag.TypeExpression.Type()) |
| 172 | } |
| 173 | } else if param.Kind == ast.KindJSDocParameterTag || param.Kind == ast.KindJSDocPropertyTag { |
| 174 | jsparam := param.AsJSDocParameterOrPropertyTag() |
| 175 | // Skip sub-property parameters (e.g., @param x.y) - these have QualifiedNames |
| 176 | // and describe properties of a parent parameter, not standalone parameters. |
| 177 | if ast.IsQualifiedName(jsparam.Name()) { |
| 178 | continue |
| 179 | } |
| 180 | var dotDotDotToken *ast.Node |
| 181 | var paramType *ast.TypeNode |
| 182 | |
| 183 | if jsparam.TypeExpression != nil { |
| 184 | if jsparam.TypeExpression.Type().Kind == ast.KindJSDocVariadicType { |
| 185 | dotDotDotToken = p.factory.NewToken(ast.KindDotDotDotToken) |
| 186 | dotDotDotToken.Loc = jsparam.Loc |
| 187 | dotDotDotToken.Flags = p.contextFlags | ast.NodeFlagsReparsed |
| 188 | |
| 189 | variadicType := jsparam.TypeExpression.Type().AsJSDocVariadicType() |
| 190 | paramType = p.reparseJSDocTypeLiteral(variadicType.Type) |
| 191 | } else { |
| 192 | paramType = p.reparseJSDocTypeLiteral(jsparam.TypeExpression.Type()) |
| 193 | } |
| 194 | } |
| 195 | name := jsparam.Name() |
| 196 | if ast.IsIdentifier(name) && !scanner.IsValidIdentifier(name.AsIdentifier().Text) { |
| 197 | // drop invalid chars for _, if empty, write _0, etc., so we have a valid param name to emit later |
| 198 | result := strings.Builder{} |
| 199 | for i, ch := range name.AsIdentifier().Text { |
no test coverage detected