Skip to content

Commit 220a10d

Browse files
committed
Fixed global variables lint.
1 parent 0cece2c commit 220a10d

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

src/yuescript/yue_compiler.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ class YueCompilerImpl {
442442
std::string nl;
443443
std::unordered_set<std::string_view> globals;
444444
str_list globalList;
445+
ast_node* importContent = nullptr;
445446
};
446447
struct Scope {
447448
GlobalMode mode = GlobalMode::None;
@@ -5369,6 +5370,7 @@ class YueCompilerImpl {
53695370
_importedGlobal->indent = indent();
53705371
_importedGlobal->nl = nl(stmt);
53715372
_importedGlobal->globalCodeLine = &temp.emplace_back();
5373+
_importedGlobal->importContent = importNode->content.get();
53725374
}
53735375
}
53745376
} else {
@@ -5417,6 +5419,13 @@ class YueCompilerImpl {
54175419
auto attrib = target >= 504 ? " <const>"s : Empty;
54185420
str_list globalCodes;
54195421
for (const auto& global : importedGlobal->globalList) {
5422+
if (_config.lintGlobalVariable) {
5423+
auto item = importedGlobal->importContent;
5424+
auto key = global + ':' + std::to_string(item->m_begin.m_line) + ':' + std::to_string(item->m_begin.m_col);
5425+
if (_globals.find(key) == _globals.end()) {
5426+
_globals[key] = {global, item->m_begin.m_line, item->m_begin.m_col, AccessType::Read, false};
5427+
}
5428+
}
54205429
globalCodes.emplace_back(importedGlobal->indent + "local "s + global + attrib + " = "s + global + importedGlobal->nl);
54215430
}
54225431
*importedGlobal->globalCodeLine = join(globalCodes);

0 commit comments

Comments
 (0)