From 1302aa460db48fca165ed4b2603e7ba085cf77ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 13 Aug 2020 18:49:03 +0800 Subject: =?UTF-8?q?=E6=94=AF=E6=8C=81=20return=20{}?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script-beta/parser/guide.lua | 43 ++++++++++++++++++++++++++++---------- test-beta/crossfile/references.lua | 4 ++-- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua index 533d2fed..8f2fe1bf 100644 --- a/script-beta/parser/guide.lua +++ b/script-beta/parser/guide.lua @@ -868,6 +868,7 @@ local function buildSimpleList(obj, max) list[i] = cur break elseif cur.type == 'function' + or cur.type == 'return' or cur.type == 'main' then break else @@ -1312,17 +1313,6 @@ function m.checkSameSimpleAsTableField(status, ref, start, queue) force = true, } end - -- 检查所属的table被return出去 - --local tbl = parent.parent - --local newStatus = m.status(status) - --m.searchRefsAsFunctionReturn(newStatus, tbl, 'ref') - --for _, res in ipairs(newStatus.results) do - -- queue[#queue+1] = { - -- obj = res, - -- start = start-1, - -- force = true, - -- } - --end end function m.checkSameSimpleAsReturn(status, ref, start, queue) @@ -1340,6 +1330,33 @@ function m.checkSameSimpleAsReturn(status, ref, start, queue) end end +function m.checkSameSimpleAsReturnTableField(status, ref, start, queue) + if ref.type ~= 'tablefield' then + return + end + local tbl = ref.parent + if tbl.type ~= 'table' then + return + end + local rtn = tbl.parent + if rtn.type ~= 'return' then + return + end + local newStatus = m.status(status) + m.searchRefsAsFunctionReturn(newStatus, tbl, 'ref') + for _, res in ipairs(newStatus.results) do + queue[#queue+1] = { + obj = res, + start = start-1, + force = true, + } + end +end + +function m.checkSameSimpleAsSetValue(status, ref, start, queue) + +end + function m.checkSameSimple(status, simple, data, mode, results, queue) local ref = data.obj local start = data.start @@ -1361,6 +1378,10 @@ function m.checkSameSimple(status, simple, data, mode, results, queue) m.checkSameSimpleAsTableField(status, ref, i, queue) -- 检查形如 return m 的情况 m.checkSameSimpleAsReturn(status, ref, i, queue) + -- 检查形如 return { f = 1 } 的情况 + m.checkSameSimpleAsReturnTableField(status, ref, i, queue) + -- 检查形如 a = f 的情况 + m.checkSameSimpleAsSetValue(status, ref, i, queue) end if i == #simple then break diff --git a/test-beta/crossfile/references.lua b/test-beta/crossfile/references.lua index 07166c3d..4fae9cb7 100644 --- a/test-beta/crossfile/references.lua +++ b/test-beta/crossfile/references.lua @@ -273,7 +273,7 @@ TEST { end return { - f = , + = , } ]] }, @@ -281,7 +281,7 @@ TEST { path = 'b.lua', content = [[ local t = require 'a' - local = t.f + local = t. () -- cgit v1.2.3