diff --git a/src/generators/dom/index.ts b/src/generators/dom/index.ts index 8ffed33173..21d155c12f 100644 --- a/src/generators/dom/index.ts +++ b/src/generators/dom/index.ts @@ -95,7 +95,7 @@ export default function dom( .map(dep => `state.${dep}`) .join(', ')} ) ), oldState.${key} ) ) changed.${key} = true;`; - computationBuilder.addConditionalLine(condition, statement); + computationBuilder.addConditional(condition, statement); }); } diff --git a/src/generators/dom/visitors/Element/Attribute.ts b/src/generators/dom/visitors/Element/Attribute.ts index 12a6842658..2134ad62d0 100644 --- a/src/generators/dom/visitors/Element/Attribute.ts +++ b/src/generators/dom/visitors/Element/Attribute.ts @@ -166,16 +166,10 @@ export default function visitAttribute( ( dependencies.length ? `( ${changedCheck} ) && ${updateCachedValue}` : updateCachedValue ) : changedCheck; - // block.builders.update.addConditionalLine( - // condition, - // updater - // ); - - block.builders.update.addBlock(deindent` - if ( ${condition} ) { - ${updater} - } - `); + block.builders.update.addConditional( + condition, + updater + ); } } else { const value = attribute.value === true diff --git a/src/generators/dom/visitors/shared/Tag.ts b/src/generators/dom/visitors/shared/Tag.ts index 63185d60c5..3d4f3ed211 100644 --- a/src/generators/dom/visitors/shared/Tag.ts +++ b/src/generators/dom/visitors/shared/Tag.ts @@ -39,7 +39,7 @@ export default function visitTag( ( dependencies.length ? `( ${changedCheck} ) && ${updateCachedValue}` : updateCachedValue ) : changedCheck; - block.builders.update.addConditionalLine( + block.builders.update.addConditional( condition, update(shouldCache ? value : snippet) ); diff --git a/src/utils/CodeBuilder.ts b/src/utils/CodeBuilder.ts index 2a412a8a06..bdbcc3fcb6 100644 --- a/src/utils/CodeBuilder.ts +++ b/src/utils/CodeBuilder.ts @@ -21,7 +21,7 @@ export default class CodeBuilder { this.lastCondition = null; } - addConditionalLine(condition: string, body: string) { + addConditional(condition: string, body: string) { body = body.replace(/^/gm, '\t'); if (condition === this.lastCondition) {