feat(compiler): Expression span information and error correction (#9772)

Added error correction so the parser always returns an AST
Added span information to the expression parser
Refactored the test to account for the difference in error reporting
Added tests for error corretion
Modified tests to validate the span information
This commit is contained in:
Chuck Jazdzewski
2016-07-06 14:06:47 -07:00
committed by GitHub
parent ae62f082fd
commit 9a04fcd061
9 changed files with 572 additions and 300 deletions
@@ -10,12 +10,12 @@ import {AST, AstVisitor, Binary, BindingPipe, Chain, Conditional, EmptyExpr, Fun
import {StringWrapper, isPresent, isString} from '../../src/facade/lang';
import {DEFAULT_INTERPOLATION_CONFIG, InterpolationConfig} from '../../src/interpolation_config';
export class Unparser implements AstVisitor {
class Unparser implements AstVisitor {
private static _quoteRegExp = /"/g;
private _expression: string;
private _interpolationConfig: InterpolationConfig;
unparse(ast: AST, interpolationConfig: InterpolationConfig = DEFAULT_INTERPOLATION_CONFIG) {
unparse(ast: AST, interpolationConfig: InterpolationConfig) {
this._expression = '';
this._interpolationConfig = interpolationConfig;
this._visit(ast);
@@ -180,3 +180,10 @@ export class Unparser implements AstVisitor {
private _visit(ast: AST) { ast.visit(this); }
}
const sharedUnparser = new Unparser();
export function unparse(
ast: AST, interpolationConfig: InterpolationConfig = DEFAULT_INTERPOLATION_CONFIG): string {
return sharedUnparser.unparse(ast, interpolationConfig);
}