diff --git a/src/fbt/Transform/FbtTransform/FbtUtils.php b/src/fbt/Transform/FbtTransform/FbtUtils.php index d42a376..26319ba 100644 --- a/src/fbt/Transform/FbtTransform/FbtUtils.php +++ b/src/fbt/Transform/FbtTransform/FbtUtils.php @@ -2,6 +2,7 @@ namespace fbt\Transform\FbtTransform; +use fbt\Exceptions\FbtException; use fbt\Exceptions\FbtParserException; use function fbt\invariant; use fbt\Runtime\fbtElement; @@ -381,6 +382,11 @@ public static function filterEmptyNodes(array $nodes): array return $node->innertext; } + if ($node->isElement() && ! $node->isNamespacedElement() && ! $node->innertext()) { + // todo: this should catch in _createFbtFunctionCallNode + invariant(false, 'text cannot be null'); + } + return ! $node->isComment(); }, ARRAY_FILTER_USE_BOTH); diff --git a/tests/fbt/fbtTest.php b/tests/fbt/fbtTest.php index 7ee7325..cd058ce 100644 --- a/tests/fbt/fbtTest.php +++ b/tests/fbt/fbtTest.php @@ -4,6 +4,7 @@ namespace tests\fbt; +use fbt\Exceptions\FbtException; use fbt\Lib\IntlViewerContext; use fbt\Runtime\Shared\fbt; use fbt\Runtime\Shared\FbtHooks; @@ -17,6 +18,19 @@ private static function transform($document): string return FbtTransform::transform($document); } + public function testDisableTagsWithoutContent() + { + self::expectExceptionMessage('text cannot be null'); + + self::transform(<< + first test +

+
+FBT + ); + } + public function testPlural() { $fbt = fbt(\fbt\fbt::plural('translator', 2, ['showCount' => 'yes', 'count' => 2]), 'Plural word test');