more refactoring

pull/803/head
Rich Harris 7 years ago
parent 9fae7671a4
commit 4603d7700f

@ -82,7 +82,7 @@ const preprocessors = {
if (elementsWithoutText.has(state.parentNodeName)) return;
}
node._state.shouldCreate = true;
node.shouldCreate = true;
node.var = block.getUniqueName(`text`);
},

@ -2,6 +2,7 @@ import deindent from '../../../utils/deindent';
import visit from '../visit';
import { DomGenerator } from '../index';
import Block from '../Block';
import isDomNode from './shared/isDomNode';
import { Node } from '../../../interfaces';
import { State } from '../interfaces';
@ -19,7 +20,7 @@ export default function visitEachBlock(
const iterations = block.getUniqueName(`${each_block}_iterations`);
const params = block.params.join(', ');
const needsAnchor = node.next ? (!node.next._state || !node.next.var) : !state.parentNode;
const needsAnchor = node.next ? !isDomNode(node.next) : !state.parentNode;
const anchor = needsAnchor
? block.getUniqueName(`${each_block}_anchor`)
: (node.next && node.next.var) || 'null';

@ -2,6 +2,7 @@ import deindent from '../../../utils/deindent';
import visit from '../visit';
import { DomGenerator } from '../index';
import Block from '../Block';
import isDomNode from './shared/isDomNode';
import { Node } from '../../../interfaces';
import { State } from '../interfaces';
@ -79,7 +80,7 @@ export default function visitIfBlock(
) {
const name = generator.getUniqueName(`if_block`);
const needsAnchor = node.next ? (!node.next._state || !node.next.var) : !state.parentNode;
const needsAnchor = node.next ? !isDomNode(node.next) : !state.parentNode;
const anchor = needsAnchor
? block.getUniqueName(`${name}_anchor`)
: (node.next && node.next.var) || 'null';

@ -13,8 +13,8 @@ export default function visitRawMustacheTag(
) {
const name = node.var;
const needsAnchorBefore = node.prev ? (node.prev.type !== 'Element' || !node.prev._state || !node.prev.var) : !state.parentNode;
const needsAnchorAfter = node.next ? (node.next.type !== 'Element' || !node.next._state || !node.next.var) : !state.parentNode;
const needsAnchorBefore = node.prev ? node.prev.type !== 'Element' : !state.parentNode;
const needsAnchorAfter = node.next ? node.next.type !== 'Element' : !state.parentNode;
const anchorBefore = needsAnchorBefore
? block.getUniqueName(`${name}_before`)

@ -10,7 +10,8 @@ export default function visitText(
state: State,
node: Node
) {
if (!node._state.shouldCreate) return;
if (!node.shouldCreate) return;
block.addElement(
node.var,
`@createText( ${stringify(node.data)} )`,

@ -0,0 +1,5 @@
import { Node } from '../../../../interfaces';
export default function isDomNode(node: Node) {
return node.type === 'Element' || node.type === 'Text' || node.type === 'MustacheTag';
}
Loading…
Cancel
Save