Lint and format src/compiler/compile/render_dom/wrappers/shared/add_const_tags.js

pull/8569/head
Simon Holthausen 3 years ago
parent 39ec9fb1fd
commit 20a36b5ef2

@ -7,26 +7,37 @@ import Expression from '../../../nodes/shared/Expression.js';
* @param {string} ctx * @param {string} ctx
*/ */
export function add_const_tags(block, const_tags, ctx) { export function add_const_tags(block, const_tags, ctx) {
const const_tags_props = []; const const_tags_props = [];
const_tags.forEach((const_tag, i) => { const_tags.forEach((const_tag, i) => {
const name = `#constants_${i}`; const name = `#constants_${i}`;
const_tags_props.push(b `const ${name} = ${const_tag.expression.manipulate(block, ctx)}`); const_tags_props.push(b`const ${name} = ${const_tag.expression.manipulate(block, ctx)}`);
/** @param {string} name */ /** @param {string} name */
const to_ctx = (name) => block.renderer.context_lookup.has(name) const to_ctx = (name) =>
? x `${ctx}[${block.renderer.context_lookup.get(name).index}]` block.renderer.context_lookup.has(name)
: ( /** @type {import('code-red').Node} */({ type: 'Identifier', name })); ? x`${ctx}[${block.renderer.context_lookup.get(name).index}]`
const_tag.contexts.forEach((context) => { : /** @type {import('code-red').Node} */ ({ type: 'Identifier', name });
if (context.type === 'DestructuredVariable') { const_tag.contexts.forEach((context) => {
const_tags_props.push(b `${ctx}[${block.renderer.context_lookup.get(context.key.name).index}] = ${context.default_modifier(context.modifier({ type: 'Identifier', name }), to_ctx)}`); if (context.type === 'DestructuredVariable') {
} const_tags_props.push(
else { b`${ctx}[${
const expression = new Expression(block.renderer.component, const_tag, const_tag.scope, context.key); block.renderer.context_lookup.get(context.key.name).index
const_tags_props.push(b `const ${context.property_name} = ${expression.manipulate(block, ctx)}`); }] = ${context.default_modifier(context.modifier({ type: 'Identifier', name }), to_ctx)}`
} );
}); } else {
}); const expression = new Expression(
return const_tags_props; block.renderer.component,
const_tag,
const_tag.scope,
context.key
);
const_tags_props.push(
b`const ${context.property_name} = ${expression.manipulate(block, ctx)}`
);
}
});
});
return const_tags_props;
} }
/** /**
@ -34,15 +45,10 @@ export function add_const_tags(block, const_tags, ctx) {
* @param {import('../../../nodes/ConstTag.js').default[]} const_tags * @param {import('../../../nodes/ConstTag.js').default[]} const_tags
*/ */
export function add_const_tags_context(renderer, const_tags) { export function add_const_tags_context(renderer, const_tags) {
const_tags.forEach((const_tag) => { const_tags.forEach((const_tag) => {
const_tag.contexts.forEach((context) => { const_tag.contexts.forEach((context) => {
if (context.type !== 'DestructuredVariable') if (context.type !== 'DestructuredVariable') return;
return; renderer.add_to_context(context.key.name, true);
renderer.add_to_context(context.key.name, true); });
}); });
});
} }

Loading…
Cancel
Save