Svelte/5/Components As Functions Destroyfunction
This codemod updates Svelte component instantiation and event handling for Svelte 5:
- Converts
new Component({ target })
tomount(Component, { target })
. - Replaces
$destroy
method calls withunmount
. - Ensures compatibility with Svelte 5's function-based components and new event handling.
Before
import App from './App.svelte';const app = new App({target: document.getElementById('app'),props: { foo: 'bar' },});app.$destroy();
After
import { unmount } from 'svelte';import { mount } from 'svelte';import App from './App.svelte';const app = mount(App, {target: document.getElementById('app'),props: { foo: 'bar' },});unmount(app);
Build custom codemods
Use AI-powered codemod studio and automate undifferentiated tasks for yourself, colleagues or the community