swc_typescript/
diagnostic.rs

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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//! References
//! * <https://github.com/oxc-project/oxc/blob/main/crates/oxc_isolated_declarations/src/diagnostics.rs>

use std::{borrow::Cow, sync::Arc};

use swc_common::{FileName, Span};

use crate::fast_dts::FastDts;

#[derive(Debug, Clone)]
pub struct SourceRange {
    pub filename: Arc<FileName>,
    pub span: Span,
}

#[derive(Debug, Clone)]
pub struct DtsIssue {
    pub range: SourceRange,
    pub message: Cow<'static, str>,
}

impl FastDts {
    pub fn function_must_have_explicit_return_type(&mut self, span: Span) {
        self.mark_diagnostic(
            "TS9007: Function must have an explicit return type annotation with \
             --isolatedDeclarations.",
            span,
        );
    }

    pub fn method_must_have_explicit_return_type(&mut self, span: Span) {
        self.mark_diagnostic(
            "TS9008: Method must have an explicit return type annotation with \
             --isolatedDeclarations.",
            span,
        );
    }

    pub fn accessor_must_have_explicit_return_type(&mut self, span: Span) {
        self.mark_diagnostic(
            "TS9009: At least one accessor must have an explicit return type annotation with \
             --isolatedDeclarations.",
            span,
        );
    }

    pub fn variable_must_have_explicit_type(&mut self, span: Span) {
        self.mark_diagnostic(
            "TS9010: Variable must have an explicit type annotation with --isolatedDeclarations.",
            span,
        );
    }

    pub fn parameter_must_have_explicit_type(&mut self, span: Span) {
        self.mark_diagnostic(
            "TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations.",
            span,
        );
    }

    pub fn property_must_have_explicit_type(&mut self, span: Span) {
        self.mark_diagnostic(
            "TS9012: Property must have an explicit type annotation with --isolatedDeclarations.",
            span,
        );
    }

    pub fn inferred_type_of_expression(&mut self, span: Span) {
        self.mark_diagnostic(
            "TS9013: Expression type can't be inferred with --isolatedDeclarations.",
            span,
        );
    }

    pub fn signature_computed_property_name(&mut self, span: Span) {
        self.mark_diagnostic(
            "TS9014: Computed properties must be number or string literals, variables or dotted \
             expressions with --isolatedDeclarations.",
            span,
        );
    }

    pub fn object_with_spread_assignments(&mut self, span: Span) {
        self.mark_diagnostic(
            "TS9015: Objects that contain spread assignments can't be inferred with \
             --isolatedDeclarations.",
            span,
        );
    }

    pub fn shorthand_property(&mut self, span: Span) {
        self.mark_diagnostic(
            "TS9016: Objects that contain shorthand properties can't be inferred with \
             --isolatedDeclarations.",
            span,
        );
    }

    pub fn array_inferred(&mut self, span: Span) {
        self.mark_diagnostic(
            "TS9017: Only const arrays can be inferred with --isolatedDeclarations.",
            span,
        );
    }

    pub fn arrays_with_spread_elements(&mut self, span: Span) {
        self.mark_diagnostic(
            "TS9018: Arrays with spread elements can't inferred with --isolatedDeclarations.",
            span,
        );
    }

    pub fn binding_element_export(&mut self, span: Span) {
        self.mark_diagnostic(
            "TS9019: Binding elements can't be exported directly with --isolatedDeclarations.",
            span,
        );
    }

    pub fn enum_member_initializers(&mut self, span: Span) {
        self.mark_diagnostic(
            "TS9020: Enum member initializers must be computable without references to external \
             symbols with --isolatedDeclarations.",
            span,
        );
    }

    pub fn extends_clause_expression(&mut self, span: Span) {
        self.mark_diagnostic(
            "TS9021: Extends clause can't contain an expression with --isolatedDeclarations.",
            span,
        );
    }

    pub fn inferred_type_of_class_expression(&mut self, span: Span) {
        self.mark_diagnostic(
            "TS9022: Inference from class expressions is not supported with \
             --isolatedDeclarations.",
            span,
        );
    }

    pub fn implicitly_adding_undefined_to_type(&mut self, span: Span) {
        self.mark_diagnostic(
            "TS9025: Declaration emit for this parameter requires implicitly adding undefined to \
             it's type. This is not supported with --isolatedDeclarations.",
            span,
        );
    }

    pub fn function_with_assigning_properties(&mut self, span: Span) {
        self.mark_diagnostic(
            "TS9023: Assigning properties to functions without declaring them is not supported \
             with --isolatedDeclarations. Add an explicit declaration for the properties assigned \
             to this function.",
            span,
        );
    }

    pub fn default_export_inferred(&mut self, span: Span) {
        self.mark_diagnostic(
            "TS9037: Default exports can't be inferred with --isolatedDeclarations.",
            span,
        );
    }

    pub fn computed_property_name(&mut self, span: Span) {
        self.mark_diagnostic(
            "TS9038: Computed property names on class or object literals cannot be inferred with \
             --isolatedDeclarations.",
            span,
        );
    }

    pub fn type_containing_private_name(&mut self, name: &str, span: Span) {
        self.mark_diagnostic(
            format!(
                "TS9039: Type containing private name '{name}' can't be used with \
                 --isolatedDeclarations."
            ),
            span,
        );
    }
}