Treat `pcall(mw.loadData, "string constant value")` as being non-dynamic
starcitizen>Alistair3149 (Fix undeclared `_` variable in `getDynamicRequireList(…)`) |
starcitizen>Alistair3149 (Treat `pcall(mw.loadData, "string constant value")` as being non-dynamic) |
||
| Рядок 104: | Рядок 104: | ||
---@return string[] Sequence of strings | ---@return string[] Sequence of strings | ||
local function getDynamicRequireList( query ) | local function getDynamicRequireList( query ) | ||
local isDynamic = true; | |||
if query:find( '%.%.' ) then | if query:find( '%.%.' ) then | ||
query = mw.text.split( query, '..', true ) | query = mw.text.split( query, '..', true ) | ||
| Рядок 111: | Рядок 112: | ||
else | else | ||
local _; _, query = query:match( '(["\'])(.-)%1' ) | local _; _, query = query:match( '(["\'])(.-)%1' ) | ||
query = query:gsub( '%%%a', '%%' ) | local replacements; | ||
query, replacements = query:gsub( '%%%a', '%%' ) | |||
if replacements == 0 then | |||
isDynamic = false; | |||
end | |||
end | end | ||
query = query:gsub( '^[Mm]odule:', '' ) | query = query:gsub( '^[Mm]odule:', '' ) | ||
if query:find( '^[Dd]ata/' ) then | |||
return { 'Module:' .. query }, isDynamic; -- This format will later be used by formatDynamicQueryLink() | |||
end | |||
if dynamicRequireListQueryCache[ query ] then | if dynamicRequireListQueryCache[ query ] then | ||
return dynamicRequireListQueryCache[ query ] | return dynamicRequireListQueryCache[ query ], isDynamic; | ||
end | end | ||
| Рядок 138: | Рядок 147: | ||
dynamicRequireListQueryCache[ query ] = list | dynamicRequireListQueryCache[ query ] = list | ||
return list | return list, isDynamic; | ||
end | end | ||
| Рядок 214: | Рядок 223: | ||
match = mw.text.trim( match ) | match = mw.text.trim( match ) | ||
if func == 'require' | local dynList, isDynamic; | ||
if func == 'require' then | |||
dynList, isDynamic = getDynamicRequireList(match); | |||
if (isDynamic == false and #dynList == 1) then | |||
table.insert(requireList, dynList[1]); | |||
else for _, x in ipairs(dynList) do | |||
table.insert( dynamicRequirelist, x ) | table.insert( dynamicRequirelist, x ) | ||
end end | |||
elseif func == 'mw.loadData' then | |||
dynList, isDynamic = getDynamicRequireList(match); | |||
if (isDynamic == false and #dynList == 1) then | |||
table.insert(loadDataList, dynList[1]); | |||
else for _, x in ipairs(dynList) do | |||
table.insert( dynamicLoadDataList, x ) | |||
end end | |||
end | end | ||
end | end | ||