This repository was archived by the owner on Aug 25, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +37
-1
lines changed
Expand file tree Collapse file tree 3 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ enum CodegenFileType: int {
2424 HACK_DECL = 1 ;
2525 HACK_PARTIAL = 2 ;
2626 HACK_STRICT = 3 ;
27+ DOT_HACK = 4 ;
2728}
2829
2930/**
@@ -223,6 +224,8 @@ final class CodegenFile {
223224 return ' <?hh // partial' ;
224225 case CodegenFileType :: HACK_STRICT :
225226 return ' <?hh // strict' ;
227+ case CodegenFileType :: DOT_HACK :
228+ return ' ' ;
226229 }
227230 }
228231
@@ -298,7 +301,10 @@ final class CodegenFile {
298301 $builder -> addLine($shebang );
299302 }
300303
301- $builder -> addLine($this -> getFileTypeDeclaration());
304+ $decl = $this -> getFileTypeDeclaration();
305+ if ($decl !== ' ' ) {
306+ $builder -> addLine($decl );
307+ }
302308 $header = $this -> config -> getFileHeader();
303309 if ($header ) {
304310 foreach ($header as $line ) {
Original file line number Diff line number Diff line change @@ -35,6 +35,20 @@ const string FOO = 'bar';
3535 */
3636const string HERP = 'derp';
3737
38+ !@#$%codegentest:testDotHackExecutable
39+ #!/usr/bin/env hhvm
40+ // Codegen Tests
41+ /**
42+ * This file is generated. Do not modify it manually!
43+ *
44+ * @-generated SignedSource<<2e680a68425d6302b789a6588a8218e4>>
45+ */
46+
47+ <<__EntryPoint>>
48+ function main(): noreturn {
49+ exit(0);
50+ }
51+
3852!@#$%codegentest:testExecutable
3953#!/usr/bin/env hhvm
4054<?hh // partial
Original file line number Diff line number Diff line change @@ -316,6 +316,22 @@ final class CodegenFileTest extends CodegenBaseTest {
316316);
317317 }
318318
319+ public function testDotHackExecutable (): void {
320+ $cgf = $this -> getCodegenFactory();
321+ $code = $cgf
322+ -> codegenFile(' no_file' )
323+ -> setFileType(CodegenFileType :: DOT_HACK )
324+ -> setShebangLine(' #!/usr/bin/env hhvm' )
325+ -> addFunction(
326+ $cgf -> codegenFunction(' main' )
327+ -> setReturnType(' noreturn' )
328+ -> addEmptyUserAttribute(' __EntryPoint' )
329+ -> setBody(' exit(0);' )
330+ )
331+ -> render();
332+ expect_with_context (static :: class , $code )-> toBeUnchanged();
333+ }
334+
319335 public function testNoPseudoMainHeaderInStrict (): void {
320336 expect (() ==> {
321337 $cgf = $this -> getCodegenFactory();
You can’t perform that action at this time.
0 commit comments