Convert src/compiler/compile/render_dom/wrappers/shared/Tag.ts to JavaScript

pull/8569/head
Simon Holthausen 3 years ago
parent f62903ca19
commit f3e323fb1b

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

@ -1,5 +1,5 @@
/** /**
* @param {import('../Element.js').default | import('../InlineComponent.js').default} parent * @param {import('../Element/index.js').default | import('../InlineComponent/index.js').default} parent
* @param {import('../../../nodes/Binding.js').default} binding * @param {import('../../../nodes/Binding.js').default} binding
*/ */
export default function mark_each_block_bindings(parent, binding) { export default function mark_each_block_bindings(parent, binding) {

Loading…
Cancel
Save