diff --git a/package.json b/package.json index 0c4e225d5..d0ea89b7d 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "debug": "^4.3.1", "eslint-utils": "^3.0.0", "sourcemap-codec": "^1.4.8", - "svelte-eslint-parser": "^0.7.0" + "svelte-eslint-parser": "^0.8.0" }, "peerDependencies": { "eslint": "^7.0.0 || ^8.0.0-0", diff --git a/src/rules/indent-helpers/svelte.ts b/src/rules/indent-helpers/svelte.ts index c4dacd4e3..c3868644e 100644 --- a/src/rules/indent-helpers/svelte.ts +++ b/src/rules/indent-helpers/svelte.ts @@ -235,11 +235,7 @@ export function defineVisitor(context: IndentContext): NodeListener { 0, openToken, ) - if ( - node.else.children.length === 1 && - node.else.children[0].type === "SvelteIfBlock" && - node.else.children[0].elseif - ) { + if (node.else.elseif) { // else if return } @@ -254,11 +250,7 @@ export function defineVisitor(context: IndentContext): NodeListener { offsets.setOffsetToken(closeCloseTagToken, 0, openCloseTagToken) }, SvelteElseBlock(node: AST.SvelteElseBlock) { - if ( - node.children.length === 1 && - node.children[0].type === "SvelteIfBlock" && - node.children[0].elseif - ) { + if (node.elseif) { return } const [openToken, elseToken, closeToken] = sourceCode.getFirstTokens( @@ -351,7 +343,7 @@ export function defineVisitor(context: IndentContext): NodeListener { } if (node.then) { - if (!node.pending) { + if (node.kind === "await-then") { // {#await expression then value} const thenToken = sourceCode.getTokenAfter(exp.lastToken)! offsets.setOffsetToken(thenToken, 1, openToken) @@ -376,7 +368,7 @@ export function defineVisitor(context: IndentContext): NodeListener { } } if (node.catch) { - if (!node.pending && !node.then) { + if (node.kind === "await-catch") { // {#await expression catch error} const catchToken = sourceCode.getTokenAfter(exp.lastToken)! offsets.setOffsetToken(catchToken, 1, openToken) @@ -421,8 +413,7 @@ export function defineVisitor(context: IndentContext): NodeListener { } }, SvelteAwaitThenBlock(node: AST.SvelteAwaitThenBlock) { - const parent = node.parent - if (parent.pending) { + if (!node.awaitThen) { // {:then value} const [openToken, thenToken] = sourceCode.getFirstTokens(node, { count: 2, @@ -449,8 +440,7 @@ export function defineVisitor(context: IndentContext): NodeListener { } }, SvelteAwaitCatchBlock(node: AST.SvelteAwaitCatchBlock) { - const parent = node.parent - if (parent.pending || parent.then) { + if (!node.awaitCatch) { // {:catch error} const [openToken, catchToken] = sourceCode.getFirstTokens(node, { count: 2, diff --git a/src/rules/mustache-spacing.ts b/src/rules/mustache-spacing.ts index eacf1569b..999d970f8 100644 --- a/src/rules/mustache-spacing.ts +++ b/src/rules/mustache-spacing.ts @@ -256,11 +256,7 @@ export default createRule("mustache-spacing", { ) }, SvelteElseBlock(node) { - if ( - node.children.length === 1 && - node.children[0].type === "SvelteIfBlock" && - node.children[0].elseif - ) { + if (node.elseif) { return } const openToken = sourceCode.getFirstToken(node) @@ -377,7 +373,7 @@ export default createRule("mustache-spacing", { SvelteAwaitThenBlock(node) { const openBlockOpeningToken = sourceCode.getFirstToken(node) const openBlockLast = - node.value || (node.parent.pending ? null : node.parent.expression) + node.value || (node.awaitThen ? node.parent.expression : null) const openBlockClosingToken = openBlockLast ? sourceCode.getTokenAfter(openBlockLast, { includeComments: false, @@ -399,10 +395,7 @@ export default createRule("mustache-spacing", { SvelteAwaitCatchBlock(node) { const openBlockOpeningToken = sourceCode.getFirstToken(node) const openBlockLast = - node.error || - (node.parent.pending || node.parent.then - ? null - : node.parent.expression) + node.error || (node.awaitCatch ? node.parent.expression : null) const openBlockClosingToken = openBlockLast ? sourceCode.getTokenAfter(openBlockLast, { includeComments: false, diff --git a/src/rules/no-dupe-else-if-blocks.ts b/src/rules/no-dupe-else-if-blocks.ts index ca1015a46..e3e93a164 100644 --- a/src/rules/no-dupe-else-if-blocks.ts +++ b/src/rules/no-dupe-else-if-blocks.ts @@ -131,7 +131,9 @@ export default createRule("no-dupe-else-if-blocks", { let target = node while ( target.parent.type === "SvelteElseBlock" && - target.parent.children.includes(target) && + ( + target.parent.children as AST.SvelteElseBlock["children"][number][] + ).includes(target) && target.parent.parent.type === "SvelteIfBlock" ) { yield target.parent.parent