This repository was archived by the owner on Apr 1, 2024. It is now read-only.
Relicense to MIT, support the attribute spread operator
This release:
- is available under the MIT license
- adds support for the XHP spread operator (available in HHVM 3.24+)
The XHP Spread Operator
This is intended to be a safer replacement for the implicit attribute copying available via XHPHelpers; we expect to remove XHPHelpers from XHP 3.0.
class :inner extends :x:element {
attribute string color, int age;
}
class :outer-old extends :x:element {
use XHPHelpers;
attribute string color, int age;
public function render(): :xhp {
// `age` attribute is implicitly copied
return <inner color="red" />;
}
}
class :outer-new extends :x:element {
attribute string color, int age;
public function render(): :xhp {
// Explicitly copy all attributes from `$this` - however, the override of color takes precedence
return <inner {...$this} color="red" />;
}
}The typechecker is able to validate types - for example:
class :outer-invalid extends :x:element {
attribute string color, float age;
public function render(): :xhp {
// Type error:
// Invalid xhp value for attribute :age in :inner
// This is an int
// It is incompatible with a float
return <inner {...$this} />;
}
}