8000 Fix the error spans issue · johnangularjs/TypeScript@fad5650 · GitHub
[go: up one dir, main page]

Skip to content

Commit fad5650

Browse files
committed
Fix the error spans issue
1 parent c273798 commit fad5650

File tree

5 files changed

+7
-6
lines changed

5 files changed

+7
-6
lines changed

src/compiler/parser.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ module ts {
8181
export function createDiagnosticForNode(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): Diagnostic {
8282
node = getErrorSpanForNode(node);
8383
var file = getSourceFileOfNode(node);
84-
var start = skipTrivia(file.text, node.pos);
84+
var start = node.kind === SyntaxKind.Missing ? node.pos : skipTrivia(file.text, node.pos);
8585
var length = node.end - start;
8686

8787
return createFileDiagnostic(file, start, length, message, arg0, arg1, arg2);
@@ -2876,10 +2876,11 @@ module ts {
28762876
parseExpected(SyntaxKind.VarKeyword);
28772877
node.declarations = parseVariableDeclarationList(flags, /*noIn*/false);
28782878
parseSemicolon();
2879+
finishNode(node);
28792880
if (!node.declarations.length && file.syntacticErrors.length === errorCountBeforeVarStatement) {
28802881
grammarErrorOnNode(node, Diagnostics.Variable_declaration_list_cannot_be_empty);
28812882
}
2882-
return finishNode(node);
2883+
return node;
28832884
}
28842885

28852886
function parseFunctionDeclaration(pos?: number, flags?: NodeFlags): FunctionDeclaration {

tests/baselines/reference/parserEqualsGreaterThanAfterFunction1.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
function =>
33
~~
44
!!! Identifier expected.
5-
5+
66
!!! Function implementation is missing or not immediately following the declaration.

tests/baselines/reference/parserEqualsGreaterThanAfterFunction2.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
!!! ',' expected.
99

1010
!!! ')' expected.
11-
11+
1212
!!! Function implementation is missing or not immediately following the declaration.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
==== tests/cases/conformance/parser/ecmascript5/VariableDeclarations/parserVariableDeclaration6.ts (1 errors) ====
22
var
3-
3+
~~~
44
!!! Variable declaration list cannot be empty.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
==== tests/cases/conformance/parser/ecmascript5/VariableDeclarations/parserVariableDeclaration8.ts (1 errors) ====
22
var ;
3-
3+
~~~~~
44
!!! Variable declaration list cannot be empty.

0 commit comments

Comments
 (0)
0