Merge branch 'master' into composition

pull/1998/head
Richard Harris 7 years ago
commit 04c7705e51

477
package-lock.json generated

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -240,7 +240,7 @@ export default class Expression {
dependencies.add(name);
component.template_references.add(name);
}
} else if (!is_synthetic && !component.hoistable_names.has(name) && !component.imported_declarations.has(name)) {
} else if (!is_synthetic && isContextual(component, template_scope, name)) {
code.prependRight(node.start, key === 'key' && parent.shorthand
? `${name}: ctx.`
: 'ctx.');
@ -437,3 +437,16 @@ function get_function_name(node, parent) {
return 'func';
}
function isContextual(component: Component, scope: TemplateScope, name: string) {
// if it's a name below root scope, it's contextual
if (!scope.isTopLevel(name)) return true;
// hoistables, module declarations, and imports are non-contextual
if (component.hoistable_names.has(name)) return false;
if (component.module_scope && component.module_scope.declarations.has(name)) return false;
if (component.imported_declarations.has(name)) return false;
// assume contextual
return true;
}

@ -40,4 +40,8 @@ export default class TemplateScope {
if (this.parent) return this.parent.containsMutable(names);
else return false;
}
isTopLevel(name: string) {
return !this.parent || !this.names.has(name) && this.parent.isTopLevel(name);
}
}

@ -1,5 +1,5 @@
import { assign, isPromise } from './utils.js';
import { group_outros } from './transitions.js';
import { check_outros, group_outros, on_outro } from './transitions.js';
import { flush } from '../internal/scheduler.js';
export function handlePromise(promise, info) {
@ -18,10 +18,12 @@ export function handlePromise(promise, info) {
info.blocks.forEach((block, i) => {
if (i !== index && block) {
group_outros();
block.o(() => {
on_outro(() => {
block.d(1);
info.blocks[i] = null;
});
block.o();
check_outros();
}
});
} else {

@ -0,0 +1,5 @@
{value}
<script>
export let value = 'Loading...';
</script>

@ -0,0 +1,29 @@
export default {
async test({ assert, component, target }) {
let resolve, reject;
let promise = new Promise(ok => resolve = ok);
component.promise = promise;
assert.htmlEqual(target.innerHTML, 'Loading...');
resolve(42);
await promise;
assert.htmlEqual(target.innerHTML, '42');
promise = new Promise((ok, fail) => reject = fail);
component.promise = promise;
assert.htmlEqual(target.innerHTML, 'Loading...');
reject(99);
await promise.then(null, () => {});
assert.htmlEqual(target.innerHTML, '99');
promise = new Promise(ok => resolve = ok);
component.promise = promise;
assert.htmlEqual(target.innerHTML, 'Loading...');
resolve(1);
await promise;
assert.htmlEqual(target.innerHTML, '1');
}
};

@ -0,0 +1,12 @@
{#await promise}
<Widget />
{:then result}
<Widget value="{result}" />
{:catch err}
<Widget value="{err}" />
{/await}
<script>
import Widget from './Widget.html';
export let promise = Promise.resolve();
</script>

@ -0,0 +1,3 @@
export default {
html: '(alpaca)(baboon)(capybara)'
};

@ -0,0 +1,8 @@
{#each animals as animal}
({animal})
{/each}
<script>
let animal = 'lemur';
let animals = ['alpaca', 'baboon', 'capybara'];
</script>

@ -0,0 +1,3 @@
export default {
html: `<p>(42)(99)</p>`
};

@ -0,0 +1,9 @@
<script context="module">
const foo = 42;
</script>
<script>
export let bar = 99;
</script>
<p>({foo})({bar})</p>
Loading…
Cancel
Save