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

Commit 186d1fc

Browse files
lexidorAtry
authored andcommitted
Get typeAliasses from types if not available
1 parent 178ad28 commit 186d1fc

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/TypeAssert.hack

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,21 @@ function is_nullable_enum<Tval as arraykey, T as \HH\BuiltinEnum<Tval>>(
8282
return $value;
8383
}
8484

85-
function is_array_of_shapes_with_name_field(
85+
function is_array_of_shapes_with_name_field_and_kind(
8686
mixed $value,
8787
string $field,
88-
): varray<shape('name' => string)> {
89-
$msg = $field.'should be an vec<shape(\'name\' => string)>';
88+
): varray<shape('name' => string, 'kindOf' => string)> {
89+
$msg =
90+
$field.'should be a vec<shape(\'name\' => string, \'kindOf\' => string)>';
9091
invariant($value is Traversable<_>, '%s', $msg);
9192
$out = varray[];
9293
foreach ($value as $it) {
9394
invariant($it is KeyedContainer<_, _>, '%s', $msg);
9495
$name = $it['name'] ?? null;
9596
invariant($name is string, '%s', $msg);
96-
$out[] = shape('name' => $name);
97+
$kind_of = $it['kindOf'] ?? null;
98+
invariant($kind_of is string, '%s', $msg);
99+
$out[] = shape('name' => $name, 'kindOf' => $kind_of);
97100
}
98101
return $out;
99102
}

src/builders/FactParseScanner.hack

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
namespace Facebook\AutoloadMap;
1111

1212
use Facebook\AutoloadMap\_Private\TypeAssert;
13+
use namespace HH\Lib\{C, Vec};
1314

1415
/** Create an autoload map from a directory using `ext_factparse`. */
1516
final class FactParseScanner implements Builder {
1617
const type TFacts = darray<string, shape(
1718
'types' => varray<shape(
1819
'name' => string,
20+
'kindOf' => string,
1921
)>,
2022
'constants' => varray<string>,
2123
'functions' => varray<string>,
@@ -38,11 +40,12 @@ final class FactParseScanner implements Builder {
3840
);
3941

4042
try {
43+
$types = TypeAssert\is_array_of_shapes_with_name_field_and_kind(
44+
$facts['types'] ?? vec[],
45+
'FactParse types',
46+
);
4147
$out[$file] = shape(
42-
'types' => TypeAssert\is_array_of_shapes_with_name_field(
43-
$facts['types'] ?? vec[],
44-
'FactParse types',
45-
),
48+
'types' => $types,
4649
'constants' => TypeAssert\is_array_of_strings(
4750
$facts['constants'] ?? vec[],
4851
'FactParse constants',
@@ -56,6 +59,14 @@ final class FactParseScanner implements Builder {
5659
'FactParse typeAliases',
5760
),
5861
);
62+
63+
// On hhvm >4.160, typeAliases may not be present,
64+
// we can extract type aliases from `types` where `kindOf` === `typeAlias`.
65+
if (!C\contains_key($facts, 'typeAliases')) {
66+
$out[$file]['typeAliases'] =
67+
Vec\filter($types, $shape ==> $shape['kindOf'] === 'typeAlias')
68+
|> Vec\map($$, $shape ==> $shape['name']);
69+
}
5970
} catch (\Exception $e) {
6071
$error_level = \error_reporting(0);
6172
$file_is_empty = \filesize($file) === 0;

0 commit comments

Comments
 (0)