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

Commit

Permalink
support 3.29
Browse files Browse the repository at this point in the history
  • Loading branch information
fredemmott committed Oct 19, 2018
1 parent 208325e commit c120648
Show file tree
Hide file tree
Showing 14 changed files with 122 additions and 95 deletions.
4 changes: 3 additions & 1 deletion .hhconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ disallow_non_arraykey_keys=true
disallow_unsafe_comparisons=true
decl_override_require_hint=true
enable_experimental_tc_features=shape_field_check,sealed_classes
forward_compatibility_level=20180813
forward_compatibility_level=3.29
user_attributes=
disable_primitive_refinement=true
83 changes: 41 additions & 42 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions src/core/ComposableElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -541,25 +541,25 @@ final protected function validateAttributeValue<T>(
}
switch ($decl->getValueType()) {
case XHPAttributeType::TYPE_STRING:
if (!is_string($val)) {
if (!($val is string)) {
$val = XHPAttributeCoercion::CoerceToString($this, $attr, $val);
}
break;

case XHPAttributeType::TYPE_BOOL:
if (!is_bool($val)) {
if (!($val is bool)) {
$val = XHPAttributeCoercion::CoerceToBool($this, $attr, $val);
}
break;

case XHPAttributeType::TYPE_INTEGER:
if (!is_int($val)) {
if (!($val is int)) {
$val = XHPAttributeCoercion::CoerceToInt($this, $attr, $val);
}
break;

case XHPAttributeType::TYPE_FLOAT:
if (!is_float($val)) {
if (!($val is float)) {
$val = XHPAttributeCoercion::CoerceToFloat($this, $attr, $val);
}
break;
Expand All @@ -580,12 +580,12 @@ final protected function validateAttributeValue<T>(
}
// Things that are a valid array key without any coercion
if ($class === 'HH\arraykey') {
if (is_int($val) || is_string($val)) {
if (($val is int) || ($val is string)) {
break;
}
}
if ($class === 'HH\num') {
if (is_int($val) || is_float($val)) {
if (($val is int) || ($val is float)) {
break;
}
}
Expand All @@ -610,7 +610,7 @@ final protected function validateAttributeValue<T>(
break;

case XHPAttributeType::TYPE_ENUM:
if (!(is_string($val) && $decl->getEnumValues()->contains($val))) {
if (!(($val is string) && $decl->getEnumValues()->contains($val))) {
$enums = 'enum("'.implode('","', $decl->getEnumValues()).'")';
throw new XHPInvalidAttributeException($this, $enums, $attr, $val);
}
Expand Down Expand Up @@ -780,7 +780,7 @@ final private function validateChildrenRule(
* __getChildrenDescription.
*/
public function __getChildrenDeclaration(): string {
return (string)self::__xhpReflectionChildrenDeclaration();
return self::__xhpReflectionChildrenDeclaration()->__toString();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/core/ReflectionXHPAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function getValueClass(): string {
);
$v = $this->extraType;
invariant(
is_string($v),
$v is string,
'Class name for attribute %s is not a string',
$this->getName(),
);
Expand Down
10 changes: 5 additions & 5 deletions src/core/ReflectionXHPChildrenDeclaration.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function __toString(): string {
if ($this->getType() === XHPChildrenDeclarationType::NO_CHILDREN) {
return 'empty';
}
return (string)$this->getExpression();
return $this->getExpression()->__toString();
}
}

Expand Down Expand Up @@ -134,7 +134,7 @@ public function getConstraintString(): string {
:xhp::class2element(get_class($this->context)),
);
$data = $this->data[2];
invariant(is_string($data), 'Expected string data');
invariant($data is string, 'Expected string data');
return $data;
}

Expand Down Expand Up @@ -177,11 +177,11 @@ public function __toString(): string {

case XHPChildrenExpressionType::SUB_EXPR_SEQUENCE:
list($e1, $e2) = $this->getSubExpressions();
return $e1.','.$e2;
return $e1->__toString().','.$e2->__toString();

case XHPChildrenExpressionType::SUB_EXPR_DISJUNCTION:
list($e1, $e2) = $this->getSubExpressions();
return $e1.'|'.$e2;
return $e1->__toString().'|'.$e2->__toString();
}
}

Expand All @@ -200,7 +200,7 @@ private function __constraintToString(): string {
return '%'.$this->getConstraintString();

case XHPChildrenConstraintType::SUB_EXPR:
return '('.$this->getSubExpression().')';
return '('.$this->getSubExpression()->__toString().')';
}
}
}
11 changes: 7 additions & 4 deletions src/core/XHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,16 @@ final public function jsonSerialize(): string {
final protected static function renderChild(XHPChild $child): string {
if ($child instanceof :xhp) {
return $child->toString();
} else if ($child instanceof XHPUnsafeRenderable) {
}
if ($child instanceof XHPUnsafeRenderable) {
return $child->toHTMLString();
} else if ($child instanceof Traversable) {
}
if ($child instanceof Traversable) {
throw new XHPRenderArrayException('Can not render traversables!');
} else {
return htmlspecialchars((string)$child);
}

/* HH_FIXME[4281] stringish migration */
return htmlspecialchars((string)$child);
}

public static function element2class(string $element): string {
Expand Down
4 changes: 2 additions & 2 deletions src/core/XHPAttributeCoercion.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static function CoerceToString(
mixed $val,
): string {
self::LogCoercion($context, 'string', $attr, $val);
if (is_int($val) || is_float($val) || $val instanceof Stringish) {
if (($val is int) || ($val is float) || $val instanceof Stringish) {
return (string)$val;
}

Expand All @@ -79,7 +79,7 @@ public static function CoerceToInt(
): int {
self::LogCoercion($context, 'int', $attr, $val);
if (
(is_string($val) && is_numeric($val) && $val !== '') || is_float($val)
(($val is string) && is_numeric($val) && $val !== '') || ($val is float)
) {
return (int)$val;
}
Expand Down
2 changes: 1 addition & 1 deletion src/html/RawPcdataElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ abstract class :xhp:raw-pcdata-element extends :xhp:pcdata-element {
protected function stringify(): string {
$buf = $this->renderBaseAttrs().'>';
foreach ($this->getChildren() as $child) {
if (!is_string($child)) {
if (!($child is string)) {
throw new XHPClassException($this, 'Child must be a string');
}
$buf .= $child;
Expand Down
10 changes: 3 additions & 7 deletions src/html/tags/c/ConditionalComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,14 @@
* the conditional statement.
*/
class :x:conditional-comment extends :x:primitive {
attribute Stringish if @required;
attribute string if @required;
children (pcdata | :xhp)*;

protected function stringify(): string {
$children = $this->getChildren();
$html = '<!--[if '.(string)$this->:if.']>';
$html = '<!--[if '.$this->:if.']>';
foreach ($children as $child) {
if ($child instanceof :xhp) {
$html .= :xhp::renderChild($child);
} else {
$html .= (string)$child;
}
$html .= :xhp::renderChild($child);
}
$html .= '<![endif]-->';
return $html;
Expand Down
Loading

0 comments on commit c120648

Please sign in to comment.