summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2026-01-30 09:53:33 +0800
committerLi Jin <dragon-fly@qq.com>2026-01-30 09:53:33 +0800
commit220a10d0df3341b2bbb0beaee4f90d6480e7ae38 (patch)
tree8241db522f952236daa6308bdb8931b6e21485fd /src
parent0cece2cad82bcd95bcb20f3d984817f7085fd4f8 (diff)
downloadyuescript-220a10d0df3341b2bbb0beaee4f90d6480e7ae38.tar.gz
yuescript-220a10d0df3341b2bbb0beaee4f90d6480e7ae38.tar.bz2
yuescript-220a10d0df3341b2bbb0beaee4f90d6480e7ae38.zip
Fixed global variables lint.HEADv0.32.7main
Diffstat (limited to 'src')
-rw-r--r--src/yuescript/yue_compiler.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp
index 370cee4..6aa7cfd 100644
--- a/src/yuescript/yue_compiler.cpp
+++ b/src/yuescript/yue_compiler.cpp
@@ -442,6 +442,7 @@ private:
442 std::string nl; 442 std::string nl;
443 std::unordered_set<std::string_view> globals; 443 std::unordered_set<std::string_view> globals;
444 str_list globalList; 444 str_list globalList;
445 ast_node* importContent = nullptr;
445 }; 446 };
446 struct Scope { 447 struct Scope {
447 GlobalMode mode = GlobalMode::None; 448 GlobalMode mode = GlobalMode::None;
@@ -5369,6 +5370,7 @@ private:
5369 _importedGlobal->indent = indent(); 5370 _importedGlobal->indent = indent();
5370 _importedGlobal->nl = nl(stmt); 5371 _importedGlobal->nl = nl(stmt);
5371 _importedGlobal->globalCodeLine = &temp.emplace_back(); 5372 _importedGlobal->globalCodeLine = &temp.emplace_back();
5373 _importedGlobal->importContent = importNode->content.get();
5372 } 5374 }
5373 } 5375 }
5374 } else { 5376 } else {
@@ -5417,6 +5419,13 @@ private:
5417 auto attrib = target >= 504 ? " <const>"s : Empty; 5419 auto attrib = target >= 504 ? " <const>"s : Empty;
5418 str_list globalCodes; 5420 str_list globalCodes;
5419 for (const auto& global : importedGlobal->globalList) { 5421 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 }
5420 globalCodes.emplace_back(importedGlobal->indent + "local "s + global + attrib + " = "s + global + importedGlobal->nl); 5429 globalCodes.emplace_back(importedGlobal->indent + "local "s + global + attrib + " = "s + global + importedGlobal->nl);
5421 } 5430 }
5422 *importedGlobal->globalCodeLine = join(globalCodes); 5431 *importedGlobal->globalCodeLine = join(globalCodes);