Skip to content

Commit

Permalink
fix: incorrect location for { #await expr then v } with spaces (#438)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Nov 22, 2023
1 parent 3dfc12e commit c21b54c
Show file tree
Hide file tree
Showing 6 changed files with 17,165 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/tasty-ants-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte-eslint-parser": patch
---

fix: incorrect location for `{ #await expr then v }` with spaces
4 changes: 2 additions & 2 deletions src/parser/converts/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export function convertAwaitBlock(
(awaitBlock as SvelteAwaitBlockAwaitThen).kind = "await-then";
}

const thenStart = awaitBlock.pending ? node.then.start : node.start;
const thenStart = awaitBlock.pending ? node.then.start : nodeStart;
const thenBlock: SvelteAwaitThenBlock = {
type: "SvelteAwaitThenBlock",
awaitThen,
Expand Down Expand Up @@ -374,7 +374,7 @@ export function convertAwaitBlock(
(awaitBlock as SvelteAwaitBlockAwaitCatch).kind = "await-catch";
}
const catchStart =
awaitBlock.pending || awaitBlock.then ? node.catch.start : node.start;
awaitBlock.pending || awaitBlock.then ? node.catch.start : nodeStart;
const catchBlock = {
type: "SvelteAwaitCatchBlock",
awaitCatch,
Expand Down
46 changes: 46 additions & 0 deletions tests/fixtures/parser/ast/space-in-blocks-input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<script>
const foo = 'foo';
let text = '';
let value = '';
let input;
const myClass = 'my-class';
const id = 'id';
const attrs = {};
const bar = '<div></div>';
const o1 = 1,
o2 = 2;
const expression = true;
const list = [];
</script>

<!-- prettier-ignore -->
<div>
{ foo }
<input bind:value={ text } this={ input } class="foo { myClass }" />
<input bind:value { id } />
<input { ...attrs } />
{ @html bar }
{ @debug o1 }
{ @debug o1, o2 }

{ #if expression }...{ /if }
{ #if expression }...{ :else if expression }...{ /if }
{ #if expression }...{ :else }...{ /if }
{ #if expression }{ :else }{ /if }

{ #each list as item }...{ /each }
{ #each list as item, index }...{ /each }
{ #each list as item (item.key) }...{ /each }
{ #each list as item, index (item.key) }...{ /each }
{ #each list as item }...{ :else }...{ /each }

{ #await expression }...{ :then name }...{ :catch name }...{ /await }
{ #await expression }...{ :then name }...{ /await }
{ #await expression then name }...{ /await }
{ #await expression catch name }...{ /await }
{ #await expression then }...{ /await }
{ #await expression catch }...{ /await }
{ #await expression }...{ :then}...{ :catch}...{ /await }

{ #key expression }...{ /key }
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[
{
"ruleId": "no-unused-vars",
"code": "item",
"line": 31,
"column": 17
},
{
"ruleId": "no-unused-vars",
"code": "item",
"line": 32,
"column": 17
},
{
"ruleId": "no-unused-vars",
"code": "index",
"line": 32,
"column": 23
},
{
"ruleId": "no-unused-vars",
"code": "index",
"line": 34,
"column": 23
},
{
"ruleId": "no-unused-vars",
"code": "item",
"line": 35,
"column": 17
},
{
"ruleId": "no-unused-vars",
"code": "name",
"line": 37,
"column": 33
},
{
"ruleId": "no-unused-vars",
"code": "name",
"line": 37,
"column": 51
},
{
"ruleId": "no-unused-vars",
"code": "name",
"line": 38,
"column": 33
},
{
"ruleId": "no-unused-vars",
"code": "name",
"line": 39,
"column": 26
},
{
"ruleId": "no-unused-vars",
"code": "name",
"line": 40,
"column": 27
}
]

0 comments on commit c21b54c

Please sign in to comment.