-
-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add Sveltekit snippets for Svelte 5 (#2548)
--------- Co-authored-by: Alexandre Oger <[email protected]> Co-authored-by: Simon H <[email protected]>
- Loading branch information
1 parent
156bd7d
commit 02847e0
Showing
11 changed files
with
254 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 20 additions & 11 deletions
31
packages/svelte-vscode/src/sveltekit/generateFiles/templates/error.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,30 @@ | ||
import { GenerateConfig } from '../types'; | ||
import { GenerateConfig, ProjectType, Resource } from '../types'; | ||
|
||
export default async function (config: GenerateConfig) { | ||
const ts = ` | ||
<script lang="ts"> | ||
const defaultScriptTemplate = ` | ||
<script> | ||
import { page } from '$app/stores'; | ||
</script> | ||
<h1>{$page.status}: {$page.error?.message}</h1> | ||
`.trim(); | ||
<h1>{$page.status}: {$page.error.message}</h1> | ||
`; | ||
|
||
const js = ` | ||
<script> | ||
const tsScriptTemplate = ` | ||
<script lang="ts"> | ||
import { page } from '$app/stores'; | ||
</script> | ||
<h1>{$page.status}: {$page.error.message}</h1> | ||
`.trim(); | ||
<h1>{$page.status}: {$page.error?.message}</h1> | ||
`; | ||
|
||
const scriptTemplate: ReadonlyMap<ProjectType, string> = new Map([ | ||
[ProjectType.TS_SV5, tsScriptTemplate], | ||
[ProjectType.TS_SATISFIES_SV5, tsScriptTemplate], | ||
[ProjectType.JS_SV5, defaultScriptTemplate], | ||
[ProjectType.TS, tsScriptTemplate], | ||
[ProjectType.TS_SATISFIES, tsScriptTemplate], | ||
[ProjectType.JS, defaultScriptTemplate] | ||
]); | ||
|
||
return config.type === 'js' ? js : ts; | ||
export default async function (config: GenerateConfig): ReturnType<Resource['generate']> { | ||
return (scriptTemplate.get(config.type) ?? defaultScriptTemplate).trim(); | ||
} |
35 changes: 22 additions & 13 deletions
35
packages/svelte-vscode/src/sveltekit/generateFiles/templates/layout-load.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,37 @@ | ||
import { GenerateConfig } from '../types'; | ||
import { GenerateConfig, ProjectType, Resource } from '../types'; | ||
|
||
export default async function (config: GenerateConfig) { | ||
const ts = ` | ||
const defaultScriptTemplate = ` | ||
/** @type {import('./$types').LayoutLoad} */ | ||
export async function load() { | ||
return {}; | ||
} | ||
`; | ||
|
||
const tsScriptTemplate = ` | ||
import type { LayoutLoad } from './$types'; | ||
export const load: LayoutLoad = async () => { | ||
return {}; | ||
}; | ||
`.trim(); | ||
`; | ||
|
||
const tsSatisfies = ` | ||
const tsSatisfiesScriptTemplate = ` | ||
import type { LayoutLoad } from './$types'; | ||
export const load = (async () => { | ||
return {}; | ||
}) satisfies LayoutLoad; | ||
`.trim(); | ||
`; | ||
|
||
const js = ` | ||
/** @type {import('./$types').LayoutLoad} */ | ||
export async function load() { | ||
return {}; | ||
} | ||
`.trim(); | ||
const scriptTemplate: ReadonlyMap<ProjectType, string> = new Map([ | ||
[ProjectType.TS_SV5, tsScriptTemplate], | ||
[ProjectType.TS_SATISFIES_SV5, tsSatisfiesScriptTemplate], | ||
[ProjectType.JS_SV5, defaultScriptTemplate], | ||
[ProjectType.TS, tsScriptTemplate], | ||
[ProjectType.TS_SATISFIES, tsSatisfiesScriptTemplate], | ||
[ProjectType.JS, defaultScriptTemplate] | ||
]); | ||
|
||
return config.type === 'js' ? js : config.type === 'ts' ? ts : tsSatisfies; | ||
export default async function (config: GenerateConfig): ReturnType<Resource['generate']> { | ||
return (scriptTemplate.get(config.type) ?? defaultScriptTemplate).trim(); | ||
} |
35 changes: 22 additions & 13 deletions
35
packages/svelte-vscode/src/sveltekit/generateFiles/templates/layout-server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,37 @@ | ||
import { GenerateConfig } from '../types'; | ||
import { GenerateConfig, ProjectType, Resource } from '../types'; | ||
|
||
export default async function (config: GenerateConfig) { | ||
const ts = ` | ||
const defaultScriptTemplate = ` | ||
/** @type {import('./$types').LayoutServerLoad} */ | ||
export async function load() { | ||
return {}; | ||
} | ||
`; | ||
|
||
const tsScriptTemplate = ` | ||
import type { LayoutServerLoad } from './$types'; | ||
export const load: LayoutServerLoad = async () => { | ||
return {}; | ||
}; | ||
`.trim(); | ||
`; | ||
|
||
const tsSatisfies = ` | ||
const tsSatisfiesScriptTemplate = ` | ||
import type { LayoutServerLoad } from './$types'; | ||
export const load = (async () => { | ||
return {}; | ||
}) satisfies LayoutServerLoad; | ||
`.trim(); | ||
`; | ||
|
||
const js = ` | ||
/** @type {import('./$types').LayoutServerLoad} */ | ||
export async function load() { | ||
return {}; | ||
} | ||
`.trim(); | ||
const scriptTemplate: ReadonlyMap<ProjectType, string> = new Map([ | ||
[ProjectType.TS_SV5, tsScriptTemplate], | ||
[ProjectType.TS_SATISFIES_SV5, tsSatisfiesScriptTemplate], | ||
[ProjectType.JS_SV5, defaultScriptTemplate], | ||
[ProjectType.TS, tsScriptTemplate], | ||
[ProjectType.TS_SATISFIES, tsSatisfiesScriptTemplate], | ||
[ProjectType.JS, defaultScriptTemplate] | ||
]); | ||
|
||
return config.type === 'js' ? js : config.type === 'ts' ? ts : tsSatisfies; | ||
export default async function (config: GenerateConfig): ReturnType<Resource['generate']> { | ||
return (scriptTemplate.get(config.type) ?? defaultScriptTemplate).trim(); | ||
} |
40 changes: 32 additions & 8 deletions
40
packages/svelte-vscode/src/sveltekit/generateFiles/templates/layout.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,44 @@ | ||
import { GenerateConfig } from '../types'; | ||
import { GenerateConfig, ProjectType, Resource } from '../types'; | ||
|
||
export default async function (config: GenerateConfig) { | ||
const ts = ` | ||
const defaultScriptTemplate = ` | ||
<script> | ||
/** @type {import('./$types').LayoutData} */ | ||
export let data; | ||
</script> | ||
`; | ||
|
||
const tsSv5ScriptTemplate = ` | ||
<script lang="ts"> | ||
import type { LayoutData } from './$types'; | ||
let { data }: LayoutData = $props(); | ||
</script> | ||
`; | ||
|
||
const tsScriptTemplate = ` | ||
<script lang="ts"> | ||
import type { LayoutData } from './$types'; | ||
export let data: LayoutData; | ||
</script> | ||
`.trim(); | ||
`; | ||
|
||
const js = ` | ||
const jsSv5ScriptTemplate = ` | ||
<script> | ||
/** @type {import('./$types').LayoutData} */ | ||
export let data; | ||
let { data } = $props(); | ||
</script> | ||
`.trim(); | ||
`; | ||
|
||
const scriptTemplate: ReadonlyMap<ProjectType, string> = new Map([ | ||
[ProjectType.TS_SV5, tsSv5ScriptTemplate], | ||
[ProjectType.TS_SATISFIES_SV5, tsSv5ScriptTemplate], | ||
[ProjectType.JS_SV5, jsSv5ScriptTemplate], | ||
[ProjectType.TS, tsScriptTemplate], | ||
[ProjectType.TS_SATISFIES, tsScriptTemplate], | ||
[ProjectType.JS, defaultScriptTemplate] | ||
]); | ||
|
||
return config.type === 'js' ? js : ts; | ||
export default async function (config: GenerateConfig): ReturnType<Resource['generate']> { | ||
return (scriptTemplate.get(config.type) ?? defaultScriptTemplate).trim(); | ||
} |
35 changes: 22 additions & 13 deletions
35
packages/svelte-vscode/src/sveltekit/generateFiles/templates/page-load.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,37 @@ | ||
import { GenerateConfig } from '../types'; | ||
import { GenerateConfig, ProjectType, Resource } from '../types'; | ||
|
||
export default async function (config: GenerateConfig) { | ||
const ts = ` | ||
const defaultScriptTemplate = ` | ||
/** @type {import('./$types').PageLoad} */ | ||
export async function load() { | ||
return {}; | ||
}; | ||
`; | ||
|
||
const tsScriptTemplate = ` | ||
import type { PageLoad } from './$types'; | ||
export const load: PageLoad = async () => { | ||
return {}; | ||
}; | ||
`.trim(); | ||
`; | ||
|
||
const tsSatisfies = ` | ||
const tsSatisfiesScriptTemplate = ` | ||
import type { PageLoad } from './$types'; | ||
export const load = (async () => { | ||
return {}; | ||
}) satisfies PageLoad; | ||
`.trim(); | ||
`; | ||
|
||
const js = ` | ||
/** @type {import('./$types').PageLoad} */ | ||
export async function load() { | ||
return {}; | ||
}; | ||
`.trim(); | ||
const scriptTemplate: ReadonlyMap<ProjectType, string> = new Map([ | ||
[ProjectType.TS_SV5, tsScriptTemplate], | ||
[ProjectType.TS_SATISFIES_SV5, tsSatisfiesScriptTemplate], | ||
[ProjectType.JS_SV5, defaultScriptTemplate], | ||
[ProjectType.TS, tsScriptTemplate], | ||
[ProjectType.TS_SATISFIES, tsSatisfiesScriptTemplate], | ||
[ProjectType.JS, defaultScriptTemplate] | ||
]); | ||
|
||
return config.type === 'js' ? js : config.type === 'ts' ? ts : tsSatisfies; | ||
export default async function (config: GenerateConfig): ReturnType<Resource['generate']> { | ||
return (scriptTemplate.get(config.type) ?? defaultScriptTemplate).trim(); | ||
} |
35 changes: 22 additions & 13 deletions
35
packages/svelte-vscode/src/sveltekit/generateFiles/templates/page-server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,37 @@ | ||
import { GenerateConfig } from '../types'; | ||
import { GenerateConfig, ProjectType, Resource } from '../types'; | ||
|
||
export default async function (config: GenerateConfig) { | ||
const ts = ` | ||
const defaultScriptTemplate = ` | ||
/** @type {import('./$types').PageServerLoad} */ | ||
export async function load() { | ||
return {}; | ||
}; | ||
`; | ||
|
||
const tsScriptTemplate = ` | ||
import type { PageServerLoad } from './$types'; | ||
export const load: PageServerLoad = async () => { | ||
return {}; | ||
}; | ||
`.trim(); | ||
`; | ||
|
||
const tsSatisfies = ` | ||
const tsSatisfiesScriptTemplate = ` | ||
import type { PageServerLoad } from './$types'; | ||
export const load = (async () => { | ||
return {}; | ||
}) satisfies PageServerLoad; | ||
`.trim(); | ||
`; | ||
|
||
const js = ` | ||
/** @type {import('./$types').PageServerLoad} */ | ||
export async function load() { | ||
return {}; | ||
}; | ||
`.trim(); | ||
const scriptTemplate: ReadonlyMap<ProjectType, string> = new Map([ | ||
[ProjectType.TS_SV5, tsScriptTemplate], | ||
[ProjectType.TS_SATISFIES_SV5, tsSatisfiesScriptTemplate], | ||
[ProjectType.JS_SV5, defaultScriptTemplate], | ||
[ProjectType.TS, tsScriptTemplate], | ||
[ProjectType.TS_SATISFIES, tsSatisfiesScriptTemplate], | ||
[ProjectType.JS, defaultScriptTemplate] | ||
]); | ||
|
||
return config.type === 'js' ? js : config.type === 'ts' ? ts : tsSatisfies; | ||
export default async function (config: GenerateConfig): ReturnType<Resource['generate']> { | ||
return (scriptTemplate.get(config.type) ?? defaultScriptTemplate).trim(); | ||
} |
40 changes: 32 additions & 8 deletions
40
packages/svelte-vscode/src/sveltekit/generateFiles/templates/page.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,44 @@ | ||
import { GenerateConfig } from '../types'; | ||
import { GenerateConfig, ProjectType, Resource } from '../types'; | ||
|
||
export default async function (config: GenerateConfig) { | ||
const ts = ` | ||
const defaultScriptTemplate = ` | ||
<script> | ||
/** @type {import('./$types').PageData} */ | ||
export let data; | ||
</script> | ||
`; | ||
|
||
const tsSv5ScriptTemplate = ` | ||
<script lang="ts"> | ||
import type { PageData } from './$types'; | ||
let { data }: PageData = $props(); | ||
</script> | ||
`; | ||
|
||
const tsScriptTemplate = ` | ||
<script lang="ts"> | ||
import type { PageData } from './$types'; | ||
export let data: PageData; | ||
</script> | ||
`.trim(); | ||
`; | ||
|
||
const js = ` | ||
const jsSv5ScriptTemplate = ` | ||
<script> | ||
/** @type {import('./$types').PageData} */ | ||
export let data; | ||
let { data } = $props(); | ||
</script> | ||
`.trim(); | ||
`; | ||
|
||
const scriptTemplate: ReadonlyMap<ProjectType, string> = new Map([ | ||
[ProjectType.TS_SV5, tsSv5ScriptTemplate], | ||
[ProjectType.TS_SATISFIES_SV5, tsSv5ScriptTemplate], | ||
[ProjectType.JS_SV5, jsSv5ScriptTemplate], | ||
[ProjectType.TS, tsScriptTemplate], | ||
[ProjectType.TS_SATISFIES, tsScriptTemplate], | ||
[ProjectType.JS, defaultScriptTemplate] | ||
]); | ||
|
||
return config.type === 'js' ? js : ts; | ||
export default async function (config: GenerateConfig): ReturnType<Resource['generate']> { | ||
return (scriptTemplate.get(config.type) ?? defaultScriptTemplate).trim(); | ||
} |
Oops, something went wrong.