Fix the error spans issue

This commit is contained in:
Jason Freeman 2014-09-10 17:57:51 -07:00
parent c27379827b
commit fad5650be6
5 changed files with 7 additions and 6 deletions

View File

@ -81,7 +81,7 @@ module ts {
export function createDiagnosticForNode(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): Diagnostic {
node = getErrorSpanForNode(node);
var file = getSourceFileOfNode(node);
var start = skipTrivia(file.text, node.pos);
var start = node.kind === SyntaxKind.Missing ? node.pos : skipTrivia(file.text, node.pos);
var length = node.end - start;
return createFileDiagnostic(file, start, length, message, arg0, arg1, arg2);
@ -2876,10 +2876,11 @@ module ts {
parseExpected(SyntaxKind.VarKeyword);
node.declarations = parseVariableDeclarationList(flags, /*noIn*/false);
parseSemicolon();
finishNode(node);
if (!node.declarations.length && file.syntacticErrors.length === errorCountBeforeVarStatement) {
grammarErrorOnNode(node, Diagnostics.Variable_declaration_list_cannot_be_empty);
}
return finishNode(node);
return node;
}
function parseFunctionDeclaration(pos?: number, flags?: NodeFlags): FunctionDeclaration {

View File

@ -2,5 +2,5 @@
function =>
~~
!!! Identifier expected.
!!! Function implementation is missing or not immediately following the declaration.

View File

@ -8,5 +8,5 @@
!!! ',' expected.
!!! ')' expected.
!!! Function implementation is missing or not immediately following the declaration.

View File

@ -1,4 +1,4 @@
==== tests/cases/conformance/parser/ecmascript5/VariableDeclarations/parserVariableDeclaration6.ts (1 errors) ====
var
~~~
!!! Variable declaration list cannot be empty.

View File

@ -1,4 +1,4 @@
==== tests/cases/conformance/parser/ecmascript5/VariableDeclarations/parserVariableDeclaration8.ts (1 errors) ====
var ;
~~~~~
!!! Variable declaration list cannot be empty.