This repository was archived by the owner on Dec 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathLegacyArrayTypesToHackArrayTypesMigration.hack
More file actions
63 lines (57 loc) · 1.82 KB
/
LegacyArrayTypesToHackArrayTypesMigration.hack
File metadata and controls
63 lines (57 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* Copyright (c) 2017-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\HHAST;
final class LegacyArrayTypesToHackArrayTypesMigration
extends StepBasedMigration {
<<__Override>>
public function getSteps(): Traversable<IMigrationStep> {
return vec[
new NodeTypeMigrationStep<VarrayTypeSpecifier, _>(
'Migrate varray<string> to vec<string>',
$node ==> self::migrateVarray($node),
),
new NodeTypeMigrationStep<DarrayTypeSpecifier, _>(
'Migrate darray<string, string> to dict<string, string>',
$node ==> self::migrateDarray($node),
),
];
}
private static function migrateVarray(
VarrayTypeSpecifier $varray,
): VectorTypeSpecifier {
$keyword = $varray->getKeyword();
return new VectorTypeSpecifier(
new VecToken($keyword->getLeading(), $keyword->getTrailing()),
$varray->getLeftAngle(),
$varray->getType(),
$varray->getTrailingComma(),
$varray->getRightAngle(),
);
}
private static function migrateDarray(
DarrayTypeSpecifier $darray,
): DictionaryTypeSpecifier {
$keyword = $darray->getKeyword();
$trailing_comma = $darray->getTrailingComma();
invariant(
$trailing_comma is ?Token,
'No syntax example for darray<Tk, Tv,>, Node was inferred. '.
'Assuming CommaToken, but at least Token.',
);
return new DictionaryTypeSpecifier(
new DictToken($keyword->getLeading(), $keyword->getTrailing()),
$darray->getLeftAngle(),
new NodeList(vec[
new ListItem($darray->getKey(), $darray->getComma()),
new ListItem($darray->getValue(), $trailing_comma),
]),
$darray->getRightAngle(),
);
}
}