@@ -3,8 +3,7 @@ use std::ops::Range;
33use glass_easel_template_compiler:: parse:: {
44 expr:: Expression ,
55 tag:: {
6- ClassAttribute , Comment , CommonElementAttributes , Element , ElementKind , Ident , Node ,
7- Script , StaticAttribute , StrName , StyleAttribute , TagLocation , UnknownMetaTag , Value ,
6+ ClassAttribute , Comment , CommonElementAttributes , Element , ElementKind , Ident , Node , NormalAttributePrefix , Script , StaticAttribute , StrName , StyleAttribute , TagLocation , UnknownMetaTag , Value
87 } ,
98 Position , Template ,
109} ;
@@ -222,6 +221,17 @@ pub(crate) fn find_token_in_position(template: &Template, pos: Position) -> Toke
222221 _ => None ,
223222 }
224223 }
224+ fn find_in_option_value < ' a > (
225+ v : & ' a Option < Value > ,
226+ pos : Position ,
227+ scopes : & mut Vec < ScopeKind < ' a > > ,
228+ ) -> Option < Token < ' a > > {
229+ if let Some ( v) = v {
230+ find_in_value ( v, pos, scopes)
231+ } else {
232+ None
233+ }
234+ }
225235 fn find_in_nodes < ' a > (
226236 parent : Option < & ' a Element > ,
227237 nodes : & ' a [ Node ] ,
@@ -315,23 +325,23 @@ pub(crate) fn find_token_in_position(template: &Template, pos: Position) -> Toke
315325 if ident_contains ( & attr. name , pos) {
316326 return Token :: DataKey ( & attr. name ) ;
317327 }
318- if let Some ( ret) = find_in_value ( & attr. value , pos, scopes) {
328+ if let Some ( ret) = find_in_option_value ( & attr. value , pos, scopes) {
319329 return ret;
320330 }
321331 }
322332 for attr in common. data . iter ( ) {
323333 if ident_contains ( & attr. name , pos) {
324334 return Token :: MarkKey ( & attr. name ) ;
325335 }
326- if let Some ( ret) = find_in_value ( & attr. value , pos, scopes) {
336+ if let Some ( ret) = find_in_option_value ( & attr. value , pos, scopes) {
327337 return ret;
328338 }
329339 }
330340 for ev in common. event_bindings . iter ( ) {
331341 if ident_contains ( & ev. name , pos) {
332342 return Token :: EventName ( & ev. name , elem) ;
333343 }
334- if let Some ( ret) = find_in_value ( & ev. value , pos, scopes) {
344+ if let Some ( ret) = find_in_option_value ( & ev. value , pos, scopes) {
335345 return ret;
336346 }
337347 }
@@ -357,12 +367,12 @@ pub(crate) fn find_token_in_position(template: &Template, pos: Position) -> Toke
357367 }
358368 for attr in attributes. iter ( ) {
359369 if ident_contains ( & attr. name , pos) {
360- if attr. is_model {
370+ if let NormalAttributePrefix :: Model ( _ ) = & attr. prefix {
361371 return Token :: ModelAttributeName ( & attr. name , elem) ;
362372 }
363373 return Token :: AttributeName ( & attr. name , elem) ;
364374 }
365- if let Some ( ret) = find_in_value ( & attr. value , pos, scopes) {
375+ if let Some ( ret) = find_in_option_value ( & attr. value , pos, scopes) {
366376 if let Token :: StaticValuePart ( loc, v) = ret {
367377 return Token :: AttributeStaticValue (
368378 loc, v, & attr. name , elem,
@@ -375,7 +385,7 @@ pub(crate) fn find_token_in_position(template: &Template, pos: Position) -> Toke
375385 if ident_contains ( & attr. name , pos) {
376386 return Token :: AttributeName ( & attr. name , elem) ;
377387 }
378- if let Some ( ret) = find_in_value ( & attr. value , pos, scopes) {
388+ if let Some ( ret) = find_in_option_value ( & attr. value , pos, scopes) {
379389 if let Token :: StaticValuePart ( loc, v) = ret {
380390 return Token :: AttributeStaticValue (
381391 loc, v, & attr. name , elem,
@@ -629,7 +639,7 @@ pub(crate) fn find_token_in_position(template: &Template, pos: Position) -> Toke
629639 if ident_contains ( & attr. name , pos) {
630640 return Token :: SlotValueDefinition ( & attr. name ) ;
631641 }
632- if let Some ( ret) = find_in_value ( & attr. value , pos, scopes) {
642+ if let Some ( ret) = find_in_option_value ( & attr. value , pos, scopes) {
633643 return ret;
634644 }
635645 }
@@ -866,10 +876,14 @@ pub(crate) fn for_each_template_value_in_subtree<'a>(
866876 f ( value, scopes) ;
867877 }
868878 for attr in common. data . iter ( ) . chain ( common. marks . iter ( ) ) {
869- f ( & attr. value , scopes) ;
879+ if let Some ( value) = attr. value . as_ref ( ) {
880+ f ( value, scopes) ;
881+ }
870882 }
871883 for ev in common. event_bindings . iter ( ) {
872- f ( & ev. value , scopes) ;
884+ if let Some ( value) = ev. value . as_ref ( ) {
885+ f ( value, scopes) ;
886+ }
873887 }
874888 }
875889 match node {
@@ -890,8 +904,15 @@ pub(crate) fn for_each_template_value_in_subtree<'a>(
890904 common,
891905 ..
892906 } => {
893- for attr in attributes. iter ( ) . chain ( change_attributes. iter ( ) ) {
894- f ( & attr. value , scopes) ;
907+ for attr in attributes. iter ( ) {
908+ if let Some ( value) = attr. value . as_ref ( ) {
909+ f ( value, scopes) ;
910+ }
911+ }
912+ for attr in change_attributes. iter ( ) {
913+ if let Some ( value) = attr. value . as_ref ( ) {
914+ f ( value, scopes) ;
915+ }
895916 }
896917 match class {
897918 ClassAttribute :: None => { }
@@ -961,7 +982,9 @@ pub(crate) fn for_each_template_value_in_subtree<'a>(
961982 } => {
962983 f ( & name. 1 , scopes) ;
963984 for attr in values. iter ( ) {
964- f ( & attr. value , scopes) ;
985+ if let Some ( value) = attr. value . as_ref ( ) {
986+ f ( value, scopes) ;
987+ }
965988 }
966989 handle_common ( common, scopes, & mut f) ;
967990 }
0 commit comments