@@ -36,7 +36,7 @@ def render_props(self, component: Component, context: Context):
3636 if not isinstance (node , PropNode ):
3737 continue
3838
39- value = Value (node .default , quoted = False )
39+ value = Value (node .default )
4040
4141 for idx , attr in enumerate (self .attrs ):
4242 if node .name == attr .name :
@@ -78,11 +78,7 @@ def render_prop(self, context: Context) -> str | bool | None:
7878 def from_bit (cls , bit : str ) -> Param :
7979 if "=" in bit :
8080 name , raw_value = bit .split ("=" , 1 )
81- # Check if the value is quoted
82- if raw_value .startswith (("'" , '"' )) and raw_value .endswith (raw_value [0 ]):
83- value = Value (raw_value [1 :- 1 ], quoted = True )
84- else :
85- value = Value (raw_value .strip (), quoted = False )
81+ value = Value (raw_value .strip ())
8682 else :
8783 name , value = bit , Value (True )
8884 return cls (name , value )
@@ -91,18 +87,32 @@ def from_bit(cls, bit: str) -> Param:
9187@dataclass
9288class Value :
9389 raw : str | bool | None
94- quoted : bool = False
9590
9691 def resolve (self , context : Context | dict [str , Any ]) -> Any :
97- if self .raw is None or (isinstance (self .raw , str ) and self .raw == "False" ):
98- return None
99- if (isinstance (self .raw , bool ) and self .raw ) or (
100- isinstance (self .raw , str ) and self .raw == "True"
101- ):
102- return True
103- if isinstance (self .raw , str ) and not self .quoted :
104- try :
105- return template .Variable (str (self .raw )).resolve (context )
106- except template .VariableDoesNotExist :
107- return self .raw
108- return self .raw
92+ match (self .raw , self .is_quoted ):
93+ case (None , _):
94+ return None
95+
96+ case (str (raw_str ), False ) if raw_str == "False" :
97+ return None
98+ case (str (raw_str ), False ) if raw_str == "True" :
99+ return True
100+
101+ case (bool (b ), _):
102+ return b if b else None
103+
104+ case (str (raw_str ), False ):
105+ try :
106+ return template .Variable (raw_str ).resolve (context )
107+ except template .VariableDoesNotExist :
108+ return raw_str
109+
110+ case (_, True ):
111+ return str (self .raw )[1 :- 1 ]
112+
113+ @property
114+ def is_quoted (self ) -> bool :
115+ if self .raw is None or isinstance (self .raw , bool ):
116+ return False
117+
118+ return self .raw .startswith (("'" , '"' )) and self .raw .endswith (self .raw [0 ])
0 commit comments