Skip to content

Commit

Permalink
Add HackBuilderValues::code()
Browse files Browse the repository at this point in the history
fixes #69
  • Loading branch information
fredemmott committed Jan 8, 2018
1 parent 0ac1dca commit 595b169
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/key-value-render/HackBuilderCodeRenderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?hh // strict
/*
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/

namespace Facebook\HackCodegen;

final class HackBuilderCodeRenderer
implements IHackBuilderValueRenderer<HackBuilder> {

final public function render(
IHackCodegenConfig $_,
HackBuilder $value,
): string {
return $value->getCode();
}
}
4 changes: 4 additions & 0 deletions src/key-value-render/HackBuilderValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public static function export(): IHackBuilderValueRenderer<mixed> {
return new HackBuilderValueExportRenderer();
}

public static function code(): IHackBuilderValueRenderer<HackBuilder> {
return new HackBuilderCodeRenderer();
}

public static function valueArray<Tv>(
IHackBuilderValueRenderer<Tv> $vr,
): IHackBuilderValueRenderer<array<Tv>> {
Expand Down
13 changes: 13 additions & 0 deletions test/HackBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ public function testDocBlock(): void {
$this->assertUnchanged($body->getCode(), 'docblock2');
}

public function testAsValue(): void {
$dict = $this->getHackBuilder()->addValue(
dict[
'foo' =>
$this->getHackBuilder()->addValue('bar', HackBuilderValues::literal()),
],
HackBuilderValues::dict(
HackBuilderKeys::export(),
HackBuilderValues::code(),
),
);
}

public function testShapeWithUniformRendering(): void {
$shape = $this
->getHackBuilder()
Expand Down

0 comments on commit 595b169

Please sign in to comment.