From 9586b303e9b76d5da19352bd42599480c0f2c0d1 Mon Sep 17 00:00:00 2001 From: Lei Zhu Date: Mon, 28 Dec 2020 15:44:08 +0800 Subject: =?UTF-8?q?=E4=BD=BF=E7=94=A8=20---@param=20arg=20`T`=20=E6=9D=A5?= =?UTF-8?q?=E5=AE=8C=E6=88=90'=E7=B1=BB=E5=9E=8B=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E5=85=81=E8=AE=B8=E6=98=AF=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=AD=97?= =?UTF-8?q?=E9=9D=A2=E5=80=BC=E6=9D=A5=E8=A1=A8=E8=BE=BE=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/parser/guide.lua | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) (limited to 'script/parser/guide.lua') diff --git a/script/parser/guide.lua b/script/parser/guide.lua index cc21f5fa..ec78dbea 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -101,6 +101,7 @@ m.childMap = { ['doc.vararg'] = {'vararg', 'comment'}, ['doc.type.table'] = {'key', 'value', 'comment'}, ['doc.type.function'] = {'#args', '#returns', 'comment'}, + ['doc.type.typeliteral'] = {'node'}, ['doc.overload'] = {'overload', 'comment'}, ['doc.see'] = {'name', 'field'}, } @@ -1503,25 +1504,23 @@ function m.checkSameSimpleInSpecialBranch(status, obj, start, queue) end end -local function toValidGenericType(status, obj) - if obj.type ~= 'string' then - return obj - end - - if not status.interface.docType then - return obj - end - - local docs = status.interface.docType(obj[1]) - for i = 1, #docs do - local doc = docs[i] - if doc.type == 'doc.class.name' - or doc.type == 'doc.alias.name' then - return doc +local function appendValidGenericType(results, status, typeName, obj) + if typeName.parent.type == 'doc.type.typeliteral' then + if obj.type == 'string' and status.interface.docType then + local docs = status.interface.docType(obj[1]) + for i = 1, #docs do + local doc = docs[i] + if doc.type == 'doc.class.name' + or doc.type == 'doc.alias.name' then + results[#results+1] = doc + break + end + end end + else + -- 发现没有使用 `T`,则沿用既有逻辑直接返回实参 + results[#results+1] = obj end - - return obj end local function stepRefOfGeneric(status, typeUnit, args, mode) @@ -1548,7 +1547,7 @@ local function stepRefOfGeneric(status, typeUnit, args, mode) and source.parent.type == 'funcargs' then for index, arg in ipairs(source.parent) do if arg == source then - results[#results+1] = toValidGenericType(status, args[index]) + appendValidGenericType(results, status, typeName, args[index]) end end end -- cgit v1.2.3