From c28898208cc2dd646ec42762d173c1cd75fc27ad Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 5 Mar 2020 19:41:47 -0800 Subject: [PATCH] feat(compiler): type TemplateAst values as ASTWithSource TemplateAst values are currently typed as the base class AST, but they are actually constructed with ASTWithSource. Type them as such, because ASTWithSource gives more information about the consumed expression AST to downstream customers (namely, the expression AST source). Unblocks #35271 --- packages/compiler/src/expression_parser/ast.ts | 4 ++-- .../compiler/src/template_parser/template_ast.ts | 15 ++++++++------- .../src/view_compiler/type_check_compiler.ts | 14 ++++++++------ 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/packages/compiler/src/expression_parser/ast.ts b/packages/compiler/src/expression_parser/ast.ts index b4897454883e8..03b31225a7c17 100644 --- a/packages/compiler/src/expression_parser/ast.ts +++ b/packages/compiler/src/expression_parser/ast.ts @@ -691,7 +691,7 @@ export class ParsedEvent { // Animation events have a phase constructor( public name: string, public targetOrPhase: string, public type: ParsedEventType, - public handler: AST, public sourceSpan: ParseSourceSpan, + public handler: ASTWithSource, public sourceSpan: ParseSourceSpan, public handlerSpan: ParseSourceSpan) {} } @@ -715,6 +715,6 @@ export const enum BindingType { export class BoundElementProperty { constructor( public name: string, public type: BindingType, public securityContext: SecurityContext, - public value: AST, public unit: string|null, public sourceSpan: ParseSourceSpan, + public value: ASTWithSource, public unit: string|null, public sourceSpan: ParseSourceSpan, public valueSpan?: ParseSourceSpan) {} } diff --git a/packages/compiler/src/template_parser/template_ast.ts b/packages/compiler/src/template_parser/template_ast.ts index 4041aedd72d28..02c4728e92564 100644 --- a/packages/compiler/src/template_parser/template_ast.ts +++ b/packages/compiler/src/template_parser/template_ast.ts @@ -9,7 +9,7 @@ import {AstPath} from '../ast_path'; import {CompileDirectiveSummary, CompileProviderMetadata, CompileTokenMetadata} from '../compile_metadata'; import {SecurityContext} from '../core'; -import {AST, BindingType, BoundElementProperty, ParsedEvent, ParsedEventType, ParsedVariable} from '../expression_parser/ast'; +import {ASTWithSource, BindingType, BoundElementProperty, ParsedEvent, ParsedEventType, ParsedVariable} from '../expression_parser/ast'; import {LifecycleHooks} from '../lifecycle_reflector'; import {ParseSourceSpan} from '../parse_util'; @@ -44,7 +44,8 @@ export class TextAst implements TemplateAst { */ export class BoundTextAst implements TemplateAst { constructor( - public value: AST, public ngContentIndex: number, public sourceSpan: ParseSourceSpan) {} + public value: ASTWithSource, public ngContentIndex: number, + public sourceSpan: ParseSourceSpan) {} visit(visitor: TemplateAstVisitor, context: any): any { return visitor.visitBoundText(this, context); } @@ -88,8 +89,8 @@ export class BoundElementPropertyAst implements TemplateAst { constructor( public name: string, public type: PropertyBindingType, - public securityContext: SecurityContext, public value: AST, public unit: string|null, - public sourceSpan: ParseSourceSpan) { + public securityContext: SecurityContext, public value: ASTWithSource, + public unit: string|null, public sourceSpan: ParseSourceSpan) { this.isAnimation = this.type === PropertyBindingType.Animation; } @@ -114,7 +115,7 @@ export class BoundEventAst implements TemplateAst { constructor( public name: string, public target: string|null, public phase: string|null, - public handler: AST, public sourceSpan: ParseSourceSpan, + public handler: ASTWithSource, public sourceSpan: ParseSourceSpan, public handlerSpan: ParseSourceSpan) { this.fullName = BoundEventAst.calcFullName(this.name, this.target, this.phase); this.isAnimation = !!this.phase; @@ -209,7 +210,7 @@ export class EmbeddedTemplateAst implements TemplateAst { */ export class BoundDirectivePropertyAst implements TemplateAst { constructor( - public directiveName: string, public templateName: string, public value: AST, + public directiveName: string, public templateName: string, public value: ASTWithSource, public sourceSpan: ParseSourceSpan) {} visit(visitor: TemplateAstVisitor, context: any): any { return visitor.visitDirectiveProperty(this, context); @@ -350,7 +351,7 @@ export class RecursiveTemplateAstVisitor extends NullTemplateVisitor implements }); } - protected visitChildren( + protected visitChildren( context: any, cb: (visit: ((children: V[]|undefined) => void)) => void) { let results: any[][] = []; diff --git a/packages/compiler/src/view_compiler/type_check_compiler.ts b/packages/compiler/src/view_compiler/type_check_compiler.ts index f617c47e5153c..02a3b9ec1aeac 100644 --- a/packages/compiler/src/view_compiler/type_check_compiler.ts +++ b/packages/compiler/src/view_compiler/type_check_compiler.ts @@ -9,14 +9,12 @@ import {AotCompilerOptions} from '../aot/compiler_options'; import {StaticReflector} from '../aot/static_reflector'; import {StaticSymbol} from '../aot/static_symbol'; -import {CompileDiDependencyMetadata, CompileDirectiveMetadata, CompilePipeSummary} from '../compile_metadata'; -import {BindingForm, BuiltinConverter, EventHandlerVars, LocalResolver, convertActionBinding, convertPropertyBinding, convertPropertyBindingBuiltins} from '../compiler_util/expression_converter'; +import {CompileDirectiveMetadata, CompilePipeSummary} from '../compile_metadata'; +import {BindingForm, EventHandlerVars, LocalResolver, convertActionBinding, convertPropertyBinding, convertPropertyBindingBuiltins} from '../compiler_util/expression_converter'; import {AST, ASTWithSource, Interpolation} from '../expression_parser/ast'; -import {Identifiers} from '../identifiers'; import * as o from '../output/output_ast'; -import {convertValueToOutputAst} from '../output/value_util'; import {ParseSourceSpan} from '../parse_util'; -import {AttrAst, BoundDirectivePropertyAst, BoundElementPropertyAst, BoundEventAst, BoundTextAst, DirectiveAst, ElementAst, EmbeddedTemplateAst, NgContentAst, PropertyBindingType, ProviderAst, ProviderAstType, QueryMatch, ReferenceAst, TemplateAst, TemplateAstVisitor, TextAst, VariableAst, templateVisitAll} from '../template_parser/template_ast'; +import {AttrAst, BoundDirectivePropertyAst, BoundElementPropertyAst, BoundEventAst, BoundTextAst, DirectiveAst, ElementAst, EmbeddedTemplateAst, NgContentAst, ReferenceAst, TemplateAst, TemplateAstVisitor, TextAst, VariableAst, templateVisitAll} from '../template_parser/template_ast'; import {OutputContext} from '../util'; @@ -133,7 +131,11 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver { result.push({ guard, useIf, - expression: {context: this.component, value: input.value} as Expression + expression: { + context: this.component, + value: input.value, + sourceSpan: input.sourceSpan, + }, }); } }