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.scope.add(parent.error, parent.expression.dependencies, this);
this.children = map_children(component, parent, this.scope, info.children); 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); super(component, parent, scope, info);
this.children = map_children(component, parent, scope, info.children); 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.scope.add(parent.value, parent.expression.dependencies, this);
this.children = map_children(component, parent, this.scope, info.children); 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, start,
end: null, end: null,
type: 'ThenBlock', type: 'ThenBlock',
children: [] children: [],
skip: false
}; };
await_block.then = then_block; await_block.then = then_block;
@ -196,7 +197,8 @@ export default function mustache(parser: Parser) {
start, start,
end: null, end: null,
type: 'CatchBlock', type: 'CatchBlock',
children: [] children: [],
skip: false
}; };
await_block.catch = catch_block; await_block.catch = catch_block;
@ -235,19 +237,22 @@ export default function mustache(parser: Parser) {
start: null, start: null,
end: null, end: null,
type: 'PendingBlock', type: 'PendingBlock',
children: [] children: [],
skip: true
}, },
then: { then: {
start: null, start: null,
end: null, end: null,
type: 'ThenBlock', type: 'ThenBlock',
children: [] children: [],
skip: true
}, },
catch: { catch: {
start: null, start: null,
end: null, end: null,
type: 'CatchBlock', type: 'CatchBlock',
children: [] children: [],
skip: true
}, },
} : } :
{ {
@ -303,7 +308,15 @@ export default function mustache(parser: Parser) {
parser.stack.push(block); parser.stack.push(block);
if (type === 'AwaitBlock') { 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; child_block.start = parser.index;
parser.stack.push(child_block); parser.stack.push(child_block);
} }

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