Skip to content

Commit

Permalink
Compiler::writeAttrsMacro() better exception messages for empty macros
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Apr 26, 2016
1 parent 3f53a79 commit 7b72549
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/Latte/Compiler.php
Expand Up @@ -510,7 +510,9 @@ public function writeAttrsMacro($html)
};
} else {
array_unshift($right, function () use ($name, $attrs, $attrName) {
$this->openMacro($name, $attrs[$attrName], NULL, NULL, MacroNode::PREFIX_INNER);
if ($this->openMacro($name, $attrs[$attrName], NULL, NULL, MacroNode::PREFIX_INNER)->isEmpty) {
throw new CompileException("Unable to use empty macro as n:$attrName.");
}
});
}
unset($attrs[$attrName]);
Expand All @@ -521,7 +523,9 @@ public function writeAttrsMacro($html)
$attrName = MacroNode::PREFIX_TAG . "-$name";
if (isset($attrs[$attrName])) {
$left[] = function () use ($name, $attrs, $attrName) {
$this->openMacro($name, $attrs[$attrName], NULL, NULL, MacroNode::PREFIX_TAG);
if ($this->openMacro($name, $attrs[$attrName], NULL, NULL, MacroNode::PREFIX_TAG)->isEmpty) {
throw new CompileException("Unable to use empty macro as n:$attrName.");
}
};
array_unshift($right, function () use ($name) {
$this->closeMacro($name, '', NULL, NULL, MacroNode::PREFIX_TAG);
Expand Down
4 changes: 2 additions & 2 deletions tests/Latte/Compiler.macro.empty.phpt
Expand Up @@ -56,8 +56,8 @@ Assert::match(

Assert::exception(function () use ($latte) {
$latte->compile('<div n:inner-one>@</div>');
}, 'Latte\CompileException', 'Unexpected </div> for n:inner-one');
}, 'Latte\CompileException', 'Unable to use empty macro as n:inner-one.');

Assert::exception(function () use ($latte) {
$latte->compile('<div n:tag-one>@</div>');
}, 'Latte\CompileException', 'Unexpected </div> for n:tag-one');
}, 'Latte\CompileException', 'Unable to use empty macro as n:tag-one.');

0 comments on commit 7b72549

Please sign in to comment.