pull/3766/head
Tan Li Hau 6 years ago
parent f209ae5dcb
commit d1b5961c25

@ -29,18 +29,17 @@ function optimise_text_content(children) {
while (end < children.length && text_like_node_type.has(children[end].type)) while (end < children.length && text_like_node_type.has(children[end].type))
end++; end++;
if (end > start) { // based on heuristic,
// require more than 2 neighouring text contents to merge yields smaller content
if (end > start + 2) {
const merged = merge_text_siblings(children.slice(start, end)); const merged = merge_text_siblings(children.slice(start, end));
children.splice(start, end - start, ...merged); children.splice(start, end - start, merged);
start = end;
} }
start = end;
} while (start < children.length); } while (start < children.length);
} }
function merge_text_siblings(children: Array<Text | MustacheTag>) { function merge_text_siblings(children: Array<Text | MustacheTag>) {
if (children.length < 3) {
return children;
}
const literal = { const literal = {
type: 'TemplateLiteral', type: 'TemplateLiteral',
@ -76,10 +75,10 @@ function merge_text_siblings(children: Array<Text | MustacheTag>) {
literal.quasis.push(state.quasi); literal.quasis.push(state.quasi);
return [{ return {
type: 'MustacheTag', type: 'MustacheTag',
expression: literal, expression: literal,
start: children[0].start, start: children[0].start,
end: children[children.length - 1].end, end: children[children.length - 1].end,
}]; };
} }

Loading…
Cancel
Save