forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtml_ast.ts
More file actions
39 lines (33 loc) · 1.19 KB
/
Copy pathhtml_ast.ts
File metadata and controls
39 lines (33 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import {isPresent} from 'angular2/src/core/facade/lang';
export interface HtmlAst {
sourceInfo: string;
visit(visitor: HtmlAstVisitor): any;
}
export class HtmlTextAst implements HtmlAst {
constructor(public value: string, public sourceInfo: string) {}
visit(visitor: HtmlAstVisitor): any { return visitor.visitText(this); }
}
export class HtmlAttrAst implements HtmlAst {
constructor(public name: string, public value: string, public sourceInfo: string) {}
visit(visitor: HtmlAstVisitor): any { return visitor.visitAttr(this); }
}
export class HtmlElementAst implements HtmlAst {
constructor(public name: string, public attrs: HtmlAttrAst[], public children: HtmlAst[],
public sourceInfo: string) {}
visit(visitor: HtmlAstVisitor): any { return visitor.visitElement(this); }
}
export interface HtmlAstVisitor {
visitElement(ast: HtmlElementAst): any;
visitAttr(ast: HtmlAttrAst): any;
visitText(ast: HtmlTextAst): any;
}
export function htmlVisitAll(visitor: HtmlAstVisitor, asts: HtmlAst[]): any[] {
var result = [];
asts.forEach(ast => {
var astResult = ast.visit(visitor);
if (isPresent(astResult)) {
result.push(astResult);
}
});
return result;
}