disallow binding variables declared in await and catch

pull/4279/head
Tan Li Hau 5 years ago committed by Conduitry
parent 1438994bd4
commit 527ddea289

@ -50,6 +50,13 @@ export default class Binding extends Node {
message: 'Cannot bind to a variable declared with the let: directive'
});
} else if (this.is_contextual) {
if (scope.is_await(name)) {
component.error(this, {
code: 'invalid-binding',
message: 'Cannot bind to a variable declared with {#await ... then} or {:catch} blocks'
});
}
scope.dependencies_for_name.get(name).forEach(name => {
const variable = component.var_lookup.get(name);
if (variable) {

@ -42,4 +42,9 @@ export default class TemplateScope {
const owner = this.get_owner(name);
return owner && (owner.type === 'Element' || owner.type === 'InlineComponent');
}
is_await(name: string) {
const owner = this.get_owner(name);
return owner && (owner.type === 'ThenBlock' || owner.type === 'CatchBlock');
}
}

@ -0,0 +1,9 @@
[
{
"code": "invalid-binding",
"message": "Cannot bind to a variable declared with {#await ... then} or {:catch} blocks",
"pos": 79,
"start": { "line": 6, "column": 9, "character": 79 },
"end": { "line": 6, "column": 27, "character": 97 }
}
]

@ -0,0 +1,7 @@
<script>
let promise = 0;
</script>
{#await promise}
{:catch error}
<input bind:value={error} />
{/await}

@ -0,0 +1,9 @@
[
{
"code": "invalid-binding",
"message": "Cannot bind to a variable declared with {#await ... then} or {:catch} blocks",
"pos": 78,
"start": { "line": 6, "column": 9, "character": 78 },
"end": { "line": 6, "column": 19, "character": 88 }
}
]

@ -0,0 +1,7 @@
<script>
let promise = 0;
</script>
{#await promise}
{:then value}
<input bind:value />
{/await}

@ -0,0 +1,9 @@
[
{
"code": "invalid-binding",
"message": "Cannot bind to a variable declared with {#await ... then} or {:catch} blocks",
"pos": 75,
"start": { "line": 5, "column": 9, "character": 75 },
"end": { "line": 5, "column": 19, "character": 85 }
}
]

@ -0,0 +1,6 @@
<script>
let promise = 0;
</script>
{#await promise then value}
<input bind:value />
{/await}
Loading…
Cancel
Save