Skip to content

Commit 43c8116

Browse files
authored
Upgrade parser and use new properties (#78)
1 parent 8803c3d commit 43c8116

File tree

4 files changed

+13
-28
lines changed

4 files changed

+13
-28
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"debug": "^4.3.1",
5353
"eslint-utils": "^3.0.0",
5454
"sourcemap-codec": "^1.4.8",
55-
"svelte-eslint-parser": "^0.7.0"
55+
"svelte-eslint-parser": "^0.8.0"
5656
},
5757
"peerDependencies": {
5858
"eslint": "^7.0.0 || ^8.0.0-0",

src/rules/indent-helpers/svelte.ts

+6-16
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,7 @@ export function defineVisitor(context: IndentContext): NodeListener {
235235
0,
236236
openToken,
237237
)
238-
if (
239-
node.else.children.length === 1 &&
240-
node.else.children[0].type === "SvelteIfBlock" &&
241-
node.else.children[0].elseif
242-
) {
238+
if (node.else.elseif) {
243239
// else if
244240
return
245241
}
@@ -254,11 +250,7 @@ export function defineVisitor(context: IndentContext): NodeListener {
254250
offsets.setOffsetToken(closeCloseTagToken, 0, openCloseTagToken)
255251
},
256252
SvelteElseBlock(node: AST.SvelteElseBlock) {
257-
if (
258-
node.children.length === 1 &&
259-
node.children[0].type === "SvelteIfBlock" &&
260-
node.children[0].elseif
261-
) {
253+
if (node.elseif) {
262254
return
263255
}
264256
const [openToken, elseToken, closeToken] = sourceCode.getFirstTokens(
@@ -351,7 +343,7 @@ export function defineVisitor(context: IndentContext): NodeListener {
351343
}
352344

353345
if (node.then) {
354-
if (!node.pending) {
346+
if (node.kind === "await-then") {
355347
// {#await expression then value}
356348
const thenToken = sourceCode.getTokenAfter(exp.lastToken)!
357349
offsets.setOffsetToken(thenToken, 1, openToken)
@@ -376,7 +368,7 @@ export function defineVisitor(context: IndentContext): NodeListener {
376368
}
377369
}
378370
if (node.catch) {
379-
if (!node.pending && !node.then) {
371+
if (node.kind === "await-catch") {
380372
// {#await expression catch error}
381373
const catchToken = sourceCode.getTokenAfter(exp.lastToken)!
382374
offsets.setOffsetToken(catchToken, 1, openToken)
@@ -421,8 +413,7 @@ export function defineVisitor(context: IndentContext): NodeListener {
421413
}
422414
},
423415
SvelteAwaitThenBlock(node: AST.SvelteAwaitThenBlock) {
424-
const parent = node.parent
425-
if (parent.pending) {
416+
if (!node.awaitThen) {
426417
// {:then value}
427418
const [openToken, thenToken] = sourceCode.getFirstTokens(node, {
428419
count: 2,
@@ -449,8 +440,7 @@ export function defineVisitor(context: IndentContext): NodeListener {
449440
}
450441
},
451442
SvelteAwaitCatchBlock(node: AST.SvelteAwaitCatchBlock) {
452-
const parent = node.parent
453-
if (parent.pending || parent.then) {
443+
if (!node.awaitCatch) {
454444
// {:catch error}
455445
const [openToken, catchToken] = sourceCode.getFirstTokens(node, {
456446
count: 2,

src/rules/mustache-spacing.ts

+3-10
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,7 @@ export default createRule("mustache-spacing", {
256256
)
257257
},
258258
SvelteElseBlock(node) {
259-
if (
260-
node.children.length === 1 &&
261-
node.children[0].type === "SvelteIfBlock" &&
262-
node.children[0].elseif
263-
) {
259+
if (node.elseif) {
264260
return
265261
}
266262
const openToken = sourceCode.getFirstToken(node)
@@ -377,7 +373,7 @@ export default createRule("mustache-spacing", {
377373
SvelteAwaitThenBlock(node) {
378374
const openBlockOpeningToken = sourceCode.getFirstToken(node)
379375
const openBlockLast =
380-
node.value || (node.parent.pending ? null : node.parent.expression)
376+
node.value || (node.awaitThen ? node.parent.expression : null)
381377
const openBlockClosingToken = openBlockLast
382378
? sourceCode.getTokenAfter(openBlockLast, {
383379
includeComments: false,
@@ -399,10 +395,7 @@ export default createRule("mustache-spacing", {
399395
SvelteAwaitCatchBlock(node) {
400396
const openBlockOpeningToken = sourceCode.getFirstToken(node)
401397
const openBlockLast =
402-
node.error ||
403-
(node.parent.pending || node.parent.then
404-
? null
405-
: node.parent.expression)
398+
node.error || (node.awaitCatch ? node.parent.expression : null)
406399
const openBlockClosingToken = openBlockLast
407400
? sourceCode.getTokenAfter(openBlockLast, {
408401
includeComments: false,

src/rules/no-dupe-else-if-blocks.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ export default createRule("no-dupe-else-if-blocks", {
131131
let target = node
132132
while (
133133
target.parent.type === "SvelteElseBlock" &&
134-
target.parent.children.includes(target) &&
134+
(
135+
target.parent.children as AST.SvelteElseBlock["children"][number][]
136+
).includes(target) &&
135137
target.parent.parent.type === "SvelteIfBlock"
136138
) {
137139
yield target.parent.parent

0 commit comments

Comments
 (0)