From fad5650be6583c3d68b97e8e02777fc8f0053129 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Wed, 10 Sep 2014 17:57:51 -0700 Subject: [PATCH] Fix the error spans issue --- src/compiler/parser.ts | 5 +++-- .../parserEqualsGreaterThanAfterFunction1.errors.txt | 2 +- .../parserEqualsGreaterThanAfterFunction2.errors.txt | 2 +- .../reference/parserVariableDeclaration6.errors.txt | 2 +- .../reference/parserVariableDeclaration8.errors.txt | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 68c076367d4..cfe27e7e7c3 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -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 { diff --git a/tests/baselines/reference/parserEqualsGreaterThanAfterFunction1.errors.txt b/tests/baselines/reference/parserEqualsGreaterThanAfterFunction1.errors.txt index e3ff187a00e..9f428d7fea7 100644 --- a/tests/baselines/reference/parserEqualsGreaterThanAfterFunction1.errors.txt +++ b/tests/baselines/reference/parserEqualsGreaterThanAfterFunction1.errors.txt @@ -2,5 +2,5 @@ function => ~~ !!! Identifier expected. - + !!! Function implementation is missing or not immediately following the declaration. \ No newline at end of file diff --git a/tests/baselines/reference/parserEqualsGreaterThanAfterFunction2.errors.txt b/tests/baselines/reference/parserEqualsGreaterThanAfterFunction2.errors.txt index 24866e9e424..4e9b5fbaa86 100644 --- a/tests/baselines/reference/parserEqualsGreaterThanAfterFunction2.errors.txt +++ b/tests/baselines/reference/parserEqualsGreaterThanAfterFunction2.errors.txt @@ -8,5 +8,5 @@ !!! ',' expected. !!! ')' expected. - + !!! Function implementation is missing or not immediately following the declaration. \ No newline at end of file diff --git a/tests/baselines/reference/parserVariableDeclaration6.errors.txt b/tests/baselines/reference/parserVariableDeclaration6.errors.txt index 01f3935495d..466384c7e0c 100644 --- a/tests/baselines/reference/parserVariableDeclaration6.errors.txt +++ b/tests/baselines/reference/parserVariableDeclaration6.errors.txt @@ -1,4 +1,4 @@ ==== tests/cases/conformance/parser/ecmascript5/VariableDeclarations/parserVariableDeclaration6.ts (1 errors) ==== var - + ~~~ !!! Variable declaration list cannot be empty. \ No newline at end of file diff --git a/tests/baselines/reference/parserVariableDeclaration8.errors.txt b/tests/baselines/reference/parserVariableDeclaration8.errors.txt index 5e7f335a920..9e2f8edfd25 100644 --- a/tests/baselines/reference/parserVariableDeclaration8.errors.txt +++ b/tests/baselines/reference/parserVariableDeclaration8.errors.txt @@ -1,4 +1,4 @@ ==== tests/cases/conformance/parser/ecmascript5/VariableDeclarations/parserVariableDeclaration8.ts (1 errors) ==== var ; - + ~~~~~ !!! Variable declaration list cannot be empty. \ No newline at end of file