|
|
@ -1755,9 +1755,9 @@ export const template_visitors = {
|
|
|
|
|
|
|
|
|
|
|
|
/** @type {import('estree').Expression[]} */
|
|
|
|
/** @type {import('estree').Expression[]} */
|
|
|
|
const args = [context.state.node];
|
|
|
|
const args = [context.state.node];
|
|
|
|
if (node.argument) {
|
|
|
|
node.arguments.forEach((arg) =>
|
|
|
|
args.push(b.thunk(/** @type {import('estree').Expression} */ (context.visit(node.argument))));
|
|
|
|
args.push(b.thunk(/** @type {import('estree').Expression} */ (context.visit(arg))))
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
let snippet_function = /** @type {import('estree').Expression} */ (
|
|
|
|
let snippet_function = /** @type {import('estree').Expression} */ (
|
|
|
|
context.visit(node.expression)
|
|
|
|
context.visit(node.expression)
|
|
|
@ -2445,21 +2445,21 @@ export const template_visitors = {
|
|
|
|
/** @type {import('estree').BlockStatement} */
|
|
|
|
/** @type {import('estree').BlockStatement} */
|
|
|
|
let body;
|
|
|
|
let body;
|
|
|
|
|
|
|
|
|
|
|
|
if (node.context) {
|
|
|
|
|
|
|
|
const id = node.context.type === 'Identifier' ? node.context : b.id('$$context');
|
|
|
|
|
|
|
|
args.push(id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @type {import('estree').Statement[]} */
|
|
|
|
/** @type {import('estree').Statement[]} */
|
|
|
|
const declarations = [];
|
|
|
|
const declarations = [];
|
|
|
|
|
|
|
|
|
|
|
|
// some of this is duplicated with EachBlock — TODO dedupe?
|
|
|
|
node.context.elements.forEach((element, i) => {
|
|
|
|
if (node.context.type === 'Identifier') {
|
|
|
|
if (!element) return;
|
|
|
|
|
|
|
|
const id = element.type === 'Identifier' ? element : b.id(`$$context${i}`);
|
|
|
|
|
|
|
|
args.push(id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (element.type === 'Identifier') {
|
|
|
|
const binding = /** @type {import('#compiler').Binding} */ (
|
|
|
|
const binding = /** @type {import('#compiler').Binding} */ (
|
|
|
|
context.state.scope.get(id.name)
|
|
|
|
context.state.scope.get(id.name)
|
|
|
|
);
|
|
|
|
);
|
|
|
|
binding.expression = b.call(id);
|
|
|
|
binding.expression = b.call(id);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
const paths = extract_paths(node.context);
|
|
|
|
const paths = extract_paths(element);
|
|
|
|
|
|
|
|
|
|
|
|
for (const path of paths) {
|
|
|
|
for (const path of paths) {
|
|
|
|
const name = /** @type {import('estree').Identifier} */ (path.node).name;
|
|
|
|
const name = /** @type {import('estree').Identifier} */ (path.node).name;
|
|
|
@ -2471,7 +2471,7 @@ export const template_visitors = {
|
|
|
|
path.node,
|
|
|
|
path.node,
|
|
|
|
b.thunk(
|
|
|
|
b.thunk(
|
|
|
|
/** @type {import('estree').Expression} */ (
|
|
|
|
/** @type {import('estree').Expression} */ (
|
|
|
|
context.visit(path.expression?.(b.call('$$context')))
|
|
|
|
context.visit(path.expression?.(b.call(`$$arg${i}`)))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -2486,14 +2486,12 @@ export const template_visitors = {
|
|
|
|
binding.expression = b.call(name);
|
|
|
|
binding.expression = b.call(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
body = b.block([
|
|
|
|
body = b.block([
|
|
|
|
...declarations,
|
|
|
|
...declarations,
|
|
|
|
.../** @type {import('estree').BlockStatement} */ (context.visit(node.body)).body
|
|
|
|
.../** @type {import('estree').BlockStatement} */ (context.visit(node.body)).body
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
body = /** @type {import('estree').BlockStatement} */ (context.visit(node.body));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const path = context.path;
|
|
|
|
const path = context.path;
|
|
|
|
// If we're top-level, then we can create a function for the snippet so that it can be referenced
|
|
|
|
// If we're top-level, then we can create a function for the snippet so that it can be referenced
|
|
|
|