|
|
|
@ -959,6 +959,23 @@ function serialize_bind_this(bind_this, context, node) {
|
|
|
|
|
return b.call('$.bind_this', ...args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {import('../types.js').SourceLocation[]} locations
|
|
|
|
|
*/
|
|
|
|
|
function serialize_locations(locations) {
|
|
|
|
|
return b.array(
|
|
|
|
|
locations.map((loc) => {
|
|
|
|
|
const expression = b.array([b.literal(loc[0]), b.literal(loc[1])]);
|
|
|
|
|
|
|
|
|
|
if (loc.length === 3) {
|
|
|
|
|
expression.elements.push(serialize_locations(loc[2]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return expression;
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a new block which looks roughly like this:
|
|
|
|
|
* ```js
|
|
|
|
@ -1014,6 +1031,7 @@ function create_block(parent, name, nodes, context) {
|
|
|
|
|
update: [],
|
|
|
|
|
after_update: [],
|
|
|
|
|
template: [],
|
|
|
|
|
locations: [],
|
|
|
|
|
metadata: {
|
|
|
|
|
context: {
|
|
|
|
|
template_needs_import_node: false,
|
|
|
|
@ -1028,6 +1046,24 @@ function create_block(parent, name, nodes, context) {
|
|
|
|
|
context.visit(node, state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {import('estree').Identifier} template_name
|
|
|
|
|
* @param {import('estree').Expression[]} args
|
|
|
|
|
*/
|
|
|
|
|
const add_template = (template_name, args) => {
|
|
|
|
|
let call = b.call(get_template_function(namespace, state), ...args);
|
|
|
|
|
if (context.state.options.dev) {
|
|
|
|
|
call = b.call(
|
|
|
|
|
'$.add_locations',
|
|
|
|
|
call,
|
|
|
|
|
b.member(b.id(context.state.analysis.name), b.id('filename')),
|
|
|
|
|
serialize_locations(state.locations)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
context.state.hoisted.push(b.var(template_name, call));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (is_single_element) {
|
|
|
|
|
const element = /** @type {import('#compiler').RegularElement} */ (trimmed[0]);
|
|
|
|
|
|
|
|
|
@ -1045,9 +1081,7 @@ function create_block(parent, name, nodes, context) {
|
|
|
|
|
args.push(b.literal(TEMPLATE_USE_IMPORT_NODE));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
context.state.hoisted.push(
|
|
|
|
|
b.var(template_name, b.call(get_template_function(namespace, state), ...args))
|
|
|
|
|
);
|
|
|
|
|
add_template(template_name, args);
|
|
|
|
|
|
|
|
|
|
body.push(b.var(id, b.call(template_name)), ...state.before_init, ...state.init);
|
|
|
|
|
close = b.stmt(b.call('$.append', b.id('$$anchor'), id));
|
|
|
|
@ -1091,16 +1125,10 @@ function create_block(parent, name, nodes, context) {
|
|
|
|
|
flags |= TEMPLATE_USE_IMPORT_NODE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
state.hoisted.push(
|
|
|
|
|
b.var(
|
|
|
|
|
template_name,
|
|
|
|
|
b.call(
|
|
|
|
|
get_template_function(namespace, state),
|
|
|
|
|
b.template([b.quasi(state.template.join(''), true)], []),
|
|
|
|
|
b.literal(flags)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
add_template(template_name, [
|
|
|
|
|
b.template([b.quasi(state.template.join(''), true)], []),
|
|
|
|
|
b.literal(flags)
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
body.push(b.var(id, b.call(template_name)));
|
|
|
|
|
}
|
|
|
|
@ -1809,6 +1837,18 @@ export const template_visitors = {
|
|
|
|
|
state.init.push(b.stmt(b.call('$.transition', ...args)));
|
|
|
|
|
},
|
|
|
|
|
RegularElement(node, context) {
|
|
|
|
|
/** @type {import('../types.js').SourceLocation} */
|
|
|
|
|
let location = [-1, -1];
|
|
|
|
|
|
|
|
|
|
if (context.state.options.dev) {
|
|
|
|
|
const loc = context.state.source_locator(node.start);
|
|
|
|
|
if (loc) {
|
|
|
|
|
location[0] = loc.line;
|
|
|
|
|
location[1] = loc.column;
|
|
|
|
|
context.state.locations.push(location);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (node.name === 'noscript') {
|
|
|
|
|
context.state.template.push('<!>');
|
|
|
|
|
return;
|
|
|
|
@ -1993,10 +2033,14 @@ export const template_visitors = {
|
|
|
|
|
|
|
|
|
|
context.state.template.push('>');
|
|
|
|
|
|
|
|
|
|
/** @type {import('../types.js').SourceLocation[]} */
|
|
|
|
|
const child_locations = [];
|
|
|
|
|
|
|
|
|
|
/** @type {import('../types').ComponentClientTransformState} */
|
|
|
|
|
const state = {
|
|
|
|
|
...context.state,
|
|
|
|
|
metadata: child_metadata,
|
|
|
|
|
locations: child_locations,
|
|
|
|
|
scope: /** @type {import('../../../scope').Scope} */ (
|
|
|
|
|
context.state.scopes.get(node.fragment)
|
|
|
|
|
),
|
|
|
|
@ -2032,6 +2076,11 @@ export const template_visitors = {
|
|
|
|
|
{ ...context, state }
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (child_locations.length > 0) {
|
|
|
|
|
// @ts-expect-error
|
|
|
|
|
location.push(child_locations);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!VoidElements.includes(node.name)) {
|
|
|
|
|
context.state.template.push(`</${node.name}>`);
|
|
|
|
|
}
|
|
|
|
@ -2131,19 +2180,21 @@ export const template_visitors = {
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const args = [
|
|
|
|
|
context.state.node,
|
|
|
|
|
get_tag,
|
|
|
|
|
node.metadata.svg || node.metadata.mathml ? b.true : b.false
|
|
|
|
|
];
|
|
|
|
|
if (inner.length > 0) {
|
|
|
|
|
args.push(b.arrow([element_id, b.id('$$anchor')], b.block(inner)));
|
|
|
|
|
}
|
|
|
|
|
if (dynamic_namespace) {
|
|
|
|
|
if (inner.length === 0) args.push(b.id('undefined'));
|
|
|
|
|
args.push(b.thunk(serialize_attribute_value(dynamic_namespace, context)[1]));
|
|
|
|
|
}
|
|
|
|
|
context.state.init.push(b.stmt(b.call('$.element', ...args)));
|
|
|
|
|
const location = context.state.options.dev && context.state.source_locator(node.start);
|
|
|
|
|
|
|
|
|
|
context.state.init.push(
|
|
|
|
|
b.stmt(
|
|
|
|
|
b.call(
|
|
|
|
|
'$.element',
|
|
|
|
|
context.state.node,
|
|
|
|
|
get_tag,
|
|
|
|
|
node.metadata.svg || node.metadata.mathml ? b.true : b.false,
|
|
|
|
|
inner.length > 0 && b.arrow([element_id, b.id('$$anchor')], b.block(inner)),
|
|
|
|
|
dynamic_namespace && b.thunk(serialize_attribute_value(dynamic_namespace, context)[1]),
|
|
|
|
|
location && b.array([b.literal(location.line), b.literal(location.column)])
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
EachBlock(node, context) {
|
|
|
|
|
const each_node_meta = node.metadata;
|
|
|
|
|