Skip to content

Commit 79b22e6

Browse files
committed
Revert "fix: update svelte to 5.0.0-next.181 and fix for {:else if}"
This reverts commit 01f0ed5.
1 parent 19e0099 commit 79b22e6

18 files changed

+68
-174
lines changed

package.json

+12-12
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"version:ci": "env-cmd -e version-ci pnpm run build:meta && changeset version"
4848
},
4949
"peerDependencies": {
50-
"svelte": "^3.37.0 || ^4.0.0 || ^5.0.0-next.181"
50+
"svelte": "^3.37.0 || ^4.0.0 || ^5.0.0-next.115"
5151
},
5252
"peerDependenciesMeta": {
5353
"svelte": {
@@ -58,22 +58,22 @@
5858
"eslint-scope": "^7.2.2",
5959
"eslint-visitor-keys": "^3.4.3",
6060
"espree": "^9.6.1",
61-
"postcss": "^8.4.39",
61+
"postcss": "^8.4.38",
6262
"postcss-scss": "^4.0.9"
6363
},
6464
"devDependencies": {
6565
"@changesets/changelog-github": "^0.5.0",
66-
"@changesets/cli": "^2.27.7",
67-
"@changesets/get-release-plan": "^4.0.3",
66+
"@changesets/cli": "^2.27.5",
67+
"@changesets/get-release-plan": "^4.0.2",
6868
"@ota-meshi/eslint-plugin": "^0.15.3",
6969
"@types/benchmark": "^2.1.5",
7070
"@types/chai": "^4.3.16",
7171
"@types/eslint": "^8.56.10",
7272
"@types/eslint-scope": "^3.7.7",
7373
"@types/eslint-visitor-keys": "^3.3.0",
7474
"@types/estree": "^1.0.5",
75-
"@types/mocha": "^10.0.7",
76-
"@types/node": "^20.14.10",
75+
"@types/mocha": "^10.0.6",
76+
"@types/node": "^20.14.4",
7777
"@types/semver": "^7.5.8",
7878
"@typescript-eslint/eslint-plugin": "^7.16.0",
7979
"@typescript-eslint/parser": "~7.16.0",
@@ -86,28 +86,28 @@
8686
"eslint": "^8.57.0",
8787
"eslint-config-prettier": "^9.1.0",
8888
"eslint-plugin-eslint-comments": "^3.2.0",
89-
"eslint-plugin-json-schema-validator": "^5.1.2",
89+
"eslint-plugin-json-schema-validator": "^5.1.0",
9090
"eslint-plugin-jsonc": "^2.16.0",
9191
"eslint-plugin-n": "^17.9.0",
9292
"eslint-plugin-node-dependencies": "^0.12.0",
9393
"eslint-plugin-prettier": "^5.1.3",
9494
"eslint-plugin-regexp": "^2.6.0",
95-
"eslint-plugin-svelte": "^2.41.0",
95+
"eslint-plugin-svelte": "^2.40.0",
9696
"eslint-plugin-yml": "^1.14.0",
9797
"estree-walker": "^3.0.3",
9898
"locate-character": "^3.0.0",
9999
"magic-string": "^0.30.10",
100-
"mocha": "^10.6.0",
100+
"mocha": "^10.4.0",
101101
"mocha-chai-jest-snapshot": "^1.1.4",
102102
"nyc": "^17.0.0",
103103
"prettier": "~3.3.2",
104104
"prettier-plugin-pkg": "^0.18.1",
105105
"prettier-plugin-svelte": "^3.2.5",
106106
"rimraf": "^6.0.0",
107107
"semver": "^7.6.2",
108-
"svelte": "^5.0.0-next.181",
109-
"svelte2tsx": "^0.7.13",
110-
"typescript": "~5.5.3",
108+
"svelte": "^5.0.0-next.158",
109+
"svelte2tsx": "^0.7.10",
110+
"typescript": "~5.5.0",
111111
"typescript-eslint-parser-for-extra-files": "^0.7.0"
112112
},
113113
"publishConfig": {

src/context/index.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type {
1212
} from "../ast";
1313
import type ESTree from "estree";
1414
import type * as SvAST from "../parser/svelte-ast-types";
15-
import type * as Compiler from "../parser/svelte-ast-types-for-v5";
15+
import type * as Compiler from "svelte/compiler";
1616
import { ScriptLetContext } from "./script-let";
1717
import { LetDirectiveCollections } from "./let-directive-collection";
1818
import { parseAttributes } from "../parser/html";
@@ -169,7 +169,19 @@ export class Context {
169169
| SvAST.SlotTemplate
170170
| SvAST.Slot
171171
| SvAST.Title
172-
| Compiler.ElementLike
172+
| Compiler.RegularElement
173+
| Compiler.Component
174+
| Compiler.SvelteComponent
175+
| Compiler.SvelteElement
176+
| Compiler.SvelteWindow
177+
| Compiler.SvelteBody
178+
| Compiler.SvelteHead
179+
| Compiler.SvelteDocument
180+
| Compiler.SvelteFragment
181+
| Compiler.SvelteSelf
182+
| Compiler.SvelteOptionsRaw
183+
| Compiler.SlotElement
184+
| Compiler.TitleElement
173185
>();
174186

175187
public readonly snippets: SvelteSnippetBlock[] = [];

src/parser/compat.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** Compatibility for Svelte v4 <-> v5 */
22
import type ESTree from "estree";
33
import type * as SvAST from "./svelte-ast-types";
4-
import type * as Compiler from "./svelte-ast-types-for-v5";
4+
import type * as Compiler from "svelte/compiler";
55

66
export type Child =
77
| Compiler.Text

src/parser/converts/attr.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import type {
2424
import type ESTree from "estree";
2525
import type { Context } from "../../context";
2626
import type * as SvAST from "../svelte-ast-types";
27-
import type * as Compiler from "../svelte-ast-types-for-v5";
27+
import type * as Compiler from "svelte/compiler";
2828
import { getWithLoc, indexOf } from "./common";
2929
import { convertMustacheTag } from "./mustache";
3030
import { convertTextToLiteral } from "./text";

src/parser/converts/block.ts

+16-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type * as SvAST from "../svelte-ast-types";
2-
import type * as Compiler from "../svelte-ast-types-for-v5";
2+
import type * as Compiler from "svelte/compiler";
33
import type {
44
SvelteAwaitBlock,
55
SvelteAwaitBlockAwaitCatch,
@@ -114,21 +114,20 @@ export function convertIfBlock(
114114
node: SvAST.IfBlock | Compiler.IfBlock,
115115
parent: SvelteIfBlock["parent"],
116116
ctx: Context,
117-
elseifContext?: { start: number },
117+
elseif: true,
118118
): SvelteIfBlockElseIf;
119119
/** Convert for IfBlock */
120120
export function convertIfBlock(
121121
node: SvAST.IfBlock | Compiler.IfBlock,
122122
parent: SvelteIfBlock["parent"],
123123
ctx: Context,
124-
elseifContext?: { start: number },
124+
elseif?: true,
125125
): SvelteIfBlock {
126126
// {#if expr} {:else} {/if}
127127
// {:else if expr} {/if}
128-
const elseif = Boolean(elseifContext);
129128
const nodeStart = startBlockIndex(
130129
ctx.code,
131-
elseifContext?.start ?? node.start,
130+
elseif ? node.start - 1 : node.start,
132131
elseif ? ":else" : "#if",
133132
);
134133
const ifBlock: SvelteIfBlock = {
@@ -189,9 +188,7 @@ export function convertIfBlock(
189188
};
190189
ifBlock.else = elseBlock;
191190

192-
const elseIfBlock = convertIfBlock(c, elseBlock, ctx, {
193-
start: elseStart,
194-
});
191+
const elseIfBlock = convertIfBlock(c, elseBlock, ctx, true);
195192
// adjust loc
196193
elseBlock.range[1] = elseIfBlock.range[1];
197194
elseBlock.loc.end = {
@@ -241,21 +238,22 @@ function startBlockIndexForElse(
241238
lastExpression: ESTree.Node | { start: number; end: number },
242239
ctx: Context,
243240
) {
241+
let baseStart: number;
244242
const elseChildren = getChildren(elseFragment);
245243
if (elseChildren.length > 0) {
246244
const c = elseChildren[0];
245+
baseStart = c.start;
247246
if (c.type === "IfBlock" && c.elseif) {
248-
const contentStart = getWithLoc(getTestFromIfBlock(c)).start;
249-
if (contentStart <= c.start) {
250-
return startBlockIndex(ctx.code, contentStart - 1, ":else");
251-
}
247+
baseStart = Math.min(baseStart, getWithLoc(getTestFromIfBlock(c)).start);
252248
}
253-
return startBlockIndex(ctx.code, c.start, ":else");
249+
} else {
250+
const beforeEnd = endIndexFromFragment(beforeFragment, () => {
251+
return ctx.code.indexOf("}", getWithLoc(lastExpression).end) + 1;
252+
});
253+
baseStart = beforeEnd + 1;
254254
}
255-
const beforeEnd = endIndexFromFragment(beforeFragment, () => {
256-
return ctx.code.indexOf("}", getWithLoc(lastExpression).end) + 1;
257-
});
258-
return startBlockIndex(ctx.code, beforeEnd, ":else");
255+
256+
return startBlockIndex(ctx.code, baseStart - 1, ":else");
259257
}
260258

261259
/** Convert for EachBlock */
@@ -708,7 +706,7 @@ function extractMustacheBlockTokens(
708706
| SvelteKeyBlock
709707
| SvelteSnippetBlock,
710708
ctx: Context,
711-
option?: { startOnly?: boolean },
709+
option?: { startOnly?: true },
712710
) {
713711
const startSectionNameStart = indexOf(
714712
ctx.code,

src/parser/converts/const.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { SvelteConstTag } from "../../ast";
22
import type { Context } from "../../context";
33
import { getDeclaratorFromConstTag } from "../compat";
44
import type * as SvAST from "../svelte-ast-types";
5-
import type * as Compiler from "../svelte-ast-types-for-v5";
5+
import type * as Compiler from "svelte/compiler";
66

77
/** Convert for ConstTag */
88
export function convertConstTag(

src/parser/converts/element.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import type {
3030
import type ESTree from "estree";
3131
import type { Context } from "../../context";
3232
import type * as SvAST from "../svelte-ast-types";
33-
import type * as Compiler from "../svelte-ast-types-for-v5";
33+
import type * as Compiler from "svelte/compiler";
3434

3535
import {
3636
convertAwaitBlock,

src/parser/converts/mustache.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
import type { Context } from "../../context";
88
import type * as SvAST from "../svelte-ast-types";
99
import { hasTypeInfo } from "../../utils";
10-
import type * as Compiler from "../svelte-ast-types-for-v5";
10+
import type * as Compiler from "svelte/compiler";
1111

1212
/** Convert for MustacheTag */
1313
export function convertMustacheTag(

src/parser/converts/render.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type * as ESTree from "estree";
22
import type { SvelteRenderTag } from "../../ast";
33
import type { Context } from "../../context";
44
import { getWithLoc } from "./common";
5-
import type * as Compiler from "../svelte-ast-types-for-v5";
5+
import type * as Compiler from "svelte/compiler";
66

77
/** Convert for RenderTag */
88
export function convertRenderTag(

src/parser/converts/root.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type * as SvAST from "../svelte-ast-types";
2-
import type * as Compiler from "../svelte-ast-types-for-v5";
2+
import type * as Compiler from "svelte/compiler";
33
import type {
44
SvelteAttribute,
55
SvelteGenericsDirective,

src/parser/html.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type * as Compiler from "./svelte-ast-types-for-v5";
1+
import type * as Compiler from "svelte/compiler";
22
import type ESTree from "estree";
33
import { getEspree } from "./espree";
44

src/parser/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type { ScopeManager } from "eslint-scope";
1212
import { Variable } from "eslint-scope";
1313
import { parseScript, parseScriptInSvelte } from "./script";
1414
import type * as SvAST from "./svelte-ast-types";
15-
import type * as Compiler from "./svelte-ast-types-for-v5";
15+
import type * as Compiler from "svelte/compiler";
1616
import { sortNodes } from "./sort";
1717
import { parseTemplate } from "./template";
1818
import {

src/parser/svelte-ast-types-for-v5.ts

-116
This file was deleted.

src/parser/svelte-parse-context.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type * as Compiler from "./svelte-ast-types-for-v5";
1+
import type * as Compiler from "svelte/compiler";
22
import type * as SvAST from "./svelte-ast-types";
33
import type { NormalizedParserOptions } from "./parser-options";
44
import { compilerVersion, svelteVersion } from "./svelte-version";

src/parser/template.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type {} from "svelte"; // FIXME: Workaround to get type information for "svelte/compiler"
22
import { parse } from "svelte/compiler";
3-
import type * as Compiler from "./svelte-ast-types-for-v5";
3+
import type * as Compiler from "svelte/compiler";
44
import type * as SvAST from "./svelte-ast-types";
55
import type { Context } from "../context";
66
import { convertSvelteRoot } from "./converts/index";

0 commit comments

Comments
 (0)