Skip to content

Commit cb6cccc

Browse files
committed
WIP: Support for Svelte v5
1 parent d3047a4 commit cb6cccc

File tree

16 files changed

+429
-48
lines changed

16 files changed

+429
-48
lines changed

.github/workflows/NodeCI.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,26 @@ jobs:
3535
run: pnpm install
3636
- name: Test
3737
run: pnpm run test
38+
test-for-svelte-v4:
39+
runs-on: ubuntu-latest
40+
strategy:
41+
matrix:
42+
node-version: [14.x]
43+
steps:
44+
- uses: actions/checkout@v4
45+
- uses: pnpm/action-setup@v2
46+
- name: Use Node.js ${{ matrix.node-version }}
47+
uses: actions/setup-node@v4
48+
with:
49+
node-version: ${{ matrix.node-version }}
50+
- name: Install Svelte v4
51+
run: |+
52+
pnpm install -D svelte@4
53+
rm -rf node_modules
54+
- name: Install Packages
55+
run: pnpm install
56+
- name: Test
57+
run: pnpm run test
3858
test-for-svelte-v3:
3959
runs-on: ubuntu-latest
4060
strategy:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
"prettier-plugin-svelte": "^3.0.0",
104104
"rimraf": "^5.0.1",
105105
"semver": "^7.5.1",
106-
"svelte": "^4.2.0",
106+
"svelte": "^5.0.0-0",
107107
"svelte2tsx": "^0.6.20",
108108
"typescript": "~5.1.3",
109109
"typescript-eslint-parser-for-extra-files": "^0.5.0"

src/parser/converts/element.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import { ParseError } from "../..";
5252
/** Convert for Fragment or Element or ... */
5353
export function* convertChildren(
5454
/* eslint-enable complexity -- X */
55-
fragment: { children: SvAST.TemplateNode[] },
55+
fragment: { children?: SvAST.TemplateNode[] },
5656
parent:
5757
| SvelteProgram
5858
| SvelteElement
@@ -76,6 +76,7 @@ export function* convertChildren(
7676
| SvelteKeyBlock
7777
| SvelteHTMLComment
7878
> {
79+
if (!fragment.children) return;
7980
for (const child of fragment.children) {
8081
if (child.type === "Comment") {
8182
yield convertComment(child, parent, ctx);
@@ -199,8 +200,9 @@ function extractLetDirectives(fragment: {
199200

200201
/** Check if children needs a scope. */
201202
function needScopeByChildren(fragment: {
202-
children: SvAST.TemplateNode[];
203+
children?: SvAST.TemplateNode[];
203204
}): boolean {
205+
if (!fragment.children) return false;
204206
for (const child of fragment.children) {
205207
if (child.type === "ConstTag") {
206208
return true;

src/parser/svelte-ast-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export interface Title extends BaseNode {
162162
export interface Options extends BaseNode {
163163
type: "Options";
164164
name: "svelte:options";
165-
children: TemplateNode[];
165+
children?: TemplateNode[]; // This property does not exist in Svelte v5.
166166
attributes: AttributeOrDirective[];
167167
}
168168
export interface SlotTemplate extends BaseNode {

src/parser/template.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function parseTemplate(
2121
try {
2222
const svelteAst = parse(code, {
2323
filename: parserOptions.filePath,
24-
}) as SvAST.Ast;
24+
}) as never as SvAST.Ast;
2525
const ast = convertSvelteRoot(svelteAst, ctx);
2626
sortNodes(ast.body);
2727

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"TODO": "As of now, Svelte v5 gives an error with single-line await blocks.",
3+
"test": {
4+
"svelte": "^4 || ^3"
5+
}
6+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"test": {
3+
"svelte": "^4 || ^3"
4+
}
5+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<svelte:options tag="my-custom-element"/>
1+
<svelte:options customElement="my-custom-element"/>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<svelte:options tag="my-custom-element"/>

0 commit comments

Comments
 (0)