Merge pull request #2596 from EmilTholin/await-empty-block-warnings

Don't show 'Empty block' warnings for non-existent await branches
pull/2675/head
Rich Harris 5 years ago committed by GitHub
commit 006509a0ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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();
}
}
}
}

@ -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();
}
}
}
}

@ -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();
}
}
}
}

@ -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
},
} :
{
@ -303,7 +308,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);
}

@ -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
}
}

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

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