import {isPresent} from '../src/facade/lang'; import {AST} from './expression_parser/ast'; import {CompileDirectiveMetadata, CompileTokenMetadata, CompileProviderMetadata,} from './compile_metadata'; import {ParseSourceSpan} from './parse_util'; import {SecurityContext} from '../core_private'; /** * An Abstract Syntax Tree node representing part of a parsed Angular template. */ export interface TemplateAst { /** * The source span from which this node was parsed. */ sourceSpan: ParseSourceSpan; /** * Visit this node and possibly transform it. */ visit(visitor: TemplateAstVisitor, context: any): any; } /** * A segment of text within the template. */ export class TextAst implements TemplateAst { constructor( public value: string, public ngContentIndex: number, public sourceSpan: ParseSourceSpan) {} visit(visitor: TemplateAstVisitor, context: any): any { return visitor.visitText(this, context); } } /** * A bound expression within the text of a template. */ export class BoundTextAst implements TemplateAst { constructor( public value: AST, public ngContentIndex: number, public sourceSpan: ParseSourceSpan) {} visit(visitor: TemplateAstVisitor, context: any): any { return visitor.visitBoundText(this, context); } } /** * A plain attribute on an element. */ export class AttrAst implements TemplateAst { constructor(public name: string, public value: string, public sourceSpan: ParseSourceSpan) {} visit(visitor: TemplateAstVisitor, context: any): any { return visitor.visitAttr(this, context); } } /** * A binding for an element property (e.g. `[property]="expression"`). */ export class BoundElementPropertyAst implements TemplateAst { constructor( public name: string, public type: PropertyBindingType, public securityContext: SecurityContext, public value: AST, public unit: string, public sourceSpan: ParseSourceSpan) {} visit(visitor: TemplateAstVisitor, context: any): any { return visitor.visitElementProperty(this, context); } } /** * A binding for an element event (e.g. `(event)="handler()"`). */ export class BoundEventAst implements TemplateAst { constructor( public name: string, public target: string, public handler: AST, public sourceSpan: ParseSourceSpan) {} visit(visitor: TemplateAstVisitor, context: any): any { return visitor.visitEvent(this, context); } get fullName() { if (isPresent(this.target)) { return `${this.target}:${this.name}`; } else { return this.name; } } } /** * A reference declaration on an element (e.g. `let someName="expression"`). */ export class ReferenceAst implements TemplateAst { constructor( public name: string, public value: CompileTokenMetadata, public sourceSpan: ParseSourceSpan) { } visit(visitor: TemplateAstVisitor, context: any): any { return visitor.visitReference(this, context); } } /** * A variable declaration on a