0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-12-01 01:11:24 +01:00

Don't show 'Empty block' warnings for non-existent await branches

This commit is contained in:
Emil Tholin 2019-04-27 21:35:32 +02:00
parent 93f7ecca1d
commit 7ec1bdb712
9 changed files with 53 additions and 13 deletions

View File

@ -15,6 +15,8 @@ export default class CatchBlock extends Node {
this.scope.add(parent.error, parent.expression.dependencies, this);
this.children = map_children(component, parent, this.scope, info.children);
this.warn_if_empty_block();
if (!info.skip) {
this.warn_if_empty_block();
}
}
}
}

View File

@ -10,6 +10,8 @@ export default class PendingBlock extends Node {
super(component, parent, scope, info);
this.children = map_children(component, parent, scope, info.children);
this.warn_if_empty_block();
if (!info.skip) {
this.warn_if_empty_block();
}
}
}
}

View File

@ -15,6 +15,8 @@ export default class ThenBlock extends Node {
this.scope.add(parent.value, parent.expression.dependencies, this);
this.children = map_children(component, parent, this.scope, info.children);
this.warn_if_empty_block();
if (!info.skip) {
this.warn_if_empty_block();
}
}
}
}

View File

@ -172,7 +172,8 @@ export default function mustache(parser: Parser) {
start,
end: null,
type: 'ThenBlock',
children: []
children: [],
skip: false
};
await_block.then = then_block;
@ -196,7 +197,8 @@ export default function mustache(parser: Parser) {
start,
end: null,
type: 'CatchBlock',
children: []
children: [],
skip: false
};
await_block.catch = catch_block;
@ -235,19 +237,22 @@ export default function mustache(parser: Parser) {
start: null,
end: null,
type: 'PendingBlock',
children: []
children: [],
skip: true
},
then: {
start: null,
end: null,
type: 'ThenBlock',
children: []
children: [],
skip: true
},
catch: {
start: null,
end: null,
type: 'CatchBlock',
children: []
children: [],
skip: true
},
} :
{
@ -310,7 +315,15 @@ export default function mustache(parser: Parser) {
parser.stack.push(block);
if (type === 'AwaitBlock') {
const child_block = await_block_shorthand ? block.then : block.pending;
let child_block;
if (await_block_shorthand) {
block.then.skip = false;
child_block = block.then;
} else {
block.pending.skip = false;
child_block = block.pending;
}
child_block.start = parser.index;
parser.stack.push(child_block);
}

View File

@ -19,6 +19,7 @@
"pending": {
"start": 19,
"end": 39,
"skip": false,
"type": "PendingBlock",
"children": [
{
@ -53,6 +54,7 @@
"then": {
"start": 39,
"end": 88,
"skip": false,
"type": "ThenBlock",
"children": [
{
@ -98,6 +100,7 @@
"catch": {
"start": 88,
"end": 140,
"skip": false,
"type": "CatchBlock",
"children": [
{
@ -158,4 +161,4 @@
"css": null,
"instance": null,
"module": null
}
}

View File

@ -0,0 +1,9 @@
<script>
let promise;
</script>
{#await promise}
<p>Loading</p>
{:then data}
<p>Data: {data}</p>
{/await}

View File

@ -0,0 +1 @@
[]

View File

@ -0,0 +1,7 @@
<script>
let promise;
</script>
{#await promise then data}
<p>Data: {data}</p>
{/await}

View File

@ -0,0 +1 @@
[]