Skip to content
This repository was archived by the owner on Apr 1, 2024. It is now read-only.

Commit f233e39

Browse files
committed
Add runtime errors when constructing any element with children or categories
- children declarations are meant to be (and appear to be) parse errors with the new syntax - categories can be fully be replaced with interfaces; let's ban them here in expectation of a hack/parser ban in the future - remove the consistency validation trait: it can't be used even before this diff, but doubly so now that it throws - raising exceptions from the constructor gives clearer traces than from render
1 parent 3163ad6 commit f233e39

File tree

4 files changed

+20
-68
lines changed

4 files changed

+20
-68
lines changed

src/ChildValidation/ConsistencyValidation.hack

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/ChildValidation/Validation.hack

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,4 @@ trait Validation {
2323
): mixed {
2424
return static::getChildrenDeclaration()->legacySerialize();
2525
}
26-
27-
final public function validateChildren(): void {
28-
invariant(
29-
$this->__xhpChildrenDeclaration() ===
30-
x\element::__NO_LEGACY_CHILDREN_DECLARATION,
31-
"The XHPChildValidation trait can not be used with a 'children' ".
32-
"declaration; override 'getChildrenDeclaration()'' instead",
33-
);
34-
35-
parent::validateChildren();
36-
}
3726
}

src/core/Node.hack

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ abstract xhp class node implements \XHPChild {
5252
Traversable<\XHPChild> $children,
5353
dynamic ...$debug_info
5454
) {
55+
invariant(
56+
$this->__xhpChildrenDeclaration() === self::__NO_LEGACY_CHILDREN_DECLARATION,
57+
'The `children` keyword is no longer supported',
58+
);
59+
invariant(
60+
$this->__xhpCategoryDeclaration() === self::__NO_LEGACY_CATEGORY_DECLARATION,
61+
'The `category` keyword is no longer supported',
62+
);
63+
5564
foreach ($children as $child) {
5665
$this->appendChild($child);
5766
}
@@ -573,10 +582,11 @@ abstract xhp class node implements \XHPChild {
573582
* categories an element belongs to. Each category is a key with value 1.
574583
*/
575584
protected function __xhpCategoryDeclaration(): darray<string, int> {
576-
return darray[];
585+
return self::__NO_LEGACY_CATEGORY_DECLARATION;
577586
}
578587

579588
const int __NO_LEGACY_CHILDREN_DECLARATION = -31337;
589+
const darray<string, int> __NO_LEGACY_CATEGORY_DECLARATION = darray["\0INVALID\0" => 0];
580590

581591
/**
582592
* Defined in elements by the `children` keyword. This returns a pattern of

tests/ChildRuleTest.hack

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,11 +429,15 @@ class ChildRuleTest extends Facebook\HackTest\HackTest {
429429
}
430430

431431
public async function testCommaCategory(): Awaitable<void> {
432-
$x =
433-
<test:needs_comma_category>
434-
<test:has_comma_category />
435-
</test:needs_comma_category>;
436-
expect(await $x->toStringAsync())->toEqual('<div></div>');
432+
expect(
433+
() ==>
434+
<test:needs_comma_category>
435+
<test:has_comma_category />
436+
</test:needs_comma_category>,
437+
)->toThrow(
438+
InvariantException::class,
439+
'no longer supported',
440+
);
437441
}
438442

439443
public async function testFrags(): Awaitable<void> {

0 commit comments

Comments
 (0)