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

pull/8569/head
Simon Holthausen 3 years ago
parent cc2372b5e1
commit a6fb5c13f5

@ -3,48 +3,44 @@ import Wrapper from './Wrapper.js';
/** @extends Wrapper */ /** @extends Wrapper */
export default class Tag extends Wrapper { export default class Tag extends Wrapper {
/** @type {import('../../../nodes/MustacheTag.js').default | import('../../../nodes/RawMustacheTag.js').default} */
/** @type {import('../../../nodes/MustacheTag.js').default | import('../../../nodes/RawMustacheTag.js').default} */ node;
node;
/**
/** * @param {import('../../Renderer.js').default} renderer
* @param {import('../../Renderer.js').default} renderer * @param {import('../../Block.js').default} block
* @param {import('../../Block.js').default} block * @param {import('./Wrapper.js').default} parent
* @param {import('./Wrapper.js').default} parent * @param {import('../../../nodes/MustacheTag.js').default | import('../../../nodes/RawMustacheTag.js').default} node
* @param {import('../../../nodes/MustacheTag.js').default | import('../../../nodes/RawMustacheTag.js').default} node */
*/ constructor(renderer, block, parent, node) {
constructor(renderer, block, parent, node) { super(renderer, block, parent, node);
super(renderer, block, parent, node); block.add_dependencies(node.expression.dependencies);
block.add_dependencies(node.expression.dependencies); }
}
/**
/** * @param {import('../../Block.js').default} block
* @param {import('../../Block.js').default} block * @param {(value: import('estree').Node) => import('estree').Node | import('estree').Node[]} update
* @param {(value: import('estree').Node) => import('estree').Node | import('estree').Node[]} update */
*/ rename_this_method(block, update) {
rename_this_method(block, update) { const dependencies = this.node.expression.dynamic_dependencies();
const dependencies = this.node.expression.dynamic_dependencies(); let snippet = this.node.expression.manipulate(block);
let snippet = this.node.expression.manipulate(block); const value = this.node.should_cache && block.get_unique_name(`${this.var.name}_value`);
const value = this.node.should_cache && block.get_unique_name(`${this.var.name}_value`); const content = this.node.should_cache ? value : snippet;
const content = this.node.should_cache ? value : snippet; snippet = x`${snippet} + ""`;
snippet = x `${snippet} + ""`; if (this.node.should_cache) block.add_variable(value, snippet); // TODO may need to coerce snippet to string
if (this.node.should_cache) if (dependencies.length > 0) {
block.add_variable(value, snippet); // TODO may need to coerce snippet to string let condition = block.renderer.dirty(dependencies);
if (dependencies.length > 0) { if (block.has_outros) {
let condition = block.renderer.dirty(dependencies); condition = x`!#current || ${condition}`;
if (block.has_outros) { }
condition = x `!#current || ${condition}`; const update_cached_value = x`${value} !== (${value} = ${snippet})`;
} if (this.node.should_cache) {
const update_cached_value = x `${value} !== (${value} = ${snippet})`; condition = x`${condition} && ${update_cached_value}`;
if (this.node.should_cache) { }
condition = x `${condition} && ${update_cached_value}`; block.chunks.update.push(
} b`if (${condition}) ${update(/** @type {import('estree').Node} */ (content))}`
block.chunks.update.push(b `if (${condition}) ${update(/** @type {import('estree').Node} */ (content))}`); );
} }
return { init: content }; return { init: content };
} }
} }

Loading…
Cancel
Save