put logic inside a helper

pull/12396/head
Rich Harris 2 years ago
parent 4137491fd0
commit 6a733c8b37

@ -1169,18 +1169,7 @@ const template_visitors = {
},
HtmlTag(node, context) {
const expression = /** @type {import('estree').Expression} */ (context.visit(node.expression));
/**
* @type {import("estree").Literal | import("estree").TemplateLiteral}
*/
let first_comment = empty_comment;
if (context.state.options.dev) {
first_comment = b.template(
[b.quasi('<!--'), b.quasi('-->', true)],
[b.call('$.hash', expression)]
);
}
context.state.template.push(first_comment, expression, empty_comment);
context.state.template.push(b.call('$.html', expression));
},
ConstTag(node, { state, visit }) {
const declaration = node.declaration.declarations[0];

@ -0,0 +1,10 @@
import { DEV } from 'esm-env';
import { hash } from '../dev.js';
/**
* @param {string} value
*/
export function html(value) {
var open = DEV ? `<!--${hash(value)}-->` : '<!---->';
return `${open}${value}<!---->`;
}

@ -545,6 +545,8 @@ export function once(get_value) {
};
}
export { html } from './blocks/html.js';
export { push, pop } from './context.js';
export { push_element, pop_element, hash } from './dev.js';

Loading…
Cancel
Save