@@ -71,7 +71,7 @@ def transpile(self) -> Tuple[str, SourceMap]:
7171 if parsed .directives :
7272 for d in parsed .directives :
7373 if isinstance (d , PathDirective ):
74- start_line = d .line - 1
74+ start_line = max ( 0 , d .line - 1 )
7575 end_line = start_line
7676 if not d .is_simple_string :
7777 for i in range (start_line , len (self .lines )):
@@ -88,7 +88,10 @@ def transpile(self) -> Tuple[str, SourceMap]:
8888 self .generated_code .append (f"__path = { routes_repr } \n " )
8989 self .generated_line_idx += 1
9090 elif isinstance (d , LayoutDirective ):
91- self .directive_ranges ["layout" ] = (d .line - 1 , d .line - 1 )
91+ self .directive_ranges ["layout" ] = (
92+ max (0 , d .line - 1 ),
93+ max (0 , d .line - 1 ),
94+ )
9295 else :
9396 # Fallback for directives if parser missed them
9497 self ._scan_directives_legacy ()
@@ -182,7 +185,7 @@ def _traverse_node(self, node: TemplateNode):
182185 # skip control blocks like {$if ...}
183186 continue
184187
185- line = node .line - 1
188+ line = max ( 0 , node .line - 1 )
186189 col = node .column
187190 prefix = "_ = "
188191 self .generated_code .append (prefix )
@@ -194,7 +197,7 @@ def _traverse_node(self, node: TemplateNode):
194197 self .generated_line_idx += 1
195198
196199 def _emit_interpolation_from_node (self , node : InterpolationNode ):
197- line = node .line - 1
200+ line = max ( 0 , node .line - 1 )
198201 col = node .column
199202 expr = node .expression
200203 prefix = "_ = "
@@ -281,7 +284,7 @@ def _find_attr_location(
281284 return start_line , start_col , start_col + 1
282285
283286 def _emit_control_flow (self , attr ):
284- line = attr .line - 1
287+ line = max ( 0 , attr .line - 1 )
285288 col = attr .column
286289 prefix = ""
287290 expr = ""
@@ -340,7 +343,7 @@ def _emit_control_flow(self, attr):
340343 self .generated_line_idx += 1
341344
342345 def _emit_event_handler (self , attr : EventAttribute ):
343- line = attr .line - 1
346+ line = max ( 0 , attr .line - 1 )
344347 col = attr .column
345348 # ... event_cls logic ...
346349 event_cls = "EventData"
@@ -387,7 +390,7 @@ def _emit_event_handler(self, attr: EventAttribute):
387390 self .generated_line_idx += 1
388391
389392 def _emit_reactive_attr (self , attr : ReactiveAttribute ):
390- line = attr .line - 1
393+ line = max ( 0 , attr .line - 1 )
391394 col = attr .column
392395 prefix = "_ = "
393396 self .generated_code .append (prefix )
@@ -404,7 +407,7 @@ def _emit_reactive_attr(self, attr: ReactiveAttribute):
404407 self .generated_line_idx += 1
405408
406409 def _emit_spread_attr (self , attr : SpreadAttribute ):
407- line = attr .line - 1
410+ line = max ( 0 , attr .line - 1 )
408411 col = attr .column
409412 prefix = "_ = **"
410413 self .generated_code .append (prefix )
0 commit comments