diff --git a/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp b/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp index 5864e03905c8ea279bc60292ea04d96e63840ea8..30b22ef0bee4629ad088cc018c71c143269f93e2 100644 --- a/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp +++ b/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp @@ -403,6 +403,24 @@ void TSDeclGen::GenExportNamedDeclarations() } } +void TSDeclGen::GenInitModuleGlueCode() +{ + for (auto *stmt : program_->Ast()->Statements()) { + if (!stmt->IsExpressionStatement()) { + continue; + } + if (!stmt->AsExpressionStatement()->GetExpression()->IsCallExpression()) { + continue; + } + auto *callExpr = stmt->AsExpressionStatement()->GetExpression()->AsCallExpression(); + if (callExpr->Callee()->IsIdentifier() && + callExpr->Callee()->AsIdentifier()->Name() == compiler::Signatures::INIT_MODULE_METHOD) { + OutTs("import \"", callExpr->Arguments()[0]->ToString(), "\""); + OutEndlTs(); + } + } +} + void TSDeclGen::GenImportDeclarations() { for (auto *globalStatement : program_->Ast()->Statements()) { @@ -2575,13 +2593,17 @@ bool GenerateTsDeclarations(checker::ETSChecker *checker, const ark::es2panda::p declBuilder.ResetTsOutput(); declBuilder.ResetDtsOutput(); + declBuilder.GenInitModuleGlueCode(); + std::string initModuleOutputEts = declBuilder.GetTsOutput(); + declBuilder.ResetTsOutput(); + compiler::GetPhaseManager()->SetCurrentPhaseIdWithoutReCheck(afterCheckerId); declBuilder.GenImportDeclarations(); std::string importOutputEts = declBuilder.GetTsOutput(); std::string importOutputDEts = declBuilder.GetDtsOutput(); - std::string combineEts = importOutputEts + outputEts + exportOutputEts; + std::string combineEts = importOutputEts + initModuleOutputEts + outputEts + exportOutputEts; std::string combinedDEts = importOutputDEts + outputDEts + exportOutputDEts; if (!declBuilder.GetDeclgenOptions().recordFile.empty()) { diff --git a/ets2panda/declgen_ets2ts/declgenEts2Ts.h b/ets2panda/declgen_ets2ts/declgenEts2Ts.h index 363f74c8ab06ab037e3eac7c4c597b6a9f39e704..7e79a37f53dd68670a761269820aa93329fb4e8d 100644 --- a/ets2panda/declgen_ets2ts/declgenEts2Ts.h +++ b/ets2panda/declgen_ets2ts/declgenEts2Ts.h @@ -75,6 +75,7 @@ public: bool Generate(); void GenImportDeclarations(); void GenExportNamedDeclarations(); + void GenInitModuleGlueCode(); void GenImportRecordDeclarations(const std::string &source); std::string GetDtsOutput() const