feat: current tests pass; I'm sure I'm missing stuff for new things

pull/10320/head
S. Elliott Johnson 2 years ago
parent 5beaf36d35
commit 33a39bf85e

@ -298,7 +298,8 @@ function open(parser) {
throw new Error();
}
parser.eat(raw_snippet_declaration);
// slice the `{#` off the beginning since it's already been eaten
parser.eat(raw_snippet_declaration.slice(2), true);
const block = parser.append(
/** @type {Omit<import('#compiler').SnippetBlock, 'parent'>} */

@ -1755,9 +1755,17 @@ export const template_visitors = {
/** @type {import('estree').Expression[]} */
const args = [context.state.node];
node.arguments.forEach((arg) =>
args.push(b.thunk(/** @type {import('estree').Expression} */ (context.visit(arg))))
);
node.arguments.forEach((arg) => {
if (arg.type === 'SpreadElement') {
// this is a spread operation, meaning we need to thunkify all of its members
args.push(
/** @type {import('estree').Expression} */ (
context.visit(b.spread(b.call('$.shallow_thunk', arg.argument)))
)
);
}
args.push(b.thunk(/** @type {import('estree').Expression} */ (context.visit(arg))));
});
let snippet_function = /** @type {import('estree').Expression} */ (
context.visit(node.expression)

@ -1127,18 +1127,13 @@ const template_visitors = {
const snippet_function = state.options.dev
? b.call('$.validate_snippet', node.expression)
: node.expression;
const snippet_args = node.arguments.map((arg) => {
return /** @type {import('estree').Expression} */ (context.visit(arg));
});
state.template.push(
t_statement(
b.stmt(
b.call(
snippet_function,
b.id('$$payload'),
...node.arguments.map(
(arg) => /** @type {import('estree').Expression} */ (context.visit(arg))
)
)
)
)
t_statement(b.stmt(b.call(snippet_function, b.id('$$payload'), ...snippet_args)))
);
state.template.push(t_expression(anchor_id));

@ -16,3 +16,18 @@ export var get_descriptors = Object.getOwnPropertyDescriptors;
export function is_function(thing) {
return typeof thing === 'function';
}
/**
* TODO: Do the types matter on this? If so, can we improve them so that
* `shallow_thunk(['one', 2])` returns a tuple type instead of a union?
* @template {unknown} T
* @param {Iterable<T>} iterable
* @returns {(() => T)[]}
*/
function shallow_thunk(iterable) {
const thunks = [];
for (const item of iterable) {
thunks.push(() => item);
}
return thunks;
}

Loading…
Cancel
Save