diff --git a/lib/lvelements/compiler/src/compiler.cpp b/lib/lvelements/compiler/src/compiler.cpp index 14ae52e4..caa5004c 100644 --- a/lib/lvelements/compiler/src/compiler.cpp +++ b/lib/lvelements/compiler/src/compiler.cpp @@ -395,6 +395,7 @@ Compiler::Config::Config(bool fileOutput, const std::string &outputExtension, Fi , m_fileIO(ioInterface) , m_outputExtension(outputExtension) , m_enableJsImports(true) + , m_enableComponentMetaInfo(true) , m_allowUnresolved(true) { if ( m_fileOutput && !m_fileIO ){ diff --git a/lib/lvelements/compiler/src/languagenodes.cpp b/lib/lvelements/compiler/src/languagenodes.cpp index 6ceefc0a..35326104 100644 --- a/lib/lvelements/compiler/src/languagenodes.cpp +++ b/lib/lvelements/compiler/src/languagenodes.cpp @@ -197,14 +197,16 @@ JsBlockNode *BaseNode::addUsedIdentifier(BaseNode *parent, IdentifierNode *idNod return nullptr; } +std::string BaseNode::nodeSourceFilePath(BaseNode *p){ + while (p && !p->isNodeType() ) + p = p->parent(); + return p && p->isNodeType() ? static_cast(p)->m_filePath : ""; +} + void BaseNode::assertValid(BaseNode *from, const TSNode &node, const std::string& message){ if ( ts_node_is_null(node) ){ SyntaxException se = CREATE_EXCEPTION(SyntaxException, "Syntax error: " + message, Exception::toCode("~Language")); - BaseNode* p = from; - while (p && p->nodeType() != ProgramNode::nodeInfoType()) - p = p->parent(); - - std::string fileName = p && p->isNodeType() ? static_cast(p)->m_filePath : ""; + std::string fileName = BaseNode::nodeSourceFilePath(from); int line = from ? ts_node_start_point(from->current()).row : -2; int column = from ? ts_node_start_point(from->current()).column : -2; int startByte = from ? ts_node_start_byte(from->current()) : -1; @@ -218,11 +220,7 @@ void BaseNode::assertValid(BaseNode *from, const TSNode &node, const std::string void BaseNode::assertError(BaseNode *from, const TSNode &node, const std::string &message){ if ( strcmp(ts_node_type(node), "ERROR") == 0 ){ SyntaxException se = CREATE_EXCEPTION(SyntaxException, "Syntax error: " + message, Exception::toCode("~Language")); - BaseNode* p = from; - while (p && !p->isNodeType() ) - p = p->parent(); - - std::string fileName = p && p->isNodeType() ? static_cast(p)->m_filePath : ""; + std::string fileName = BaseNode::nodeSourceFilePath(from); se.setParseLocation(ts_node_start_point(node).row + 1, ts_node_start_point(node).column + 1, ts_node_start_byte(node), fileName); throw se; } @@ -230,11 +228,7 @@ void BaseNode::assertError(BaseNode *from, const TSNode &node, const std::string void BaseNode::throwError(BaseNode *from, const TSNode &node, const std::string &message){ SyntaxException se = CREATE_EXCEPTION(SyntaxException, "Syntax error: " + message, Exception::toCode("~LanguageNodes")); - BaseNode* p = from; - while (p && !p->isNodeType() ) - p = p->parent(); - - std::string fileName = p && p->isNodeType() ? static_cast(p)->m_filePath : ""; + std::string fileName = BaseNode::nodeSourceFilePath(from); se.setParseLocation(ts_node_start_point(node).row + 1, ts_node_start_point(node).column + 1, ts_node_start_byte(node), fileName); throw se; } @@ -453,11 +447,7 @@ void BaseNode::visit(BaseNode *parent, const TSNode &node){ visitTryCatchBlock(parent, node); } else if ( strcmp(ts_node_type(node), "ERROR") == 0 ){ SyntaxException se = CREATE_EXCEPTION(SyntaxException, "Syntax error.", Exception::toCode("~LanguageNodes")); - BaseNode* p = parent; - while (p && !p->isNodeType() ) - p = p->parent(); - - std::string fileName = p && p->isNodeType() ? static_cast(p)->m_filePath : ""; + std::string fileName = BaseNode::nodeSourceFilePath(parent); se.setParseLocation(ts_node_start_point(node).row + 1, ts_node_start_point(node).column + 1, ts_node_start_byte(node), fileName); throw se; diff --git a/lib/lvelements/compiler/src/languagenodes_p.h b/lib/lvelements/compiler/src/languagenodes_p.h index b5cb1603..5b8e6166 100644 --- a/lib/lvelements/compiler/src/languagenodes_p.h +++ b/lib/lvelements/compiler/src/languagenodes_p.h @@ -121,6 +121,7 @@ class BaseNode{ BaseNode* parent() const{ return m_parent; } void setParent(BaseNode* parent){ m_parent = parent; } + static std::string nodeSourceFilePath(BaseNode* node); static TSNode nodeChildByFieldName(const TSNode& node, const std::string& name); static std::vector fromNestedIdentifier(BaseNode* parent, const TSNode& node); static ParameterListNode* scanFormalParameters(BaseNode* parent, const TSNode& formalParameters); diff --git a/lib/lvelements/compiler/test/unit/data/ParserErrorTest03.lv b/lib/lvelements/compiler/test/unit/data/ParserErrorTest03.lv index 560fae2f..c29205e3 100644 --- a/lib/lvelements/compiler/test/unit/data/ParserErrorTest03.lv +++ b/lib/lvelements/compiler/test/unit/data/ParserErrorTest03.lv @@ -1,4 +1,4 @@ component X{ style = { fontSize: '12px' } other = { return {clicks: 0 } } -} \ No newline at end of file +}