diff --git a/src/CodegenFile.hack b/src/CodegenFile.hack index 2bc8cd22..e3a3eadd 100644 --- a/src/CodegenFile.hack +++ b/src/CodegenFile.hack @@ -24,6 +24,7 @@ enum CodegenFileType: int { HACK_DECL = 1; HACK_PARTIAL = 2; HACK_STRICT = 3; + DOT_HACK = 4; } /** @@ -223,6 +224,8 @@ final class CodegenFile { return 'addLine($shebang); } - $builder->addLine($this->getFileTypeDeclaration()); + $decl = $this->getFileTypeDeclaration(); + if ($decl !== '') { + $builder->addLine($decl); + } $header = $this->config->getFileHeader(); if ($header) { foreach ($header as $line) { diff --git a/tests/CodegenFileTest.codegen b/tests/CodegenFileTest.codegen index ac0c3ff9..f53be17e 100644 --- a/tests/CodegenFileTest.codegen +++ b/tests/CodegenFileTest.codegen @@ -35,6 +35,20 @@ const string FOO = 'bar'; */ const string HERP = 'derp'; +!@#$%codegentest:testDotHackExecutable +#!/usr/bin/env hhvm +// Codegen Tests +/** + * This file is generated. Do not modify it manually! + * + * @-generated SignedSource<<2e680a68425d6302b789a6588a8218e4>> + */ + +<<__EntryPoint>> +function main(): noreturn { + exit(0); +} + !@#$%codegentest:testExecutable #!/usr/bin/env hhvm getCodegenFactory(); + $code = $cgf + ->codegenFile('no_file') + ->setFileType(CodegenFileType::DOT_HACK) + ->setShebangLine('#!/usr/bin/env hhvm') + ->addFunction( + $cgf->codegenFunction('main') + ->setReturnType('noreturn') + ->addEmptyUserAttribute('__EntryPoint') + ->setBody('exit(0);') + ) + ->render(); + expect_with_context(static::class, $code)->toBeUnchanged(); + } + public function testNoPseudoMainHeaderInStrict(): void { expect(() ==> { $cgf = $this->getCodegenFactory();