diff --git a/src/compiler/core.ts b/src/compiler/core.ts index fbf767b91a..c549231eac 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -198,6 +198,9 @@ module ts { export function createFileDiagnostic(file: SourceFile, start: number, length: number, message: DiagnosticMessage, ...args: any[]): Diagnostic; export function createFileDiagnostic(file: SourceFile, start: number, length: number, message: DiagnosticMessage): Diagnostic { + Debug.assert(start >= 0, "start must be non-negative, is " + start); + Debug.assert(length >= 0, "length must be non-negative, is " + length); + var text = getLocaleSpecificMessage(message.key); if (arguments.length > 4) { @@ -252,6 +255,9 @@ module ts { } export function flattenDiagnosticChain(file: SourceFile, start: number, length: number, diagnosticChain: DiagnosticMessageChain, newLine: string): Diagnostic { + Debug.assert(start >= 0, "start must be non-negative, is " + start); + Debug.assert(length >= 0, "length must be non-negative, is " + length); + var code = diagnosticChain.code; var category = diagnosticChain.category; var messageText = ""; diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 68c076367d..cfe27e7e7c 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 e3ff187a00..9f428d7fea 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 24866e9e42..4e9b5fbaa8 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 01f3935495..466384c7e0 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 5e7f335a92..9e2f8edfd2 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