@inthedark/dxlint 0.1.14 → 0.1.17
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/README.md +16 -9
- package/bin/dxlint-darwin-arm64 +0 -0
- package/bin/dxlint-linux-x64 +0 -0
- package/bin/dxlint-win32-x64.exe +0 -0
- package/esbuild.mjs +134 -0
- package/package.json +20 -2
- package/rules/bugs.dx +1 -0
- package/std/ts/arithmetic.dx +10 -0
- package/std/ts/assertions.dx +56 -4
- package/std/ts/calls.dx +45 -15
- package/std/ts/conditions.dx +2 -0
- package/std/ts/constants.dx +2 -1
- package/std/ts/content-mapper.dx +48 -0
- package/std/ts/deprecation.dx +38 -18
- package/std/ts/effects.dx +8 -1
- package/std/ts/enums.dx +32 -4
- package/std/ts/format.dx +1 -1
- package/std/ts/grammar.dx +29 -15
- package/std/ts/import-no-deprecated.dx +4 -2
- package/std/ts/javascript.dx +496 -0
- package/std/ts/layout/literals.dx +14 -7
- package/std/ts/layout/separators.dx +6 -1
- package/std/ts/layout/shared.dx +36 -37
- package/std/ts/layout/types.dx +4 -0
- package/std/ts/literals.dx +1 -0
- package/std/ts/methods.dx +3 -0
- package/std/ts/modules.dx +60 -2
- package/std/ts/names.dx +30 -13
- package/std/ts/narrowing.dx +20 -14
- package/std/ts/parentheses.dx +27 -0
- package/std/ts/problems/control-flow.dx +1 -0
- package/std/ts/problems/numeric-precision.dx +1 -0
- package/std/ts/problems/regexp.dx +1 -0
- package/std/ts/regex/checks.dx +1 -0
- package/std/ts/regex/findings.dx +10 -6
- package/std/ts/regex/values.dx +4 -15
- package/std/ts/restrictions.dx +76 -0
- package/std/ts/scoping/member-uses.dx +5 -3
- package/std/ts/scoping/shadowing.dx +1 -0
- package/std/ts/scoping/usage.dx +3 -3
- package/std/ts/spreads.dx +1 -1
- package/std/ts/structure/padding.dx +10 -8
- package/std/ts/style/expressions.dx +8 -4
- package/std/ts/style/returns.dx +3 -1
- package/std/ts/style/signatures.dx +5 -0
- package/std/ts/style/type-exports.dx +1 -0
- package/std/ts/suggestions/builtins.dx +1 -1
- package/std/ts/suggestions/comparisons.dx +1 -0
- package/std/ts/suggestions/expressions.dx +1 -0
- package/std/ts/suggestions/object-spread.dx +1 -1
- package/std/ts/tokens.dx +14 -5
- package/std/ts/type-specifiers.dx +19 -3
- package/std/ts/typed/awaitability.dx +1 -0
- package/std/ts/typed/collection-iteration.dx +24 -0
- package/std/ts/typed/floating-promises.dx +45 -14
- package/std/ts/typed/includes.dx +3 -4
- package/std/ts/typed/promises.dx +16 -13
- package/std/ts/typed/readonly-parameters.dx +11 -2
- package/std/ts/typed/string-boundaries.dx +1 -0
- package/std/ts/typed/switches.dx +1 -0
- package/std/ts/typed/transfers.dx +54 -7
- package/std/ts/typed/type-arguments.dx +19 -20
- package/std/ts/typed/type-conversions.dx +1 -0
- package/std/ts/typed/type-parameters.dx +1 -1
- package/std/ts/typed/using-disposable.dx +98 -0
- package/std/ts/typed.dx +22 -9
- package/std/ts/values/arguments.dx +1 -1
- package/std/ts/values/enums.dx +5 -1
- package/std/ts/values/inspection.dx +26 -7
- package/std/ts/values.dx +98 -39
- package/std/ts.dx +10 -4
package/std/ts/deprecation.dx
CHANGED
|
@@ -52,30 +52,42 @@ fn import_deprecation_doc(n, site) = {
|
|
|
52
52
|
doc => doc != null))
|
|
53
53
|
}
|
|
54
54
|
fn import_remote_sites(n, sites) = filter(sites ?? [], site => import_remote_site(n, site))
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
fn export_specifier_named(n, specifier, name) = {
|
|
56
|
+
value exported: first(site_field(n, specifier, "exported") ?? []) ?? first(site_field(n, specifier, "local") ?? [])
|
|
57
|
+
value exported != null && site_text(n, exported).text == name
|
|
58
|
+
}
|
|
59
|
+
# `export { /** @deprecated */ X }` or `/** @deprecated */ export { X }`: the
|
|
60
|
+
# specifier or its statement carries the documentation, not `X`'s declaration.
|
|
61
|
+
# Found among the statements of the declaring file.
|
|
62
|
+
fn import_specifier_docs(n, site, name) = if !site_mentions(n, site, "@deprecated") then [] else {
|
|
58
63
|
value root: last(walk([site], current => site_parent(n, current)))
|
|
59
64
|
value exports: filter(site_field(n, root, "body") ?? [], statement => statement.kind == "ts_export")
|
|
60
|
-
value
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
value exported != null && site_text(n, exported).text == name
|
|
64
|
-
})
|
|
65
|
-
value map(named, specifier => deprecation_leading_doc(site_text(n, specifier).leading))
|
|
65
|
+
value flat_map(exports, statement => flat_map(
|
|
66
|
+
filter(site_field(n, statement, "specifier") ?? [], specifier => export_specifier_named(n, specifier, name)),
|
|
67
|
+
specifier => [deprecation_leading_doc(site_text(n, specifier).leading), deprecation_leading_doc(site_text(n, statement).leading)]))
|
|
66
68
|
}
|
|
67
|
-
|
|
69
|
+
# `declarations`: whether the declarations' own docs count, beside the export
|
|
70
|
+
# specifiers'; a call with one selected signature reads only that signature's.
|
|
71
|
+
fn import_deprecation_tag(n, declarations) = {
|
|
68
72
|
value values: import_remote_sites(n, name_definitions(n, "value"))
|
|
69
73
|
value types: if count(values) > 0 then [] else import_remote_sites(n, name_definitions(n, "type"))
|
|
70
|
-
value sites: if count(values) > 0 then values else types
|
|
71
|
-
value
|
|
72
|
-
|
|
74
|
+
value sites: filter(if count(values) > 0 then values else types, site => site_mentions(n, site, "@deprecated"))
|
|
75
|
+
value if count(sites) == 0 then null else {
|
|
76
|
+
value imported: name_binding(n).node.imported_name ?? n.text
|
|
77
|
+
value deprecation_first(flat_map(reverse(sites), site =>
|
|
78
|
+
(if declarations then [import_deprecation_doc(n, site)] else []) import_specifier_docs(n, site, imported)))
|
|
79
|
+
}
|
|
73
80
|
}
|
|
74
81
|
fn deprecation_local_doc(n) = {
|
|
75
82
|
value owner: find(walk([] n.declaration, current =>
|
|
76
83
|
if current is (ts_declarator, ts_identifier) then current.parent.node else null),
|
|
77
84
|
current => current is ts_variable_declaration)
|
|
78
|
-
value if owner == null then null else deprecation_leading_doc(owner.
|
|
85
|
+
value if owner == null then null else deprecation_leading_doc(owner.deprecation_leading)
|
|
86
|
+
}
|
|
87
|
+
# From the code before it: comments are children only under some configs.
|
|
88
|
+
in ts_variable_declaration let deprecation_leading {
|
|
89
|
+
value lead: token(node, "before")
|
|
90
|
+
value byte_slice(source, if lead == null then 0 else lead.end, offset)
|
|
79
91
|
}
|
|
80
92
|
fn deprecation_subject(n) = if n is (ts_member.property, ts_qualified_name.right) then n.parent.node
|
|
81
93
|
else if n.deprecation_shorthand then n.declaration else n
|
|
@@ -140,7 +152,11 @@ fn deprecation_reason(n) = {
|
|
|
140
152
|
else site_sources(subject, site).sites ?? [])
|
|
141
153
|
value members: if subject is (ts_member, ts_index) || subject.deprecation_pattern_key then deprecation_symbols(subject).sites else []
|
|
142
154
|
value origin: declaration_identity(subject)
|
|
143
|
-
|
|
155
|
+
# A name read from a destructured member (`const { old: local } = o; local`)
|
|
156
|
+
# is not that member: only a member access reports it.
|
|
157
|
+
value own_sites: if subject not ts_identifier then sites else filter(sites, site =>
|
|
158
|
+
!contains(["ts_property_signature", "ts_property", "ts_pattern_property", "ts_method_signature", "ts_class_property"], site.kind))
|
|
159
|
+
value declarations: unique([] members (if origin != null then [origin] else []) own_sites)
|
|
144
160
|
value owners: if call == null then declarations else filter(roots.sites ?? [], site =>
|
|
145
161
|
!contains(["ts_function", "ts_arrow", "ts_method", "ts_function_type", "ts_method_signature", "ts_call_signature"], site.kind))
|
|
146
162
|
value signatures: if call != null && selection != null && !selection.uncertain && count(selection.selected) == 1
|
|
@@ -152,9 +168,11 @@ fn deprecation_reason(n) = {
|
|
|
152
168
|
&& name_binding(subject.object.node).node is ts_import.namespace
|
|
153
169
|
value published: if namespace then flat_map(members, site => import_specifier_docs(subject, site, deprecation_symbols(subject).name)) else []
|
|
154
170
|
value own: deprecation_first([deprecation_local_doc(subject)] docs published)
|
|
155
|
-
# A name bound by an import is deprecated where its module publishes it
|
|
156
|
-
|
|
157
|
-
|
|
171
|
+
# A name bound by an import is deprecated where its module publishes it;
|
|
172
|
+
# with one selected signature, only the export specifiers' docs join its own.
|
|
173
|
+
value imported: if own == null && subject is ts_identifier
|
|
174
|
+
&& (name_binding(subject).node.deprecation_import == true || subject.deprecation_reexport)
|
|
175
|
+
then import_deprecation_tag(subject, count(signatures) == 0) else null
|
|
158
176
|
value own ?? imported
|
|
159
177
|
}
|
|
160
178
|
|
|
@@ -162,6 +180,8 @@ in ts_node let deprecation_import
|
|
|
162
180
|
if is (ts_import, ts_import_equals) then true
|
|
163
181
|
else if is (ts_program, ts_block, ts_function, ts_arrow, ts_class, ts_interface) then false
|
|
164
182
|
else parent.deprecation_import == true
|
|
183
|
+
# `export { x } from "m"`: `x` names the module's export, bound by nothing local.
|
|
184
|
+
in ts_node let deprecation_reexport is ts_export_specifier.local && parent.parent.from != null
|
|
165
185
|
in ts_node let deprecation_pattern_key is ts_pattern_property.key || is ts_property.key && parent.flow_destructuring_target
|
|
166
186
|
in ts_node let deprecation_shorthand is ts_property.key && parent.value.node == null && !deprecation_pattern_key
|
|
167
187
|
in ts_node let deprecation_excluded
|
package/std/ts/effects.dx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import .ts/javascript
|
|
1
2
|
# .ts/effects: evaluation order and separate execution entries.
|
|
2
3
|
|
|
3
4
|
define {
|
|
@@ -96,7 +97,13 @@ in ts_identifier, ts_member, ts_index let flow_assignment_scalar true
|
|
|
96
97
|
in ts_parenthesized, ts_as, ts_satisfies, ts_non_null, ts_type_assertion, ts_instantiation let flow_assignment_scalar expression.flow_assignment_scalar
|
|
97
98
|
in ts_property, ts_pattern_property let flow_shorthand_default value is ts_assignment_pattern && value.left == null
|
|
98
99
|
in ts_node let flow_destructuring_target
|
|
99
|
-
if is (ts_for_in.left, ts_for_of.left
|
|
100
|
+
if !(is (ts_for_in.left, ts_for_of.left, ts_declarator.name, ts_assignment.left,
|
|
101
|
+
ts_array.element, ts_array_pattern.element, ts_object.property, ts_object_pattern.property,
|
|
102
|
+
ts_object_pattern.rest, ts_rest.argument, ts_spread.argument, ts_assignment_pattern.left,
|
|
103
|
+
ts_parenthesized.expression, ts_as.expression, ts_satisfies.expression, ts_non_null.expression,
|
|
104
|
+
ts_type_assertion.expression, ts_instantiation.expression, ts_property.value, ts_pattern_property.value,
|
|
105
|
+
ts_property.key, ts_pattern_property.key)) then false
|
|
106
|
+
else if is (ts_for_in.left, ts_for_of.left) then true
|
|
100
107
|
else if is ts_declarator.name then
|
|
101
108
|
(node.parent.init != null && flow_assignment_scalar == false)
|
|
102
109
|
|| node.parent.parent is (ts_for_in.left, ts_for_of.left)
|
package/std/ts/enums.dx
CHANGED
|
@@ -14,8 +14,9 @@ fn enum_root_bad(sender, receiver) = sender != null && receiver != null && len(r
|
|
|
14
14
|
&& any(receiver, target => any(domains, domain => any(target, part => contains(part.traits, domain))))
|
|
15
15
|
&& !any(receiver, target => any(enum_origins(target), b => any(origins, a =>
|
|
16
16
|
a.carrier.file == b.carrier.file && a.carrier.node == b.carrier.node)))
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
# A type parameter stands for its constraint, the arm's other parts.
|
|
18
|
+
&& all(source, part => contains(part.traits, "parameter") || !contains(part.traits, "any")
|
|
19
|
+
&& !contains(part.traits, "unknown") && !contains(part.uncertain_traits, "enum"))
|
|
19
20
|
})
|
|
20
21
|
fn enum_relation_children(pair, source) = {
|
|
21
22
|
value identity: {sender: pair.sender, receiver: pair.receiver}
|
|
@@ -109,6 +110,22 @@ fn enum_annotation_target(context) = {
|
|
|
109
110
|
value if frame == null then null else
|
|
110
111
|
fold(frame.path, frame.target, (target, key) => value_lookup(target, key).member)
|
|
111
112
|
}
|
|
113
|
+
# The key a computed access must match: the key constraint of the mapped
|
|
114
|
+
# type (`[P in E]`) or the computed member key (`[E.A]: ...`) it reads. An
|
|
115
|
+
# unknown key (`value[key]`, `key: K`) reads the one site all members share.
|
|
116
|
+
fn enum_index_target(n) = {
|
|
117
|
+
value key: value_key(n.index.node)
|
|
118
|
+
value sites: if key != null then flat_map(value_lookup(n.object.node, key).alternatives ?? [], arm =>
|
|
119
|
+
if arm.matched then map(arm.sources ?? [], origin => origin.site) else [])
|
|
120
|
+
else unique(flat_map(value_children(n.object.node, true, []) ?? [], edge =>
|
|
121
|
+
map(edge.member.sources ?? [], origin => origin.site)))
|
|
122
|
+
value member: if key == null && count(sites) != 1 then null else first(sites)
|
|
123
|
+
value parameter: if member == null then null else first(site_field(n, member, "type_parameter") ?? [])
|
|
124
|
+
value computed: if member == null || parameter != null then null else first(site_field(n, member, "key") ?? [])
|
|
125
|
+
value key_site: if parameter != null then first(site_field(n, parameter, "constraint") ?? [])
|
|
126
|
+
else if computed != null then first(site_field(n, computed, "expression") ?? []) else null
|
|
127
|
+
value if key_site != null then declaration_value(n, key_site) else null
|
|
128
|
+
}
|
|
112
129
|
fn enum_policy(site, source) = {
|
|
113
130
|
value context: if site is ts_property then site
|
|
114
131
|
else if source is ts_spread && source.parent is ts_object
|
|
@@ -118,12 +135,16 @@ fn enum_policy(site, source) = {
|
|
|
118
135
|
value target: if site is ts_update || site is ts_assignment && site.enum_mutation then source
|
|
119
136
|
else if site is (ts_as, ts_type_assertion) then site.type.node
|
|
120
137
|
else if site.type != null then site.type.node
|
|
138
|
+
else if site is ts_index then enum_index_target(site)
|
|
121
139
|
else if context != null && expected.present == true then value_expected_handle(context)
|
|
122
140
|
else if context != null then enum_annotation_target(context) else null
|
|
123
141
|
value owner: if source is ts_return.argument || source is ts_arrow.body then return_value_owner(source) else null
|
|
124
142
|
value asynchronous: owner != null && contains([] owner.modifier, "async")
|
|
125
143
|
value receiver_handle: if asynchronous && target != null then ts_awaited_value(target, target) else target
|
|
126
|
-
|
|
144
|
+
# `[...numbers]` sends each element of the spread array.
|
|
145
|
+
value spread_element: if source is ts_spread && source.parent is ts_array
|
|
146
|
+
then value_lookup(source.argument.node, {domain: "ordinal"}).member else null
|
|
147
|
+
value sender_handle: if asynchronous && source != null then ts_awaited_value(source, source) else spread_element ?? source
|
|
127
148
|
value receiver: if receiver_handle != null then value_constituents(receiver_handle) else null
|
|
128
149
|
value sender: if sender_handle != null then value_constituents(sender_handle) else null
|
|
129
150
|
value pairs: enum_relation_pairs(sender_handle, receiver_handle, source)
|
|
@@ -194,6 +215,8 @@ in enum_transfer rule es-no-unsafe-enum-assignment {
|
|
|
194
215
|
else "The value assigned here does not have a shared enum type with the expected enum {enum_names_text(contexts)}."
|
|
195
216
|
}
|
|
196
217
|
in ts_array.element rule es-no-unsafe-enum-assignment:element {
|
|
218
|
+
# A spread argument's elements are arguments (`:arguments` reports them).
|
|
219
|
+
when !(parent.parent is ts_spread && parent.parent.parent is (ts_call, ts_new))
|
|
197
220
|
when !parent.enum_checked && unparenthesised_node(node) not (ts_object, ts_array)
|
|
198
221
|
let contexts enum_policy(node, node)
|
|
199
222
|
when any(contexts, context => enum_context_bad(context))
|
|
@@ -214,7 +237,12 @@ in ts_jsx_expression.expression rule es-no-unsafe-enum-assignment:jsx {
|
|
|
214
237
|
in ts_call.argument, ts_new.argument, ts_template.expression rule es-no-unsafe-enum-assignment:arguments {
|
|
215
238
|
when !(is ts_template.expression) || parent is ts_tagged_template.quasi
|
|
216
239
|
when unparenthesised_node(node) not (ts_object, ts_array)
|
|
217
|
-
|
|
240
|
+
# `f(...[1])` passes the elements: reported at the spread. One with a spread
|
|
241
|
+
# of its own (`...[1, ...numbers]`) passes as the whole array.
|
|
242
|
+
let passed if node is ts_spread && node.argument is ts_array
|
|
243
|
+
&& !any(node.argument.element.nodes, element => element is ts_spread) then filter(node.argument.element.nodes,
|
|
244
|
+
item => unparenthesised_node(item) not (ts_object, ts_array)) else [node]
|
|
245
|
+
let contexts flat_map(passed, item => enum_policy(item, item))
|
|
218
246
|
when any(contexts, context => enum_context_bad(context))
|
|
219
247
|
warn "The argument passed here does not have a shared enum type with the expected enum {enum_names_text(contexts)}."
|
|
220
248
|
}
|
package/std/ts/format.dx
CHANGED
|
@@ -12,7 +12,7 @@ define {
|
|
|
12
12
|
# ---- blank lines ---------------------------------------------------------
|
|
13
13
|
|
|
14
14
|
# No blank lines between a header and its single-statement body.
|
|
15
|
-
in ts_if.consequent, ts_while.body, ts_for.body, ts_for_in.body, ts_for_of.body rule es-no-blank-lines-in-optional-blocks warn "Avoid blank lines between a conditional or loop statement and its single non-block statement." {
|
|
15
|
+
in ts_if.consequent, ts_while.body, ts_do_while.body, ts_for.body, ts_for_in.body, ts_for_of.body rule es-no-blank-lines-in-optional-blocks warn "Avoid blank lines between a conditional or loop statement and its single non-block statement." {
|
|
16
16
|
when not ts_block && !space_before.comments && space_before.blank_lines > 0
|
|
17
17
|
let optional_header { value space_before.text; re_find /^[ \t]*/; nonempty } ?? ""
|
|
18
18
|
let optional_indent { value space_before.text; re_find /[ \t]*\z/; nonempty } ?? ""
|
package/std/ts/grammar.dx
CHANGED
|
@@ -5,31 +5,36 @@
|
|
|
5
5
|
@macro ts_parser_signature (type_parameter:type_parameters)? parameter:parameters (":" return_type:return_type)?
|
|
6
6
|
@macro ts_parser_tuple_member (name:type_identifier optional:"?"? ":" type:type_expression | type:type_expression optional:"?"?)
|
|
7
7
|
@macro ts_parser_method_header (kind:/get|set/ peek(accessor_next))? key:property_key optional:"?"? (type_parameter:goal(types, type_parameters))? parameter:parameters (":" return_type:goal(types, return_type))?
|
|
8
|
-
@macro ts_parser_class_header modifier:/declare|abstract/* "class" name:(not(/extends|implements/) type_identifier)? (type_parameter:goal(types, type_parameters))? ("extends" extends:lhs_expression (type_argument:goal(types, type_arguments))?)? ("implements" implements:goal(types, type_expression) ("," implements:goal(types, type_expression))*)?
|
|
9
|
-
@macro ts_parser_class_modifiers (modifier:
|
|
8
|
+
@macro ts_parser_class_header modifier:/declare|abstract/* "class" name:(not(/extends|implements/) type_identifier)? (type_parameter:goal(types, type_parameters))? ("extends" extends:set(heritage, lhs_expression) (type_argument:goal(types, type_arguments))?)? ("implements" implements:goal(types, type_expression) ("," implements:goal(types, type_expression))*)?
|
|
9
|
+
@macro ts_parser_class_modifiers (modifier:class_modifier)*
|
|
10
10
|
@macro ts_parser_import_kind (kind:"type" peek("{" | "*" | not("from") type_identifier))?
|
|
11
11
|
@macro ts_parser_specifier_kind (kind:"type" peek(not("as") (type_identifier | ts_string)))?
|
|
12
12
|
@macro ts_parser_semi terminator(";", before("}"), newline, eof)
|
|
13
13
|
@macro ts_parser_instantiation_end not(/<|>|\+|-/) (not(same_line) | peek(/instanceof|in|as|satisfies|\?\?|\|\||&&|\||\^|&|==|!=|===|!==|<=|>=|<<|>>|>>>|\*|\/|%|\*\*/) | not(peek(type_identifier | ts_number | ts_bigint | ts_string | ts_template | /\(|\[|\{|!|~|\+\+|--|\/|\/=|@|\.\.\.|#/)))
|
|
14
14
|
@macro ts_parser_arrow_tail same_line operator:"=>" cut body:clear(generator, (clear(no_in, ts_block) | assignment))
|
|
15
|
-
parser
|
|
15
|
+
parser ts in js {
|
|
16
16
|
trivia /\A\u{feff}?#![^\n]*/
|
|
17
17
|
trivia /[ \t\r\n\x0b\x0c\u{00a0}\u{1680}\u{2000}-\u{200a}\u{2028}\u{2029}\u{202f}\u{205f}\u{3000}\u{feff}]+/
|
|
18
18
|
trivia /\/\/[^\r\n\u{2028}\u{2029}]*/
|
|
19
19
|
trivia /\/\*(?:[^*]|\*+[^*/])*\*+\//
|
|
20
20
|
line_break /[\r\n\u{2028}\u{2029}]/
|
|
21
|
+
# `a` and `\u{61}` in a name are `a`.
|
|
22
|
+
name_escape /\\u\{([0-9a-fA-F]+)\}|\\u([0-9a-fA-F]{4})/
|
|
21
23
|
|
|
22
24
|
flag jsx option
|
|
23
25
|
flag generator
|
|
24
26
|
flag async
|
|
25
27
|
flag no_in
|
|
26
28
|
flag no_cond
|
|
29
|
+
flag heritage
|
|
27
30
|
|
|
28
31
|
token keyword /(?:break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|finally|for|function|if|import|in|instanceof|new|null|return|super|switch|this|throw|true|try|typeof|var|void|while|with|yield|let|static|implements|interface|package|private|protected|public|await|async|abstract|declare|type|namespace|module|as|satisfies|keyof|infer|readonly|is|asserts|of|using)/ as ts_keyword
|
|
29
|
-
token word /(?:[A-Za-z_$]|[^\x00-\x7f\u{00a0}\u{1680}\u{2000}-\u{200a}\u{2028}\u{2029}\u{202f}\u{205f}\u{3000}\u{feff}]|\\u(?:[0-9a-fA-F]{4}|\{[0-9a-fA-F]+\}))(?:[A-Za-z0-9_$]|[^\x00-\x7f\u{00a0}\u{1680}\u{2000}-\u{200a}\u{2028}\u{2029}\u{202f}\u{205f}\u{3000}\u{feff}]|\\u(?:[0-9a-fA-F]{4}|\{[0-9a-fA-F]+\}))*/
|
|
30
|
-
token private_name /#(?:[A-Za-z_$]|[^\x00-\x7f])(?:[A-Za-z0-9_$]|[^\x00-\x7f])*/
|
|
32
|
+
token word /(?:[A-Za-z_$]|[^\x00-\x7f\u{00a0}\u{1680}\u{2000}-\u{200a}\u{2028}\u{2029}\u{202f}\u{205f}\u{3000}\u{feff}]|\\u(?:[0-9a-fA-F]{4}|\{[0-9a-fA-F]+\}))(?:[A-Za-z0-9_$]|[^\x00-\x7f\u{00a0}\u{1680}\u{2000}-\u{200a}\u{2028}\u{2029}\u{202f}\u{205f}\u{3000}\u{feff}]|\\u(?:[0-9a-fA-F]{4}|\{[0-9a-fA-F]+\}))*/ as ts_keyword
|
|
33
|
+
token private_name /#(?:[A-Za-z_$]|[^\x00-\x7f]|\\u(?:[0-9a-fA-F]{4}|\{[0-9a-fA-F]+\}))(?:[A-Za-z0-9_$]|[^\x00-\x7f]|\\u(?:[0-9a-fA-F]{4}|\{[0-9a-fA-F]+\}))*/
|
|
31
34
|
token bigint /(?:0[xX][0-9a-fA-F_]+|0[bB][01_]+|0[oO][0-7_]+|[0-9][0-9_]*)n/
|
|
32
|
-
|
|
35
|
+
# A legacy octal (`0123`) takes no fraction or exponent: `0123.a` reads a
|
|
36
|
+
# member. Alternatives are tried in order.
|
|
37
|
+
token number /(?:0[xX][0-9a-fA-F_]+|0[bB][01_]+|0[oO][0-7_]+|(?:(?:0[0-7]*[89][0-9_]*|[1-9][0-9_]*)(?:\.[0-9_]*)?|\.[0-9][0-9_]*)(?:[eE][+-]?[0-9][0-9_]*)?|0[0-7]+|0(?:\.[0-9_]*)?(?:[eE][+-]?[0-9][0-9_]*)?)/
|
|
33
38
|
token string /(?:"(?:\\\r\n|\\[\s\S]|[^"\\\n])*"|'(?:\\\r\n|\\[\s\S]|[^'\\\n])*')/
|
|
34
39
|
token regexp /\/(?:\\[\s\S]|\[(?:\\[\s\S]|[^\]\\\n])*\]|[^\/\\\[\n])+\/(?:[A-Za-z0-9_$\\]|[^\x00-\x7f])*/
|
|
35
40
|
token template /`(?:\\[\s\S]|[^\\`$]|\$+(?:\\[\s\S]|[^\\`{$]))*\$*`/
|
|
@@ -37,7 +42,7 @@ parser ts_syntax in js {
|
|
|
37
42
|
token template_middle /\}(?:\\[\s\S]|[^\\`$]|\$+(?:\\[\s\S]|[^\\`{$]))*\$*\$\{/
|
|
38
43
|
token template_tail /\}(?:\\[\s\S]|[^\\`$]|\$+(?:\\[\s\S]|[^\\`{$]))*\$*`/
|
|
39
44
|
token jsx_name /(?:[A-Za-z_$]|[^\x00-\x7f\u{00a0}\u{1680}\u{2000}-\u{200a}\u{2028}\u{2029}\u{202f}\u{205f}\u{3000}\u{feff}])(?:[A-Za-z0-9_$-]|[^\x00-\x7f\u{00a0}\u{1680}\u{2000}-\u{200a}\u{2028}\u{2029}\u{202f}\u{205f}\u{3000}\u{feff}])*/
|
|
40
|
-
token jsx_text /[^<{]+/
|
|
45
|
+
token jsx_text /[^<{]+/ lines
|
|
41
46
|
token jsx_string /(?:"[^"]*"|'[^']*')/
|
|
42
47
|
token jsx_value_comment /[ \t\r\n\x0b\x0c\u{00a0}\u{1680}\u{2000}-\u{200a}\u{2028}\u{2029}\u{202f}\u{205f}\u{3000}\u{feff}]*(?:\/\/|\/\*)/
|
|
43
48
|
|
|
@@ -195,7 +200,7 @@ parser ts_syntax in js {
|
|
|
195
200
|
node ts_property_signature { modifier?: text, key: property_key, optional?: text, type?: type_expression }
|
|
196
201
|
node ts_method_signature { modifier?: text, kind?: text, key: property_key, optional?: text, type_parameter?: ts_type_parameter*, parameter?: ts_parameter*, return_type?: return_type }
|
|
197
202
|
node ts_call_signature { kind?: text, type_parameter?: ts_type_parameter*, parameter?: ts_parameter*, return_type?: return_type }
|
|
198
|
-
node ts_index_signature { decorator?: ts_decorator*, modifier?: text*, parameter: ts_parameter
|
|
203
|
+
node ts_index_signature { decorator?: ts_decorator*, modifier?: text*, parameter: ts_parameter+, type?: type_expression }
|
|
199
204
|
node ts_tuple_type { element?: ts_tuple_member | ts_rest* }
|
|
200
205
|
node ts_tuple_member { name?: type_identifier, optional?: text, type: type_expression }
|
|
201
206
|
node ts_type_query { name: entity_query | ts_import_type, type_argument?: type_expression* }
|
|
@@ -249,7 +254,7 @@ parser ts_syntax in js {
|
|
|
249
254
|
production ts_case = ("case" test:expression | "default") ":" body:(not(/case|default|\}/) statement)*
|
|
250
255
|
production ts_try = "try" cut block:ts_block (kind:"catch" ("(" parameter:binding (":" type:goal(types, type_expression))? ")")? handler:ts_block)? ("finally" finalizer:ts_block)?
|
|
251
256
|
production ts_labeled = label:ts_identifier ":" cut body:statement
|
|
252
|
-
production ts_variable_declaration = modifier:
|
|
257
|
+
production ts_variable_declaration = modifier:variable_modifier* @ts_parser_variable terminator(";", before("}"), newline, eof)
|
|
253
258
|
production ts_declarator = name:binding "!"? (":" type:goal(types, type_expression))? ("=" init:assignment)?
|
|
254
259
|
production ts_expression_statement = expression:expression terminator(";", before("}"), newline, eof)
|
|
255
260
|
production binding = ts_identifier | ts_object_pattern | ts_array_pattern
|
|
@@ -283,7 +288,7 @@ parser ts_syntax in js {
|
|
|
283
288
|
production ts_decorator = "@" expression:lhs_expression
|
|
284
289
|
production ts_parameter = decorator:ts_decorator* (modifier:/public|private|protected|readonly|override/ same_line peek(property_key))* name:(ts_rest | ts_this | binding) (optional:"?")? (":" type:goal(types, type_expression))? ("=" init:goal(code, clear(no_in, assignment)))?
|
|
285
290
|
production parameters = "(" (parameter:ts_parameter ("," parameter:ts_parameter)* ","?)? ")"
|
|
286
|
-
production ts_function = modifier:
|
|
291
|
+
production ts_function = modifier:function_modifier* (modifier:"async" same_line)? "function" (modifier:"*" @ts_parser_function_header (body:clear(no_in, set(generator, ts_block)) | @ts_parser_semi) | @ts_parser_function_header (body:clear(no_in, clear(generator, ts_block)) | @ts_parser_semi))
|
|
287
292
|
production ts_arrow = try(
|
|
288
293
|
peek(ts_identifier same_line "=>" | "(" | "<" | "async" same_line (ts_identifier same_line "=>" | "(" | "<"))
|
|
289
294
|
(
|
|
@@ -340,9 +345,10 @@ parser ts_syntax in js {
|
|
|
340
345
|
suffix 1 (same_line "!") => ts_non_null(expression)
|
|
341
346
|
suffix 1 quasi:ts_template => ts_tagged_template(tag)
|
|
342
347
|
suffix 1 try(type_argument:goal(types, type_arguments) quasi:ts_template) => ts_tagged_template(tag)
|
|
343
|
-
|
|
348
|
+
# A class heritage's `<...>` are its type arguments, never an instantiation.
|
|
349
|
+
suffix 1 try(type_argument:goal(types, type_arguments) if(heritage, not(()), (@ts_parser_instantiation_end))) => ts_instantiation(expression)
|
|
344
350
|
}
|
|
345
|
-
production arguments = "(" (argument:(ts_spread | clear(no_in, assignment)) ("," argument:(ts_spread | clear(no_in, assignment)))* ","?)? ")"
|
|
351
|
+
production arguments = "(" clear(heritage, (argument:(ts_spread | clear(no_in, assignment)) ("," argument:(ts_spread | clear(no_in, assignment)))* ","?)?) ")"
|
|
346
352
|
production new_callee precedence goal(primary, primary_expression) {
|
|
347
353
|
suffix 1 ("." property:property_name) => ts_member(object)
|
|
348
354
|
suffix 1 ("[" index:clear(no_in, expression) "]") => ts_index(object)
|
|
@@ -431,7 +437,7 @@ parser ts_syntax in js {
|
|
|
431
437
|
production type_members = "{" (type_member (";" | "," | terminator(";", before("}"), newline)))* "}"
|
|
432
438
|
production type_member = try(ts_call_signature) | try(ts_index_signature) | try(ts_method_signature) | ts_property_signature
|
|
433
439
|
production ts_call_signature = kind:"new"? @ts_parser_signature
|
|
434
|
-
production ts_index_signature = (modifier:"readonly" same_line peek("["))? "[" parameter:emit(ts_parameter, name:type_identifier optional:"?"? ":" type:type_expression) "]" (":" type:type_expression)?
|
|
440
|
+
production ts_index_signature = (modifier:"readonly" same_line peek("["))? "[" parameter:emit(ts_parameter, name:type_identifier optional:"?"? ":" type:type_expression) ("," parameter:emit(ts_parameter, name:type_identifier optional:"?"? ":" type:type_expression))* "]" (":" type:type_expression)?
|
|
435
441
|
production ts_method_signature = (modifier:"readonly" same_line peek(property_key))? (kind:/get|set/ same_line peek(property_key))? key:property_key optional:"?"? (type_parameter:type_parameters)? parameter:parameters (":" return_type:return_type)?
|
|
436
442
|
production ts_property_signature = (modifier:"readonly" same_line peek(property_key))? (discard(/get|set/) same_line peek(property_key))? key:property_key optional:"?"? (":" type:type_expression)?
|
|
437
443
|
|
|
@@ -445,7 +451,7 @@ parser ts_syntax in js {
|
|
|
445
451
|
))
|
|
446
452
|
production class_member = try(ts_static_block) | try(class_index_signature) | try(class_method) | ts_class_property
|
|
447
453
|
production ts_static_block = discard(ts_decorator*) "static" body:clear(no_in, ts_block)
|
|
448
|
-
production class_index_signature = emit(ts_index_signature, decorator:ts_decorator* @ts_parser_class_modifiers "[" parameter:emit(ts_parameter, name:type_identifier optional:"?"? ":" type:goal(types, type_expression)) "]" (":" type:goal(types, type_expression))?) discard(@ts_parser_semi)
|
|
454
|
+
production class_index_signature = emit(ts_index_signature, decorator:ts_decorator* @ts_parser_class_modifiers "[" parameter:emit(ts_parameter, name:type_identifier optional:"?"? ":" type:goal(types, type_expression)) ("," parameter:emit(ts_parameter, name:type_identifier optional:"?"? ":" type:goal(types, type_expression)))* "]" (":" type:goal(types, type_expression))?) discard(@ts_parser_semi)
|
|
449
455
|
production class_method = emit(ts_method, decorator:ts_decorator* @ts_parser_class_modifiers (
|
|
450
456
|
modifier:"*" @ts_parser_method_header (body:clear(no_in, set(generator, ts_block)) | @ts_parser_semi) |
|
|
451
457
|
@ts_parser_method_header (body:clear(no_in, clear(generator, ts_block)) | @ts_parser_semi)
|
|
@@ -454,7 +460,15 @@ parser ts_syntax in js {
|
|
|
454
460
|
modifier:"*" @ts_parser_method_header (body:clear(no_in, set(generator, ts_block)) | @ts_parser_semi) |
|
|
455
461
|
@ts_parser_method_header (body:clear(no_in, clear(generator, ts_block)) | @ts_parser_semi)
|
|
456
462
|
))
|
|
457
|
-
|
|
463
|
+
# Extension points: `extend parser ts { production class_modifier |= ... }`
|
|
464
|
+
# adds member modifiers, `class_initializer` tokens standing for `=`,
|
|
465
|
+
# `function_modifier` and `variable_modifier` words before `function` and
|
|
466
|
+
# `const`/`let`/`var`.
|
|
467
|
+
production function_modifier = text("declare")
|
|
468
|
+
production variable_modifier = text("declare")
|
|
469
|
+
production class_modifier = text("static") peek(accessor_next) | /public|private|protected|readonly|abstract|override|declare|accessor|async/ same_line peek(accessor_next)
|
|
470
|
+
production class_initializer = "="
|
|
471
|
+
production ts_class_property = decorator:ts_decorator* @ts_parser_class_modifiers modifier:"*"? (kind:/get|set/ peek(accessor_next))? key:property_key optional:"?"? "!"? (":" type:goal(types, type_expression))? (discard(class_initializer) init:clear(no_in, assignment))? @ts_parser_semi
|
|
458
472
|
production ts_interface = modifier:"declare"* "interface" same_line name:type_identifier (type_parameter:goal(types, type_parameters))? ("extends" extends:goal(types, type_expression) ("," extends:goal(types, type_expression))*)? member:goal(types, type_members)
|
|
459
473
|
production ts_type_alias = modifier:"declare"* "type" same_line name:type_identifier (type_parameter:goal(types, type_parameters))? "=" type:goal(types, type_expression) @ts_parser_semi
|
|
460
474
|
production ts_enum = modifier:"declare"* modifier:"const"? "enum" name:type_identifier "{" (member:ts_enum_member ("," member:ts_enum_member)* ","?)? "}"
|
|
@@ -17,8 +17,8 @@ fn import_namespace(n) = {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
# Found once per import, not once per use of the name it binds.
|
|
20
|
-
in ts_import_specifier let import_tag import_deprecation_tag(local.node ?? imported.node)
|
|
21
|
-
in ts_import let import_default_tag if default_import == null then null else import_deprecation_tag(default_import.node)
|
|
20
|
+
in ts_import_specifier let import_tag import_deprecation_tag(local.node ?? imported.node, true)
|
|
21
|
+
in ts_import let import_default_tag if default_import == null then null else import_deprecation_tag(default_import.node, true)
|
|
22
22
|
|
|
23
23
|
in ts_import_specifier rule es-import-no-deprecated:specifier {
|
|
24
24
|
when import_tag != null
|
|
@@ -44,7 +44,9 @@ in ts_program let import_deprecated_defaults {
|
|
|
44
44
|
map (item) item.default_import.node.text
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
in ts_program let import_deprecated_any count(import_deprecated_names) > 0 || count(import_deprecated_defaults) > 0
|
|
47
48
|
in ts_identifier rule es-import-no-deprecated:use {
|
|
49
|
+
when ts_program.import_deprecated_any
|
|
48
50
|
when contains(ts_program.import_deprecated_names, text) || contains(ts_program.import_deprecated_defaults, text)
|
|
49
51
|
when resolved == "import"
|
|
50
52
|
when containing(ts_jsx_opening) == null && containing(ts_jsx_closing) == null
|