File tree Expand file tree Collapse file tree
codeflash/languages/javascript Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -603,6 +603,10 @@ def transform(self, code: str) -> str:
603603 """Transform all expect calls in the code."""
604604 result : list [str ] = []
605605 pos = 0
606+ # Track string state incrementally to avoid O(n²) rescanning
607+ in_string = False
608+ string_char = None
609+ last_checked_pos = 0
606610
607611 while pos < len (code ):
608612 expect_match = self ._expect_pattern .search (code , pos )
@@ -627,8 +631,32 @@ def transform(self, code: str) -> str:
627631 result .append (code [pos :])
628632 break
629633
634+ # Update string state up to match.start() incrementally
635+ match_start = match .start ()
636+ i = last_checked_pos
637+ while i < match_start :
638+ char = code [i ]
639+
640+ if in_string :
641+ # Check for escape sequence
642+ if char == "\\ " and i + 1 < len (code ):
643+ i += 2
644+ continue
645+ # Check for end of string
646+ if char == string_char :
647+ in_string = False
648+ string_char = None
649+ # Check for start of string
650+ elif char in "\" '`" :
651+ in_string = True
652+ string_char = char
653+
654+ i += 1
655+
656+ last_checked_pos = match_start
657+
630658 # Skip if inside a string literal (e.g., test description)
631- if is_inside_string ( code , match . start ()) :
659+ if in_string :
632660 result .append (code [pos : match .end ()])
633661 pos = match .end ()
634662 continue
You can’t perform that action at this time.
0 commit comments