Skip to content

Commit

Permalink
chore(es/typescript): Remove unreachable_visit_mut_type (#9390)
Browse files Browse the repository at this point in the history
  • Loading branch information
magic-akari authored Aug 7, 2024
1 parent 679682c commit 8e49c90
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 78 deletions.
6 changes: 6 additions & 0 deletions .changeset/forty-pigs-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
swc_ecma_visit: patch
swc_ecma_transforms_typescript: patch
---

chore(es/typescript): Remove `unreachable_visit_mut_type`
71 changes: 0 additions & 71 deletions crates/swc_ecma_transforms_typescript/src/macros.rs
Original file line number Diff line number Diff line change
@@ -1,74 +1,3 @@
#[macro_export]
macro_rules! unreachable_visit_mut_type {
($name:ident, $N:ident) => {
fn $name(&mut self, _: &mut swc_ecma_ast::$N) {
#[cfg(debug_assertions)]
unreachable!(stringify!($name));
#[cfg(not(debug_assertions))]
unreachable!();
}
};
() => {
unreachable_visit_mut_type!(visit_mut_accessibility, Accessibility);
unreachable_visit_mut_type!(visit_mut_true_plus_minus, TruePlusMinus);
unreachable_visit_mut_type!(visit_mut_ts_array_type, TsArrayType);
unreachable_visit_mut_type!(visit_mut_ts_call_signature_decl, TsCallSignatureDecl);
unreachable_visit_mut_type!(visit_mut_ts_conditional_type, TsConditionalType);
unreachable_visit_mut_type!(
visit_mut_ts_construct_signature_decl,
TsConstructSignatureDecl
);
unreachable_visit_mut_type!(visit_mut_ts_constructor_type, TsConstructorType);
unreachable_visit_mut_type!(visit_mut_ts_entity_name, TsEntityName);
unreachable_visit_mut_type!(visit_mut_ts_external_module_ref, TsExternalModuleRef);
unreachable_visit_mut_type!(visit_mut_ts_fn_or_constructor_type, TsFnOrConstructorType);
unreachable_visit_mut_type!(visit_mut_ts_fn_param, TsFnParam);
unreachable_visit_mut_type!(visit_mut_ts_fn_type, TsFnType);
unreachable_visit_mut_type!(visit_mut_ts_import_type, TsImportType);
unreachable_visit_mut_type!(visit_mut_ts_index_signature, TsIndexSignature);
unreachable_visit_mut_type!(visit_mut_ts_indexed_access_type, TsIndexedAccessType);
unreachable_visit_mut_type!(visit_mut_ts_infer_type, TsInferType);
unreachable_visit_mut_type!(visit_mut_ts_interface_body, TsInterfaceBody);
unreachable_visit_mut_type!(visit_mut_ts_interface_decl, TsInterfaceDecl);
unreachable_visit_mut_type!(visit_mut_ts_intersection_type, TsIntersectionType);
unreachable_visit_mut_type!(visit_mut_ts_keyword_type, TsKeywordType);
unreachable_visit_mut_type!(visit_mut_ts_keyword_type_kind, TsKeywordTypeKind);
unreachable_visit_mut_type!(visit_mut_ts_mapped_type, TsMappedType);
unreachable_visit_mut_type!(visit_mut_ts_method_signature, TsMethodSignature);
unreachable_visit_mut_type!(visit_mut_ts_module_ref, TsModuleRef);
unreachable_visit_mut_type!(visit_mut_ts_optional_type, TsOptionalType);
unreachable_visit_mut_type!(visit_mut_ts_parenthesized_type, TsParenthesizedType);
unreachable_visit_mut_type!(visit_mut_ts_property_signature, TsPropertySignature);
unreachable_visit_mut_type!(visit_mut_ts_qualified_name, TsQualifiedName);
unreachable_visit_mut_type!(visit_mut_ts_rest_type, TsRestType);
unreachable_visit_mut_type!(visit_mut_ts_this_type, TsThisType);
unreachable_visit_mut_type!(visit_mut_ts_this_type_or_ident, TsThisTypeOrIdent);
unreachable_visit_mut_type!(visit_mut_ts_tuple_type, TsTupleType);
unreachable_visit_mut_type!(visit_mut_ts_type, TsType);
unreachable_visit_mut_type!(visit_mut_ts_type_alias_decl, TsTypeAliasDecl);
unreachable_visit_mut_type!(visit_mut_ts_type_ann, TsTypeAnn);
unreachable_visit_mut_type!(visit_mut_ts_type_element, TsTypeElement);
unreachable_visit_mut_type!(visit_mut_ts_type_lit, TsTypeLit);
unreachable_visit_mut_type!(visit_mut_ts_type_operator, TsTypeOperator);
unreachable_visit_mut_type!(visit_mut_ts_type_operator_op, TsTypeOperatorOp);
unreachable_visit_mut_type!(visit_mut_ts_type_param, TsTypeParam);
unreachable_visit_mut_type!(visit_mut_ts_type_param_decl, TsTypeParamDecl);
unreachable_visit_mut_type!(
visit_mut_ts_type_param_instantiation,
TsTypeParamInstantiation
);
unreachable_visit_mut_type!(visit_mut_ts_type_predicate, TsTypePredicate);
unreachable_visit_mut_type!(visit_mut_ts_type_query, TsTypeQuery);
unreachable_visit_mut_type!(visit_mut_ts_type_query_expr, TsTypeQueryExpr);
unreachable_visit_mut_type!(visit_mut_ts_type_ref, TsTypeRef);
unreachable_visit_mut_type!(
visit_mut_ts_union_or_intersection_type,
TsUnionOrIntersectionType
);
unreachable_visit_mut_type!(visit_mut_ts_union_type, TsUnionType);
};
}

#[macro_export]
macro_rules! type_to_none {
($name:ident, $T:ty) => {
Expand Down
6 changes: 3 additions & 3 deletions crates/swc_ecma_transforms_typescript/src/strip_type.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use swc_common::util::take::Take;
use swc_ecma_ast::*;
use swc_ecma_utils::stack_size::maybe_grow_default;
use swc_ecma_visit::{VisitMut, VisitMutWith};
use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith};

use crate::{type_to_none, unreachable_visit_mut_type};
use crate::type_to_none;

pub fn strip_type() -> impl VisitMut {
StripType::default()
Expand All @@ -15,7 +15,7 @@ pub fn strip_type() -> impl VisitMut {
pub(crate) struct StripType {}

impl VisitMut for StripType {
unreachable_visit_mut_type!();
noop_visit_mut_type!(fail);

type_to_none!(visit_mut_opt_ts_type, Box<TsType>);

Expand Down
9 changes: 5 additions & 4 deletions crates/swc_ecma_visit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ macro_rules! noop_visit_type {
($name:ident, $N:tt, fail) => {
#[cfg_attr(not(debug_assertions), inline(always))]
fn $name(&mut self, _: &$crate::swc_ecma_ast::$N) {
$crate::fail_no_typescript();
$crate::fail_no_typescript(stringify!($name));
}
};
($name:ident, $N:tt) => {
Expand All @@ -549,10 +549,11 @@ pub fn fail_not_standard() {
/// NOT A PUBLIC API
#[doc(hidden)]
#[cfg_attr(not(debug_assertions), inline(always))]
pub fn fail_no_typescript() {
pub fn fail_no_typescript(visitor_name: &str) {
unsafe {
debug_unreachable::debug_unreachable!(
"This visitor does not support typescript. This method fails for optimization purpose."
"This visitor does not support TypeScript. This method fails for optimization \
purposes. Encountered in unreachable visitor: {visitor_name}"
)
}
}
Expand Down Expand Up @@ -907,7 +908,7 @@ macro_rules! noop_visit_mut_type {
($name:ident, $N:ident, fail) => {
#[cfg_attr(not(debug_assertions), inline(always))]
fn $name(&mut self, _: &mut $crate::swc_ecma_ast::$N) {
$crate::fail_no_typescript();
$crate::fail_no_typescript(stringify!($name));
}
};
($name:ident, $N:ident) => {
Expand Down

0 comments on commit 8e49c90

Please sign in to comment.