feat(compiler): Added spans to HTML parser errors

Allows using the HTML parser in contexts errors are reported in a development tool such as an editor.
This commit is contained in:
Chuck Jazdzewski
2016-02-16 16:46:51 -08:00
committed by Vikram Subramanian
parent a3d7629134
commit 19a08f3a43
6 changed files with 57 additions and 44 deletions

View File

@ -581,7 +581,8 @@ export function main() {
let src = "111\n222\n333\nE\n444\n555\n666\n";
let file = new ParseSourceFile(src, 'file://');
let location = new ParseLocation(file, 12, 123, 456);
let error = new HtmlTokenError('**ERROR**', null, location);
let span = new ParseSourceSpan(location, location);
let error = new HtmlTokenError('**ERROR**', null, span);
expect(error.toString())
.toEqual(`**ERROR** ("\n222\n333\n[ERROR ->]E\n444\n555\n"): file://@123:456`);
});
@ -631,7 +632,9 @@ function tokenizeAndHumanizeLineColumn(input: string): any[] {
function tokenizeAndHumanizeErrors(input: string): any[] {
return tokenizeHtml(input, 'someUrl')
.errors.map(
tokenError =>
[<any>tokenError.tokenType, tokenError.msg, humanizeLineColumn(tokenError.location)]);
.errors.map(tokenError => [
<any>tokenError.tokenType,
tokenError.msg,
humanizeLineColumn(tokenError.span.start)
]);
}

View File

@ -328,10 +328,10 @@ function humanizeErrors(errors: ParseError[]): any[] {
return errors.map(error => {
if (error instanceof HtmlTreeError) {
// Parser errors
return [<any>error.elementName, error.msg, humanizeLineColumn(error.location)];
return [<any>error.elementName, error.msg, humanizeLineColumn(error.span.start)];
}
// Tokenizer errors
return [(<any>error).tokenType, error.msg, humanizeLineColumn(error.location)];
return [(<any>error).tokenType, error.msg, humanizeLineColumn(error.span.start)];
});
}