Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions codeflash/languages/javascript/code_replacer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

from operator import attrgetter
from typing import TYPE_CHECKING

from codeflash.cli_cmds.console import logger
Expand Down Expand Up @@ -103,9 +104,7 @@ def _filter_new_declarations(optimized_declarations: list, existing_names: set[s
seen_sources: set[str] = set()

# Sort by line number to maintain order from optimized code
sorted_declarations = sorted(optimized_declarations, key=lambda d: d.start_line)

for decl in sorted_declarations:
for decl in sorted(optimized_declarations, key=attrgetter("start_line")):
if decl.name not in existing_names and decl.source_code not in seen_sources:
new_declarations.append(decl)
seen_sources.add(decl.source_code)
Expand Down
Loading