/** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import {ASTWithSource, AbsoluteSourceSpan, NullAstVisitor} from '@angular/compiler'; import * as t from '../../src/render3/r3_ast'; import {parseR3 as parse} from './view/util'; class ExpressionLocationHumanizer extends NullAstVisitor implements t.Visitor { result: any[] = []; visitASTWithSource(ast: ASTWithSource) { this.result.push([ast.source, ast.sourceSpan]); } visitTemplate(ast: t.Template) { t.visitAll(this, ast.children); } visitElement(ast: t.Element) { t.visitAll(this, ast.children); t.visitAll(this, ast.inputs); t.visitAll(this, ast.outputs); } visitReference(ast: t.Reference) {} visitVariable(ast: t.Variable) {} visitEvent(ast: t.BoundEvent) { ast.handler.visit(this); } visitTextAttribute(ast: t.TextAttribute) {} visitBoundAttribute(ast: t.BoundAttribute) { ast.value.visit(this); } visitBoundEvent(ast: t.BoundEvent) { ast.handler.visit(this); } visitBoundText(ast: t.BoundText) { ast.value.visit(this); } visitContent(ast: t.Content) {} visitText(ast: t.Text) {} visitIcu(ast: t.Icu) {} } function humanizeExpressionLocation(templateAsts: t.Node[]): any[] { const humanizer = new ExpressionLocationHumanizer(); t.visitAll(humanizer, templateAsts); return humanizer.result; } describe('expression AST absolute source spans', () => { // TODO(ayazhafiz): duplicate this test without `preserveWhitespaces` once whitespace rewriting is // moved to post-R3AST generation. it('should provide absolute offsets with arbitrary whitespace', () => { expect(humanizeExpressionLocation( parse('