Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.

Commit 595b169

Browse files
committed
Add HackBuilderValues::code()
fixes #69
1 parent 0ac1dca commit 595b169

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?hh // strict
2+
/*
3+
* Copyright (c) 2015, Facebook, Inc.
4+
* All rights reserved.
5+
*
6+
* This source code is licensed under the BSD-style license found in the
7+
* LICENSE file in the root directory of this source tree. An additional grant
8+
* of patent rights can be found in the PATENTS file in the same directory.
9+
*
10+
*/
11+
12+
namespace Facebook\HackCodegen;
13+
14+
final class HackBuilderCodeRenderer
15+
implements IHackBuilderValueRenderer<HackBuilder> {
16+
17+
final public function render(
18+
IHackCodegenConfig $_,
19+
HackBuilder $value,
20+
): string {
21+
return $value->getCode();
22+
}
23+
}

src/key-value-render/HackBuilderValues.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ public static function export(): IHackBuilderValueRenderer<mixed> {
2323
return new HackBuilderValueExportRenderer();
2424
}
2525

26+
public static function code(): IHackBuilderValueRenderer<HackBuilder> {
27+
return new HackBuilderCodeRenderer();
28+
}
29+
2630
public static function valueArray<Tv>(
2731
IHackBuilderValueRenderer<Tv> $vr,
2832
): IHackBuilderValueRenderer<array<Tv>> {

test/HackBuilderTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ public function testDocBlock(): void {
6565
$this->assertUnchanged($body->getCode(), 'docblock2');
6666
}
6767

68+
public function testAsValue(): void {
69+
$dict = $this->getHackBuilder()->addValue(
70+
dict[
71+
'foo' =>
72+
$this->getHackBuilder()->addValue('bar', HackBuilderValues::literal()),
73+
],
74+
HackBuilderValues::dict(
75+
HackBuilderKeys::export(),
76+
HackBuilderValues::code(),
77+
),
78+
);
79+
}
80+
6881
public function testShapeWithUniformRendering(): void {
6982
$shape = $this
7083
->getHackBuilder()

0 commit comments

Comments
 (0)