Skip to content

Commit 7f903e2

Browse files
committed
重新实现只有注释的文件的格式化
1 parent 66a38c0 commit 7f903e2

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

LuaParser/src/LuaParser.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,21 @@ void LuaParser::BuildAstWithComment()
127127
{
128128
BuildAst();
129129

130-
auto chunkChildren = _chunkAstNode->GetChildren();
130+
auto& chunkChildren = _chunkAstNode->GetChildren();
131+
auto& comments = _tokenParser->GetComments();
131132
if (chunkChildren.empty())
132133
{
133-
return;
134+
if (comments.empty()) {
135+
return;
136+
137+
}
138+
auto block = CreateAstNode(LuaAstNodeType::Block);
139+
chunkChildren.push_back(block);
134140
}
135141

136142
auto blockNode = chunkChildren.front();
137143

138-
auto& comments = _tokenParser->GetComments();
144+
139145
// 将注释注入AST中
140146
if (!comments.empty())
141147
{

0 commit comments

Comments
 (0)