ws-cleanup-types: archive, audio, data, font, image, layered, music, playlist, subtitle, vector, video: annotations, casts, one value per re-assignment where the solver loses the type
This commit is contained in:
1 parent
dc98aec2ec
commit
f459b2dcdf
44 files changed
+172
-119
No files matched your search
@@ -48,7 +48,7 @@ local LOCAL: { [string]: boolean } = {
|
||||
filter = true,
|
||||
}
|
||||
|
||||
local UNSUPPORTED = { text = true, image = true, pattern = true, mask = true, marker = true, filter = true, foreignObject = true, textPath = true, tspan = true }
|
||||
local UNSUPPORTED: { [string]: boolean } = { text = true, image = true, pattern = true, mask = true, marker = true, filter = true, foreignObject = true, textPath = true, tspan = true }
|
||||
local CONTAINERS = { g = true, a = true, switch = true }
|
||||
local SHAPES = { path = true, rect = true, circle = true, ellipse = true, line = true, polyline = true, polygon = true }
|
||||
|
||||
@@ -103,7 +103,7 @@ local function specified(n: Node, ctx: Ctx): { [string]: string }
|
||||
for c in string.gmatch(attr(n, "class") or "", "%S+") do
|
||||
classes[c] = true
|
||||
end
|
||||
local hits = {}
|
||||
local hits: { Style.Rule } = {}
|
||||
for _, r in ctx.rules do
|
||||
if Style.matches(r.selector, local_(n), attr(n, "id"), classes) then
|
||||
table.insert(hits, r)
|
||||
@@ -296,7 +296,7 @@ local function shape(n: Node, st: { [string]: string }, ctx: Ctx): { PathData.Cm
|
||||
if w <= 0 or h <= 0 then
|
||||
return nil
|
||||
end
|
||||
local rx, ry = len(attr(n, "rx"), vw, st), len(attr(n, "ry"), vh, st)
|
||||
local rx: number?, ry: number? = len(attr(n, "rx"), vw, st), len(attr(n, "ry"), vh, st)
|
||||
if rx and rx < 0 then
|
||||
rx = nil
|
||||
end
|
||||
@@ -305,9 +305,9 @@ local function shape(n: Node, st: { [string]: string }, ctx: Ctx): { PathData.Cm
|
||||
end
|
||||
rx = rx or ry or 0
|
||||
ry = ry or rx
|
||||
rx, ry = math.min(rx :: number, w / 2), math.min(ry :: number, h / 2)
|
||||
local rx: number, ry: number = math.min(rx :: number, w / 2), math.min(ry :: number, h / 2)
|
||||
if rx <= 0 or ry <= 0 then
|
||||
return { { op = "M", x, y }, { op = "L", x + w, y }, { op = "L", x + w, y + h }, { op = "L", x, y + h }, { op = "Z" } }
|
||||
return { { op = "M", x, y }, { op = "L", x + w, y }, { op = "L", x + w, y + h }, { op = "L", x, y + h }, { op = "Z" } } :: { PathData.Cmd }
|
||||
end
|
||||
local out: { PathData.Cmd } = { { op = "M", x + rx, y }, { op = "L", x + w - rx, y } }
|
||||
PathData.arc(x + w - rx, y, rx, ry, 0, false, true, x + w, y + ry, out)
|
||||
@@ -317,7 +317,7 @@ local function shape(n: Node, st: { [string]: string }, ctx: Ctx): { PathData.Cm
|
||||
PathData.arc(x + rx, y + h, rx, ry, 0, false, true, x, y + h - ry, out)
|
||||
table.insert(out, { op = "L", x, y + ry })
|
||||
PathData.arc(x, y + ry, rx, ry, 0, false, true, x + rx, y, out)
|
||||
table.insert(out, { op = "Z" })
|
||||
table.insert(out, { op = "Z" } :: PathData.Cmd)
|
||||
return out
|
||||
elseif kind == "circle" or kind == "ellipse" then
|
||||
local cx, cy = len(attr(n, "cx"), vw, st, 0) :: number, len(attr(n, "cy"), vh, st, 0) :: number
|
||||
@@ -338,12 +338,12 @@ local function shape(n: Node, st: { [string]: string }, ctx: Ctx): { PathData.Cm
|
||||
PathData.arc(cx, cy + ry, rx, ry, 0, false, true, cx - rx, cy, out)
|
||||
PathData.arc(cx - rx, cy, rx, ry, 0, false, true, cx, cy - ry, out)
|
||||
PathData.arc(cx, cy - ry, rx, ry, 0, false, true, cx + rx, cy, out)
|
||||
table.insert(out, { op = "Z" })
|
||||
table.insert(out, { op = "Z" } :: PathData.Cmd)
|
||||
return out
|
||||
elseif kind == "line" then
|
||||
local x1, y1 = len(attr(n, "x1"), vw, st, 0) :: number, len(attr(n, "y1"), vh, st, 0) :: number
|
||||
local x2, y2 = len(attr(n, "x2"), vw, st, 0) :: number, len(attr(n, "y2"), vh, st, 0) :: number
|
||||
return { { op = "M", x1, y1 }, { op = "L", x2, y2 } }
|
||||
return { { op = "M", x1, y1 }, { op = "L", x2, y2 } } :: { PathData.Cmd }
|
||||
elseif kind == "polyline" or kind == "polygon" then
|
||||
local v = Style.numbers(attr(n, "points"))
|
||||
if #v < 4 then
|
||||
@@ -354,7 +354,7 @@ local function shape(n: Node, st: { [string]: string }, ctx: Ctx): { PathData.Cm
|
||||
table.insert(out, { op = "L", v[i], v[i + 1] })
|
||||
end
|
||||
if kind == "polygon" then
|
||||
table.insert(out, { op = "Z" })
|
||||
table.insert(out, { op = "Z" } :: PathData.Cmd)
|
||||
end
|
||||
return out
|
||||
end
|
||||
|
||||
@@ -91,7 +91,7 @@ function PathData.parse(d: string): ({ Cmd }, boolean)
|
||||
local last = "" -- previous command letter (upper case)
|
||||
local cmd: string? = nil
|
||||
local rel = false
|
||||
local nums: { number } = table.create(7)
|
||||
local nums: { number } = table.create(7) :: { number }
|
||||
local function ws()
|
||||
while i <= n do
|
||||
local c = byte(d, i)
|
||||
@@ -175,7 +175,7 @@ function PathData.parse(d: string): ({ Cmd }, boolean)
|
||||
rel = c ~= up
|
||||
i += 1
|
||||
if up == "Z" then
|
||||
table.insert(out, { op = "Z" })
|
||||
table.insert(out, { op = "Z" } :: Cmd)
|
||||
cx, cy = sx, sy
|
||||
last = "Z"
|
||||
cmd = nil
|
||||
|
||||
@@ -194,7 +194,7 @@ local function scan(s: string, i: number): (number?, number)
|
||||
end
|
||||
|
||||
-- length(s, ref?, fontSize?) -> number in user units | nil. ref: what 100% is (default 100)
|
||||
local UNITS = { px = 1, pt = 4 / 3, pc = 16, mm = 96 / 25.4, cm = 96 / 2.54, ["in"] = 96, q = 96 / 101.6 }
|
||||
local UNITS: { [string]: number } = { px = 1, pt = 4 / 3, pc = 16, mm = 96 / 25.4, cm = 96 / 2.54, ["in"] = 96, q = 96 / 101.6 }
|
||||
function Style.length(s: string?, ref: number?, fontSize: number?): number?
|
||||
if s == nil then
|
||||
return nil
|
||||
@@ -355,11 +355,11 @@ function Style.css(text: string, rules: { Rule }?): { Rule }
|
||||
if not s then
|
||||
break
|
||||
end
|
||||
text = string.sub(text, 1, s - 1) .. string.sub(text, e + 1)
|
||||
text = string.sub(text, 1, s - 1) .. string.sub(text, (e :: number) + 1)
|
||||
end
|
||||
text = string.gsub(text, "@[%w-]+[^;{]*;", "")
|
||||
for sels, body in string.gmatch(text, "([^{}]+)(%b{})") do
|
||||
local decls = Style.declarations(string.sub(body, 2, -2))
|
||||
local decls = Style.declarations(string.sub(body :: string, 2, -2))
|
||||
for one in string.gmatch(sels, "[^,]+") do
|
||||
local sel = selector(one)
|
||||
if sel then
|
||||
|
||||
@@ -163,7 +163,7 @@ function Write.vector(v: Types.Vector): (string?, string?)
|
||||
for k, d in p.strokeDashArray do
|
||||
parts[k] = num(tonumber(d) or 0)
|
||||
end
|
||||
table.insert(attrs, { "stroke-dasharray", table.concat(parts, " ") })
|
||||
table.insert(attrs, { "stroke-dasharray", table.concat(parts :: { string }, " ") })
|
||||
local off = tonumber(p.strokeDashOffset)
|
||||
table.insert(attrs, { "stroke-dashoffset", if off and off ~= 0 then off else nil })
|
||||
end
|
||||
|
||||
@@ -42,11 +42,11 @@ function Data.base64(text: string, compression: string?): ({ number }?, string?,
|
||||
return nil, "compression " .. compression .. " is not supported", true
|
||||
end
|
||||
local n = buffer.len(bytes) // 4
|
||||
local out = table.create(n)
|
||||
local out: { number } = table.create(n) :: { number }
|
||||
for i = 0, n - 1 do
|
||||
out[i + 1] = buffer.readu32(bytes, i * 4)
|
||||
end
|
||||
return out, nil
|
||||
return out, nil, nil
|
||||
end
|
||||
|
||||
-- toBase64(gids, compression?, level?) -> text | nil, message
|
||||
|
||||
@@ -144,7 +144,7 @@ function Tiled.encode(map: Types.TileMap, opts: EncodeOptions?): (buffer?, Err.E
|
||||
if o.compression and o.compression ~= "zlib" and o.compression ~= "gzip" then
|
||||
return nil, Err.new(Err.ARG, "compression must be zlib or gzip")
|
||||
end
|
||||
local wo = { encoding = o.encoding, compression = o.compression, level = o.level }
|
||||
local wo: Tmx.WriteOptions = { encoding = o.encoding :: string?, compression = o.compression, level = o.level }
|
||||
if fmt == "tmx" or fmt == "tsx" or fmt == "xml" then
|
||||
local doc: any, err: string?
|
||||
if tilesetOnly then
|
||||
|
||||
Reference in new issue
Block a user