@@ -564,43 +564,28 @@ defmodule Surface.Compiler do
564
564
]
565
565
end
566
566
567
- # TODO: Validate attributes with custom messages
568
-
569
567
has_root? = has_attribute? ( attributes , :root )
570
- has_for? = ! has_root? and has_attribute? ( attributes , "for" )
571
-
572
- name =
573
- extract_name_from_root ( attributes ) || attribute_value_as_atom ( attributes , "name" , nil ) ||
574
- extract_name_from_for ( attributes )
568
+ name = extract_name_from_root ( attributes )
575
569
576
570
name =
577
- if ! name and ! has_for? and ! has_root? do
571
+ if ! name and ! has_root? do
578
572
:default
579
573
else
580
574
name
581
575
end
582
576
583
- default_syntax? = not has_attribute? ( attributes , "name" ) && not has_for? && not has_root?
577
+ default_syntax? = not has_root?
584
578
585
579
render_slot_args =
586
580
if has_root? do
587
581
attribute_value_as_ast ( attributes , :root , :render_slot , % Surface.AST.Literal { value: nil } , compile_meta )
588
582
end
589
583
590
- for_ast =
591
- cond do
592
- has_for? ->
593
- attribute_value_as_ast ( attributes , "for" , :any , % Surface.AST.Literal { value: nil } , compile_meta )
594
-
595
- has_root? ->
596
- render_slot_args . slot
597
-
598
- true ->
599
- nil
584
+ slot_entry_ast =
585
+ if has_root? do
586
+ render_slot_args . slot
600
587
end
601
588
602
- index = attribute_value_as_ast ( attributes , "index" , % Surface.AST.Literal { value: 0 } , compile_meta )
603
-
604
589
{ :ok , directives , attrs } = collect_directives ( @ slot_directive_handlers , attributes , meta )
605
590
validate_slot_attrs! ( attrs , meta . caller )
606
591
@@ -620,7 +605,7 @@ defmodule Surface.Compiler do
620
605
maybe_warn_required_slot_with_default_value (
621
606
slot ,
622
607
children ,
623
- for_ast ,
608
+ slot_entry_ast ,
624
609
meta
625
610
)
626
611
@@ -666,8 +651,7 @@ defmodule Surface.Compiler do
666
651
% AST.Slot {
667
652
name: name ,
668
653
as: if ( slot , do: slot [ :opts ] [ :as ] ) ,
669
- index: index ,
670
- for: for_ast ,
654
+ for: slot_entry_ast ,
671
655
directives: directives ,
672
656
default: to_ast ( children , compile_meta ) ,
673
657
arg: arg ,
@@ -960,14 +944,6 @@ defmodule Surface.Compiler do
960
944
node
961
945
end
962
946
963
- defp attribute_value_as_atom ( attributes , attr_name , default ) do
964
- Enum . find_value ( attributes , default , fn { name , value , _ } ->
965
- if name == attr_name do
966
- String . to_atom ( value )
967
- end
968
- end )
969
- end
970
-
971
947
defp attribute_raw_value ( attributes , attr_name , default ) do
972
948
Enum . find_value ( attributes , default , fn
973
949
{ ^ attr_name , { :attribute_expr , expr , _ } , _ } ->
@@ -978,20 +954,6 @@ defmodule Surface.Compiler do
978
954
end )
979
955
end
980
956
981
- defp extract_name_from_for ( attributes ) do
982
- with value when is_binary ( value ) <- attribute_raw_value ( attributes , "for" , nil ) ,
983
- { :ok , { :@ , _ , [ { assign_name , _ , _ } ] } } when is_atom ( assign_name ) <- Code . string_to_quoted ( value ) do
984
- assign_name
985
- else
986
- { :error , _ } ->
987
- # TODO: raise
988
- nil
989
-
990
- _ ->
991
- nil
992
- end
993
- end
994
-
995
957
defp extract_name_from_root ( attributes ) do
996
958
with value when is_binary ( value ) <- attribute_raw_value ( attributes , :root , nil ) ,
997
959
{ :ok , [ { :@ , _ , [ { assign_name , _ , _ } ] } | _rest ] } <-
0 commit comments