@@ -20,6 +20,7 @@ import {
2020
2121import { DomProtoView , DomProtoViewRef , resolveInternalDomProtoView } from './proto_view' ;
2222import { DomElementBinder , Event , HostAction } from './element_binder' ;
23+ import { ElementSchemaRegistry } from '../schema/element_schema_registry' ;
2324
2425import * as api from '../../api' ;
2526
@@ -68,7 +69,7 @@ export class ProtoViewBuilder {
6869
6970 setHostAttribute ( name : string , value : string ) { this . hostAttributes . set ( name , value ) ; }
7071
71- build ( ) : api . ProtoViewDto {
72+ build ( schemaRegistry : ElementSchemaRegistry ) : api . ProtoViewDto {
7273 var domElementBinders = [ ] ;
7374
7475 var apiElementBinders = [ ] ;
@@ -91,12 +92,12 @@ export class ProtoViewBuilder {
9192 directiveIndex : dbb . directiveIndex ,
9293 propertyBindings : dbb . propertyBindings ,
9394 eventBindings : dbb . eventBindings ,
94- hostPropertyBindings :
95- buildElementPropertyBindings ( ebb . element , isPresent ( ebb . componentId ) ,
96- dbb . hostPropertyBindings , directiveTemplatePropertyNames )
95+ hostPropertyBindings : buildElementPropertyBindings ( schemaRegistry , ebb . element , true ,
96+ dbb . hostPropertyBindings , new Set ( ) )
9797 } ) ;
9898 } ) ;
99- var nestedProtoView = isPresent ( ebb . nestedProtoView ) ? ebb . nestedProtoView . build ( ) : null ;
99+ var nestedProtoView =
100+ isPresent ( ebb . nestedProtoView ) ? ebb . nestedProtoView . build ( schemaRegistry ) : null ;
100101 if ( isPresent ( nestedProtoView ) ) {
101102 transitiveNgContentCount += nestedProtoView . transitiveNgContentCount ;
102103 }
@@ -113,7 +114,7 @@ export class ProtoViewBuilder {
113114 directives : apiDirectiveBinders ,
114115 nestedProtoView : nestedProtoView ,
115116 propertyBindings :
116- buildElementPropertyBindings ( ebb . element , isPresent ( ebb . componentId ) ,
117+ buildElementPropertyBindings ( schemaRegistry , ebb . element , isPresent ( ebb . componentId ) ,
117118 ebb . propertyBindings , directiveTemplatePropertyNames ) ,
118119 variableBindings : ebb . variableBindings ,
119120 eventBindings : ebb . eventBindings ,
@@ -325,14 +326,15 @@ const ATTRIBUTE_PREFIX = 'attr';
325326const CLASS_PREFIX = 'class' ;
326327const STYLE_PREFIX = 'style' ;
327328
328- function buildElementPropertyBindings ( protoElement : /*element*/ any , isNgComponent : boolean ,
329- bindingsInTemplate : Map < string , ASTWithSource > ,
330- directiveTempaltePropertyNames : Set < string > ) :
329+ function buildElementPropertyBindings (
330+ schemaRegistry : ElementSchemaRegistry , protoElement : /*element*/ any , isNgComponent : boolean ,
331+ bindingsInTemplate : Map < string , ASTWithSource > , directiveTempaltePropertyNames : Set < string > ) :
331332 List < api . ElementPropertyBinding > {
332333 var propertyBindings = [ ] ;
333334 MapWrapper . forEach ( bindingsInTemplate , ( ast , propertyNameInTemplate ) => {
334- var propertyBinding = createElementPropertyBinding ( ast , propertyNameInTemplate ) ;
335- if ( isValidElementPropertyBinding ( protoElement , isNgComponent , propertyBinding ) ) {
335+ var propertyBinding = createElementPropertyBinding ( schemaRegistry , ast , propertyNameInTemplate ) ;
336+ if ( isValidElementPropertyBinding ( schemaRegistry , protoElement , isNgComponent ,
337+ propertyBinding ) ) {
336338 propertyBindings . push ( propertyBinding ) ;
337339 } else if ( ! SetWrapper . has ( directiveTempaltePropertyNames , propertyNameInTemplate ) ) {
338340 throw new BaseException (
@@ -342,29 +344,25 @@ function buildElementPropertyBindings(protoElement: /*element*/ any, isNgCompone
342344 return propertyBindings ;
343345}
344346
345- function isValidElementPropertyBinding ( protoElement : /*element*/ any , isNgComponent : boolean ,
347+ function isValidElementPropertyBinding ( schemaRegistry : ElementSchemaRegistry ,
348+ protoElement : /*element*/ any , isNgComponent : boolean ,
346349 binding : api . ElementPropertyBinding ) : boolean {
347350 if ( binding . type === api . PropertyBindingType . PROPERTY ) {
348- var tagName = DOM . tagName ( protoElement ) ;
349- var possibleCustomElement = tagName . indexOf ( '-' ) !== - 1 ;
350- if ( possibleCustomElement && ! isNgComponent ) {
351- // can't tell now as we don't know which properties a custom element will get
352- // once it is instantiated
353- return true ;
351+ if ( ! isNgComponent ) {
352+ return schemaRegistry . hasProperty ( protoElement , binding . property ) ;
354353 } else {
354+ // TODO(pk): change this logic as soon as we can properly detect custom elements
355355 return DOM . hasProperty ( protoElement , binding . property ) ;
356356 }
357357 }
358358 return true ;
359359}
360360
361- function createElementPropertyBinding ( ast : ASTWithSource , propertyNameInTemplate : string ) :
362- api . ElementPropertyBinding {
361+ function createElementPropertyBinding ( schemaRegistry : ElementSchemaRegistry , ast : ASTWithSource ,
362+ propertyNameInTemplate : string ) : api . ElementPropertyBinding {
363363 var parts = StringWrapper . split ( propertyNameInTemplate , PROPERTY_PARTS_SEPARATOR ) ;
364364 if ( parts . length === 1 ) {
365- var propName = parts [ 0 ] ;
366- var mappedPropName = StringMapWrapper . get ( DOM . attrToPropMap , propName ) ;
367- propName = isPresent ( mappedPropName ) ? mappedPropName : propName ;
365+ var propName = schemaRegistry . getMappedPropName ( parts [ 0 ] ) ;
368366 return new api . ElementPropertyBinding ( api . PropertyBindingType . PROPERTY , ast , propName ) ;
369367 } else if ( parts [ 0 ] == ATTRIBUTE_PREFIX ) {
370368 return new api . ElementPropertyBinding ( api . PropertyBindingType . ATTRIBUTE , ast , parts [ 1 ] ) ;
0 commit comments