mirror of https://github.com/sveltejs/svelte
parent
91d758e35b
commit
96156d0f07
@ -0,0 +1,28 @@
|
||||
const SQUARE_BRACKET_OPEN = "[".charCodeAt(0);
|
||||
const SQUARE_BRACKET_CLOSE = "]".charCodeAt(0);
|
||||
const CURLY_BRACKET_OPEN = "{".charCodeAt(0);
|
||||
const CURLY_BRACKET_CLOSE = "}".charCodeAt(0);
|
||||
|
||||
export function is_bracket_open(code) {
|
||||
return code === SQUARE_BRACKET_OPEN || code === CURLY_BRACKET_OPEN;
|
||||
}
|
||||
|
||||
export function is_bracket_close(code) {
|
||||
return code === SQUARE_BRACKET_CLOSE || code === CURLY_BRACKET_CLOSE;
|
||||
}
|
||||
|
||||
export function is_bracket_pair(open, close) {
|
||||
return (
|
||||
(open === SQUARE_BRACKET_OPEN && close === SQUARE_BRACKET_CLOSE) ||
|
||||
(open === CURLY_BRACKET_OPEN && close === CURLY_BRACKET_CLOSE)
|
||||
);
|
||||
}
|
||||
|
||||
export function get_bracket_close(open) {
|
||||
if (open === SQUARE_BRACKET_OPEN) {
|
||||
return SQUARE_BRACKET_CLOSE;
|
||||
}
|
||||
if (open === CURLY_BRACKET_OPEN) {
|
||||
return CURLY_BRACKET_CLOSE;
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
export default {
|
||||
props: {
|
||||
thePromise: new Promise(resolve => {}),
|
||||
},
|
||||
|
||||
html: `
|
||||
loading...
|
||||
`,
|
||||
|
||||
async test({ assert, component, target }) {
|
||||
let promise = Promise.resolve([1, 2]);
|
||||
component.thePromise = promise;
|
||||
|
||||
await promise;
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<p>a: 1</p>
|
||||
<p>b: 2</p>
|
||||
`);
|
||||
|
||||
promise = Promise.resolve([4, 5]);
|
||||
component.thePromise = promise;
|
||||
|
||||
await promise;
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<p>a: 4</p>
|
||||
<p>b: 5</p>
|
||||
`);
|
||||
}
|
||||
};
|
@ -0,0 +1,10 @@
|
||||
<script>
|
||||
export let thePromise;
|
||||
</script>
|
||||
|
||||
{#await thePromise}
|
||||
loading...
|
||||
{:then [ a, b ]}
|
||||
<p>a: {a}</p>
|
||||
<p>b: {b}</p>
|
||||
{/await}
|
@ -0,0 +1,27 @@
|
||||
export default {
|
||||
props: {
|
||||
thePromise: new Promise(resolve => {}),
|
||||
},
|
||||
|
||||
html: `
|
||||
loading...
|
||||
`,
|
||||
|
||||
async test({ assert, component, target }) {
|
||||
let promise = Promise.resolve({ error: 'error message' });
|
||||
component.thePromise = promise;
|
||||
|
||||
await promise;
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<p>error: error message</p>
|
||||
`);
|
||||
|
||||
promise = Promise.resolve({ result: '42' });
|
||||
component.thePromise = promise;
|
||||
|
||||
await promise;
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<p>result: 42</p>
|
||||
`);
|
||||
}
|
||||
};
|
@ -0,0 +1,13 @@
|
||||
<script>
|
||||
export let thePromise;
|
||||
</script>
|
||||
|
||||
{#await thePromise}
|
||||
loading...
|
||||
{:then { result, error }}
|
||||
{#if error}
|
||||
<p>error: { error }</p>
|
||||
{:else}
|
||||
<p>result: {result}</p>
|
||||
{/if}
|
||||
{/await}
|
Loading…
Reference in new issue