Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: incorrect location for { #await expr then v } with spaces #438

Merged
merged 2 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
}
]