Skip to content

Commit

Permalink
lvelements.compiler: Added component meta inclusion as default.
Browse files Browse the repository at this point in the history
  • Loading branch information
dinusv committed Nov 10, 2023
1 parent 8fa5c95 commit d4056da
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 21 deletions.
1 change: 1 addition & 0 deletions lib/lvelements/compiler/src/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ){
Expand Down
30 changes: 10 additions & 20 deletions lib/lvelements/compiler/src/languagenodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,16 @@ JsBlockNode *BaseNode::addUsedIdentifier(BaseNode *parent, IdentifierNode *idNod
return nullptr;
}

std::string BaseNode::nodeSourceFilePath(BaseNode *p){
while (p && !p->isNodeType<ProgramNode>() )
p = p->parent();
return p && p->isNodeType<ProgramNode>() ? static_cast<ProgramNode*>(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<ProgramNode>() ? static_cast<ProgramNode*>(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;
Expand All @@ -218,23 +220,15 @@ 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<ProgramNode>() )
p = p->parent();

std::string fileName = p && p->isNodeType<ProgramNode>() ? static_cast<ProgramNode*>(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;
}
}

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<ProgramNode>() )
p = p->parent();

std::string fileName = p && p->isNodeType<ProgramNode>() ? static_cast<ProgramNode*>(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;
}
Expand Down Expand Up @@ -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<ProgramNode>() )
p = p->parent();

std::string fileName = p && p->isNodeType<ProgramNode>() ? static_cast<ProgramNode*>(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;
Expand Down
1 change: 1 addition & 0 deletions lib/lvelements/compiler/src/languagenodes_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<IdentifierNode*> fromNestedIdentifier(BaseNode* parent, const TSNode& node);
static ParameterListNode* scanFormalParameters(BaseNode* parent, const TSNode& formalParameters);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
component X{
style = { fontSize: '12px' }
other = { return {clicks: 0 } }
}
}

0 comments on commit d4056da

Please sign in to comment.