mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-15 12:53:27 -05:00
Report assignability errors on the return/yield keywords (#52943)
This commit is contained in:
committed by
GitHub
parent
5240f060b8
commit
967911c389
@@ -2179,13 +2179,14 @@ function getErrorSpanForArrowFunction(sourceFile: SourceFile, node: ArrowFunctio
|
||||
export function getErrorSpanForNode(sourceFile: SourceFile, node: Node): TextSpan {
|
||||
let errorNode: Node | undefined = node;
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.SourceFile:
|
||||
case SyntaxKind.SourceFile: {
|
||||
const pos = skipTrivia(sourceFile.text, 0, /*stopAfterLineBreak*/ false);
|
||||
if (pos === sourceFile.text.length) {
|
||||
// file is empty - return span for the beginning of the file
|
||||
return createTextSpan(0, 0);
|
||||
}
|
||||
return getSpanOfTokenAtPosition(sourceFile, pos);
|
||||
}
|
||||
// This list is a work in progress. Add missing node kinds to improve their error
|
||||
// spans.
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
@@ -2210,10 +2211,16 @@ export function getErrorSpanForNode(sourceFile: SourceFile, node: Node): TextSpa
|
||||
case SyntaxKind.ArrowFunction:
|
||||
return getErrorSpanForArrowFunction(sourceFile, node as ArrowFunction);
|
||||
case SyntaxKind.CaseClause:
|
||||
case SyntaxKind.DefaultClause:
|
||||
case SyntaxKind.DefaultClause: {
|
||||
const start = skipTrivia(sourceFile.text, (node as CaseOrDefaultClause).pos);
|
||||
const end = (node as CaseOrDefaultClause).statements.length > 0 ? (node as CaseOrDefaultClause).statements[0].pos : (node as CaseOrDefaultClause).end;
|
||||
return createTextSpanFromBounds(start, end);
|
||||
}
|
||||
case SyntaxKind.ReturnStatement:
|
||||
case SyntaxKind.YieldExpression: {
|
||||
const pos = skipTrivia(sourceFile.text, (node as ReturnStatement | YieldExpression).pos);
|
||||
return getSpanOfTokenAtPosition(sourceFile, pos);
|
||||
}
|
||||
}
|
||||
|
||||
if (errorNode === undefined) {
|
||||
|
||||
Reference in New Issue
Block a user