cut out the middleman

aaa
Rich Harris 8 months ago
parent 074afa9bec
commit ef13cda2ca

@ -14,11 +14,8 @@ export function AwaitExpression(node, context) {
} }
return b.call( return b.call(
b.member(
b.await( b.await(
b.call('$.save', node.argument && /** @type {Expression} */ (context.visit(node.argument))) b.call('$.save', node.argument && /** @type {Expression} */ (context.visit(node.argument)))
),
'restore'
) )
); );
} }

@ -168,7 +168,6 @@ export function VariableDeclaration(node, context) {
b.declarator( b.declarator(
declarator.id, declarator.id,
b.call( b.call(
b.member(
b.await( b.await(
b.call( b.call(
'$.save', '$.save',
@ -177,8 +176,6 @@ export function VariableDeclaration(node, context) {
rune === '$derived.by' ? value : b.thunk(value, true) rune === '$derived.by' ? value : b.thunk(value, true)
) )
) )
),
'restore'
) )
) )
) )

@ -295,17 +295,15 @@ export function suspend() {
/** /**
* @template T * @template T
* @param {Promise<T>} promise * @param {Promise<T>} promise
* @returns {Promise<{ restore: () => T }>} * @returns {Promise<() => T>}
*/ */
export async function save(promise) { export async function save(promise) {
var restore = capture(); var restore = capture();
var value = await promise; var value = await promise;
return { return () => {
restore() {
restore(); restore();
return value; return value;
}
}; };
} }

Loading…
Cancel
Save