Ensure that empty modules can build in TypeScript isolatedModules mode (#7726)

This commit is contained in:
Max Burke 2023-01-06 16:42:26 -08:00 committed by GitHub
parent 4d6a7aa8b7
commit 81724e5b20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 0 deletions

View File

@ -277,6 +277,13 @@ class TsGenerator : public BaseGenerator {
for (auto it = imports_all_.begin(); it != imports_all_.end(); it++) {
code += it->second.export_statement + "\n";
}
if (imports_all_.empty()) {
// if the file is empty, add an empty export so that tsc doesn't
// complain when running under `--isolatedModules` mode
code += "export {}";
}
const std::string path =
GeneratedFileName(path_, file_name_, parser_.opts);
SaveFile(path.c_str(), code, false);