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
//! `Getter` implementation for TypeScript.
#![allow(clippy::wildcard_imports, clippy::enum_glob_use)]
use super::*;
impl Getter for TypescriptCode {
fn get_space_kind(node: &Node) -> SpaceKind {
use Typescript::*;
match node.kind_id().into() {
FunctionExpression
| MethodDefinition
| GeneratorFunction
| FunctionDeclaration
| GeneratorFunctionDeclaration
| ArrowFunction => SpaceKind::Function,
Class | ClassDeclaration | AbstractClassDeclaration => SpaceKind::Class,
InterfaceDeclaration => SpaceKind::Interface,
Program => SpaceKind::Unit,
_ => SpaceKind::Unknown,
}
}
fn get_func_space_name<'a>(node: &Node, code: &'a [u8]) -> Option<&'a str> {
if let Some(name) = node.child_by_field_name("name") {
node_text(code, &name)
} else {
// We can be in a pair: foo: function() {}
// Or in a variable declaration: var aFun = function() {}
if let Some(parent) = node.parent() {
match parent.kind_id().into() {
Typescript::Pair => {
if let Some(name) = parent.child_by_field_name("key") {
return node_text(code, &name);
}
}
Typescript::VariableDeclarator => {
if let Some(name) = parent.child_by_field_name("name") {
return node_text(code, &name);
}
}
_ => {}
}
}
Some("<anonymous>")
}
}
// TS exposes `String2` as the anonymous `"string"` alias for the
// type-annotation keyword (kind_id 135, in the type-keyword block
// of the enum). `Checker::is_string` already matches it (#283);
// including it here closes the Checker/Getter agreement gap
// (#313). `NestedIdentifier` and `MemberExpression4` are TS-only
// member-expression productions.
impl_js_family_get_op_type!(
Typescript,
op_extras: [QMARKDOT, PredefinedType],
operand_extras: [String2, NestedIdentifier, MemberExpression4],
predefined_void: PredefinedType,
);
get_operator!(Typescript);
}