
committed by
Misko Hevery

parent
a4934a74b6
commit
92e80af875
@ -7,38 +7,11 @@
|
||||
*/
|
||||
|
||||
import {BindingType} from '../../src/expression_parser/ast';
|
||||
import {Lexer} from '../../src/expression_parser/lexer';
|
||||
import {Parser} from '../../src/expression_parser/parser';
|
||||
import {HtmlParser} from '../../src/ml_parser/html_parser';
|
||||
import {DEFAULT_INTERPOLATION_CONFIG} from '../../src/ml_parser/interpolation_config';
|
||||
import * as t from '../../src/render3/r3_ast';
|
||||
import {Render3ParseResult, htmlAstToRender3Ast} from '../../src/render3/r3_template_transform';
|
||||
import {BindingParser} from '../../src/template_parser/binding_parser';
|
||||
import {MockSchemaRegistry} from '../../testing';
|
||||
import {unparse} from '../expression_parser/utils/unparser';
|
||||
import {parseR3 as parse} from './view/util';
|
||||
|
||||
|
||||
// Parse an html string to IVY specific info
|
||||
function parse(html: string): Render3ParseResult {
|
||||
const htmlParser = new HtmlParser();
|
||||
|
||||
const parseResult = htmlParser.parse(html, 'path:://to/template', true);
|
||||
|
||||
if (parseResult.errors.length > 0) {
|
||||
const msg = parseResult.errors.map(e => e.toString()).join('\n');
|
||||
throw new Error(msg);
|
||||
}
|
||||
|
||||
const htmlNodes = parseResult.rootNodes;
|
||||
const expressionParser = new Parser(new Lexer());
|
||||
const schemaRegistry = new MockSchemaRegistry(
|
||||
{'invalidProp': false}, {'mappedAttr': 'mappedProp'}, {'unknown': false, 'un-known': false},
|
||||
['onEvent'], ['onEvent']);
|
||||
const bindingParser =
|
||||
new BindingParser(expressionParser, DEFAULT_INTERPOLATION_CONFIG, schemaRegistry, null, []);
|
||||
return htmlAstToRender3Ast(htmlNodes, bindingParser);
|
||||
}
|
||||
|
||||
// Transform an IVY AST to a flat list of nodes to ease testing
|
||||
class R3AstHumanizer implements t.Visitor<void> {
|
||||
result: any[] = [];
|
||||
@ -104,6 +77,8 @@ class R3AstHumanizer implements t.Visitor<void> {
|
||||
|
||||
visitBoundText(text: t.BoundText) { this.result.push(['BoundText', unparse(text.value)]); }
|
||||
|
||||
visitIcu(icu: t.Icu) { return null; }
|
||||
|
||||
private visitAll(nodes: t.Node[][]) { nodes.forEach(node => t.visitAll(this, node)); }
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user