Skip to content

Commit

Permalink
remove unused imports after delete
Browse files Browse the repository at this point in the history
  • Loading branch information
liady committed Dec 19, 2023
1 parent cbacbf9 commit 34974fd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions editor/src/components/editor/actions/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,7 @@ function deleteElements(
return {
...simpleSuccess,
utopiaComponents: withTargetRemoved.components,
imports: withTargetRemoved.imports,
}
}, success)
}
Expand Down
16 changes: 9 additions & 7 deletions editor/src/components/editor/store/editor-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1908,21 +1908,23 @@ type RemoveElementResult = {
export function removeElementAtPath(
target: ElementPath,
components: Array<UtopiaJSXComponent>,
imports?: Imports,
originalImports?: Imports,
): RemoveElementResult {
const staticTarget = EP.dynamicPathToStaticPath(target)
let resultImports = imports ?? emptyImports()
let resultImports = originalImports ?? emptyImports()
if (staticTarget == null) {
return { components, imports: resultImports }
} else {
const element = findJSXElementAtStaticPath(components, staticTarget)
const resultComponents = removeJSXElementChild(staticTarget, components)
if (element != null) {
const removedElement = findJSXElementAtStaticPath(components, staticTarget)
const remainingComponents = removeJSXElementChild(staticTarget, components)
if (removedElement != null) {
resultImports =
imports != null ? removeUnusedImports(element, resultComponents, imports) : emptyImports()
originalImports != null
? removeUnusedImports(removedElement, remainingComponents, originalImports)
: emptyImports()
}
return {
components: resultComponents,
components: remainingComponents,
imports: resultImports,
}
}
Expand Down

0 comments on commit 34974fd

Please sign in to comment.