From 07d04aba1d170ebdca262374a956688a14988200 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 5 Oct 2017 14:34:47 -0400 Subject: [PATCH] Support `{{unless}}` in virtual dom templates --- lib/javascripts/widget-hbs-compiler.js.es6 | 6 +++++- script/test_hbs_compiler.rb | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/javascripts/widget-hbs-compiler.js.es6 b/lib/javascripts/widget-hbs-compiler.js.es6 index 2561d9362d2..8b3a20be962 100644 --- a/lib/javascripts/widget-hbs-compiler.js.es6 +++ b/lib/javascripts/widget-hbs-compiler.js.es6 @@ -140,9 +140,13 @@ class Compiler { } break; case "BlockStatement": + let negate = ''; + switch(node.path.original) { + case 'unless': + negate = '!'; case 'if': - instructions.push(`if (${node.params[0].original}) {`); + instructions.push(`if (${negate}${node.params[0].original}) {`); node.program.body.forEach(child => { instructions = instructions.concat(this.processNode(parentAcc, child)); }); diff --git a/script/test_hbs_compiler.rb b/script/test_hbs_compiler.rb index 773908c5b4c..9bfe595261a 100644 --- a/script/test_hbs_compiler.rb +++ b/script/test_hbs_compiler.rb @@ -5,6 +5,9 @@ template = <<~HBS {{#if state.category}} {{attach widget="category-display" attrs=(hash category=state.category someNumber=123 someString="wat")}} {{/if}} + {{#unless state.hello}} + XYZ + {{/unless}} HBS ctx = MiniRacer::Context.new(timeout: 15000)