@@ -73,32 +73,57 @@ export function main() {
7373 expect ( creationArgs [ 'index' ] ) . toBe ( protoView . elementBinders . length ) ; 
7474 } ) ; 
7575
76-  it ( 'should inherit the ProtoElementInjector down to children without directives' ,  ( )  =>  { 
77-  var  directives  =  [ SomeDecoratorDirective ] ; 
78-  var  results  =  createPipeline ( directives ) . process ( createElement ( '<div directives><span></span></div>' ) ) ; 
79-  expect ( results [ 1 ] . inheritedProtoElementInjector ) . toBe ( results [ 0 ] . inheritedProtoElementInjector ) ; 
80-  } ) ; 
81- 
82-  it ( 'should use the ProtoElementInjector of the parent element as parent' ,  ( )  =>  { 
83-  var  el  =  createElement ( '<div directives><span><a directives></a></span></div>' ) ; 
84-  var  directives  =  [ SomeDecoratorDirective ] ; 
85-  var  results  =  createPipeline ( directives ) . process ( el ) ; 
86-  expect ( results [ 2 ] . inheritedProtoElementInjector . parent ) . toBe ( 
87-  results [ 0 ] . inheritedProtoElementInjector ) ; 
76+  describe ( "inheritedProtoElementInjector" ,  ( )  =>  { 
77+  it ( 'should inherit the ProtoElementInjector down to children without directives' ,  ( )  =>  { 
78+  var  directives  =  [ SomeDecoratorDirective ] ; 
79+  var  results  =  createPipeline ( directives ) . process ( createElement ( '<div directives><span></span></div>' ) ) ; 
80+  expect ( results [ 1 ] . inheritedProtoElementInjector ) . toBe ( results [ 0 ] . inheritedProtoElementInjector ) ; 
81+  } ) ; 
82+ 
83+  it ( 'should use the ProtoElementInjector of the parent element as parent' ,  ( )  =>  { 
84+  var  el  =  createElement ( '<div directives><span><a directives></a></span></div>' ) ; 
85+  var  directives  =  [ SomeDecoratorDirective ] ; 
86+  var  results  =  createPipeline ( directives ) . process ( el ) ; 
87+  expect ( results [ 2 ] . inheritedProtoElementInjector . parent ) . toBe ( 
88+  results [ 0 ] . inheritedProtoElementInjector ) ; 
89+  } ) ; 
90+ 
91+  it ( 'should use a null parent for viewRoots' ,  ( )  =>  { 
92+  var  el  =  createElement ( '<div directives><span viewroot directives></span></div>' ) ; 
93+  var  directives  =  [ SomeDecoratorDirective ] ; 
94+  var  results  =  createPipeline ( directives ) . process ( el ) ; 
95+  expect ( results [ 1 ] . inheritedProtoElementInjector . parent ) . toBe ( null ) ; 
96+  } ) ; 
97+ 
98+  it ( 'should use a null parent if there is an intermediate viewRoot' ,  ( )  =>  { 
99+  var  el  =  createElement ( '<div directives><span viewroot><a directives></a></span></div>' ) ; 
100+  var  directives  =  [ SomeDecoratorDirective ] ; 
101+  var  results  =  createPipeline ( directives ) . process ( el ) ; 
102+  expect ( results [ 2 ] . inheritedProtoElementInjector . parent ) . toBe ( null ) ; 
103+  } ) ; 
88104 } ) ; 
89105
90-  it ( 'should use a null parent for viewRoots' ,  ( )  =>  { 
91-  var  el  =  createElement ( '<div directives><span viewroot directives></span></div>' ) ; 
92-  var  directives  =  [ SomeDecoratorDirective ] ; 
93-  var  results  =  createPipeline ( directives ) . process ( el ) ; 
94-  expect ( results [ 1 ] . inheritedProtoElementInjector . parent ) . toBe ( null ) ; 
95-  } ) ; 
96- 
97-  it ( 'should use a null parent if there is an intermediate viewRoot' ,  ( )  =>  { 
98-  var  el  =  createElement ( '<div directives><span viewroot><a directives></a></span></div>' ) ; 
99-  var  directives  =  [ SomeDecoratorDirective ] ; 
100-  var  results  =  createPipeline ( directives ) . process ( el ) ; 
101-  expect ( results [ 2 ] . inheritedProtoElementInjector . parent ) . toBe ( null ) ; 
106+  describe ( "distanceToParentInjector" ,  ( )  =>  { 
107+  it ( "should be 0 for root elements" ,  ( )  =>  { 
108+  var  el  =  createElement ( '<div directives></div>' ) ; 
109+  var  directives  =  [ SomeDecoratorDirective ] ; 
110+  var  results  =  createPipeline ( directives ) . process ( el ) ; 
111+  expect ( results [ 0 ] . inheritedProtoElementInjector . distanceToParent ) . toBe ( 0 ) ; 
112+  } ) ; 
113+ 
114+  it ( "should be 1 when a parent element has an injector" ,  ( )  =>  { 
115+  var  el  =  createElement ( '<div directives><span directives></span></div>' ) ; 
116+  var  directives  =  [ SomeDecoratorDirective ] ; 
117+  var  results  =  createPipeline ( directives ) . process ( el ) ; 
118+  expect ( results [ 1 ] . inheritedProtoElementInjector . distanceToParent ) . toBe ( 1 ) ; 
119+  } ) ; 
120+ 
121+  it ( "should add 1 for every element that does not have an injector" ,  ( )  =>  { 
122+  var  el  =  createElement ( '<div directives><a><b><span directives></span></b></a></div>' ) ; 
123+  var  directives  =  [ SomeDecoratorDirective ] ; 
124+  var  results  =  createPipeline ( directives ) . process ( el ) ; 
125+  expect ( results [ 3 ] . inheritedProtoElementInjector . distanceToParent ) . toBe ( 3 ) ; 
126+  } ) ; 
102127 } ) ; 
103128 } ) ; 
104129} 
@@ -117,8 +142,8 @@ class TestableProtoElementInjectorBuilder extends ProtoElementInjectorBuilder {
117142 } 
118143 return  null ; 
119144 } 
120-  internalCreateProtoElementInjector ( parent ,  index ,  bindings ,  firstBindingIsComponent )  { 
121-  var  result  =  new  ProtoElementInjector ( parent ,  index ,  bindings ,  firstBindingIsComponent ) ; 
145+  internalCreateProtoElementInjector ( parent ,  index ,  bindings ,  firstBindingIsComponent ,   distance )  { 
146+  var  result  =  new  ProtoElementInjector ( parent ,  index ,  bindings ,  firstBindingIsComponent ,   distance ) ; 
122147 ListWrapper . push ( this . debugObjects ,  result ) ; 
123148 ListWrapper . push ( this . debugObjects ,  { 'parent' : parent ,  'index' : index ,  'bindings' : bindings ,  'firstBindingIsComponent' : firstBindingIsComponent } ) ; 
124149 return  result ; 
0 commit comments