(sourceFile, node)
| 15361 | return ts.createTextSpanFromBounds(pos, node.end); |
| 15362 | } |
| 15363 | function getErrorSpanForNode(sourceFile, node) { |
| 15364 | var errorNode = node; |
| 15365 | switch (node.kind) { |
| 15366 | case 305 /* SyntaxKind.SourceFile */: |
| 15367 | var pos_1 = ts.skipTrivia(sourceFile.text, 0, /*stopAfterLineBreak*/ false); |
| 15368 | if (pos_1 === sourceFile.text.length) { |
| 15369 | // file is empty - return span for the beginning of the file |
| 15370 | return ts.createTextSpan(0, 0); |
| 15371 | } |
| 15372 | return getSpanOfTokenAtPosition(sourceFile, pos_1); |
| 15373 | // This list is a work in progress. Add missing node kinds to improve their error |
| 15374 | // spans. |
| 15375 | case 254 /* SyntaxKind.VariableDeclaration */: |
| 15376 | case 203 /* SyntaxKind.BindingElement */: |
| 15377 | case 257 /* SyntaxKind.ClassDeclaration */: |
| 15378 | case 226 /* SyntaxKind.ClassExpression */: |
| 15379 | case 258 /* SyntaxKind.InterfaceDeclaration */: |
| 15380 | case 261 /* SyntaxKind.ModuleDeclaration */: |
| 15381 | case 260 /* SyntaxKind.EnumDeclaration */: |
| 15382 | case 299 /* SyntaxKind.EnumMember */: |
| 15383 | case 256 /* SyntaxKind.FunctionDeclaration */: |
| 15384 | case 213 /* SyntaxKind.FunctionExpression */: |
| 15385 | case 169 /* SyntaxKind.MethodDeclaration */: |
| 15386 | case 172 /* SyntaxKind.GetAccessor */: |
| 15387 | case 173 /* SyntaxKind.SetAccessor */: |
| 15388 | case 259 /* SyntaxKind.TypeAliasDeclaration */: |
| 15389 | case 167 /* SyntaxKind.PropertyDeclaration */: |
| 15390 | case 166 /* SyntaxKind.PropertySignature */: |
| 15391 | case 268 /* SyntaxKind.NamespaceImport */: |
| 15392 | errorNode = node.name; |
| 15393 | break; |
| 15394 | case 214 /* SyntaxKind.ArrowFunction */: |
| 15395 | return getErrorSpanForArrowFunction(sourceFile, node); |
| 15396 | case 289 /* SyntaxKind.CaseClause */: |
| 15397 | case 290 /* SyntaxKind.DefaultClause */: |
| 15398 | var start = ts.skipTrivia(sourceFile.text, node.pos); |
| 15399 | var end = node.statements.length > 0 ? node.statements[0].pos : node.end; |
| 15400 | return ts.createTextSpanFromBounds(start, end); |
| 15401 | } |
| 15402 | if (errorNode === undefined) { |
| 15403 | // If we don't have a better node, then just set the error on the first token of |
| 15404 | // construct. |
| 15405 | return getSpanOfTokenAtPosition(sourceFile, node.pos); |
| 15406 | } |
| 15407 | ts.Debug.assert(!ts.isJSDoc(errorNode)); |
| 15408 | var isMissing = nodeIsMissing(errorNode); |
| 15409 | var pos = isMissing || ts.isJsxText(node) |
| 15410 | ? errorNode.pos |
| 15411 | : ts.skipTrivia(sourceFile.text, errorNode.pos); |
| 15412 | // These asserts should all be satisfied for a properly constructed `errorNode`. |
| 15413 | if (isMissing) { |
| 15414 | ts.Debug.assert(pos === errorNode.pos, "This failure could trigger https://github.com/Microsoft/TypeScript/issues/20809"); |
| 15415 | ts.Debug.assert(pos === errorNode.end, "This failure could trigger https://github.com/Microsoft/TypeScript/issues/20809"); |
| 15416 | } |
| 15417 | else { |
| 15418 | ts.Debug.assert(pos >= errorNode.pos, "This failure could trigger https://github.com/Microsoft/TypeScript/issues/20809"); |
| 15419 | ts.Debug.assert(pos <= errorNode.end, "This failure could trigger https://github.com/Microsoft/TypeScript/issues/20809"); |
| 15420 | } |
no test coverage detected
searching dependent graphs…