@inthedark/dxlint 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/dxlint-linux-x64
CHANGED
|
Binary file
|
package/bin/dxlint-win32-x64.exe
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -227,8 +227,8 @@ fn type_argument_unresolved(n) = {
|
|
|
227
227
|
value parts: value_constituents(n)
|
|
228
228
|
value parts != null && !type_argument_known(parts)
|
|
229
229
|
}
|
|
230
|
-
|
|
231
|
-
|
|
230
|
+
# Whether `annotation` names `formal` itself (alone or as a union member).
|
|
231
|
+
fn type_argument_names_formal(n, annotation, formal) = {
|
|
232
232
|
value candidates: if annotation != null && annotation.kind == "ts_union"
|
|
233
233
|
then site_field(n, annotation, "type") ?? [] else [annotation]
|
|
234
234
|
value any(candidates, candidate => candidate != null && candidate.kind == "ts_type_reference"
|
|
@@ -237,6 +237,25 @@ fn type_argument_parameter_direct(n, parameter, formal) = {
|
|
|
237
237
|
value found: if name != null then site_text(n, name) else null
|
|
238
238
|
value found != null && found.text == formal.name })
|
|
239
239
|
}
|
|
240
|
+
fn type_argument_parameter_direct(n, parameter, formal) =
|
|
241
|
+
type_argument_names_formal(n, first(site_field(n, parameter, "type") ?? []), formal)
|
|
242
|
+
# TypeScript infers a literal argument's own type (`E.A`, `"a"`) for a type
|
|
243
|
+
# parameter its signature returns at top level, and widens it elsewhere.
|
|
244
|
+
fn type_argument_returned(n, site, formal) = site != null
|
|
245
|
+
&& type_argument_names_formal(n, first(site_field(n, site, "return_type") ?? []), formal)
|
|
246
|
+
# Whether the argument's type is a literal widening would change.
|
|
247
|
+
fn type_argument_literal(argument) = {
|
|
248
|
+
value raw: value_constituents(argument)
|
|
249
|
+
value widened: value_widened(argument)
|
|
250
|
+
value raw != null && widened != null && raw != widened
|
|
251
|
+
}
|
|
252
|
+
# Whether `parameter`'s annotation mentions `formal` anywhere (another
|
|
253
|
+
# inference site for it).
|
|
254
|
+
fn type_argument_mentions(n, parameter, formal) = {
|
|
255
|
+
value annotation: first(site_field(n, parameter, "type") ?? [])
|
|
256
|
+
value text: if annotation != null then site_text(n, annotation).text else null
|
|
257
|
+
value text != null && contains(split({ value text; re_replace /[^A-Za-z0-9_$]+/ ' ' }, " "), formal.name)
|
|
258
|
+
}
|
|
240
259
|
fn type_argument_parameter_sites(n, site, signature) = if signature != null then
|
|
241
260
|
map(signature.parameters ?? [], parameter => parameter.site)
|
|
242
261
|
else if site == null then []
|
|
@@ -248,11 +267,16 @@ fn type_argument_parameter_sites(n, site, signature) = if signature != null then
|
|
|
248
267
|
# default once any is written.
|
|
249
268
|
fn type_argument_inferred(n, site, signature, formal) = count(n.parent.type_argument.nodes) == 1 && {
|
|
250
269
|
value owner: n.parent.node
|
|
251
|
-
value
|
|
270
|
+
value parameters: type_argument_parameter_sites(n, site, signature)
|
|
271
|
+
value pairs: zip(parameters, owner.argument.nodes)
|
|
252
272
|
value pair: find(pairs, pair => pair != null && first(pair) != null && last(pair) != null
|
|
253
273
|
&& last(pair) not (ts_this, ts_spread)
|
|
254
274
|
&& type_argument_parameter_direct(n, first(pair), formal))
|
|
255
|
-
|
|
275
|
+
# A literal the only inference site of a returned type parameter stays
|
|
276
|
+
# literal: the written (wider) type argument is needed.
|
|
277
|
+
value literal_only: pair != null && type_argument_returned(n, site, formal) && type_argument_literal(last(pair))
|
|
278
|
+
&& !any(parameters, parameter => parameter != null && parameter != first(pair) && type_argument_mentions(n, parameter, formal))
|
|
279
|
+
value pair != null && !literal_only && type_argument_same(n, last(pair), true)
|
|
256
280
|
}
|
|
257
281
|
fn type_argument_redundancy(n) = {
|
|
258
282
|
value owner: n.parent.node
|