-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat better error message for else,elseif,then,catch with unclosed tag
- Loading branch information
Showing
23 changed files
with
164 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { TemplateNode } from '../../interfaces'; | ||
|
||
export function to_string(node: TemplateNode) { | ||
switch (node.type) { | ||
case 'IfBlock': | ||
return '{#if} block'; | ||
case 'ThenBlock': | ||
return '{:then} block'; | ||
case 'ElseBlock': | ||
return '{:else} block'; | ||
case 'PendingBlock': | ||
case 'AwaitBlock': | ||
return '{#await} block'; | ||
case 'CatchBlock': | ||
return '{:catch} block'; | ||
case 'EachBlock': | ||
return '{#each} block'; | ||
case 'RawMustacheTag': | ||
return '{@html} block'; | ||
case 'DebugTag': | ||
return '{@debug} block'; | ||
case 'Element': | ||
case 'InlineComponent': | ||
case 'Slot': | ||
case 'Title': | ||
return `<${node.name}> tag`; | ||
default: | ||
return node.type; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"code": "unclosed-open-tag", | ||
"message": "Expect to close {#each} block before {:catch} block", | ||
"start": { "line": 3, "column": 9, "character": 44 }, | ||
"pos": 44 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{#await true} | ||
{#each foo as bar} | ||
{:catch f} | ||
{/await} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"code": "unclosed-open-tag", | ||
"message": "Expect to close {#await} block before {:else} block", | ||
"start": { "line": 3, "column": 8, "character": 32 }, | ||
"pos": 32 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{#if true} | ||
{#await p} | ||
{:else} | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"code": "invalid-else-placement", | ||
"message": "Cannot have an {:else} block outside an {#if ...} or {#each ...} block", | ||
"start": { "line": 2, "column": 6, "character": 11 }, | ||
"pos": 11 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<li> | ||
{:else} |
6 changes: 6 additions & 0 deletions
6
test/parser/samples/error-else-before-closing/error-else-before-closing-2/error.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"code": "unclosed-open-tag", | ||
"message": "Expect to close {#await} block before {:else} block", | ||
"start": { "line": 3, "column": 8, "character": 32 }, | ||
"pos": 32 | ||
} |
4 changes: 4 additions & 0 deletions
4
test/parser/samples/error-else-before-closing/error-else-before-closing-2/input.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{#if true} | ||
{#await p} | ||
{:else} | ||
{/if} |
6 changes: 6 additions & 0 deletions
6
test/parser/samples/error-else-before-closing/error-else-before-closing-3/error.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"code": "invalid-else-placement", | ||
"message": "Cannot have an {:else} block outside an {#if ...} or {#each ...} block", | ||
"start": { "line": 2, "column": 6, "character": 11 }, | ||
"pos": 11 | ||
} |
2 changes: 2 additions & 0 deletions
2
test/parser/samples/error-else-before-closing/error-else-before-closing-3/input.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<li> | ||
{:else} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"code": "unclosed-open-tag", | ||
"message": "Expect to close <li> tag before {:else} block", | ||
"start": { "line": 3, "column": 8, "character": 26 }, | ||
"pos": 26 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{#if true} | ||
<li> | ||
{:else} | ||
{/if} |
6 changes: 6 additions & 0 deletions
6
test/parser/samples/error-else-if-before-closing-2/error.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"code": "unclosed-open-tag", | ||
"message": "Expect to close <p> tag before {:else if ...} block", | ||
"start": { "line": 3, "column": 11, "character": 28 }, | ||
"pos": 28 | ||
} |
4 changes: 4 additions & 0 deletions
4
test/parser/samples/error-else-if-before-closing-2/input.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{#if true} | ||
<p> | ||
{:else if false} | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"code": "unclosed-open-tag", | ||
"message": "Expect to close {#await} block before {:else if ...} block", | ||
"start": { "line": 3, "column": 11, "character": 37 }, | ||
"pos": 37 | ||
} |
4 changes: 4 additions & 0 deletions
4
test/parser/samples/error-else-if-before-closing/input.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{#if true} | ||
{#await foo} | ||
{:else if false} | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"code": "invalid-elseif-placement", | ||
"message": "Cannot have an {:else if ...} block outside an {#if ...} block", | ||
"start": { "line": 3, "column": 11, "character": 36 }, | ||
"pos": 36 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{#await foo} | ||
{:then bar} | ||
{:else if} | ||
{/await} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"code": "unclosed-open-tag", | ||
"message": "Expect to close <li> tag before {:then} block", | ||
"start": { "line": 3, "column": 8, "character": 29 }, | ||
"pos": 29 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{#await true} | ||
<li> | ||
{:then f} | ||
{/await} |