swc_typescript/
diagnostic.rs1use std::{borrow::Cow, sync::Arc};
5
6use swc_common::{FileName, Span};
7
8use crate::fast_dts::FastDts;
9
10#[derive(Debug, Clone)]
11pub struct SourceRange {
12 pub filename: Arc<FileName>,
13 pub span: Span,
14}
15
16#[derive(Debug, Clone)]
17pub struct DtsIssue {
18 pub range: SourceRange,
19 pub message: Cow<'static, str>,
20}
21
22impl FastDts {
23 pub fn function_must_have_explicit_return_type(&mut self, span: Span) {
24 self.mark_diagnostic(
25 "TS9007: Function must have an explicit return type annotation with \
26 --isolatedDeclarations.",
27 span,
28 );
29 }
30
31 pub fn method_must_have_explicit_return_type(&mut self, span: Span) {
32 self.mark_diagnostic(
33 "TS9008: Method must have an explicit return type annotation with \
34 --isolatedDeclarations.",
35 span,
36 );
37 }
38
39 pub fn accessor_must_have_explicit_return_type(&mut self, span: Span) {
40 self.mark_diagnostic(
41 "TS9009: At least one accessor must have an explicit return type annotation with \
42 --isolatedDeclarations.",
43 span,
44 );
45 }
46
47 pub fn variable_must_have_explicit_type(&mut self, span: Span) {
48 self.mark_diagnostic(
49 "TS9010: Variable must have an explicit type annotation with --isolatedDeclarations.",
50 span,
51 );
52 }
53
54 pub fn parameter_must_have_explicit_type(&mut self, span: Span) {
55 self.mark_diagnostic(
56 "TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations.",
57 span,
58 );
59 }
60
61 pub fn property_must_have_explicit_type(&mut self, span: Span) {
62 self.mark_diagnostic(
63 "TS9012: Property must have an explicit type annotation with --isolatedDeclarations.",
64 span,
65 );
66 }
67
68 pub fn inferred_type_of_expression(&mut self, span: Span) {
69 self.mark_diagnostic(
70 "TS9013: Expression type can't be inferred with --isolatedDeclarations.",
71 span,
72 );
73 }
74
75 pub fn signature_computed_property_name(&mut self, span: Span) {
76 self.mark_diagnostic(
77 "TS9014: Computed properties must be number or string literals, variables or dotted \
78 expressions with --isolatedDeclarations.",
79 span,
80 );
81 }
82
83 pub fn object_with_spread_assignments(&mut self, span: Span) {
84 self.mark_diagnostic(
85 "TS9015: Objects that contain spread assignments can't be inferred with \
86 --isolatedDeclarations.",
87 span,
88 );
89 }
90
91 pub fn shorthand_property(&mut self, span: Span) {
92 self.mark_diagnostic(
93 "TS9016: Objects that contain shorthand properties can't be inferred with \
94 --isolatedDeclarations.",
95 span,
96 );
97 }
98
99 pub fn array_inferred(&mut self, span: Span) {
100 self.mark_diagnostic(
101 "TS9017: Only const arrays can be inferred with --isolatedDeclarations.",
102 span,
103 );
104 }
105
106 pub fn arrays_with_spread_elements(&mut self, span: Span) {
107 self.mark_diagnostic(
108 "TS9018: Arrays with spread elements can't inferred with --isolatedDeclarations.",
109 span,
110 );
111 }
112
113 pub fn binding_element_export(&mut self, span: Span) {
114 self.mark_diagnostic(
115 "TS9019: Binding elements can't be exported directly with --isolatedDeclarations.",
116 span,
117 );
118 }
119
120 pub fn enum_member_initializers(&mut self, span: Span) {
121 self.mark_diagnostic(
122 "TS9020: Enum member initializers must be computable without references to external \
123 symbols with --isolatedDeclarations.",
124 span,
125 );
126 }
127
128 pub fn extends_clause_expression(&mut self, span: Span) {
129 self.mark_diagnostic(
130 "TS9021: Extends clause can't contain an expression with --isolatedDeclarations.",
131 span,
132 );
133 }
134
135 pub fn inferred_type_of_class_expression(&mut self, span: Span) {
136 self.mark_diagnostic(
137 "TS9022: Inference from class expressions is not supported with \
138 --isolatedDeclarations.",
139 span,
140 );
141 }
142
143 pub fn implicitly_adding_undefined_to_type(&mut self, span: Span) {
144 self.mark_diagnostic(
145 "TS9025: Declaration emit for this parameter requires implicitly adding undefined to \
146 it's type. This is not supported with --isolatedDeclarations.",
147 span,
148 );
149 }
150
151 pub fn function_with_assigning_properties(&mut self, span: Span) {
152 self.mark_diagnostic(
153 "TS9023: Assigning properties to functions without declaring them is not supported \
154 with --isolatedDeclarations. Add an explicit declaration for the properties assigned \
155 to this function.",
156 span,
157 );
158 }
159
160 pub fn default_export_inferred(&mut self, span: Span) {
161 self.mark_diagnostic(
162 "TS9037: Default exports can't be inferred with --isolatedDeclarations.",
163 span,
164 );
165 }
166
167 pub fn computed_property_name(&mut self, span: Span) {
168 self.mark_diagnostic(
169 "TS9038: Computed property names on class or object literals cannot be inferred with \
170 --isolatedDeclarations.",
171 span,
172 );
173 }
174
175 pub fn type_containing_private_name(&mut self, name: &str, span: Span) {
176 self.mark_diagnostic(
177 format!(
178 "TS9039: Type containing private name '{name}' can't be used with \
179 --isolatedDeclarations."
180 ),
181 span,
182 );
183 }
184}