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

Commit

Permalink
Fix :xhp::__construct $children type
Browse files Browse the repository at this point in the history
Hack now typechecks XHP constructors (facebook/hhvm@af6f350)
which revealed this error.
  • Loading branch information
jjergus committed Feb 18, 2021
1 parent 55bbdcb commit e21656f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/core/ComposableElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected function init(): void {
*/
final public function __construct(
KeyedTraversable<string, mixed> $attributes,
Traversable<XHPChild> $children,
Traversable<?XHPChild> $children,
dynamic ...$debug_info
) {
parent::__construct($attributes, $children);
Expand Down
2 changes: 1 addition & 1 deletion src/core/XHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ abstract class :xhp implements XHPChild, JsonSerializable {

public function __construct(
KeyedTraversable<string, mixed> $attributes,
Traversable<XHPChild> $children,
Traversable<?XHPChild> $children,
): void {
}
abstract public function appendChild(mixed $child): this;
Expand Down
5 changes: 5 additions & 0 deletions tests/BasicsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public function testXFrag(): void {
expect($xhp->toString())->toEqual('<div>herpderp</div>');
}

public async function testScalarChildren(): Awaitable<void> {
$xhp = <div>{42}{' str '}{3.14}{null}</div>;
expect($xhp->toString())->toEqual('<div>42 str 3.14</div>');
}

public function testEscaping(): void {
$xhp = <div>{"foo<SCRIPT>bar"}</div>;
expect($xhp->toString())->toEqual('<div>foo&lt;SCRIPT&gt;bar</div>');
Expand Down

0 comments on commit e21656f

Please sign in to comment.