Skip to content

Instantly share code, notes, and snippets.

@fredemmott
Created February 25, 2020 17:00
Show Gist options
  • Save fredemmott/04b62e7b0f46e59fd9559e03fc22ece6 to your computer and use it in GitHub Desktop.
Save fredemmott/04b62e7b0f46e59fd9559e03fc22ece6 to your computer and use it in GitHub Desktop.
diff --git a/.travis.sh b/.travis.sh
index 1f6d6d9..021f46c 100755
--- a/.travis.sh
+++ b/.travis.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
set -ex
apt update -y
DEBIAN_FRONTEND=noninteractive apt install -y php-cli zip unzip
@@ -13,3 +13,24 @@ composer install
hh_client
vendor/bin/hacktest tests/
+
+if [ "$(hhvm --php -r 'var_dump(HHVM_VERSION_ID >= 44600);')" = "bool(true)" ]; then
+ vendor/bin/hhast-migrate \
+ --demangle-xhp-class-names \
+ --add-xhp-children-declaration-method \
+ --remove-xhp-child-declarations \
+ src/ tests/
+
+ hh_client stop
+ echo disable_xhp_element_mangling=true >> .hhconfig
+ echo enable_xhp_class_modifier=true >> .hhconfig
+ hh_client
+ hhvm -dhhvm.hack.lang.disable_xhp_element_mangling=true -dhhvm.hack.lang.enable_xhp_class_modifier=true vendor/bin/hh-autoload
+ hhvm -dhhvm.hack.lang.disable_xhp_element_mangling=true -dhhvm.hack.lang.enable_xhp_class_modifier=true vendor/bin/hacktest tests/
+
+ vendor/bin/hhast-migrate --xhp-class-modifier src tests
+
+ hh_client
+ hhvm -dhhvm.hack.lang.disable_xhp_element_mangling=true -dhhvm.hack.lang.enable_xhp_class_modifier=true vendor/bin/hh-autoload
+ hhvm -dhhvm.hack.lang.disable_xhp_element_mangling=true -dhhvm.hack.lang.enable_xhp_class_modifier=true vendor/bin/hacktest tests/
+fi
diff --git a/.travis.yml b/.travis.yml
index 7fb90f7..b016fe7 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,7 +2,7 @@ sudo: required
language: generic
services: docker
env:
-- HHVM_VERSION=4.25-latest
+- HHVM_VERSION=4.33-latest
- HHVM_VERSION=latest
- HHVM_VERSION=nightly
install:
diff --git a/composer.json b/composer.json
index 45c4bae..7fd61c2 100644
--- a/composer.json
+++ b/composer.json
@@ -11,6 +11,7 @@
"require-dev": {
"facebook/fbexpect": "^2.0.0",
"hhvm/hhvm-autoload": "^2.0|^3.0",
+ "hhvm/hhast": "^4.33.7",
"hhvm/hacktest": "^2.0"
},
"extra": {
diff --git a/src/children/private.hack b/src/children/private.hack
new file mode 100644
index 0000000..e71f170
--- /dev/null
+++ b/src/children/private.hack
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2004-present, Facebook, Inc.
+ * All rights reserved.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ *
+ */
+
+namespace Facebook\XHP\ChildValidation\_Private;
+
+use namespace Facebook\XHP\ChildValidation as XHPChild;
+
+function normalize(mixed $x): mixed {
+ if (
+ $x is (int, int, mixed) &&
+ $x[0] === XHPChild\LegacyExpressionType::EXACTLY_ONE &&
+ $x[1] === XHPChild\LegacyConstraintType::EXPRESSION
+ ) {
+ return normalize($x[2]);
+ }
+
+ if ($x is (int, mixed, mixed)) {
+ return tuple($x[0], normalize($x[1]), normalize($x[2]));
+ }
+
+ return $x;
+}
diff --git a/src/core/ReflectionXHPChildrenDeclaration.php b/src/core/ReflectionXHPChildrenDeclaration.php
index f695f9e..467ded9 100644
--- a/src/core/ReflectionXHPChildrenDeclaration.php
+++ b/src/core/ReflectionXHPChildrenDeclaration.php
@@ -35,7 +35,9 @@ enum XHPChildrenConstraintType: int {
}
class ReflectionXHPChildrenDeclaration {
- public function __construct(private string $context, private mixed $data) {
+ private mixed $data;
+ public function __construct(private string $context, mixed $data) {
+ $this->data = \Facebook\XHP\ChildValidation\_Private\normalize($data);
}
<<__Memoize>>
diff --git a/tests/ChildRuleTest.php b/tests/ChildRuleTest.php
index fa04b74..65e92d5 100644
--- a/tests/ChildRuleTest.php
+++ b/tests/ChildRuleTest.php
@@ -285,17 +285,17 @@ class ChildRuleTest extends Facebook\HackTest\HackTest {
return vec[
tuple(<test:any-children />, 'any'),
tuple(<test:no-children />, 'empty'),
- tuple(<test:single-child />, '(:div)'),
- tuple(<test:optional-child />, '(:div?)'),
- tuple(<test:any-number-of-child />, '(:div*)'),
- tuple(<test:at-least-one-child />, '(:div+)'),
- tuple(<test:two-children />, '(:div,:div)'),
- tuple(<test:three-children />, '(:div,:div,:div)'),
- tuple(<test:either-of-two-children />, '(:div|:code)'),
- tuple(<test:any-of-three-children />, '(:div|:code|:p)'),
- tuple(<test:nested-rule />, '(:div|(:code+))'),
- tuple(<test:pcdata-child />, '(pcdata)'),
- tuple(<test:category-child />, '(%flow)'),
+ tuple(<test:single-child />, ':div'),
+ tuple(<test:optional-child />, ':div?'),
+ tuple(<test:any-number-of-child />, ':div*'),
+ tuple(<test:at-least-one-child />, ':div+'),
+ tuple(<test:two-children />, ':div,:div'),
+ tuple(<test:three-children />, ':div,:div,:div'),
+ tuple(<test:either-of-two-children />, ':div|:code'),
+ tuple(<test:any-of-three-children />, ':div|:code|:p'),
+ tuple(<test:nested-rule />, ':div|:code+'),
+ tuple(<test:pcdata-child />, 'pcdata'),
+ tuple(<test:category-child />, '%flow'),
];
}
@@ -461,10 +461,4 @@ class ChildRuleTest extends Facebook\HackTest\HackTest {
)->toString(),
)->toThrow(XHPInvalidChildrenException::class);
}
-
-
- public function testConflictingNewAndOldChildDeclarations(): void {
- expect(() ==> (<test:new-and-old-child-declarations />)->toString())
- ->toThrow(InvariantException::class);
- }
}
diff --git a/tests/ReflectionTest.php b/tests/ReflectionTest.php
index 4bbf66d..adf1ab1 100644
--- a/tests/ReflectionTest.php
+++ b/tests/ReflectionTest.php
@@ -35,7 +35,10 @@ class ReflectionTest extends Facebook\HackTest\HackTest {
}
public function testElementName(): void {
- expect($this->rxc?->getElementName())->toEqual('test:for-reflection');
+ $name = $this->rxc?->getElementName() ?? 'NULL';
+ expect(keyset['test:for-reflection', 'test:for_reflection'])->toContainKey(
+ $name,
+ );
}
public function testReflectionClass(): void {
@@ -47,7 +50,7 @@ class ReflectionTest extends Facebook\HackTest\HackTest {
public function testGetChildren(): void {
$children = $this->rxc?->getChildren();
expect($children)->toBeInstanceOf(ReflectionXHPChildrenDeclaration::class);
- expect($children?->__toString())->toEqual('(:div+,(:code,:a)?)');
+ expect($children?->__toString())->toEqual(':div+,(:code,:a)?');
}
public function testGetAttributes(): void {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment