From 220a10d0df3341b2bbb0beaee4f90d6480e7ae38 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Fri, 30 Jan 2026 09:53:33 +0800 Subject: Fixed global variables lint. --- src/yuescript/yue_compiler.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src') 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: std::string nl; std::unordered_set globals; str_list globalList; + ast_node* importContent = nullptr; }; struct Scope { GlobalMode mode = GlobalMode::None; @@ -5369,6 +5370,7 @@ private: _importedGlobal->indent = indent(); _importedGlobal->nl = nl(stmt); _importedGlobal->globalCodeLine = &temp.emplace_back(); + _importedGlobal->importContent = importNode->content.get(); } } } else { @@ -5417,6 +5419,13 @@ private: auto attrib = target >= 504 ? " "s : Empty; str_list globalCodes; for (const auto& global : importedGlobal->globalList) { + if (_config.lintGlobalVariable) { + auto item = importedGlobal->importContent; + auto key = global + ':' + std::to_string(item->m_begin.m_line) + ':' + std::to_string(item->m_begin.m_col); + if (_globals.find(key) == _globals.end()) { + _globals[key] = {global, item->m_begin.m_line, item->m_begin.m_col, AccessType::Read, false}; + } + } globalCodes.emplace_back(importedGlobal->indent + "local "s + global + attrib + " = "s + global + importedGlobal->nl); } *importedGlobal->globalCodeLine = join(globalCodes); -- cgit v1.2.3-55-g6feb