Skip to content

Commit 4e1c771

Browse files
gkzmeta-codesync[bot]
authored andcommitted
[flow][tslib] Delete dead ETSSyntax error variants for unconditionally-accepted TS syntax
Summary: The `TSUnknown`, `TSKeyof`, and `TSTypeParamExtends` variants of `ts_syntax_kind` were defined and matched in code-action handlers but never actually emitted: `unknown`, `keyof`, and `T extends U` in type-parameter bounds are all accepted unconditionally by the type-annotation converter, so the corresponding `ETSSyntax` errors are never produced and the `Convert to mixed` / `Convert to $Keys<T>` / `Convert to : T` autofixes can never fire. Removes the variants from `error_message.ml`, the matching `MessageTS*` cases from `flow_intermediate_error_types.ml` and `flow_intermediate_error.ml`, the dead handlers in `code_action_service.ml`, and the unused `convert_unknown_type` / `convert_keyof_type` / `convert_type_param_extends` autofix functions (plus their type-mapper cases) in `autofix_ts_syntax.ml`/`.mli`. Changelog: [internal] Reviewed By: marcoww6 Differential Revision: D105753396 fbshipit-source-id: 1b9278151cc4d7ff5005def0442fd744192185fd
1 parent 9e8adce commit 4e1c771

12 files changed

Lines changed: 0 additions & 281 deletions

File tree

rust_port/crates/flow_services_code_action/src/autofix_ts_syntax.rs

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,10 @@ use crate::contains_mapper::ContainsMapper;
2525

2626
#[derive(PartialEq, Eq)]
2727
enum Kind {
28-
UnknownType,
2928
NeverType,
3029
UndefinedType,
31-
KeyofType,
3230
ReadOnlyArrayType,
3331
ReadOnlyTupleType,
34-
TypeParamExtends,
3532
TypeParamColon,
3633
InOutVariance,
3734
ReadonlyVariance,
@@ -61,11 +58,6 @@ impl AstVisitor<'_, Loc> for Mapper {
6158

6259
fn map_type_(&mut self, t: &ast::types::Type<Loc, Loc>) -> ast::types::Type<Loc, Loc> {
6360
match &**t {
64-
TypeInner::Unknown { loc, comments }
65-
if self.kind == Kind::UnknownType && self.contains.is_target(loc) =>
66-
{
67-
ast_builder::types::mixed(None, comments.clone())
68-
}
6961
TypeInner::Never { loc, comments }
7062
if self.kind == Kind::NeverType && self.contains.is_target(loc) =>
7163
{
@@ -76,21 +68,6 @@ impl AstVisitor<'_, Loc> for Mapper {
7668
{
7769
ast_builder::types::void(None, comments.clone())
7870
}
79-
TypeInner::Keyof { loc, inner }
80-
if self.kind == Kind::KeyofType && self.contains.is_target(loc) =>
81-
{
82-
let targs = ast_builder::types::type_args(
83-
None,
84-
None,
85-
vec![map_type_default(self, &inner.argument)],
86-
);
87-
ast_builder::types::unqualified_generic(
88-
inner.comments.clone(),
89-
None,
90-
Some(targs),
91-
"$Keys",
92-
)
93-
}
9471
TypeInner::ReadOnly { loc, inner }
9572
if self.kind == Kind::ReadOnlyArrayType && self.contains.is_target(loc) =>
9673
{
@@ -144,17 +121,6 @@ impl AstVisitor<'_, Loc> for Mapper {
144121
) -> ast::types::TypeParam<Loc, Loc> {
145122
use ast::types::type_param::BoundKind;
146123
match tparam {
147-
ast::types::TypeParam {
148-
bound_kind: BoundKind::Extends,
149-
loc,
150-
..
151-
} if self.kind == Kind::TypeParamExtends && self.contains.is_target(loc) => {
152-
ast::types::TypeParam {
153-
loc: LOC_NONE,
154-
bound_kind: BoundKind::Colon,
155-
..tparam.clone()
156-
}
157-
}
158124
ast::types::TypeParam {
159125
bound_kind: BoundKind::Colon,
160126
loc,
@@ -310,14 +276,6 @@ impl AstVisitor<'_, Loc> for Mapper {
310276
}
311277
}
312278

313-
pub fn convert_unknown_type(ast: &ast::Program<Loc, Loc>, loc: Loc) -> ast::Program<Loc, Loc> {
314-
let mut mapper = Mapper {
315-
contains: ContainsMapper::new(loc),
316-
kind: Kind::UnknownType,
317-
};
318-
mapper.map_program(ast)
319-
}
320-
321279
pub fn convert_never_type(ast: &ast::Program<Loc, Loc>, loc: Loc) -> ast::Program<Loc, Loc> {
322280
let mut mapper = Mapper {
323281
contains: ContainsMapper::new(loc),
@@ -334,25 +292,6 @@ pub fn convert_undefined_type(ast: &ast::Program<Loc, Loc>, loc: Loc) -> ast::Pr
334292
mapper.map_program(ast)
335293
}
336294

337-
pub fn convert_keyof_type(ast: &ast::Program<Loc, Loc>, loc: Loc) -> ast::Program<Loc, Loc> {
338-
let mut mapper = Mapper {
339-
contains: ContainsMapper::new(loc),
340-
kind: Kind::KeyofType,
341-
};
342-
mapper.map_program(ast)
343-
}
344-
345-
pub fn convert_type_param_extends(
346-
ast: &ast::Program<Loc, Loc>,
347-
loc: Loc,
348-
) -> ast::Program<Loc, Loc> {
349-
let mut mapper = Mapper {
350-
contains: ContainsMapper::new(loc),
351-
kind: Kind::TypeParamExtends,
352-
};
353-
mapper.map_program(ast)
354-
}
355-
356295
pub fn convert_type_param_colon(ast: &ast::Program<Loc, Loc>, loc: Loc) -> ast::Program<Loc, Loc> {
357296
let mut mapper = Mapper {
358297
contains: ContainsMapper::new(loc),

rust_port/crates/flow_services_code_action/src/code_action_service.rs

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,24 +1451,6 @@ pub fn ast_transforms_of_error(
14511451
vec![]
14521452
}
14531453
}
1454-
ErrorMessage::ETSSyntax(box ETSSyntaxData {
1455-
kind: TSSyntaxKind::TSUnknown,
1456-
loc: error_loc,
1457-
}) => {
1458-
if loc_opt_intersects(loc, error_loc.dupe()) {
1459-
vec![AstTransformOfError {
1460-
title: "Convert to `mixed`".to_string(),
1461-
diagnostic_title: "convert_unknown_type".to_string(),
1462-
transform: untyped_ast_transform(Box::new(|ast, loc| {
1463-
autofix_ts_syntax::convert_unknown_type(ast, loc)
1464-
})),
1465-
target_loc: error_loc.dupe(),
1466-
confidence: QuickfixConfidence::WillFixErrorAndSafeForRunningOnSave,
1467-
}]
1468-
} else {
1469-
vec![]
1470-
}
1471-
}
14721454
ErrorMessage::ETSSyntax(box ETSSyntaxData {
14731455
kind: TSSyntaxKind::TSNever,
14741456
loc: error_loc,
@@ -1505,42 +1487,6 @@ pub fn ast_transforms_of_error(
15051487
vec![]
15061488
}
15071489
}
1508-
ErrorMessage::ETSSyntax(box ETSSyntaxData {
1509-
kind: TSSyntaxKind::TSKeyof,
1510-
loc: error_loc,
1511-
}) => {
1512-
if loc_opt_intersects(loc, error_loc.dupe()) {
1513-
vec![AstTransformOfError {
1514-
title: "Convert to `$Keys<T>`".to_string(),
1515-
diagnostic_title: "convert_keyof_type".to_string(),
1516-
transform: untyped_ast_transform(Box::new(|ast, loc| {
1517-
autofix_ts_syntax::convert_keyof_type(ast, loc)
1518-
})),
1519-
target_loc: error_loc.dupe(),
1520-
confidence: QuickfixConfidence::WillFixErrorAndSafeForRunningOnSave,
1521-
}]
1522-
} else {
1523-
vec![]
1524-
}
1525-
}
1526-
ErrorMessage::ETSSyntax(box ETSSyntaxData {
1527-
kind: TSSyntaxKind::TSTypeParamExtends,
1528-
loc: error_loc,
1529-
}) => {
1530-
if loc_opt_intersects(loc, error_loc.dupe()) {
1531-
vec![AstTransformOfError {
1532-
title: "Convert to `: T`".to_string(),
1533-
diagnostic_title: "convert_type_param_extends".to_string(),
1534-
transform: untyped_ast_transform(Box::new(|ast, loc| {
1535-
autofix_ts_syntax::convert_type_param_extends(ast, loc)
1536-
})),
1537-
target_loc: error_loc.dupe(),
1538-
confidence: QuickfixConfidence::WillFixErrorAndSafeForRunningOnSave,
1539-
}]
1540-
} else {
1541-
vec![]
1542-
}
1543-
}
15441490
ErrorMessage::ETSSyntax(box ETSSyntaxData {
15451491
kind: TSSyntaxKind::DeprecatedTypeParamColon,
15461492
loc: error_loc,

rust_port/crates/flow_typing_errors/src/error_message.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3001,11 +3001,8 @@ pub enum UpperKind<L: Dupe> {
30013001
serde::Deserialize
30023002
)]
30033003
pub enum TSSyntaxKind {
3004-
TSUnknown,
30053004
TSNever,
30063005
TSUndefined,
3007-
TSKeyof,
3008-
TSTypeParamExtends,
30093006
TSReadonlyVariance,
30103007
TSInOutVariance(InOutVariance),
30113008
TSReadonlyType(Option<ReadonlyTypeKind>),
@@ -8863,11 +8860,8 @@ impl<L: Dupe + PartialEq + Eq + PartialOrd + Ord> ErrorMessage<L> {
88638860
ErrorMessage::ETSSyntax(box ETSSyntaxData { kind, .. }) => {
88648861
use crate::intermediate_error_types::Message;
88658862
let msg = match kind {
8866-
TSSyntaxKind::TSUnknown => Message::MessageTSUnknownType,
88678863
TSSyntaxKind::TSNever => Message::MessageTSNeverType,
88688864
TSSyntaxKind::TSUndefined => Message::MessageTSUndefinedType,
8869-
TSSyntaxKind::TSKeyof => Message::MessageTSKeyofType,
8870-
TSSyntaxKind::TSTypeParamExtends => Message::MessageTSParamExtends,
88718865
TSSyntaxKind::TSReadonlyVariance => Message::MessageTSVarianceReadOnly,
88728866
TSSyntaxKind::TSInOutVariance(InOutVariance::In) => {
88738867
Message::MessageTSVarianceIn

rust_port/crates/flow_typing_errors/src/intermediate_error.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8131,33 +8131,13 @@ where
81318131
features.extend(suggestion);
81328132
friendly::Message(features)
81338133
}
8134-
MessageTSKeyofType => friendly::Message(vec![
8135-
code("keyof"),
8136-
text(" is only supported when used inline in a mapped type. "),
8137-
text("The equivalent of TypeScript's "),
8138-
code("keyof"),
8139-
text(" type operator in Flow is the "),
8140-
code("$Keys"),
8141-
text(" utility type, used in the form "),
8142-
code("$Keys<T>"),
8143-
text("."),
8144-
]),
81458134
MessageTSNeverType => friendly::Message(vec![
81468135
text("The closest equivalent of TypeScript's "),
81478136
code("never"),
81488137
text(" type in Flow is "),
81498138
code("empty"),
81508139
text("."),
81518140
]),
8152-
MessageTSParamExtends => friendly::Message(vec![
8153-
text("While TypeScript uses "),
8154-
code("extends"),
8155-
text(" to specify type parameter bounds, Flow uses "),
8156-
code(":"),
8157-
text(" in the form "),
8158-
code("type T<A: B> = ..."),
8159-
text("."),
8160-
]),
81618141
MessageTSReadonlyOperatorOnArray => friendly::Message(vec![
81628142
text("The equivalent of TypeScript's "),
81638143
code("readonly"),
@@ -8311,13 +8291,6 @@ where
83118291
code("undefined"),
83128292
text(" types."),
83138293
]),
8314-
MessageTSUnknownType => friendly::Message(vec![
8315-
text("The equivalent of TypeScript's "),
8316-
code("unknown"),
8317-
text(" type in Flow is "),
8318-
code("mixed"),
8319-
text("."),
8320-
]),
83218294
MessageUnclearType => friendly::Message(vec![
83228295
text("Unclear type. Using "),
83238296
code("any"),

rust_port/crates/flow_typing_errors/src/intermediate_error_types.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,9 +2179,7 @@ pub enum Message<L: Dupe> {
21792179

21802180
MessageThisSuperInObject(VirtualReason<L>, ThisFinderKind),
21812181

2182-
MessageTSKeyofType,
21832182
MessageTSNeverType,
2184-
MessageTSParamExtends,
21852183
MessageTSReadonlyOperatorOnArray,
21862184
MessageTSReadonlyOperatorOnTuple,
21872185
MessageTSReadonlyType,
@@ -2196,7 +2194,6 @@ pub enum Message<L: Dupe> {
21962194
MessageAbstractClass,
21972195
MessageAbstractMethod,
21982196
MessageTSUndefinedType,
2199-
MessageTSUnknownType,
22002197

22012198
MessageTupleElementNotReadable(Box<MessageTupleElementNotReadableData<L>>),
22022199

rust_port/crates/flow_typing_statement/src/type_annotation.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -796,15 +796,6 @@ fn convert_inner<'a>(
796796
})
797797
}
798798
TypeInner::Unknown { loc, comments } => {
799-
if !(cx.ts_syntax() || cx.ts_utility_syntax()) {
800-
flow_js_utils::add_output_non_speculating(
801-
cx,
802-
ErrorMessage::ETSSyntax(Box::new(ETSSyntaxData {
803-
kind: flow_typing_errors::error_message::TSSyntaxKind::TSUnknown,
804-
loc: loc.dupe(),
805-
})),
806-
);
807-
}
808799
let rt = mixed_t::at(loc.dupe());
809800
ast::types::Type::new(TypeInner::Unknown {
810801
loc: (loc.dupe(), rt),
@@ -963,15 +954,6 @@ fn convert_inner<'a>(
963954
reason::mk_reason(reason::VirtualReasonDesc::RKeySet, loc.dupe()),
964955
arg_t,
965956
));
966-
if !(cx.ts_syntax() || cx.ts_utility_syntax()) {
967-
flow_js_utils::add_output_non_speculating(
968-
cx,
969-
ErrorMessage::ETSSyntax(Box::new(ETSSyntaxData {
970-
kind: flow_typing_errors::error_message::TSSyntaxKind::TSKeyof,
971-
loc: loc.dupe(),
972-
})),
973-
);
974-
}
975957
ast::types::Type::new(TypeInner::Keyof {
976958
loc: (loc.dupe(), t),
977959
inner: ast::types::Keyof {

src/services/code_action/autofix_ts_syntax.ml

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,10 @@ class mapper target_loc kind =
1212
method! type_ t =
1313
let open Flow_ast.Type in
1414
match t with
15-
| (loc, Unknown comments) when kind = `UnknownType && this#is_target loc ->
16-
Ast_builder.Types.mixed ?comments ()
1715
| (loc, Never comments) when kind = `NeverType && this#is_target loc ->
1816
Ast_builder.Types.empty ?comments ()
1917
| (loc, Undefined comments) when kind = `UndefinedType && this#is_target loc ->
2018
Ast_builder.Types.void ?comments ()
21-
| (loc, Keyof { Keyof.argument; comments }) when kind = `KeyofType && this#is_target loc ->
22-
let targs = Ast_builder.Types.type_args [super#type_ argument] in
23-
Ast_builder.Types.unqualified_generic ?comments ~targs "$Keys"
2419
| (loc, ReadOnly { ReadOnly.argument = (_, Array { Array.argument; _ }); comments })
2520
when kind = `ReadOnlyArrayType && this#is_target loc ->
2621
let targs = Ast_builder.Types.type_args [super#type_ argument] in
@@ -34,8 +29,6 @@ class mapper target_loc kind =
3429
method! type_param ~kind:k (loc, tparam) =
3530
let open Flow_ast.Type.TypeParam in
3631
match tparam with
37-
| { bound_kind = Extends; _ } when kind = `TypeParamExtends && this#is_target loc ->
38-
(Loc.none, { tparam with bound_kind = Colon })
3932
| { bound_kind = Colon; _ } when kind = `TypeParamColon && this#is_target loc ->
4033
(Loc.none, { tparam with bound_kind = Extends })
4134
| { variance = Some (v_loc, Flow_ast.Variance.{ kind = InOut; _ }); _ }
@@ -77,10 +70,6 @@ class mapper target_loc kind =
7770
| _ -> super#expression e
7871
end
7972

80-
let convert_unknown_type ast loc =
81-
let mapper = new mapper loc `UnknownType in
82-
mapper#program ast
83-
8473
let convert_never_type ast loc =
8574
let mapper = new mapper loc `NeverType in
8675
mapper#program ast
@@ -89,14 +78,6 @@ let convert_undefined_type ast loc =
8978
let mapper = new mapper loc `UndefinedType in
9079
mapper#program ast
9180

92-
let convert_keyof_type ast loc =
93-
let mapper = new mapper loc `KeyofType in
94-
mapper#program ast
95-
96-
let convert_type_param_extends ast loc =
97-
let mapper = new mapper loc `TypeParamExtends in
98-
mapper#program ast
99-
10081
let convert_type_param_colon ast loc =
10182
let mapper = new mapper loc `TypeParamColon in
10283
mapper#program ast

src/services/code_action/autofix_ts_syntax.mli

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
* LICENSE file in the root directory of this source tree.
66
*)
77

8-
val convert_unknown_type :
9-
(Loc.t, Loc.t) Flow_ast_mapper.Ast.Program.t ->
10-
Loc.t ->
11-
(Loc.t, Loc.t) Flow_ast_mapper.Ast.Program.t
12-
138
val convert_never_type :
149
(Loc.t, Loc.t) Flow_ast_mapper.Ast.Program.t ->
1510
Loc.t ->
@@ -20,16 +15,6 @@ val convert_undefined_type :
2015
Loc.t ->
2116
(Loc.t, Loc.t) Flow_ast_mapper.Ast.Program.t
2217

23-
val convert_keyof_type :
24-
(Loc.t, Loc.t) Flow_ast_mapper.Ast.Program.t ->
25-
Loc.t ->
26-
(Loc.t, Loc.t) Flow_ast_mapper.Ast.Program.t
27-
28-
val convert_type_param_extends :
29-
(Loc.t, Loc.t) Flow_ast_mapper.Ast.Program.t ->
30-
Loc.t ->
31-
(Loc.t, Loc.t) Flow_ast_mapper.Ast.Program.t
32-
3318
val convert_type_param_colon :
3419
(Loc.t, Loc.t) Flow_ast_mapper.Ast.Program.t ->
3520
Loc.t ->

0 commit comments

Comments
 (0)