Pass end=-1 to parse the text to the end
(parent *ast.Node, start int, end int, fullStart int)
| 137 | |
| 138 | // Pass end=-1 to parse the text to the end |
| 139 | func (p *Parser) parseJSDocComment(parent *ast.Node, start int, end int, fullStart int) *ast.Node { |
| 140 | if end == -1 { |
| 141 | end = len(p.sourceText) |
| 142 | } |
| 143 | // Check for /** (JSDoc opening part) |
| 144 | if !isJSDocLikeText(p.sourceText[start:]) { |
| 145 | // TODO: This should be a panic, unless parseSingleJSDocComment is calling this (not ported yet) |
| 146 | return nil |
| 147 | } |
| 148 | |
| 149 | saveSourceText := p.sourceText |
| 150 | saveToken := p.token |
| 151 | saveContextFlags := p.contextFlags |
| 152 | saveParsingContexts := p.parsingContexts |
| 153 | saveScannerState := p.scanner.Mark() |
| 154 | saveDiagnosticsLength := len(p.diagnostics) |
| 155 | saveHasParseError := p.hasParseError |
| 156 | saveHasAwaitIdentifier := p.statementHasAwaitIdentifier |
| 157 | |
| 158 | // initial indent is start+4 to account for leading `/** ` |
| 159 | // + 1 because \n is one character before the first character in the line and, |
| 160 | // if there is no \n before start, -1 is one index before the first character in the string |
| 161 | initialIndent := start + 4 - (strings.LastIndex(p.sourceText[:start], "\n") + 1) |
| 162 | // -2 for trailing `*/` |
| 163 | p.sourceText = p.sourceText[:end-2] |
| 164 | p.scanner.SetText(p.sourceText) |
| 165 | // +3 for leading `/**` |
| 166 | p.scanner.ResetPos(start + 3) |
| 167 | p.setContextFlags(ast.NodeFlagsJSDoc, true) |
| 168 | p.parsingContexts |= 1 << PCJSDocComment |
| 169 | |
| 170 | comment := p.parseJSDocCommentWorker(start, end, fullStart, initialIndent) |
| 171 | // move jsdoc diagnostics to jsdocDiagnostics -- for JS files only |
| 172 | if p.contextFlags&ast.NodeFlagsJavaScriptFile != 0 { |
| 173 | p.jsdocDiagnostics = append(p.jsdocDiagnostics, p.diagnostics[saveDiagnosticsLength:]...) |
| 174 | } |
| 175 | p.diagnostics = p.diagnostics[0:saveDiagnosticsLength] |
| 176 | |
| 177 | p.sourceText = saveSourceText |
| 178 | p.scanner.SetText(p.sourceText) |
| 179 | p.parsingContexts = saveParsingContexts |
| 180 | p.contextFlags = saveContextFlags |
| 181 | p.scanner.Rewind(saveScannerState) |
| 182 | p.token = saveToken |
| 183 | p.hasParseError = saveHasParseError |
| 184 | p.statementHasAwaitIdentifier = saveHasAwaitIdentifier |
| 185 | |
| 186 | return comment |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * @param offset - the offset in the containing file |
no test coverage detected