1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//! `Checker` implementation for TypeScript.
#![allow(clippy::wildcard_imports, clippy::enum_glob_use)]
use super::*;
// The `DocTarget` row under tsc's wrapper context (#1699).
tsdoc_target!(Typescript, typescript);
impl Checker for TypescriptCode {
// tsc reads `/***` as JSDoc, so TypeScript follows tsc, not JSDoc.
// The Annex-B `<!-- -->` `html_comment` is a comment kind for
// loc / tokens / find parity (#697) and never documentation.
// JSDoc documents inner symbols (`outer~inner`), so a `/** */` on a
// function or property declared in a body is documentation.
impl_doc_comment_rows_in_bodies!(typescript);
// tsc's `getJSDocCommentsAndTags` takes the last `/**` before a
// declaration's first token, past every plain comment; a comment after
// a decorator is inside the declaration and documents nothing. TypeDoc
// withholds a `@module` or `@packageDocumentation` comment from the
// declaration and reads it as the file's (#1613). tsc reads a
// declaration's leading comments from the line break after the token
// before it, so a doc comment after code on its row documents nothing,
// except before a parameter, whose trailing comments it reads too.
impl_js_family_doc_binding!(
Typescript,
|node, code| Self::is_comment(node) && !Self::is_doc_comment(node, code),
crate::lang_helpers::doc_comment::tsdoc_module,
tsdoc_target,
// role-bypass: allow(DocTarget) — the parameter subset of the targets before
// which a doc comment after code on its row still documents: consumer
// policy over the row, not membership (no `Parameter` row, by decision #1796)
|target| matches!(
target.kind_id().into(),
Typescript::RequiredParameter
| Typescript::RequiredParameter2
| Typescript::OptionalParameter
| Typescript::OptionalParameter2
)
);
// The space tree is declared in `roles/typescript.rs` (#1696): the
// `FuncOpener` row (every function form, the ES2022 `static { … }`
// block — #1184) and the `Container` row are what the walk
// promotes, and `opens_space` labels them; which function form is
// a *function* rather than a closure is the binding-site question
// the rows' gates answer off the chain (#1188). The byte-less
// `is_func_space` is the legacy wrapper: no `opens` here is gated,
// so it answers the same with no chain.
impl_byte_less_func_space!(typescript);
fn is_func_space_with_code<'a>(
node: &Node<'a>,
code: &[u8],
ancestors: Ancestors<'a, '_>,
) -> bool {
crate::roles::typescript::opens_space(node, code, ancestors) != SpaceKind::Unknown
}
fn is_func<'a>(node: &Node<'a>, ancestors: Ancestors<'a, '_>) -> bool {
crate::roles::typescript::func_opener::is_callable(node, &[], ancestors)
}
fn is_closure<'a>(node: &Node<'a>, ancestors: Ancestors<'a, '_>) -> bool {
crate::roles::typescript::closure::owns(node, &[], ancestors)
}
// `Call` and `StringLit` are the rows of `roles/typescript.rs` (#1698);
// the byte-less spellings are their kind tables, gates aside.
impl_row_predicates!(typescript, call, is_call, is_call_with_code);
impl_row_predicates!(typescript, string_lit, is_string, is_string_with_code);
fn is_non_arg(node: &Node) -> bool {
matches!(
node.kind_id().into(),
Typescript::LPAREN | Typescript::COMMA | Typescript::RPAREN
)
}
// The `ElseIf` row of `roles/typescript.rs`: an `if_statement` whose
// parent is the `else_clause`, read off the caller's chain. The row
// reads no bytes, so the empty code is exact (#1697).
impl_else_if_from_row!(typescript);
// A primitive is the `Primitive` row's kind table, gates aside.
#[inline]
fn is_primitive(node: &Node) -> bool {
crate::roles::typescript::primitive::lists_kind(node.kind_id())
}
#[inline]
fn keys_operator_by_text<'a>(
node: &Node<'a>,
_code: &[u8],
_ancestors: Ancestors<'a, '_>,
) -> bool {
// role-bypass: allow(Primitive) — key selection after the row
// has classified the node: the wrapper is one kind for many
// spellings and so is keyed by text, not whether the node is a
// primitive
node.kind_id() == Typescript::PredefinedType
}
}