diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index af5e8fe7d5bad4d3c61a4f8ff2420d1900263594..0e7f067ca1c2db751f63b53cd10dcf44d0bb2bd1 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -1035,7 +1035,9 @@ ir::ImportSource *ETSParser::ParseSourceFromClause(bool requireFrom) if (Lexer()->GetToken().Type() != lexer::TokenType::LITERAL_STRING) { LogExpectedToken(lexer::TokenType::LITERAL_STRING); - return nullptr; // Error processing. + // Try to create DUMMY import source as error placeholder + auto errorLiteral = AllocNode(ERROR_LITERAL); + return Allocator()->New(errorLiteral, errorLiteral, Language(Language::Id::ETS), false); } ES2PANDA_ASSERT(Lexer()->GetToken().Type() == lexer::TokenType::LITERAL_STRING); @@ -1065,11 +1067,6 @@ ir::Statement *ETSParser::ParseImportDeclarationHelper(lexer::SourcePosition sta ir::ImportKinds importKind) { auto const importSource = ParseSourceFromClause(true); - if (importSource == nullptr) { - // Error is logged inside ParseSourceFromClause - return AllocBrokenStatement(); // Error processing. - } - const auto endLocDef = importSource->Source()->End(); auto *const importDeclaration = AllocNode(importSource, std::move(specifiers), importKind); @@ -1108,9 +1105,7 @@ ArenaVector ETSParser::ParseImportDeclarations() auto pos = Lexer()->Save(); if (!specifiers.empty()) { auto *const importDecl = ParseImportDeclarationHelper(startLoc, specifiers, importKind); - if (!importDecl->IsBrokenStatement()) { - statements.push_back(importDecl->AsETSImportDeclaration()); - } + statements.push_back(importDecl->AsETSImportDeclaration()); } if (!defaultSpecifiers.empty()) { diff --git a/ets2panda/parser/parserImpl.cpp b/ets2panda/parser/parserImpl.cpp index 4c4411ab8c41b45e513a6edc4ad326e865dbafb2..b5755a6692ac63ea48d5df356540751c37039a1d 100644 --- a/ets2panda/parser/parserImpl.cpp +++ b/ets2panda/parser/parserImpl.cpp @@ -1280,7 +1280,9 @@ void ParserImpl::LogUnexpectedToken(lexer::TokenType tokenType) void ParserImpl::LogUnexpectedToken(lexer::Token const &token) { - LogSyntaxError(std::string(UNEXPECTED_TOKEN).append(token.ToString()).append("'.")); + if (token.ToString() != ERROR_LITERAL) { + LogError(diagnostic::UNEXPECTED_TOKEN_PARAM, {token.ToString()}); + } } void ParserImpl::LogExpectedToken(lexer::TokenType tokenType) diff --git a/ets2panda/varbinder/ETSBinder.cpp b/ets2panda/varbinder/ETSBinder.cpp index 3889f09cb86a7cb35697ce21e09d16899364848d..893a6b075fc545b414a1d46833ae1a5e387fcccb 100644 --- a/ets2panda/varbinder/ETSBinder.cpp +++ b/ets2panda/varbinder/ETSBinder.cpp @@ -921,6 +921,11 @@ varbinder::Variable *ETSBinder::FindStaticBinding(const ArenaVector ETSBinder::GetExternalProgram(const util::StringView &sourceName, const ir::StringLiteral *importPath) { + if (sourceName == ERROR_LITERAL) { + // avoid logging rediculus messages, there must be a syntax error + ASSERT(GetContext()->diagnosticEngine->IsAnyError()); + return ArenaVector(Allocator()->Adapter()); + } // NOTE: quick fix to make sure not to look for the global program among the external sources if (sourceName.Compare(globalRecordTable_.Program()->AbsoluteName()) == 0) { ArenaVector mainModule(Allocator()->Adapter());