diff --git a/crates/dbg-swc/src/util/minifier.rs b/crates/dbg-swc/src/util/minifier.rs index 76fd48dee946..fff396c745ca 100644 --- a/crates/dbg-swc/src/util/minifier.rs +++ b/crates/dbg-swc/src/util/minifier.rs @@ -9,7 +9,7 @@ use swc_common::{FileName, SourceMap}; use swc_ecma_ast::*; use swc_ecma_minifier::option::{CompressOptions, MangleOptions, MinifyOptions}; use swc_ecma_transforms_base::fixer::fixer; -use swc_ecma_visit::{standard_only_visit_mut, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; use super::{parse_js, print_js, wrap_task, ModuleRecord}; @@ -136,7 +136,7 @@ pub fn get_esbuild_output(file: &Path, mangle: bool) -> Result { struct Normalizer {} impl VisitMut for Normalizer { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_prop(&mut self, p: &mut Prop) { p.visit_mut_children_with(self); diff --git a/crates/swc/src/builder.rs b/crates/swc/src/builder.rs index 40944087a143..1096afe491a6 100644 --- a/crates/swc/src/builder.rs +++ b/crates/swc/src/builder.rs @@ -22,7 +22,7 @@ use swc_ecma_transforms::{ pass::Optional, resolver, Assumptions, }; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, VisitMut, VisitMutWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, VisitMut, VisitMutWith}; use crate::config::{CompiledPaths, GlobalPassOption, JsMinifyOptions, ModuleConfig}; @@ -382,7 +382,7 @@ struct MinifierPass<'a> { } impl VisitMut for MinifierPass<'_> { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_module(&mut self, m: &mut Module) { if let Some(options) = &self.options { diff --git a/crates/swc/src/dropped_comments_preserver.rs b/crates/swc/src/dropped_comments_preserver.rs index 1554a27ad166..d87a680e1f33 100644 --- a/crates/swc/src/dropped_comments_preserver.rs +++ b/crates/swc/src/dropped_comments_preserver.rs @@ -3,7 +3,7 @@ use swc_common::{ BytePos, Span, DUMMY_SP, }; use swc_ecma_ast::{Module, Script}; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; /// Preserves comments that would otherwise be dropped. /// @@ -36,7 +36,7 @@ struct DroppedCommentsPreserver { type CommentEntries = Vec<(BytePos, Vec)>; impl VisitMut for DroppedCommentsPreserver { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_module(&mut self, module: &mut Module) { module.visit_mut_children_with(self); diff --git a/crates/swc/tests/fixture/issues-9xxx/9204/input/.swcrc b/crates/swc/tests/fixture/issues-9xxx/9204/input/.swcrc new file mode 100644 index 000000000000..a7566af718b7 --- /dev/null +++ b/crates/swc/tests/fixture/issues-9xxx/9204/input/.swcrc @@ -0,0 +1,64 @@ +{ + "jsc": { + "parser": { + "syntax": "typescript", + "tsx": true + }, + "target": "es2022", + "loose": false, + "minify": { + "compress": { + "arguments": true, + "arrows": true, + "booleans": true, + "booleans_as_integers": true, + "collapse_vars": true, + "comparisons": true, + "computed_props": true, + "conditionals": true, + "dead_code": false, + "directives": true, + "drop_console": true, + "drop_debugger": true, + "evaluate": true, + "expression": true, + "hoist_funs": true, + "hoist_props": true, + "hoist_vars": true, + "if_return": true, + "join_vars": false, + "keep_classnames": true, + "keep_fargs": true, + "keep_fnames": false, + "keep_infinity": true, + "loops": true, + "negate_iife": false, + "properties": true, + "reduce_funcs": true, + "reduce_vars": false, + "side_effects": true, + "switches": true, + "typeofs": true, + "unsafe": false, + "unsafe_arrows": false, + "unsafe_comps": false, + "unsafe_Function": false, + "unsafe_math": false, + "unsafe_symbols": false, + "unsafe_methods": false, + "unsafe_proto": false, + "unsafe_regexp": false, + "unsafe_undefined": false, + "unused": true, + "const_to_let": true, + "pristine_globals": true + }, + "mangle": false + } + }, + "module": { + "type": "es6" + }, + "minify": false, + "isModule": true +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-9xxx/9204/input/1.js b/crates/swc/tests/fixture/issues-9xxx/9204/input/1.js new file mode 100644 index 000000000000..22d333eb2ec9 --- /dev/null +++ b/crates/swc/tests/fixture/issues-9xxx/9204/input/1.js @@ -0,0 +1,8 @@ +const Foo = createFoo(); +export function App() { + return ( + + + + ); +} diff --git a/crates/swc/tests/fixture/issues-9xxx/9204/output/1.js b/crates/swc/tests/fixture/issues-9xxx/9204/output/1.js new file mode 100644 index 000000000000..1c3d2c217274 --- /dev/null +++ b/crates/swc/tests/fixture/issues-9xxx/9204/output/1.js @@ -0,0 +1,4 @@ +let Foo = createFoo(); +export function App() { + return React.createElement("view", null, React.createElement(Foo, null)); +} diff --git a/crates/swc/tests/rust_api.rs b/crates/swc/tests/rust_api.rs index 237815bd2b22..7111005e456b 100644 --- a/crates/swc/tests/rust_api.rs +++ b/crates/swc/tests/rust_api.rs @@ -6,12 +6,12 @@ use swc_common::{comments::SingleThreadedComments, FileName}; use swc_ecma_ast::*; use swc_ecma_parser::{EsSyntax, Syntax, TsSyntax}; use swc_ecma_transforms::pass::noop; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, VisitMut}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, VisitMut}; struct PanicOnVisit; impl VisitMut for PanicOnVisit { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_number(&mut self, n: &mut Number) { panic!("Expected {:?}", n.value) diff --git a/crates/swc_bundler/src/bundler/chunk/cjs.rs b/crates/swc_bundler/src/bundler/chunk/cjs.rs index f25b1afc3d21..d95849f43fa6 100644 --- a/crates/swc_bundler/src/bundler/chunk/cjs.rs +++ b/crates/swc_bundler/src/bundler/chunk/cjs.rs @@ -4,7 +4,7 @@ use anyhow::Error; use swc_common::{collections::AHashMap, Span, SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_utils::{quote_ident, ExprFactory}; -use swc_ecma_visit::{standard_only_visit_mut, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; use crate::{ bundler::{chunk::merge::Ctx, load::TransformedModule}, @@ -189,7 +189,7 @@ where L: Load, R: Resolve, { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_call_expr(&mut self, node: &mut CallExpr) { node.visit_mut_children_with(self); @@ -352,7 +352,7 @@ struct DefaultHandler { } impl VisitMut for DefaultHandler { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_expr(&mut self, e: &mut Expr) { e.visit_mut_children_with(self); @@ -375,7 +375,7 @@ struct Remapper { } impl VisitMut for Remapper { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_ident(&mut self, i: &mut Ident) { if let Some(v) = self.vars.get(&i.to_id()).copied() { diff --git a/crates/swc_bundler/src/bundler/export.rs b/crates/swc_bundler/src/bundler/export.rs index 12650b72b32f..c9b777635510 100644 --- a/crates/swc_bundler/src/bundler/export.rs +++ b/crates/swc_bundler/src/bundler/export.rs @@ -3,7 +3,7 @@ use swc_atoms::JsWord; use swc_common::{collections::ARandomState, FileName, SyntaxContext}; use swc_ecma_ast::*; use swc_ecma_utils::find_pat_ids; -use swc_ecma_visit::{standard_only_visit_mut, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; use super::{ load::{Source, Specifier}, @@ -115,7 +115,7 @@ where L: Load, R: Resolve, { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_module_item(&mut self, item: &mut ModuleItem) { match item { diff --git a/crates/swc_bundler/src/bundler/import/mod.rs b/crates/swc_bundler/src/bundler/import/mod.rs index 83583fe6806f..bcb25a439703 100644 --- a/crates/swc_bundler/src/bundler/import/mod.rs +++ b/crates/swc_bundler/src/bundler/import/mod.rs @@ -7,7 +7,7 @@ use swc_common::{ }; use swc_ecma_ast::*; use swc_ecma_utils::find_pat_ids; -use swc_ecma_visit::{standard_only_visit_mut, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; use super::Bundler; use crate::{load::Load, resolve::Resolve, util::ExportMetadata}; @@ -365,7 +365,7 @@ where L: Load, R: Resolve, { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_export_named_specifier(&mut self, s: &mut ExportNamedSpecifier) { let orig = match &s.orig { diff --git a/crates/swc_bundler/src/bundler/keywords.rs b/crates/swc_bundler/src/bundler/keywords.rs index 3f1f9c1992c9..63f13040b938 100644 --- a/crates/swc_bundler/src/bundler/keywords.rs +++ b/crates/swc_bundler/src/bundler/keywords.rs @@ -1,7 +1,7 @@ use swc_common::{collections::AHashMap, util::take::Take}; use swc_ecma_ast::*; use swc_ecma_utils::private_ident; -use swc_ecma_visit::{standard_only_visit_mut, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; use crate::id::Id; @@ -31,7 +31,7 @@ impl KeywordRenamer { } impl VisitMut for KeywordRenamer { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_binding_ident(&mut self, n: &mut BindingIdent) { if let Some(new) = self.renamed(&n.id) { diff --git a/crates/swc_bundler/src/bundler/load.rs b/crates/swc_bundler/src/bundler/load.rs index 5903b29adce5..49603c5749d1 100644 --- a/crates/swc_bundler/src/bundler/load.rs +++ b/crates/swc_bundler/src/bundler/load.rs @@ -11,7 +11,7 @@ use swc_ecma_ast::{ }; use swc_ecma_transforms_base::resolver; use swc_ecma_visit::{ - noop_visit_type, standard_only_visit_mut, FoldWith, Visit, VisitMut, VisitMutWith, VisitWith, + noop_visit_mut_type, noop_visit_type, FoldWith, Visit, VisitMut, VisitMutWith, VisitWith, }; use super::{export::Exports, helpers::Helpers, Bundler}; @@ -486,7 +486,7 @@ impl Visit for Es6ModuleDetector { #[derive(Clone, Copy)] struct ClearMark; impl VisitMut for ClearMark { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_ident(&mut self, ident: &mut Ident) { ident.ctxt = SyntaxContext::empty(); diff --git a/crates/swc_bundler/src/inline.rs b/crates/swc_bundler/src/inline.rs index 9955b51363a3..2fa15f1daf74 100644 --- a/crates/swc_bundler/src/inline.rs +++ b/crates/swc_bundler/src/inline.rs @@ -1,7 +1,7 @@ use swc_common::{collections::AHashMap, SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_visit::{ - noop_visit_type, standard_only_visit_mut, visit_mut_obj_and_computed, Visit, VisitMut, + noop_visit_mut_type, noop_visit_type, visit_mut_obj_and_computed, Visit, VisitMut, VisitMutWith, VisitWith, }; @@ -84,7 +84,7 @@ impl Visit for Analyzer<'_> { } impl VisitMut for Inliner { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); visit_mut_obj_and_computed!(); diff --git a/crates/swc_bundler/src/util.rs b/crates/swc_bundler/src/util.rs index e7c1e5a13da3..de329eb3facc 100644 --- a/crates/swc_bundler/src/util.rs +++ b/crates/swc_bundler/src/util.rs @@ -5,7 +5,7 @@ use std::hash::Hash; use swc_common::{SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_utils::ident::IdentLike; -use swc_ecma_visit::{standard_only_visit_mut, VisitMut}; +use swc_ecma_visit::{noop_visit_mut_type, VisitMut}; #[cfg(feature = "concurrent")] pub(crate) type Readonly = std::sync::Arc; @@ -149,7 +149,7 @@ where pub(crate) struct HygieneRemover; impl VisitMut for HygieneRemover { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_syntax_context(&mut self, n: &mut SyntaxContext) { *n = SyntaxContext::empty(); diff --git a/crates/swc_ecma_compat_bugfixes/src/edge_default_param.rs b/crates/swc_ecma_compat_bugfixes/src/edge_default_param.rs index 6164fa0f7b12..e3cf349ebd98 100644 --- a/crates/swc_ecma_compat_bugfixes/src/edge_default_param.rs +++ b/crates/swc_ecma_compat_bugfixes/src/edge_default_param.rs @@ -1,5 +1,5 @@ use swc_ecma_ast::*; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; /// Converts destructured parameters with default values to non-shorthand @@ -16,7 +16,7 @@ struct EdgeDefaultParam { #[swc_trace] impl VisitMut for EdgeDefaultParam { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_arrow_expr(&mut self, n: &mut ArrowExpr) { self.in_arrow = true; diff --git a/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs b/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs index 6d2dad031af9..425f297863e0 100644 --- a/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs +++ b/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs @@ -4,7 +4,7 @@ use swc_atoms::JsWord; use swc_common::{collections::AHashSet, SyntaxContext}; use swc_ecma_ast::*; use swc_ecma_transforms_base::hygiene::rename; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; pub fn safari_id_destructuring_collision_in_function_expression() -> impl Fold + VisitMut { @@ -31,7 +31,7 @@ impl SafariIdDestructuringCollisionInFunctionExpression { #[swc_trace] impl VisitMut for SafariIdDestructuringCollisionInFunctionExpression { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_assign_pat_prop(&mut self, n: &mut AssignPatProp) { self.visit_mut_pat_id(&Ident::from(&n.key)); diff --git a/crates/swc_ecma_compat_common/src/regexp.rs b/crates/swc_ecma_compat_common/src/regexp.rs index 9f2d11a0de96..aea56f5fa5e5 100644 --- a/crates/swc_ecma_compat_common/src/regexp.rs +++ b/crates/swc_ecma_compat_common/src/regexp.rs @@ -1,7 +1,7 @@ use swc_common::util::take::Take; use swc_ecma_ast::{CallExpr, Expr, Lit, Regex}; use swc_ecma_utils::{quote_ident, ExprFactory}; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; pub fn regexp(config: Config) -> impl Fold + VisitMut { as_folder(RegExp { config }) @@ -32,7 +32,7 @@ struct RegExp { } impl VisitMut for RegExp { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_expr(&mut self, expr: &mut Expr) { expr.visit_mut_children_with(self); diff --git a/crates/swc_ecma_compat_es2015/src/arrow.rs b/crates/swc_ecma_compat_es2015/src/arrow.rs index 5cefbca69b6a..381ca909f587 100644 --- a/crates/swc_ecma_compat_es2015/src/arrow.rs +++ b/crates/swc_ecma_compat_es2015/src/arrow.rs @@ -6,9 +6,7 @@ use swc_ecma_utils::{ function::{init_this, FnEnvHoister}, prepend_stmt, }; -use swc_ecma_visit::{ - as_folder, standard_only_visit_mut, Fold, InjectVars, VisitMut, VisitMutWith, -}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, InjectVars, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; /// Compile ES2015 arrow functions to ES5 @@ -74,7 +72,7 @@ struct Arrow { #[swc_trace] impl VisitMut for Arrow { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_class(&mut self, c: &mut Class) { if c.super_class.is_some() { diff --git a/crates/swc_ecma_compat_es2015/src/block_scoped_fn.rs b/crates/swc_ecma_compat_es2015/src/block_scoped_fn.rs index bef8f78c0033..b6dfb9dc5c34 100644 --- a/crates/swc_ecma_compat_es2015/src/block_scoped_fn.rs +++ b/crates/swc_ecma_compat_es2015/src/block_scoped_fn.rs @@ -1,7 +1,7 @@ use swc_common::{util::take::Take, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_utils::IdentUsageFinder; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; pub fn block_scoped_functions() -> impl Fold + VisitMut { @@ -13,7 +13,7 @@ struct BlockScopedFns; #[swc_trace] impl VisitMut for BlockScopedFns { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_function(&mut self, n: &mut Function) { let Some(body) = &mut n.body else { return }; diff --git a/crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs b/crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs index 7f3a3ec6784e..72fa7357ba75 100644 --- a/crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs +++ b/crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs @@ -16,7 +16,7 @@ use swc_ecma_utils::{ ExprFactory, StmtLike, }; use swc_ecma_visit::{ - as_folder, standard_only_visit_mut, visit_mut_obj_and_computed, Fold, VisitMut, VisitMutWith, + as_folder, noop_visit_mut_type, visit_mut_obj_and_computed, Fold, VisitMut, VisitMutWith, }; use swc_trace_macro::swc_trace; @@ -435,7 +435,7 @@ impl BlockScoping { #[swc_trace] impl VisitMut for BlockScoping { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_arrow_expr(&mut self, n: &mut ArrowExpr) { n.params.visit_mut_with(self); @@ -685,7 +685,7 @@ impl<'a> FlowHelper<'a> { #[swc_trace] impl VisitMut for FlowHelper<'_> { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); /// noop fn visit_mut_arrow_expr(&mut self, _n: &mut ArrowExpr) {} @@ -910,7 +910,7 @@ impl MutationHandler<'_> { #[swc_trace] impl VisitMut for MutationHandler<'_> { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); visit_mut_obj_and_computed!(); diff --git a/crates/swc_ecma_compat_es2015/src/block_scoping/vars.rs b/crates/swc_ecma_compat_es2015/src/block_scoping/vars.rs index d5ffbf2123c3..70633575f1bd 100644 --- a/crates/swc_ecma_compat_es2015/src/block_scoping/vars.rs +++ b/crates/swc_ecma_compat_es2015/src/block_scoping/vars.rs @@ -6,7 +6,7 @@ use swc_common::{ }; use swc_ecma_ast::*; use swc_ecma_transforms_base::{rename::remap, scope::ScopeKind}; -use swc_ecma_visit::{standard_only_visit_mut, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; pub(super) fn block_scoped_vars() -> impl VisitMut { @@ -236,7 +236,7 @@ impl ParentScope<'_> { #[swc_trace] impl VisitMut for BlockScopedVars { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_arrow_expr(&mut self, n: &mut ArrowExpr) { self.with_scope(ScopeKind::Fn, |v| { diff --git a/crates/swc_ecma_compat_es2015/src/classes/constructor.rs b/crates/swc_ecma_compat_es2015/src/classes/constructor.rs index c9ca026c9eec..35889703b671 100644 --- a/crates/swc_ecma_compat_es2015/src/classes/constructor.rs +++ b/crates/swc_ecma_compat_es2015/src/classes/constructor.rs @@ -6,7 +6,7 @@ use swc_ecma_transforms_base::helper; use swc_ecma_transforms_classes::{get_prototype_of, visit_mut_only_key}; use swc_ecma_utils::{quote_ident, ExprFactory}; use swc_ecma_visit::{ - standard_only_visit, standard_only_visit_mut, Visit, VisitMut, VisitMutWith, VisitWith, + noop_visit_mut_type, noop_visit_type, Visit, VisitMut, VisitMutWith, VisitWith, }; use swc_trace_macro::swc_trace; @@ -66,7 +66,7 @@ macro_rules! mark_as_complex { #[swc_trace] impl Visit for SuperCallFinder { - standard_only_visit!(); + noop_visit_type!(fail); mark_as_complex!(visit_arrow_expr, ArrowExpr); @@ -174,7 +174,7 @@ pub(super) enum SuperFoldingMode { #[swc_trace] impl VisitMut for ConstructorFolder<'_> { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); visit_mut_only_key!(); @@ -474,7 +474,7 @@ pub(super) fn replace_this_in_constructor(mark: Mark, c: &mut Constructor) -> bo } impl VisitMut for Replacer { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); // let computed keys be visited fn visit_mut_constructor(&mut self, _: &mut Constructor) {} diff --git a/crates/swc_ecma_compat_es2015/src/classes/mod.rs b/crates/swc_ecma_compat_es2015/src/classes/mod.rs index 6cd1f4fa87c9..2a36ad07ab45 100644 --- a/crates/swc_ecma_compat_es2015/src/classes/mod.rs +++ b/crates/swc_ecma_compat_es2015/src/classes/mod.rs @@ -15,8 +15,7 @@ use swc_ecma_utils::{ quote_str, replace_ident, ExprFactory, ModuleItemLike, StmtLike, }; use swc_ecma_visit::{ - as_folder, standard_only_visit, standard_only_visit_mut, Fold, Visit, VisitMut, VisitMutWith, - VisitWith, + as_folder, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, VisitWith, }; use swc_trace_macro::swc_trace; use tracing::debug; @@ -224,7 +223,7 @@ impl VisitMut for Classes where C: Comments, { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_module_items(&mut self, items: &mut Vec) { self.visit_mut_stmt_like(items) @@ -1262,7 +1261,7 @@ fn is_always_initialized(body: &[Stmt]) -> bool { } impl Visit for SuperFinder { - standard_only_visit!(); + noop_visit_type!(fail); fn visit_callee(&mut self, node: &Callee) { match *node { @@ -1317,7 +1316,7 @@ struct ClassFinder { } impl Visit for ClassFinder { - standard_only_visit!(); + noop_visit_type!(fail); fn visit_class(&mut self, _: &Class) { self.found = true diff --git a/crates/swc_ecma_compat_es2015/src/computed_props.rs b/crates/swc_ecma_compat_es2015/src/computed_props.rs index 20d62e997b09..c37fc5c4eef0 100644 --- a/crates/swc_ecma_compat_es2015/src/computed_props.rs +++ b/crates/swc_ecma_compat_es2015/src/computed_props.rs @@ -4,8 +4,7 @@ use swc_ecma_ast::*; use swc_ecma_transforms_base::helper; use swc_ecma_utils::{quote_ident, ExprFactory, StmtLike}; use swc_ecma_visit::{ - as_folder, standard_only_visit, standard_only_visit_mut, Fold, Visit, VisitMut, VisitMutWith, - VisitWith, + as_folder, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, VisitWith, }; use swc_trace_macro::swc_trace; @@ -63,7 +62,7 @@ struct ComputedProps { #[swc_trace] impl VisitMut for ComputedProps { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_expr(&mut self, expr: &mut Expr) { expr.visit_mut_children_with(self); @@ -356,7 +355,7 @@ struct ComplexVisitor { } impl Visit for ComplexVisitor { - standard_only_visit!(); + noop_visit_type!(fail); fn visit_prop_name(&mut self, pn: &PropName) { if let PropName::Computed(..) = *pn { @@ -443,7 +442,7 @@ struct ShouldWork { } impl Visit for ShouldWork { - standard_only_visit!(); + noop_visit_type!(fail); fn visit_prop_name(&mut self, node: &PropName) { if let PropName::Computed(_) = *node { diff --git a/crates/swc_ecma_compat_es2015/src/destructuring.rs b/crates/swc_ecma_compat_es2015/src/destructuring.rs index 3b84cae376fb..47108f1b93e5 100644 --- a/crates/swc_ecma_compat_es2015/src/destructuring.rs +++ b/crates/swc_ecma_compat_es2015/src/destructuring.rs @@ -11,8 +11,7 @@ use swc_ecma_utils::{ prop_name_to_expr, quote_ident, ExprFactory, StmtLike, }; use swc_ecma_visit::{ - as_folder, standard_only_visit, standard_only_visit_mut, Fold, Visit, VisitMut, VisitMutWith, - VisitWith, + as_folder, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, VisitWith, }; use swc_trace_macro::swc_trace; @@ -471,7 +470,7 @@ impl AssignFolder { #[swc_trace] #[fast_path(DestructuringVisitor)] impl VisitMut for Destructuring { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); impl_for_for_stmt!(visit_mut_for_in_stmt, ForInStmt); @@ -598,7 +597,7 @@ impl AssignFolder { #[swc_trace] #[fast_path(DestructuringVisitor)] impl VisitMut for AssignFolder { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_export_decl(&mut self, decl: &mut ExportDecl) { let old = self.exporting; @@ -1303,7 +1302,7 @@ struct DestructuringVisitor { } impl Visit for DestructuringVisitor { - standard_only_visit!(); + noop_visit_type!(fail); fn visit_assign_target_pat(&mut self, _: &AssignTargetPat) { self.found = true; diff --git a/crates/swc_ecma_compat_es2015/src/duplicate_keys.rs b/crates/swc_ecma_compat_es2015/src/duplicate_keys.rs index 5a037bd5be34..370298228829 100644 --- a/crates/swc_ecma_compat_es2015/src/duplicate_keys.rs +++ b/crates/swc_ecma_compat_es2015/src/duplicate_keys.rs @@ -3,7 +3,7 @@ use swc_common::{collections::AHashSet, Spanned}; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; use swc_ecma_utils::quote_str; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; pub fn duplicate_keys() -> impl Fold + VisitMut { @@ -22,7 +22,7 @@ impl Parallel for DuplicateKeys { #[swc_trace] impl VisitMut for DuplicateKeys { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_expr(&mut self, expr: &mut Expr) { expr.visit_mut_children_with(self); @@ -42,7 +42,7 @@ struct PropFolder { #[swc_trace] impl VisitMut for PropFolder { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); /// Noop fn visit_mut_expr(&mut self, _: &mut Expr) {} @@ -90,7 +90,7 @@ struct PropNameFolder<'a> { #[swc_trace] impl<'a> VisitMut for PropNameFolder<'a> { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_expr(&mut self, _: &mut Expr) {} diff --git a/crates/swc_ecma_compat_es2015/src/for_of.rs b/crates/swc_ecma_compat_es2015/src/for_of.rs index 70afe3597c7a..6803e8398366 100644 --- a/crates/swc_ecma_compat_es2015/src/for_of.rs +++ b/crates/swc_ecma_compat_es2015/src/for_of.rs @@ -11,7 +11,7 @@ use swc_ecma_transforms_macros::parallel; use swc_ecma_utils::{ alias_if_required, member_expr, prepend_stmt, private_ident, quote_ident, ExprFactory, }; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; /// `@babel/plugin-transform-for-of` @@ -687,7 +687,7 @@ impl ParExplode for ForOf { #[swc_trace] #[parallel(explode)] impl VisitMut for ForOf { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_stmt(&mut self, s: &mut Stmt) { match s { diff --git a/crates/swc_ecma_compat_es2015/src/function_name.rs b/crates/swc_ecma_compat_es2015/src/function_name.rs index ab313894661d..4ee03b5fa847 100644 --- a/crates/swc_ecma_compat_es2015/src/function_name.rs +++ b/crates/swc_ecma_compat_es2015/src/function_name.rs @@ -2,7 +2,7 @@ use swc_common::{util::take::Take, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; use swc_ecma_utils::{private_ident, IdentUsageFinder}; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; /// `@babel/plugin-transform-function-name` @@ -52,7 +52,7 @@ fn prepare(i: Ident) -> Ident { #[swc_trace] impl VisitMut for FnName { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_assign_expr(&mut self, expr: &mut AssignExpr) { expr.visit_mut_children_with(self); @@ -135,7 +135,7 @@ macro_rules! noop { } impl VisitMut for Rename { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); impl_for!(visit_mut_fn_expr, FnExpr); diff --git a/crates/swc_ecma_compat_es2015/src/generator.rs b/crates/swc_ecma_compat_es2015/src/generator.rs index afaed2ac05b0..18d6428ca6a0 100644 --- a/crates/swc_ecma_compat_es2015/src/generator.rs +++ b/crates/swc_ecma_compat_es2015/src/generator.rs @@ -17,8 +17,7 @@ use swc_ecma_utils::{ function::FnEnvHoister, private_ident, prop_name_to_expr_value, quote_ident, ExprFactory, }; use swc_ecma_visit::{ - as_folder, standard_only_visit, standard_only_visit_mut, Fold, Visit, VisitMut, VisitMutWith, - VisitWith, + as_folder, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, VisitWith, }; use tracing::debug; @@ -48,7 +47,7 @@ macro_rules! dev_span { } impl VisitMut for Wrapper { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_function(&mut self, f: &mut Function) { f.visit_mut_children_with(self); @@ -397,7 +396,7 @@ impl Default for Generator { } impl VisitMut for Generator { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_arrow_expr(&mut self, e: &mut ArrowExpr) { e.params.visit_mut_with(self); @@ -3613,7 +3612,7 @@ struct YieldFinder { } impl Visit for YieldFinder { - standard_only_visit!(); + noop_visit_type!(fail); fn visit_yield_expr(&mut self, _: &YieldExpr) { self.found = true; @@ -3642,7 +3641,7 @@ struct InvalidToLit<'a> { } impl VisitMut for InvalidToLit<'_> { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_expr(&mut self, e: &mut Expr) { e.visit_mut_children_with(self); diff --git a/crates/swc_ecma_compat_es2015/src/instanceof.rs b/crates/swc_ecma_compat_es2015/src/instanceof.rs index d0b7a2573831..80557b182f19 100644 --- a/crates/swc_ecma_compat_es2015/src/instanceof.rs +++ b/crates/swc_ecma_compat_es2015/src/instanceof.rs @@ -2,7 +2,7 @@ use swc_common::{util::take::Take, Span, Spanned}; use swc_ecma_ast::*; use swc_ecma_transforms_base::{helper, perf::Parallel}; use swc_ecma_utils::ExprFactory; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; /// `@babel/plugin-transform-instanceof` @@ -45,7 +45,7 @@ impl Parallel for InstanceOf { #[swc_trace] impl VisitMut for InstanceOf { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_expr(&mut self, expr: &mut Expr) { expr.visit_mut_children_with(self); diff --git a/crates/swc_ecma_compat_es2015/src/new_target.rs b/crates/swc_ecma_compat_es2015/src/new_target.rs index e2b3b323837c..d47bb3eacf0f 100644 --- a/crates/swc_ecma_compat_es2015/src/new_target.rs +++ b/crates/swc_ecma_compat_es2015/src/new_target.rs @@ -5,7 +5,7 @@ use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::{should_work, Check}; use swc_ecma_utils::{private_ident, quote_ident, ExprFactory}; use swc_ecma_visit::{ - as_folder, standard_only_visit, standard_only_visit_mut, Fold, Visit, VisitMut, VisitMutWith, + as_folder, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, }; use swc_trace_macro::swc_trace; @@ -37,7 +37,7 @@ impl NewTarget { #[swc_trace] impl VisitMut for NewTarget { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_class_method(&mut self, c: &mut ClassMethod) { c.key.visit_mut_with(self); @@ -149,7 +149,7 @@ struct ShouldWork { } impl Visit for ShouldWork { - standard_only_visit!(); + noop_visit_type!(fail); fn visit_meta_prop_expr(&mut self, n: &MetaPropExpr) { if let MetaPropExpr { diff --git a/crates/swc_ecma_compat_es2015/src/object_super.rs b/crates/swc_ecma_compat_es2015/src/object_super.rs index e764a77ba17f..47e2ede1702a 100644 --- a/crates/swc_ecma_compat_es2015/src/object_super.rs +++ b/crates/swc_ecma_compat_es2015/src/object_super.rs @@ -6,7 +6,7 @@ use swc_ecma_transforms_base::helper; use swc_ecma_utils::{ alias_ident_for, is_rest_arguments, prepend_stmt, private_ident, quote_ident, ExprFactory, }; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; struct ObjectSuper { @@ -21,7 +21,7 @@ pub fn object_super() -> impl Fold + VisitMut { #[swc_trace] impl VisitMut for ObjectSuper { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_module_items(&mut self, n: &mut Vec) { n.visit_mut_children_with(self); @@ -134,7 +134,7 @@ struct SuperReplacer { #[swc_trace] impl VisitMut for SuperReplacer { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_object_lit(&mut self, obj: &mut ObjectLit) { for prop_or_spread in obj.props.iter_mut() { diff --git a/crates/swc_ecma_compat_es2015/src/parameters.rs b/crates/swc_ecma_compat_es2015/src/parameters.rs index 16b8a4634595..86c0c36fa64e 100644 --- a/crates/swc_ecma_compat_es2015/src/parameters.rs +++ b/crates/swc_ecma_compat_es2015/src/parameters.rs @@ -10,7 +10,7 @@ use swc_ecma_utils::{ function::{init_this, FnEnvHoister}, member_expr, prepend_stmt, prepend_stmts, private_ident, quote_ident, ExprFactory, }; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; use tracing::trace; @@ -466,7 +466,7 @@ impl Params { #[swc_trace] impl VisitMut for Params { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); // generally speaking, there won't be class field in here, but Safari 14.1 // still has bugs in parameters diff --git a/crates/swc_ecma_compat_es2015/src/shorthand_property.rs b/crates/swc_ecma_compat_es2015/src/shorthand_property.rs index 84d94ca16c92..f710e2bfe694 100644 --- a/crates/swc_ecma_compat_es2015/src/shorthand_property.rs +++ b/crates/swc_ecma_compat_es2015/src/shorthand_property.rs @@ -1,7 +1,7 @@ use swc_common::util::take::Take; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; /// Compile ES2015 shorthand properties to ES5 @@ -55,7 +55,7 @@ impl Parallel for Shorthand { #[swc_trace] impl VisitMut for Shorthand { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_prop(&mut self, prop: &mut Prop) { prop.visit_mut_children_with(self); diff --git a/crates/swc_ecma_compat_es2015/src/spread.rs b/crates/swc_ecma_compat_es2015/src/spread.rs index ac2550b80316..75a6bade4b57 100644 --- a/crates/swc_ecma_compat_es2015/src/spread.rs +++ b/crates/swc_ecma_compat_es2015/src/spread.rs @@ -9,8 +9,7 @@ use swc_ecma_utils::{ alias_ident_for, member_expr, prepend_stmt, quote_ident, ExprFactory, StmtLike, }; use swc_ecma_visit::{ - as_folder, standard_only_visit, standard_only_visit_mut, Fold, Visit, VisitMut, VisitMutWith, - VisitWith, + as_folder, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, VisitWith, }; use swc_trace_macro::swc_trace; @@ -37,7 +36,7 @@ struct Spread { #[swc_trace] #[fast_path(SpreadFinder)] impl VisitMut for Spread { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_module_items(&mut self, n: &mut Vec) { self.visit_mut_stmt_like(n); @@ -506,7 +505,7 @@ struct SpreadFinder { } impl Visit for SpreadFinder { - standard_only_visit!(); + noop_visit_type!(fail); fn visit_expr_or_spread(&mut self, n: &ExprOrSpread) { n.visit_children_with(self); diff --git a/crates/swc_ecma_compat_es2015/src/sticky_regex.rs b/crates/swc_ecma_compat_es2015/src/sticky_regex.rs index c808f59811f6..ee76f7936df8 100644 --- a/crates/swc_ecma_compat_es2015/src/sticky_regex.rs +++ b/crates/swc_ecma_compat_es2015/src/sticky_regex.rs @@ -1,7 +1,7 @@ use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; use swc_ecma_utils::{quote_ident, ExprFactory}; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; /// Compile ES2015 sticky regex to an ES5 RegExp constructor @@ -34,7 +34,7 @@ impl Parallel for StickyRegex { #[swc_trace] impl VisitMut for StickyRegex { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_expr(&mut self, e: &mut Expr) { e.visit_mut_children_with(self); diff --git a/crates/swc_ecma_compat_es2015/src/template_literal.rs b/crates/swc_ecma_compat_es2015/src/template_literal.rs index ab63cab51897..cb557ab52d5c 100644 --- a/crates/swc_ecma_compat_es2015/src/template_literal.rs +++ b/crates/swc_ecma_compat_es2015/src/template_literal.rs @@ -6,7 +6,7 @@ use swc_common::{util::take::Take, BytePos, Spanned, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::{helper, perf::Parallel}; use swc_ecma_utils::{is_literal, prepend_stmts, private_ident, quote_ident, ExprFactory}; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; pub fn template_literal(c: Config) -> impl Fold + VisitMut { @@ -43,7 +43,7 @@ impl Parallel for TemplateLiteral { #[swc_trace] impl VisitMut for TemplateLiteral { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_expr(&mut self, e: &mut Expr) { e.visit_mut_children_with(self); diff --git a/crates/swc_ecma_compat_es2015/src/typeof_symbol.rs b/crates/swc_ecma_compat_es2015/src/typeof_symbol.rs index c792c3e21c67..d34e91e812f3 100644 --- a/crates/swc_ecma_compat_es2015/src/typeof_symbol.rs +++ b/crates/swc_ecma_compat_es2015/src/typeof_symbol.rs @@ -2,7 +2,7 @@ use swc_common::{util::take::Take, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::{helper, perf::Parallel}; use swc_ecma_utils::{quote_str, ExprFactory}; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; pub fn typeof_symbol() -> impl VisitMut + Fold { @@ -23,7 +23,7 @@ impl Parallel for TypeOfSymbol { #[swc_trace] impl VisitMut for TypeOfSymbol { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_bin_expr(&mut self, expr: &mut BinExpr) { match expr.op { diff --git a/crates/swc_ecma_compat_es2016/src/exponentiation.rs b/crates/swc_ecma_compat_es2016/src/exponentiation.rs index 5b3e1883f975..84080545cb3a 100644 --- a/crates/swc_ecma_compat_es2016/src/exponentiation.rs +++ b/crates/swc_ecma_compat_es2016/src/exponentiation.rs @@ -3,7 +3,7 @@ use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::{ParExplode, Parallel}; use swc_ecma_transforms_macros::parallel; use swc_ecma_utils::{member_expr, private_ident, ExprFactory}; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; /// `@babel/plugin-transform-exponentiation-operator` @@ -80,7 +80,7 @@ impl ParExplode for Exponentiation { #[swc_trace] #[parallel(explode)] impl VisitMut for Exponentiation { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_expr(&mut self, e: &mut Expr) { e.visit_mut_children_with(self); diff --git a/crates/swc_ecma_compat_es2017/src/async_to_generator.rs b/crates/swc_ecma_compat_es2017/src/async_to_generator.rs index 10e7acbb252a..949abd3c015a 100644 --- a/crates/swc_ecma_compat_es2017/src/async_to_generator.rs +++ b/crates/swc_ecma_compat_es2017/src/async_to_generator.rs @@ -13,8 +13,7 @@ use swc_ecma_utils::{ private_ident, quote_ident, ExprFactory, Remapper, StmtLike, }; use swc_ecma_visit::{ - as_folder, standard_only_visit, standard_only_visit_mut, Fold, Visit, VisitMut, VisitMutWith, - VisitWith, + as_folder, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, VisitWith, }; use swc_trace_macro::swc_trace; @@ -78,7 +77,7 @@ struct Actual { #[swc_trace] #[fast_path(ShouldWork)] impl VisitMut for AsyncToGenerator { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_module_items(&mut self, n: &mut Vec) { self.visit_mut_stmt_like(n); @@ -121,7 +120,7 @@ impl AsyncToGenerator { #[swc_trace] #[fast_path(ShouldWork)] impl VisitMut for Actual { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_class_method(&mut self, m: &mut ClassMethod) { if m.function.body.is_none() { @@ -450,7 +449,7 @@ macro_rules! noop { #[swc_trace] impl VisitMut for AsyncFnBodyHandler { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); noop!(visit_mut_fn_expr, FnExpr); @@ -537,7 +536,7 @@ struct ShouldWork { #[swc_trace] impl Visit for ShouldWork { - standard_only_visit!(); + noop_visit_type!(fail); fn visit_function(&mut self, f: &Function) { if f.is_async { diff --git a/crates/swc_ecma_compat_es2018/src/object_rest.rs b/crates/swc_ecma_compat_es2018/src/object_rest.rs index 8f134e7e5292..bbe8f553df2e 100644 --- a/crates/swc_ecma_compat_es2018/src/object_rest.rs +++ b/crates/swc_ecma_compat_es2018/src/object_rest.rs @@ -13,7 +13,7 @@ use swc_ecma_utils::{ var::VarCollector, ExprFactory, StmtLike, }; use swc_ecma_visit::{ - standard_only_visit, standard_only_visit_mut, Visit, VisitMut, VisitMutWith, VisitWith, + noop_visit_mut_type, noop_visit_type, Visit, VisitMut, VisitMutWith, VisitWith, }; use swc_trace_macro::swc_trace; @@ -166,7 +166,7 @@ struct RestVisitor { #[swc_trace] impl Visit for RestVisitor { - standard_only_visit!(); + noop_visit_type!(fail); fn visit_object_pat_prop(&mut self, prop: &ObjectPatProp) { match *prop { @@ -194,7 +194,7 @@ where #[swc_trace] #[fast_path(RestVisitor)] impl VisitMut for ObjectRest { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); impl_for_for_stmt!(visit_mut_for_in_stmt, ForInStmt); @@ -1013,7 +1013,7 @@ struct PatSimplifier; #[swc_trace] impl VisitMut for PatSimplifier { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_pat(&mut self, pat: &mut Pat) { pat.visit_mut_children_with(self); diff --git a/crates/swc_ecma_compat_es2018/src/object_spread.rs b/crates/swc_ecma_compat_es2018/src/object_spread.rs index 9ec9891f11b9..6b1b6ab67ad4 100644 --- a/crates/swc_ecma_compat_es2018/src/object_spread.rs +++ b/crates/swc_ecma_compat_es2018/src/object_spread.rs @@ -2,7 +2,7 @@ use swc_common::{util::take::Take, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::{helper, perf::Parallel}; use swc_ecma_utils::ExprFactory; -use swc_ecma_visit::{standard_only_visit_mut, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; use super::object_rest_spread::Config; @@ -24,7 +24,7 @@ impl Parallel for ObjectSpread { #[swc_trace] impl VisitMut for ObjectSpread { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_expr(&mut self, expr: &mut Expr) { expr.visit_mut_children_with(self); diff --git a/crates/swc_ecma_compat_es2019/src/optional_catch_binding.rs b/crates/swc_ecma_compat_es2019/src/optional_catch_binding.rs index bfb0f9cd6d46..354a7520d0c5 100644 --- a/crates/swc_ecma_compat_es2019/src/optional_catch_binding.rs +++ b/crates/swc_ecma_compat_es2019/src/optional_catch_binding.rs @@ -1,6 +1,6 @@ use swc_ecma_ast::*; use swc_ecma_utils::private_ident; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; struct OptionalCatchBinding; @@ -11,7 +11,7 @@ pub fn optional_catch_binding() -> impl Fold + VisitMut { #[swc_trace] impl VisitMut for OptionalCatchBinding { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_catch_clause(&mut self, cc: &mut CatchClause) { cc.visit_mut_children_with(self); diff --git a/crates/swc_ecma_compat_es2020/src/export_namespace_from.rs b/crates/swc_ecma_compat_es2020/src/export_namespace_from.rs index ccc26f30990a..e1a50376c076 100644 --- a/crates/swc_ecma_compat_es2020/src/export_namespace_from.rs +++ b/crates/swc_ecma_compat_es2020/src/export_namespace_from.rs @@ -1,7 +1,7 @@ use swc_atoms::JsWord; use swc_ecma_ast::*; use swc_ecma_utils::private_ident; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut}; use swc_trace_macro::swc_trace; pub fn export_namespace_from() -> impl Fold + VisitMut { @@ -12,7 +12,7 @@ struct ExportNamespaceFrom; #[swc_trace] impl VisitMut for ExportNamespaceFrom { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_module_items(&mut self, items: &mut Vec) { let count = items diff --git a/crates/swc_ecma_compat_es2020/src/nullish_coalescing.rs b/crates/swc_ecma_compat_es2020/src/nullish_coalescing.rs index abe513a33311..0014262eef2b 100644 --- a/crates/swc_ecma_compat_es2020/src/nullish_coalescing.rs +++ b/crates/swc_ecma_compat_es2020/src/nullish_coalescing.rs @@ -4,7 +4,7 @@ use serde::Deserialize; use swc_common::{util::take::Take, Span, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_utils::{alias_ident_for_simple_assign_tatget, alias_if_required, StmtLike}; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; pub fn nullish_coalescing(c: Config) -> impl Fold + VisitMut + 'static { @@ -60,7 +60,7 @@ impl NullishCoalescing { #[swc_trace] impl VisitMut for NullishCoalescing { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); /// Prevents #1123 fn visit_mut_block_stmt(&mut self, s: &mut BlockStmt) { diff --git a/crates/swc_ecma_compat_es2021/src/logical_assignments.rs b/crates/swc_ecma_compat_es2021/src/logical_assignments.rs index 4180e80f6b4d..22b0f8856af2 100644 --- a/crates/swc_ecma_compat_es2021/src/logical_assignments.rs +++ b/crates/swc_ecma_compat_es2021/src/logical_assignments.rs @@ -4,7 +4,7 @@ use swc_common::{util::take::Take, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; use swc_ecma_utils::{alias_ident_for, prepend_stmt}; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; pub fn logical_assignments() -> impl Fold + VisitMut { @@ -58,7 +58,7 @@ impl Parallel for Operators { #[swc_trace] impl VisitMut for Operators { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_expr(&mut self, e: &mut Expr) { e.visit_mut_children_with(self); diff --git a/crates/swc_ecma_compat_es2022/src/class_properties/class_name_tdz.rs b/crates/swc_ecma_compat_es2022/src/class_properties/class_name_tdz.rs index 006a9ba579b4..c16daa95f60b 100644 --- a/crates/swc_ecma_compat_es2022/src/class_properties/class_name_tdz.rs +++ b/crates/swc_ecma_compat_es2022/src/class_properties/class_name_tdz.rs @@ -2,7 +2,7 @@ use swc_common::DUMMY_SP; use swc_ecma_ast::*; use swc_ecma_transforms_base::helper; use swc_ecma_utils::ExprFactory; -use swc_ecma_visit::{standard_only_visit_mut, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; pub(super) struct ClassNameTdzFolder<'a> { @@ -11,7 +11,7 @@ pub(super) struct ClassNameTdzFolder<'a> { #[swc_trace] impl<'a> VisitMut for ClassNameTdzFolder<'a> { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_expr(&mut self, expr: &mut Expr) { match expr { diff --git a/crates/swc_ecma_compat_es2022/src/class_properties/mod.rs b/crates/swc_ecma_compat_es2022/src/class_properties/mod.rs index 5040c4bde2b0..296ec963e9e8 100644 --- a/crates/swc_ecma_compat_es2022/src/class_properties/mod.rs +++ b/crates/swc_ecma_compat_es2022/src/class_properties/mod.rs @@ -12,8 +12,7 @@ use swc_ecma_utils::{ ModuleItemLike, StmtLike, }; use swc_ecma_visit::{ - as_folder, standard_only_visit, standard_only_visit_mut, Fold, Visit, VisitMut, VisitMutWith, - VisitWith, + as_folder, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, VisitWith, }; use swc_trace_macro::swc_trace; @@ -160,7 +159,7 @@ impl Take for ClassExtra { #[swc_trace] #[fast_path(ShouldWork)] impl VisitMut for ClassProperties { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_module_items(&mut self, n: &mut Vec) { self.visit_mut_stmt_like(n); @@ -1081,7 +1080,7 @@ struct ShouldWork { #[swc_trace] impl Visit for ShouldWork { - standard_only_visit!(); + noop_visit_type!(fail); fn visit_class_method(&mut self, _: &ClassMethod) { self.found = true; @@ -1116,7 +1115,7 @@ struct SuperVisitor { } impl Visit for SuperVisitor { - standard_only_visit!(); + noop_visit_type!(fail); /// Don't recurse into constructor fn visit_constructor(&mut self, _: &Constructor) {} diff --git a/crates/swc_ecma_compat_es2022/src/class_properties/private_field.rs b/crates/swc_ecma_compat_es2022/src/class_properties/private_field.rs index d59c9e33af17..3924c82db965 100644 --- a/crates/swc_ecma_compat_es2022/src/class_properties/private_field.rs +++ b/crates/swc_ecma_compat_es2022/src/class_properties/private_field.rs @@ -8,7 +8,7 @@ use swc_common::{ use swc_ecma_ast::*; use swc_ecma_transforms_base::helper; use swc_ecma_utils::{alias_ident_for, alias_if_required, prepend_stmt, quote_ident, ExprFactory}; -use swc_ecma_visit::{standard_only_visit_mut, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; use super::Config; @@ -86,7 +86,7 @@ pub(super) struct BrandCheckHandler<'a> { #[swc_trace] impl VisitMut for BrandCheckHandler<'_> { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_expr(&mut self, e: &mut Expr) { e.visit_mut_children_with(self); @@ -205,7 +205,7 @@ macro_rules! take_vars { // super.#sdsa is invalid #[swc_trace] impl<'a> VisitMut for PrivateAccessVisitor<'a> { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); take_vars!(visit_mut_function, Function); diff --git a/crates/swc_ecma_compat_es2022/src/class_properties/this_in_static.rs b/crates/swc_ecma_compat_es2022/src/class_properties/this_in_static.rs index 5ef5df2beeed..121e21628c90 100644 --- a/crates/swc_ecma_compat_es2022/src/class_properties/this_in_static.rs +++ b/crates/swc_ecma_compat_es2022/src/class_properties/this_in_static.rs @@ -1,5 +1,5 @@ use swc_ecma_ast::*; -use swc_ecma_visit::{standard_only_visit_mut, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; pub(super) struct ThisInStaticFolder { @@ -8,7 +8,7 @@ pub(super) struct ThisInStaticFolder { #[swc_trace] impl VisitMut for ThisInStaticFolder { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); // once again, for computed props fn visit_mut_constructor(&mut self, _: &mut Constructor) {} @@ -28,7 +28,7 @@ pub(super) struct NewTargetInProp; #[swc_trace] impl VisitMut for NewTargetInProp { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); // once again, for computed props fn visit_mut_constructor(&mut self, _: &mut Constructor) {} diff --git a/crates/swc_ecma_compat_es2022/src/class_properties/used_name.rs b/crates/swc_ecma_compat_es2022/src/class_properties/used_name.rs index 4413093d9844..bcaef8a733a7 100644 --- a/crates/swc_ecma_compat_es2022/src/class_properties/used_name.rs +++ b/crates/swc_ecma_compat_es2022/src/class_properties/used_name.rs @@ -1,6 +1,6 @@ use swc_atoms::JsWord; use swc_ecma_ast::*; -use swc_ecma_visit::{standard_only_visit, Visit, VisitWith}; +use swc_ecma_visit::{noop_visit_type, Visit, VisitWith}; use swc_trace_macro::swc_trace; pub(super) struct UsedNameCollector<'a> { @@ -16,7 +16,7 @@ macro_rules! noop { #[swc_trace] impl<'a> Visit for UsedNameCollector<'a> { - standard_only_visit!(); + noop_visit_type!(fail); noop!(visit_arrow_expr, ArrowExpr); diff --git a/crates/swc_ecma_compat_es2022/src/optional_chaining_impl.rs b/crates/swc_ecma_compat_es2022/src/optional_chaining_impl.rs index 11679fe06678..c0d47541229d 100644 --- a/crates/swc_ecma_compat_es2022/src/optional_chaining_impl.rs +++ b/crates/swc_ecma_compat_es2022/src/optional_chaining_impl.rs @@ -3,7 +3,7 @@ use std::mem; use swc_common::{util::take::Take, Mark, SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_utils::{alias_ident_for, prepend_stmt, quote_ident, ExprFactory, StmtLike}; -use swc_ecma_visit::{standard_only_visit_mut, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; /// Not a public API and may break any time. Don't use it directly. pub fn optional_chaining_impl(c: Config, unresolved_mark: Mark) -> OptionalChaining { @@ -35,7 +35,7 @@ pub struct Config { } impl VisitMut for OptionalChaining { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_block_stmt_or_expr(&mut self, expr: &mut BlockStmtOrExpr) { if let BlockStmtOrExpr::Expr(e) = expr { diff --git a/crates/swc_ecma_compat_es2022/src/private_in_object.rs b/crates/swc_ecma_compat_es2022/src/private_in_object.rs index d78f31627fe5..695b3ccdfe69 100644 --- a/crates/swc_ecma_compat_es2022/src/private_in_object.rs +++ b/crates/swc_ecma_compat_es2022/src/private_in_object.rs @@ -12,8 +12,7 @@ use swc_ecma_ast::*; use swc_ecma_transforms_base::pass::JsPass; use swc_ecma_utils::{default_constructor, prepend_stmt, private_ident, quote_ident, ExprFactory}; use swc_ecma_visit::{ - as_folder, standard_only_visit, standard_only_visit_mut, Visit, VisitMut, VisitMutWith, - VisitWith, + as_folder, noop_visit_mut_type, noop_visit_type, Visit, VisitMut, VisitMutWith, VisitWith, }; /// https://github.com/tc39/proposal-private-fields-in-in @@ -131,7 +130,7 @@ impl PrivateInObject { } impl VisitMut for PrivateInObject { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_class(&mut self, n: &mut Class) { { @@ -496,7 +495,7 @@ struct ClassAnalyzer<'a> { } impl Visit for ClassAnalyzer<'_> { - standard_only_visit!(); + noop_visit_type!(fail); fn visit_bin_expr(&mut self, n: &BinExpr) { n.visit_children_with(self); diff --git a/crates/swc_ecma_compat_es2022/src/static_blocks.rs b/crates/swc_ecma_compat_es2022/src/static_blocks.rs index ebf60c3ea133..1d4f109ab831 100644 --- a/crates/swc_ecma_compat_es2022/src/static_blocks.rs +++ b/crates/swc_ecma_compat_es2022/src/static_blocks.rs @@ -2,7 +2,7 @@ use swc_atoms::JsWord; use swc_common::{collections::AHashSet, util::take::Take, Mark, SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_utils::ExprFactory; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; struct ClassStaticBlock { @@ -71,7 +71,7 @@ impl ClassStaticBlock { #[swc_trace] impl VisitMut for ClassStaticBlock { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_class(&mut self, class: &mut Class) { class.visit_mut_children_with(self); diff --git a/crates/swc_ecma_compat_es3/src/reserved_word.rs b/crates/swc_ecma_compat_es3/src/reserved_word.rs index 04ee807b5219..19c2e68a9058 100644 --- a/crates/swc_ecma_compat_es3/src/reserved_word.rs +++ b/crates/swc_ecma_compat_es3/src/reserved_word.rs @@ -1,6 +1,6 @@ use swc_common::{util::take::Take, DUMMY_SP}; use swc_ecma_ast::*; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; /// babel: `@babel/plugin-transform-reserved-words` /// @@ -27,7 +27,7 @@ struct ReservedWord { } impl VisitMut for ReservedWord { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_module_items(&mut self, n: &mut Vec) { let mut extra_exports = vec![]; diff --git a/crates/swc_ecma_minifier/src/compress/hoist_decls.rs b/crates/swc_ecma_minifier/src/compress/hoist_decls.rs index 242fc05c1f91..a9d917a7a2ae 100644 --- a/crates/swc_ecma_minifier/src/compress/hoist_decls.rs +++ b/crates/swc_ecma_minifier/src/compress/hoist_decls.rs @@ -4,7 +4,7 @@ use swc_common::{collections::AHashSet, pass::Repeated, util::take::Take, DUMMY_ use swc_ecma_ast::*; use swc_ecma_usage_analyzer::analyzer::UsageAnalyzer; use swc_ecma_utils::{find_pat_ids, StmtLike}; -use swc_ecma_visit::{standard_only_visit_mut, VisitMut, VisitMutWith, VisitWith}; +use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith, VisitWith}; use super::util::drop_invalid_stmts; use crate::{ @@ -279,7 +279,7 @@ impl Hoister<'_> { } impl VisitMut for Hoister<'_> { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_module_items(&mut self, stmts: &mut Vec) { self.handle_stmt_likes(stmts); diff --git a/crates/swc_ecma_minifier/src/compress/mod.rs b/crates/swc_ecma_minifier/src/compress/mod.rs index 6362dd829a2f..a9da8297f563 100644 --- a/crates/swc_ecma_minifier/src/compress/mod.rs +++ b/crates/swc_ecma_minifier/src/compress/mod.rs @@ -15,7 +15,7 @@ use swc_ecma_transforms_optimization::simplify::{ dead_branch_remover, expr_simplifier, ExprSimplifierConfig, }; use swc_ecma_usage_analyzer::{analyzer::UsageAnalyzer, marks::Marks}; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, VisitMut, VisitMutWith, VisitWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, VisitMut, VisitMutWith, VisitWith}; use swc_timer::timer; use tracing::{debug, error}; @@ -325,7 +325,7 @@ impl Compressor<'_> { } impl VisitMut for Compressor<'_> { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_script(&mut self, n: &mut Script) { self.optimize_unit_repeatedly(n); diff --git a/crates/swc_ecma_minifier/src/compress/optimize/arguments.rs b/crates/swc_ecma_minifier/src/compress/optimize/arguments.rs index eec94a93ab64..ec6591154fca 100644 --- a/crates/swc_ecma_minifier/src/compress/optimize/arguments.rs +++ b/crates/swc_ecma_minifier/src/compress/optimize/arguments.rs @@ -3,7 +3,7 @@ use std::iter::repeat_with; use swc_common::{util::take::Take, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_utils::{find_pat_ids, is_valid_prop_ident, private_ident}; -use swc_ecma_visit::{standard_only_visit_mut, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; use super::Optimizer; use crate::compress::optimize::is_left_access_to_arguments; @@ -146,7 +146,7 @@ impl ArgReplacer<'_> { } impl VisitMut for ArgReplacer<'_> { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); /// Noop. fn visit_mut_arrow_expr(&mut self, _: &mut ArrowExpr) {} diff --git a/crates/swc_ecma_minifier/src/compress/optimize/if_return.rs b/crates/swc_ecma_minifier/src/compress/optimize/if_return.rs index eecafd76a687..cc326cf5dce9 100644 --- a/crates/swc_ecma_minifier/src/compress/optimize/if_return.rs +++ b/crates/swc_ecma_minifier/src/compress/optimize/if_return.rs @@ -2,7 +2,7 @@ use swc_common::{util::take::Take, Spanned, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_optimization::debug_assert_valid; use swc_ecma_utils::{StmtExt, StmtLike}; -use swc_ecma_visit::{standard_only_visit, Visit, VisitWith}; +use swc_ecma_visit::{noop_visit_type, Visit, VisitWith}; use super::Optimizer; #[cfg(feature = "debug")] @@ -529,7 +529,7 @@ pub(super) struct ReturnFinder { } impl Visit for ReturnFinder { - standard_only_visit!(); + noop_visit_type!(fail); fn visit_return_stmt(&mut self, n: &ReturnStmt) { n.visit_children_with(self); diff --git a/crates/swc_ecma_minifier/src/compress/optimize/mod.rs b/crates/swc_ecma_minifier/src/compress/optimize/mod.rs index 75fd5374602b..59a45ba9b925 100644 --- a/crates/swc_ecma_minifier/src/compress/optimize/mod.rs +++ b/crates/swc_ecma_minifier/src/compress/optimize/mod.rs @@ -14,7 +14,7 @@ use swc_ecma_usage_analyzer::{analyzer::UsageAnalyzer, marks::Marks}; use swc_ecma_utils::{ prepend_stmts, ExprCtx, ExprExt, ExprFactory, IsEmpty, ModuleItemLike, StmtLike, Type, Value, }; -use swc_ecma_visit::{standard_only_visit_mut, VisitMut, VisitMutWith, VisitWith}; +use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith, VisitWith}; #[cfg(feature = "debug")] use tracing::{debug, span, Level}; use Value::Known; @@ -1497,7 +1497,7 @@ impl Optimizer<'_> { } impl VisitMut for Optimizer<'_> { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); #[cfg_attr(feature = "debug", tracing::instrument(skip_all))] fn visit_mut_arrow_expr(&mut self, n: &mut ArrowExpr) { diff --git a/crates/swc_ecma_minifier/src/compress/optimize/sequences.rs b/crates/swc_ecma_minifier/src/compress/optimize/sequences.rs index abe4b4add8d5..501ca1e27ebe 100644 --- a/crates/swc_ecma_minifier/src/compress/optimize/sequences.rs +++ b/crates/swc_ecma_minifier/src/compress/optimize/sequences.rs @@ -9,7 +9,7 @@ use swc_ecma_usage_analyzer::{ use swc_ecma_utils::{ contains_arguments, contains_this_expr, prepend_stmts, ExprExt, IdentUsageFinder, StmtLike, }; -use swc_ecma_visit::{standard_only_visit, Visit, VisitWith}; +use swc_ecma_visit::{noop_visit_type, Visit, VisitWith}; #[cfg(feature = "debug")] use tracing::{span, Level}; @@ -2597,7 +2597,7 @@ struct UsageCounter<'a> { } impl Visit for UsageCounter<'_> { - standard_only_visit!(); + noop_visit_type!(fail); fn visit_ident(&mut self, i: &Ident) { if self.target.sym == i.sym && self.target.ctxt == i.ctxt { diff --git a/crates/swc_ecma_minifier/src/compress/optimize/switches.rs b/crates/swc_ecma_minifier/src/compress/optimize/switches.rs index 95831bf6473b..c3e1c720ab49 100644 --- a/crates/swc_ecma_minifier/src/compress/optimize/switches.rs +++ b/crates/swc_ecma_minifier/src/compress/optimize/switches.rs @@ -1,7 +1,7 @@ use swc_common::{util::take::Take, EqIgnoreSpan, Spanned, SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_utils::{prepend_stmt, ExprExt, ExprFactory, StmtExt}; -use swc_ecma_visit::{standard_only_visit, Visit, VisitWith}; +use swc_ecma_visit::{noop_visit_type, Visit, VisitWith}; use super::Optimizer; use crate::{compress::util::is_primitive, util::idents_used_by}; @@ -560,7 +560,7 @@ struct BreakFinder { } impl Visit for BreakFinder { - standard_only_visit!(); + noop_visit_type!(fail); fn visit_break_stmt(&mut self, s: &BreakStmt) { if !self.top_level && s.label.is_none() { diff --git a/crates/swc_ecma_minifier/src/compress/optimize/unused.rs b/crates/swc_ecma_minifier/src/compress/optimize/unused.rs index a1fd5cd49cc9..2460f92ebc06 100644 --- a/crates/swc_ecma_minifier/src/compress/optimize/unused.rs +++ b/crates/swc_ecma_minifier/src/compress/optimize/unused.rs @@ -4,7 +4,7 @@ use swc_common::{util::take::Take, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_usage_analyzer::util::is_global_var_with_pure_property_access; use swc_ecma_utils::{contains_ident_ref, contains_this_expr, ExprExt}; -use swc_ecma_visit::{standard_only_visit, Visit, VisitWith}; +use swc_ecma_visit::{noop_visit_type, Visit, VisitWith}; use super::Optimizer; #[cfg(feature = "debug")] @@ -942,7 +942,7 @@ struct ThisPropertyVisitor { } impl Visit for ThisPropertyVisitor { - standard_only_visit!(); + noop_visit_type!(fail); fn visit_assign_expr(&mut self, e: &AssignExpr) { if self.should_abort { diff --git a/crates/swc_ecma_minifier/src/compress/optimize/util.rs b/crates/swc_ecma_minifier/src/compress/optimize/util.rs index 63af8a3ef74f..bd14f03146d3 100644 --- a/crates/swc_ecma_minifier/src/compress/optimize/util.rs +++ b/crates/swc_ecma_minifier/src/compress/optimize/util.rs @@ -9,7 +9,7 @@ use swc_common::{collections::AHashSet, util::take::Take, Mark, SyntaxContext, D use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::{Parallel, ParallelExt}; use swc_ecma_utils::{collect_decls, ExprCtx, ExprExt, Remapper}; -use swc_ecma_visit::{standard_only_visit_mut, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; use tracing::debug; use super::{Ctx, Optimizer}; @@ -307,7 +307,7 @@ enum FinalizerMode { } impl VisitMut for Finalizer<'_> { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_callee(&mut self, e: &mut Callee) { e.visit_mut_children_with(self); @@ -483,7 +483,7 @@ impl<'a> NormalMultiReplacer<'a> { } impl VisitMut for NormalMultiReplacer<'_> { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_expr(&mut self, e: &mut Expr) { if self.vars.is_empty() { @@ -568,7 +568,7 @@ impl ExprReplacer { } impl VisitMut for ExprReplacer { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_expr(&mut self, e: &mut Expr) { e.visit_mut_children_with(self); diff --git a/crates/swc_ecma_minifier/src/compress/pure/dead_code.rs b/crates/swc_ecma_minifier/src/compress/pure/dead_code.rs index e1a83a55b196..47010c05a25d 100644 --- a/crates/swc_ecma_minifier/src/compress/pure/dead_code.rs +++ b/crates/swc_ecma_minifier/src/compress/pure/dead_code.rs @@ -3,7 +3,7 @@ use rayon::prelude::*; use swc_common::{util::take::Take, EqIgnoreSpan, Spanned, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_utils::{extract_var_ids, ExprCtx, ExprExt, StmtExt, StmtLike, Value}; -use swc_ecma_visit::{standard_only_visit, Visit, VisitWith}; +use swc_ecma_visit::{noop_visit_type, Visit, VisitWith}; use super::Pure; use crate::{compress::util::is_fine_for_if_cons, maybe_par, util::ModuleItemExt}; @@ -610,7 +610,7 @@ struct LabelFinder<'a> { found: bool, } impl Visit for LabelFinder<'_> { - standard_only_visit!(); + noop_visit_type!(fail); fn visit_break_stmt(&mut self, s: &BreakStmt) { match &s.label { diff --git a/crates/swc_ecma_minifier/src/compress/pure/mod.rs b/crates/swc_ecma_minifier/src/compress/pure/mod.rs index 174c3b456884..9174adb73594 100644 --- a/crates/swc_ecma_minifier/src/compress/pure/mod.rs +++ b/crates/swc_ecma_minifier/src/compress/pure/mod.rs @@ -7,7 +7,7 @@ use swc_ecma_ast::*; use swc_ecma_transforms_optimization::debug_assert_valid; use swc_ecma_usage_analyzer::marks::Marks; use swc_ecma_utils::ExprCtx; -use swc_ecma_visit::{standard_only_visit_mut, VisitMut, VisitMutWith, VisitWith}; +use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith, VisitWith}; #[cfg(feature = "debug")] use tracing::{debug, span, Level}; @@ -254,7 +254,7 @@ impl Pure<'_> { } impl VisitMut for Pure<'_> { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_assign_expr(&mut self, e: &mut AssignExpr) { { diff --git a/crates/swc_ecma_minifier/src/compress/pure/vars.rs b/crates/swc_ecma_minifier/src/compress/pure/vars.rs index f8d944ef7500..b30bcb58aea2 100644 --- a/crates/swc_ecma_minifier/src/compress/pure/vars.rs +++ b/crates/swc_ecma_minifier/src/compress/pure/vars.rs @@ -3,7 +3,7 @@ use swc_common::{util::take::Take, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_utils::{prepend_stmt, StmtLike}; use swc_ecma_visit::{ - standard_only_visit, standard_only_visit_mut, Visit, VisitMut, VisitMutWith, VisitWith, + noop_visit_mut_type, noop_visit_type, Visit, VisitMut, VisitMutWith, VisitWith, }; use super::Pure; @@ -300,7 +300,7 @@ pub(super) struct VarWithOutInitCounter { } impl Visit for VarWithOutInitCounter { - standard_only_visit!(); + noop_visit_type!(fail); fn visit_arrow_expr(&mut self, _: &ArrowExpr) {} @@ -368,7 +368,7 @@ pub(super) struct VarMover { } impl VisitMut for VarMover { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); /// Noop fn visit_mut_arrow_expr(&mut self, _: &mut ArrowExpr) {} @@ -486,7 +486,7 @@ pub(super) struct VarPrepender { } impl VisitMut for VarPrepender { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); /// Noop fn visit_mut_arrow_expr(&mut self, _: &mut ArrowExpr) {} diff --git a/crates/swc_ecma_minifier/src/compress/util/mod.rs b/crates/swc_ecma_minifier/src/compress/util/mod.rs index be656e3836a7..948b8aa4c59b 100644 --- a/crates/swc_ecma_minifier/src/compress/util/mod.rs +++ b/crates/swc_ecma_minifier/src/compress/util/mod.rs @@ -8,7 +8,7 @@ use swc_ecma_utils::{number::JsNumber, ExprCtx, ExprExt, IdentUsageFinder, Value #[cfg(feature = "debug")] use swc_ecma_visit::{as_folder, FoldWith}; use swc_ecma_visit::{ - standard_only_visit, standard_only_visit_mut, Visit, VisitMut, VisitMutWith, VisitWith, + noop_visit_mut_type, noop_visit_type, Visit, VisitMut, VisitMutWith, VisitWith, }; #[cfg(feature = "debug")] @@ -568,7 +568,7 @@ impl VisitMut for ExprReplacer where F: FnMut(&mut Expr), { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_expr(&mut self, e: &mut Expr) { e.visit_mut_children_with(self); @@ -687,7 +687,7 @@ impl UnreachableHandler { } impl VisitMut for UnreachableHandler { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_arrow_expr(&mut self, _: &mut ArrowExpr) {} @@ -737,7 +737,7 @@ pub struct SuperFinder { } impl Visit for SuperFinder { - standard_only_visit!(); + noop_visit_type!(fail); /// Don't recurse into constructor fn visit_constructor(&mut self, _: &Constructor) {} diff --git a/crates/swc_ecma_minifier/src/compress/util/tests.rs b/crates/swc_ecma_minifier/src/compress/util/tests.rs index 0e11b519d5f9..171ff070b8ef 100644 --- a/crates/swc_ecma_minifier/src/compress/util/tests.rs +++ b/crates/swc_ecma_minifier/src/compress/util/tests.rs @@ -3,7 +3,7 @@ use swc_ecma_ast::*; use swc_ecma_parser::parse_file_as_expr; use swc_ecma_transforms_base::fixer::fixer; use swc_ecma_utils::ExprCtx; -use swc_ecma_visit::{standard_only_visit_mut, FoldWith, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, FoldWith, VisitMut, VisitMutWith}; use tracing::{info, warn}; use super::negate_cost; @@ -11,7 +11,7 @@ use crate::{compress::util::negate, debug::dump}; struct UnwrapParen; impl VisitMut for UnwrapParen { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_expr(&mut self, e: &mut Expr) { e.visit_mut_children_with(self); diff --git a/crates/swc_ecma_minifier/src/debug.rs b/crates/swc_ecma_minifier/src/debug.rs index b76e1cfc94dd..d512b2c60a2e 100644 --- a/crates/swc_ecma_minifier/src/debug.rs +++ b/crates/swc_ecma_minifier/src/debug.rs @@ -9,13 +9,13 @@ use swc_ecma_codegen::{text_writer::JsWriter, Emitter}; use swc_ecma_transforms_base::{fixer::fixer, hygiene::hygiene}; pub use swc_ecma_transforms_optimization::{debug_assert_valid, AssertValid}; use swc_ecma_utils::{drop_span, DropSpan}; -use swc_ecma_visit::{standard_only_visit_mut, FoldWith, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, FoldWith, VisitMut, VisitMutWith}; use tracing::debug; pub(crate) struct Debugger {} impl VisitMut for Debugger { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_ident(&mut self, n: &mut Ident) { if !cfg!(feature = "debug") { diff --git a/crates/swc_ecma_minifier/src/metadata/mod.rs b/crates/swc_ecma_minifier/src/metadata/mod.rs index 6fa165a5c0f2..a171287857e5 100644 --- a/crates/swc_ecma_minifier/src/metadata/mod.rs +++ b/crates/swc_ecma_minifier/src/metadata/mod.rs @@ -7,7 +7,7 @@ use swc_ecma_ast::*; use swc_ecma_usage_analyzer::marks::Marks; use swc_ecma_utils::NodeIgnoringSpan; use swc_ecma_visit::{ - standard_only_visit, standard_only_visit_mut, Visit, VisitMut, VisitMutWith, VisitWith, + noop_visit_mut_type, noop_visit_type, Visit, VisitMut, VisitMutWith, VisitWith, }; use crate::option::CompressOptions; @@ -91,7 +91,7 @@ impl InfoMarker<'_> { } impl VisitMut for InfoMarker<'_> { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_call_expr(&mut self, n: &mut CallExpr) { n.visit_mut_children_with(self); @@ -234,7 +234,7 @@ struct InfoCollector<'a> { } impl Visit for InfoCollector<'_> { - standard_only_visit!(); + noop_visit_type!(fail); fn visit_export_decl(&mut self, f: &ExportDecl) { f.visit_children_with(self); diff --git a/crates/swc_ecma_minifier/src/pass/global_defs.rs b/crates/swc_ecma_minifier/src/pass/global_defs.rs index 518e8ff7c629..2837b3df257f 100644 --- a/crates/swc_ecma_minifier/src/pass/global_defs.rs +++ b/crates/swc_ecma_minifier/src/pass/global_defs.rs @@ -2,7 +2,7 @@ use std::borrow::Cow; use swc_common::{pass::CompilerPass, EqIgnoreSpan, Mark, SyntaxContext}; use swc_ecma_ast::*; -use swc_ecma_visit::{standard_only_visit_mut, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; pub fn globals_defs( defs: Vec<(Box, Box)>, @@ -35,7 +35,7 @@ impl CompilerPass for GlobalDefs { /// We use [VisitMut] instead of [swc_ecma_visit::Fold] because it's faster. impl VisitMut for GlobalDefs { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_assign_expr(&mut self, n: &mut AssignExpr) { let old = self.in_lhs_of_assign; diff --git a/crates/swc_ecma_minifier/src/pass/hygiene/vars.rs b/crates/swc_ecma_minifier/src/pass/hygiene/vars.rs index 386116c23669..28a2330d327c 100644 --- a/crates/swc_ecma_minifier/src/pass/hygiene/vars.rs +++ b/crates/swc_ecma_minifier/src/pass/hygiene/vars.rs @@ -51,10 +51,7 @@ impl<'a> Scope<'a> { while let Some(scope) = cur { let mut w = scope.data.borrow_mut(); - w.decls - .entry(i.sym.clone()) - .or_default() - .insert(i.ctxt); + w.decls.entry(i.sym.clone()).or_default().insert(i.ctxt); cur = scope.parent; } @@ -86,7 +83,7 @@ macro_rules! scoped { } impl Visit for VarAnalyzer<'_> { - standard_only_visit!(); + noop_visit_type!(fail); fn visit_arrow_expr(&mut self, n: &ArrowExpr) { scoped!(self, n); diff --git a/crates/swc_ecma_minifier/src/pass/mangle_names/mod.rs b/crates/swc_ecma_minifier/src/pass/mangle_names/mod.rs index 3e25cc754d6d..6cfda83841fd 100644 --- a/crates/swc_ecma_minifier/src/pass/mangle_names/mod.rs +++ b/crates/swc_ecma_minifier/src/pass/mangle_names/mod.rs @@ -3,7 +3,7 @@ use swc_atoms::JsWord; use swc_common::{chain, Mark}; use swc_ecma_ast::*; use swc_ecma_transforms_base::rename::{renamer, Renamer}; -use swc_ecma_visit::{standard_only_visit_mut, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; pub(crate) use self::preserver::idents_to_preserve; use crate::{option::MangleOptions, util::base54::Base54Chars}; @@ -77,7 +77,7 @@ impl LabelMangler { } impl VisitMut for LabelMangler { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_labeled_stmt(&mut self, s: &mut LabeledStmt) { self.mangle(&mut s.label); diff --git a/crates/swc_ecma_minifier/src/pass/mangle_names/preserver.rs b/crates/swc_ecma_minifier/src/pass/mangle_names/preserver.rs index d9caacadbbd5..5242016a7c5f 100644 --- a/crates/swc_ecma_minifier/src/pass/mangle_names/preserver.rs +++ b/crates/swc_ecma_minifier/src/pass/mangle_names/preserver.rs @@ -1,7 +1,7 @@ use rustc_hash::FxHashSet; use swc_ecma_ast::*; use swc_ecma_utils::find_pat_ids; -use swc_ecma_visit::{standard_only_visit, Visit, VisitWith}; +use swc_ecma_visit::{noop_visit_type, Visit, VisitWith}; use crate::option::MangleOptions; @@ -35,7 +35,7 @@ impl Preserver { } impl Visit for Preserver { - standard_only_visit!(); + noop_visit_type!(fail); fn visit_block_stmt(&mut self, n: &BlockStmt) { let old_top_level = self.in_top_level; diff --git a/crates/swc_ecma_minifier/src/pass/mangle_names/private_name.rs b/crates/swc_ecma_minifier/src/pass/mangle_names/private_name.rs index 228e30364fa8..3058ed02b747 100644 --- a/crates/swc_ecma_minifier/src/pass/mangle_names/private_name.rs +++ b/crates/swc_ecma_minifier/src/pass/mangle_names/private_name.rs @@ -1,7 +1,7 @@ use swc_atoms::JsWord; use swc_common::collections::AHashMap; use swc_ecma_ast::*; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use super::Base54Chars; @@ -43,7 +43,7 @@ impl PrivateNameMangler { } impl VisitMut for PrivateNameMangler { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_member_expr(&mut self, n: &mut MemberExpr) { n.obj.visit_mut_with(self); diff --git a/crates/swc_ecma_minifier/src/pass/mangle_props.rs b/crates/swc_ecma_minifier/src/pass/mangle_props.rs index 9e578d7625c7..e269bfd66763 100644 --- a/crates/swc_ecma_minifier/src/pass/mangle_props.rs +++ b/crates/swc_ecma_minifier/src/pass/mangle_props.rs @@ -7,7 +7,7 @@ use swc_ecma_ast::{ CallExpr, Callee, Expr, IdentName, KeyValueProp, Lit, MemberExpr, MemberProp, Program, Prop, PropName, Str, SuperProp, SuperPropExpr, }; -use swc_ecma_visit::{standard_only_visit_mut, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; use crate::{ option::ManglePropertiesOptions, @@ -238,7 +238,7 @@ impl Mangler<'_> { } impl VisitMut for Mangler<'_> { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_call_expr(&mut self, call: &mut CallExpr) { call.visit_mut_children_with(self); diff --git a/crates/swc_ecma_minifier/src/pass/merge_exports.rs b/crates/swc_ecma_minifier/src/pass/merge_exports.rs index ff3be75ca886..6fcf65313902 100644 --- a/crates/swc_ecma_minifier/src/pass/merge_exports.rs +++ b/crates/swc_ecma_minifier/src/pass/merge_exports.rs @@ -1,6 +1,6 @@ use swc_common::{util::take::Take, DUMMY_SP}; use swc_ecma_ast::*; -use swc_ecma_visit::{standard_only_visit_mut, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; use crate::maybe_par; @@ -16,7 +16,7 @@ struct Merger { } impl VisitMut for Merger { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_module_items(&mut self, stmts: &mut Vec) { let was_module = maybe_par!( diff --git a/crates/swc_ecma_minifier/src/pass/postcompress.rs b/crates/swc_ecma_minifier/src/pass/postcompress.rs index 6bbb6d2dd3f4..ca8b293befb8 100644 --- a/crates/swc_ecma_minifier/src/pass/postcompress.rs +++ b/crates/swc_ecma_minifier/src/pass/postcompress.rs @@ -1,7 +1,7 @@ use swc_common::util::take::Take; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::{Parallel, ParallelExt}; -use swc_ecma_visit::{standard_only_visit_mut, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; use crate::{maybe_par, option::CompressOptions, LIGHT_TASK_PARALLELS}; @@ -36,7 +36,7 @@ impl Parallel for PostcompressOptimizer<'_> { } impl VisitMut for PostcompressOptimizer<'_> { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_export_decl(&mut self, export: &mut ExportDecl) { match &mut export.decl { diff --git a/crates/swc_ecma_minifier/src/pass/precompress.rs b/crates/swc_ecma_minifier/src/pass/precompress.rs index 74f6c8e28efa..6252ce537a7b 100644 --- a/crates/swc_ecma_minifier/src/pass/precompress.rs +++ b/crates/swc_ecma_minifier/src/pass/precompress.rs @@ -2,7 +2,7 @@ use std::vec::Vec; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::{Parallel, ParallelExt}; -use swc_ecma_visit::{standard_only_visit_mut, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; use crate::HEAVY_TASK_PARALLELS; @@ -26,7 +26,7 @@ impl Parallel for PrecompressOptimizer { } impl VisitMut for PrecompressOptimizer { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_stmts(&mut self, n: &mut Vec) { self.maybe_par(*HEAVY_TASK_PARALLELS, n, |v, n| { diff --git a/crates/swc_ecma_minifier/src/util/base54.rs b/crates/swc_ecma_minifier/src/util/base54.rs index c474588d365c..47ccf1a07863 100644 --- a/crates/swc_ecma_minifier/src/util/base54.rs +++ b/crates/swc_ecma_minifier/src/util/base54.rs @@ -8,7 +8,7 @@ use swc_common::{ }; use swc_ecma_ast::*; use swc_ecma_codegen::{text_writer::WriteJs, Emitter}; -use swc_ecma_visit::{standard_only_visit, visit_obj_and_computed, Visit, VisitWith}; +use swc_ecma_visit::{noop_visit_type, visit_obj_and_computed, Visit, VisitWith}; #[derive(Clone, Copy)] @@ -296,7 +296,7 @@ struct CharFreqAnalyzer<'a> { } impl Visit for CharFreqAnalyzer<'_> { - standard_only_visit!(); + noop_visit_type!(fail); visit_obj_and_computed!(); diff --git a/crates/swc_ecma_minifier/src/util/mod.rs b/crates/swc_ecma_minifier/src/util/mod.rs index c3796221bb8e..55ccef1f890e 100644 --- a/crates/swc_ecma_minifier/src/util/mod.rs +++ b/crates/swc_ecma_minifier/src/util/mod.rs @@ -7,7 +7,7 @@ use swc_atoms::Atom; use swc_common::{util::take::Take, Span, Spanned, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_utils::{stack_size::maybe_grow_default, ModuleItemLike, StmtLike, Value}; -use swc_ecma_visit::{standard_only_visit, visit_obj_and_computed, Visit, VisitWith}; +use swc_ecma_visit::{noop_visit_type, visit_obj_and_computed, Visit, VisitWith}; pub(crate) mod base54; pub(crate) mod size; @@ -216,7 +216,7 @@ pub(crate) struct LeapFinder { } impl Visit for LeapFinder { - standard_only_visit!(); + noop_visit_type!(fail); fn visit_await_expr(&mut self, n: &AwaitExpr) { n.visit_children_with(self); @@ -308,7 +308,7 @@ pub struct DeepThisExprVisitor { } impl Visit for DeepThisExprVisitor { - standard_only_visit!(); + noop_visit_type!(fail); fn visit_this_expr(&mut self, _: &ThisExpr) { self.found = true; @@ -331,7 +331,7 @@ pub(crate) struct IdentUsageCollector { } impl Visit for IdentUsageCollector { - standard_only_visit!(); + noop_visit_type!(fail); visit_obj_and_computed!(); @@ -379,12 +379,6 @@ impl Visit for IdentUsageCollector { self.ids.insert(n.to_id()); } - fn visit_member_prop(&mut self, n: &MemberProp) { - if let MemberProp::Computed(..) = n { - n.visit_children_with(self); - } - } - fn visit_prop_name(&mut self, n: &PropName) { if let PropName::Computed(..) = n { n.visit_children_with(self); @@ -399,7 +393,7 @@ pub(crate) struct CapturedIdCollector { } impl Visit for CapturedIdCollector { - standard_only_visit!(); + noop_visit_type!(fail); visit_obj_and_computed!(); @@ -503,7 +497,7 @@ pub(crate) struct EvalFinder { } impl Visit for EvalFinder { - standard_only_visit!(); + noop_visit_type!(fail); visit_obj_and_computed!(); diff --git a/crates/swc_ecma_minifier/tests/eval.rs b/crates/swc_ecma_minifier/tests/eval.rs index 3e2859c225ca..d530a2649232 100644 --- a/crates/swc_ecma_minifier/tests/eval.rs +++ b/crates/swc_ecma_minifier/tests/eval.rs @@ -10,7 +10,7 @@ use swc_ecma_minifier::{ }; use swc_ecma_parser::{parse_file_as_expr, parse_file_as_module, EsSyntax, Syntax}; use swc_ecma_transforms_base::resolver; -use swc_ecma_visit::{standard_only_visit_mut, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; use testing::{assert_eq, DebugUsingDisplay}; fn eval(module: &str, expr: &str) -> Option { @@ -169,7 +169,7 @@ impl PartialInliner { } impl VisitMut for PartialInliner { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_expr(&mut self, e: &mut Expr) { e.visit_mut_children_with(self); diff --git a/crates/swc_ecma_preset_env/src/corejs2/entry.rs b/crates/swc_ecma_preset_env/src/corejs2/entry.rs index f5faa2486f32..ddbc856cce19 100644 --- a/crates/swc_ecma_preset_env/src/corejs2/entry.rs +++ b/crates/swc_ecma_preset_env/src/corejs2/entry.rs @@ -3,7 +3,7 @@ use preset_env_base::{version::should_enable, Versions}; use swc_atoms::js_word; use swc_common::{collections::ARandomState, DUMMY_SP}; use swc_ecma_ast::*; -use swc_ecma_visit::{standard_only_visit_mut, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; use super::builtin::BUILTINS; @@ -65,7 +65,7 @@ impl Entry { } impl VisitMut for Entry { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_import_decl(&mut self, i: &mut ImportDecl) { let remove = i.specifiers.is_empty() && self.add_all(&i.src.value); diff --git a/crates/swc_ecma_preset_env/src/corejs2/mod.rs b/crates/swc_ecma_preset_env/src/corejs2/mod.rs index 46cfe3787a51..cb671645bec0 100644 --- a/crates/swc_ecma_preset_env/src/corejs2/mod.rs +++ b/crates/swc_ecma_preset_env/src/corejs2/mod.rs @@ -3,7 +3,7 @@ use preset_env_base::{version::should_enable, Versions}; use swc_atoms::JsWord; use swc_common::collections::ARandomState; use swc_ecma_ast::*; -use swc_ecma_visit::{standard_only_visit, Visit, VisitWith}; +use swc_ecma_visit::{noop_visit_type, Visit, VisitWith}; pub(crate) use self::entry::Entry; use self::{ @@ -124,7 +124,7 @@ impl UsageVisitor { /// Detects usage of types impl Visit for UsageVisitor { - standard_only_visit!(); + noop_visit_type!(fail); fn visit_ident(&mut self, node: &Ident) { node.visit_children_with(self); diff --git a/crates/swc_ecma_preset_env/src/corejs3/usage.rs b/crates/swc_ecma_preset_env/src/corejs3/usage.rs index 5a0f0a6b51e6..e30be0577355 100644 --- a/crates/swc_ecma_preset_env/src/corejs3/usage.rs +++ b/crates/swc_ecma_preset_env/src/corejs3/usage.rs @@ -3,7 +3,7 @@ use preset_env_base::version::{should_enable, Version}; use swc_atoms::JsWord; use swc_common::collections::ARandomState; use swc_ecma_ast::*; -use swc_ecma_visit::{standard_only_visit, Visit, VisitWith}; +use swc_ecma_visit::{noop_visit_type, Visit, VisitWith}; use super::{ builtin::{ @@ -154,7 +154,7 @@ impl UsageVisitor { } impl Visit for UsageVisitor { - standard_only_visit!(); + noop_visit_type!(fail); /// `[a, b] = c` fn visit_array_pat(&mut self, p: &ArrayPat) { diff --git a/crates/swc_ecma_transforms_base/tests/fixture.rs b/crates/swc_ecma_transforms_base/tests/fixture.rs index 9a880de24dc6..6001406cdbd7 100644 --- a/crates/swc_ecma_transforms_base/tests/fixture.rs +++ b/crates/swc_ecma_transforms_base/tests/fixture.rs @@ -123,10 +123,6 @@ impl VisitMut for TsHygiene { i.ctxt = SyntaxContext::empty(); } - fn visit_mut_jsx_member_expr(&mut self, n: &mut JSXMemberExpr) { - n.obj.visit_mut_with(self); - } - fn visit_mut_prop_name(&mut self, n: &mut PropName) { if let PropName::Computed(n) = n { n.visit_mut_with(self); diff --git a/crates/swc_ecma_transforms_classes/src/super_field.rs b/crates/swc_ecma_transforms_classes/src/super_field.rs index e0f696e03f1d..2b0311b6a56a 100644 --- a/crates/swc_ecma_transforms_classes/src/super_field.rs +++ b/crates/swc_ecma_transforms_classes/src/super_field.rs @@ -4,7 +4,7 @@ use swc_common::{util::take::Take, Mark, Span, SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::helper; use swc_ecma_utils::{is_rest_arguments, quote_ident, ExprFactory}; -use swc_ecma_visit::{standard_only_visit_mut, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; use super::get_prototype_of; @@ -65,7 +65,7 @@ macro_rules! mark_nested { } impl<'a> VisitMut for SuperFieldAccessFolder<'a> { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); // mark_nested!(fold_function, Function); mark_nested!(visit_mut_class, Class); diff --git a/crates/swc_ecma_transforms_compat/src/class_fields_use_set.rs b/crates/swc_ecma_transforms_compat/src/class_fields_use_set.rs index 3ed57542f2e7..76689e2e225b 100644 --- a/crates/swc_ecma_transforms_compat/src/class_fields_use_set.rs +++ b/crates/swc_ecma_transforms_compat/src/class_fields_use_set.rs @@ -6,7 +6,7 @@ use swc_ecma_utils::{ constructor::inject_after_super, default_constructor, is_literal, is_simple_pure_expr, private_ident, prop_name_to_member_prop, ExprFactory, ModuleItemLike, StmtLike, }; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; /// # What does this module do? /// @@ -93,7 +93,7 @@ struct ClassFieldsUseSet { } impl VisitMut for ClassFieldsUseSet { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_module_items(&mut self, n: &mut Vec) { self.visit_mut_stmts_like(n); @@ -164,7 +164,7 @@ struct FieldsHandler { } impl VisitMut for FieldsHandler { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_class(&mut self, _: &mut Class) { // skip inner classes @@ -268,7 +268,7 @@ struct ComputedFieldsHandler { } impl VisitMut for ComputedFieldsHandler { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_class_prop(&mut self, n: &mut ClassProp) { match &mut n.key { diff --git a/crates/swc_ecma_transforms_compat/src/reserved_words.rs b/crates/swc_ecma_transforms_compat/src/reserved_words.rs index bcdef34189ad..41454a85af0b 100644 --- a/crates/swc_ecma_transforms_compat/src/reserved_words.rs +++ b/crates/swc_ecma_transforms_compat/src/reserved_words.rs @@ -2,7 +2,7 @@ use swc_atoms::JsWord; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; use swc_ecma_visit::{ - as_folder, standard_only_visit_mut, visit_mut_obj_and_computed, Fold, VisitMut, VisitMutWith, + as_folder, noop_visit_mut_type, visit_mut_obj_and_computed, Fold, VisitMut, VisitMutWith, }; pub fn reserved_words() -> impl 'static + Fold + VisitMut { @@ -21,7 +21,7 @@ impl Parallel for EsReservedWord { } impl VisitMut for EsReservedWord { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); visit_mut_obj_and_computed!(); diff --git a/crates/swc_ecma_transforms_module/src/amd.rs b/crates/swc_ecma_transforms_module/src/amd.rs index 9d4062f5ff31..fc139f75e530 100644 --- a/crates/swc_ecma_transforms_module/src/amd.rs +++ b/crates/swc_ecma_transforms_module/src/amd.rs @@ -12,7 +12,7 @@ use swc_ecma_transforms_base::{feature::FeatureFlag, helper_expr}; use swc_ecma_utils::{ member_expr, private_ident, quote_ident, quote_str, ExprFactory, FunctionFactory, IsDirective, }; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; pub use super::util::Config as InnerConfig; use crate::{ @@ -135,7 +135,7 @@ impl VisitMut for Amd where C: Comments, { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_module(&mut self, n: &mut Module) { if self.module_id.is_none() { diff --git a/crates/swc_ecma_transforms_module/src/common_js.rs b/crates/swc_ecma_transforms_module/src/common_js.rs index 7f1b1cfec913..d9d8f10a2852 100644 --- a/crates/swc_ecma_transforms_module/src/common_js.rs +++ b/crates/swc_ecma_transforms_module/src/common_js.rs @@ -7,7 +7,7 @@ use swc_ecma_transforms_base::{feature::FeatureFlag, helper_expr}; use swc_ecma_utils::{ member_expr, private_ident, quote_expr, quote_ident, ExprFactory, FunctionFactory, IsDirective, }; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; pub use super::util::Config; use crate::{ @@ -90,7 +90,7 @@ impl VisitMut for Cjs where C: Comments, { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_module(&mut self, n: &mut Module) { let mut stmts: Vec = Vec::with_capacity(n.body.len() + 6); diff --git a/crates/swc_ecma_transforms_module/src/import_analysis.rs b/crates/swc_ecma_transforms_module/src/import_analysis.rs index 04dfb0c88261..0a89d6807892 100644 --- a/crates/swc_ecma_transforms_module/src/import_analysis.rs +++ b/crates/swc_ecma_transforms_module/src/import_analysis.rs @@ -3,7 +3,7 @@ use swc_common::collections::AHashMap; use swc_ecma_ast::*; use swc_ecma_transforms_base::enable_helper; use swc_ecma_visit::{ - as_folder, standard_only_visit, standard_only_visit_mut, Fold, Visit, VisitMut, VisitWith, + as_folder, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitWith, }; use crate::{module_decl_strip::LinkFlag, util::ImportInterop}; @@ -30,7 +30,7 @@ pub struct ImportAnalyzer { /// Inject required helpers methods **for** module transform passes. impl VisitMut for ImportAnalyzer { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_module(&mut self, module: &mut Module) { self.visit_module(&*module); @@ -38,7 +38,7 @@ impl VisitMut for ImportAnalyzer { } impl Visit for ImportAnalyzer { - standard_only_visit!(); + noop_visit_type!(fail); fn visit_module_items(&mut self, n: &[ModuleItem]) { for item in n.iter() { diff --git a/crates/swc_ecma_transforms_module/src/module_decl_strip.rs b/crates/swc_ecma_transforms_module/src/module_decl_strip.rs index 02deed7cf8b0..d9712a3de1c4 100644 --- a/crates/swc_ecma_transforms_module/src/module_decl_strip.rs +++ b/crates/swc_ecma_transforms_module/src/module_decl_strip.rs @@ -7,7 +7,7 @@ use swc_common::{ }; use swc_ecma_ast::*; use swc_ecma_utils::{find_pat_ids, private_ident, quote_ident, ExprFactory}; -use swc_ecma_visit::{standard_only_visit_mut, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; use crate::{module_ref_rewriter::ImportMap, SpanCtx}; @@ -52,7 +52,7 @@ impl ModuleDeclStrip { } impl VisitMut for ModuleDeclStrip { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_module_items(&mut self, n: &mut Vec) { let mut list = Vec::with_capacity(n.len()); diff --git a/crates/swc_ecma_transforms_module/src/rewriter.rs b/crates/swc_ecma_transforms_module/src/rewriter.rs index 36f8e15b00d8..1e05dde6fff4 100644 --- a/crates/swc_ecma_transforms_module/src/rewriter.rs +++ b/crates/swc_ecma_transforms_module/src/rewriter.rs @@ -1,7 +1,7 @@ use anyhow::Context; use swc_common::FileName; use swc_ecma_ast::*; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use crate::path::ImportResolver; @@ -25,7 +25,7 @@ impl VisitMut for Rewriter where R: ImportResolver, { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_call_expr(&mut self, e: &mut CallExpr) { e.visit_mut_children_with(self); diff --git a/crates/swc_ecma_transforms_module/src/top_level_this.rs b/crates/swc_ecma_transforms_module/src/top_level_this.rs index 93b52f708dbf..628def59af8a 100644 --- a/crates/swc_ecma_transforms_module/src/top_level_this.rs +++ b/crates/swc_ecma_transforms_module/src/top_level_this.rs @@ -1,5 +1,5 @@ use swc_ecma_ast::*; -use swc_ecma_visit::{noop_visit_mut_type, standard_only_visit_mut, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; pub struct TopLevelThis { found: bool, @@ -19,7 +19,7 @@ where } impl VisitMut for TopLevelThis { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); noop_visit_mut_type!(visit_mut_function, Function); diff --git a/crates/swc_ecma_transforms_module/src/umd.rs b/crates/swc_ecma_transforms_module/src/umd.rs index a5b7c0734778..46c873b93240 100644 --- a/crates/swc_ecma_transforms_module/src/umd.rs +++ b/crates/swc_ecma_transforms_module/src/umd.rs @@ -9,7 +9,7 @@ use swc_ecma_transforms_base::{feature::FeatureFlag, helper_expr}; use swc_ecma_utils::{ is_valid_prop_ident, private_ident, quote_ident, quote_str, ExprFactory, IsDirective, }; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use self::config::BuiltConfig; pub use self::config::Config; @@ -107,7 +107,7 @@ impl VisitMut for Umd where C: Comments, { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_module(&mut self, module: &mut Module) { let module_items = &mut module.body; diff --git a/crates/swc_ecma_transforms_optimization/src/const_modules.rs b/crates/swc_ecma_transforms_optimization/src/const_modules.rs index c2bb8fe65930..7cf689620316 100644 --- a/crates/swc_ecma_transforms_optimization/src/const_modules.rs +++ b/crates/swc_ecma_transforms_optimization/src/const_modules.rs @@ -17,7 +17,7 @@ use swc_common::{ use swc_ecma_ast::*; use swc_ecma_parser::parse_file_as_expr; use swc_ecma_utils::drop_span; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; pub fn const_modules( cm: Lrc, @@ -93,7 +93,7 @@ struct Scope { } impl VisitMut for ConstModules { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_module_items(&mut self, n: &mut Vec) { *n = n.take().move_flat_map(|item| match item { diff --git a/crates/swc_ecma_transforms_optimization/src/debug.rs b/crates/swc_ecma_transforms_optimization/src/debug.rs index f9b14f567ab5..5cd2ea86c053 100644 --- a/crates/swc_ecma_transforms_optimization/src/debug.rs +++ b/crates/swc_ecma_transforms_optimization/src/debug.rs @@ -3,7 +3,7 @@ use std::{fmt::Debug, mem::forget}; use swc_ecma_ast::*; -use swc_ecma_visit::{noop_visit_type, standard_only_visit, Visit, VisitWith}; +use swc_ecma_visit::{noop_visit_type, Visit, VisitWith}; /// Assert in debug mode. This is noop in release build. pub fn debug_assert_valid(node: &N) @@ -29,7 +29,7 @@ impl Drop for Ctx<'_> { pub struct AssertValid; impl Visit for AssertValid { - standard_only_visit!(); + noop_visit_type!(fail); #[cfg(debug_assertions)] fn visit_expr(&mut self, n: &Expr) { diff --git a/crates/swc_ecma_transforms_optimization/src/inline_globals.rs b/crates/swc_ecma_transforms_optimization/src/inline_globals.rs index 32c5c435bfe1..8ddd29273162 100644 --- a/crates/swc_ecma_transforms_optimization/src/inline_globals.rs +++ b/crates/swc_ecma_transforms_optimization/src/inline_globals.rs @@ -6,7 +6,7 @@ use swc_common::{ use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::{ParVisitMut, Parallel}; use swc_ecma_utils::{collect_decls, parallel::cpu_count, NodeIgnoringSpan}; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; /// The key will be compared using [EqIgnoreSpan::eq_ignore_span], and matched /// expressions will be replaced with the value. @@ -63,7 +63,7 @@ impl Parallel for InlineGlobals { } impl VisitMut for InlineGlobals { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_expr(&mut self, expr: &mut Expr) { if let Expr::Ident(Ident { ref sym, ctxt, .. }) = expr { diff --git a/crates/swc_ecma_transforms_optimization/src/json_parse.rs b/crates/swc_ecma_transforms_optimization/src/json_parse.rs index 1b5522a861d2..b829f43947f7 100644 --- a/crates/swc_ecma_transforms_optimization/src/json_parse.rs +++ b/crates/swc_ecma_transforms_optimization/src/json_parse.rs @@ -3,7 +3,7 @@ use swc_common::{util::take::Take, Spanned, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; use swc_ecma_utils::{calc_literal_cost, member_expr, ExprFactory}; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; /// Transform to optimize performance of literals. /// @@ -52,7 +52,7 @@ impl Default for JsonParse { } impl VisitMut for JsonParse { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); /// Handles parent expressions before child expressions. fn visit_mut_expr(&mut self, expr: &mut Expr) { diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/branch/mod.rs b/crates/swc_ecma_transforms_optimization/src/simplify/branch/mod.rs index e6adb6013493..effbd510a9ed 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/branch/mod.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/branch/mod.rs @@ -15,8 +15,7 @@ use swc_ecma_utils::{ StmtExt, StmtLike, Value::Known, }; use swc_ecma_visit::{ - as_folder, standard_only_visit, standard_only_visit_mut, Visit, VisitMut, VisitMutWith, - VisitWith, + as_folder, noop_visit_mut_type, noop_visit_type, Visit, VisitMut, VisitMutWith, VisitWith, }; use tracing::{debug, trace}; @@ -73,7 +72,7 @@ impl Parallel for Remover { } impl VisitMut for Remover { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_expr(&mut self, e: &mut Expr) { e.visit_mut_children_with(self); @@ -1906,7 +1905,7 @@ fn check_for_stopper(s: &[Stmt], only_conditional: bool) -> bool { } impl Visit for Visitor { - standard_only_visit!(); + noop_visit_type!(fail); fn visit_switch_case(&mut self, node: &SwitchCase) { let old = self.in_cond; diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/const_propagation.rs b/crates/swc_ecma_transforms_optimization/src/simplify/const_propagation.rs index aff4d4200dfb..0e60cc295aab 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/const_propagation.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/const_propagation.rs @@ -2,7 +2,7 @@ use swc_common::{collections::AHashMap, util::take::Take}; use swc_ecma_ast::*; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; /// This pass is kind of inliner, but it's far faster. pub fn constant_propagation() -> impl 'static + Fold + VisitMut { @@ -38,7 +38,7 @@ impl<'a> Scope<'a> { } impl VisitMut for ConstPropagation<'_> { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); /// No-op fn visit_mut_assign_expr(&mut self, _: &mut AssignExpr) {} diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/dce/mod.rs b/crates/swc_ecma_transforms_optimization/src/simplify/dce/mod.rs index 3e7b0260607f..80e21431be52 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/dce/mod.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/dce/mod.rs @@ -19,8 +19,7 @@ use swc_ecma_utils::{ collect_decls, find_pat_ids, ExprCtx, ExprExt, IsEmpty, ModuleItemLike, StmtLike, }; use swc_ecma_visit::{ - as_folder, standard_only_visit, standard_only_visit_mut, Fold, Visit, VisitMut, VisitMutWith, - VisitWith, + as_folder, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, VisitWith, }; use swc_fast_graph::digraph::FastDiGraphMap; use tracing::{debug, span, Level}; @@ -356,7 +355,7 @@ impl Analyzer<'_> { } impl Visit for Analyzer<'_> { - standard_only_visit!(); + noop_visit_type!(fail); fn visit_callee(&mut self, n: &Callee) { n.visit_children_with(self); @@ -659,7 +658,7 @@ impl TreeShaker { } impl VisitMut for TreeShaker { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_assign_expr(&mut self, n: &mut AssignExpr) { n.visit_mut_children_with(self); diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/expr/mod.rs b/crates/swc_ecma_transforms_optimization/src/simplify/expr/mod.rs index 837d215b875b..734f6399c301 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/expr/mod.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/expr/mod.rs @@ -16,7 +16,7 @@ use swc_ecma_utils::{ is_literal, number::JsNumber, prop_name_eq, to_int32, BoolType, ExprCtx, ExprExt, NullType, NumberType, ObjectType, StringType, SymbolType, UndefinedType, Value, }; -use swc_ecma_visit::{as_folder, standard_only_visit_mut, VisitMut, VisitMutWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, VisitMut, VisitMutWith}; use Value::{Known, Unknown}; use crate::debug::debug_assert_valid; @@ -1213,7 +1213,7 @@ impl SimplifyExpr { } impl VisitMut for SimplifyExpr { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_assign_expr(&mut self, n: &mut AssignExpr) { let old = self.is_modifying; diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/inlining/mod.rs b/crates/swc_ecma_transforms_optimization/src/simplify/inlining/mod.rs index 499d5178b6bc..e9327117556e 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/inlining/mod.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/inlining/mod.rs @@ -8,8 +8,8 @@ use swc_ecma_ast::*; use swc_ecma_transforms_base::{pass::RepeatedJsPass, scope::IdentType}; use swc_ecma_utils::{contains_this_expr, find_pat_ids}; use swc_ecma_visit::{ - as_folder, standard_only_visit, standard_only_visit_mut, visit_obj_and_computed, Visit, - VisitMut, VisitMutWith, VisitWith, + as_folder, noop_visit_mut_type, noop_visit_type, visit_obj_and_computed, Visit, VisitMut, + VisitMutWith, VisitWith, }; use tracing::{span, Level}; @@ -103,7 +103,7 @@ impl Inlining<'_> { } impl VisitMut for Inlining<'_> { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_arrow_expr(&mut self, node: &mut ArrowExpr) { self.visit_with_child(ScopeKind::Fn { named: false }, node) @@ -739,7 +739,7 @@ struct IdentListVisitor<'a, 'b> { } impl Visit for IdentListVisitor<'_, '_> { - standard_only_visit!(); + noop_visit_type!(fail); visit_obj_and_computed!(); @@ -754,7 +754,7 @@ struct WriteVisitor<'a, 'b> { } impl Visit for WriteVisitor<'_, '_> { - standard_only_visit!(); + noop_visit_type!(fail); visit_obj_and_computed!(); diff --git a/crates/swc_ecma_transforms_optimization/tests/dce-jsx/property/input.js b/crates/swc_ecma_transforms_optimization/tests/dce-jsx/property/input.js new file mode 100644 index 000000000000..d69b17010155 --- /dev/null +++ b/crates/swc_ecma_transforms_optimization/tests/dce-jsx/property/input.js @@ -0,0 +1,7 @@ +function A() { + return "a"; +} +const b = "b"; +export function c() { + return ; +} diff --git a/crates/swc_ecma_transforms_optimization/tests/dce-jsx/property/output.js b/crates/swc_ecma_transforms_optimization/tests/dce-jsx/property/output.js new file mode 100644 index 000000000000..dcc099a5ba65 --- /dev/null +++ b/crates/swc_ecma_transforms_optimization/tests/dce-jsx/property/output.js @@ -0,0 +1,6 @@ +function A() { + return "a"; +} +export function c() { + return ; +} diff --git a/crates/swc_ecma_transforms_optimization/tests/dce-jsx/property2/input.js b/crates/swc_ecma_transforms_optimization/tests/dce-jsx/property2/input.js new file mode 100644 index 000000000000..450635316d53 --- /dev/null +++ b/crates/swc_ecma_transforms_optimization/tests/dce-jsx/property2/input.js @@ -0,0 +1,8 @@ +function A() { + return "a"; +} +const b = "b"; +const c = "c"; +export function d() { + return ; +} diff --git a/crates/swc_ecma_transforms_optimization/tests/dce-jsx/property2/output.js b/crates/swc_ecma_transforms_optimization/tests/dce-jsx/property2/output.js new file mode 100644 index 000000000000..ef1f791b5cf2 --- /dev/null +++ b/crates/swc_ecma_transforms_optimization/tests/dce-jsx/property2/output.js @@ -0,0 +1,6 @@ +function A() { + return "a"; +} +export function d() { + return ; +} diff --git a/crates/swc_ecma_transforms_optimization/tests/dce-jsx/spread/input.js b/crates/swc_ecma_transforms_optimization/tests/dce-jsx/spread/input.js new file mode 100644 index 000000000000..a5ee2839c7e8 --- /dev/null +++ b/crates/swc_ecma_transforms_optimization/tests/dce-jsx/spread/input.js @@ -0,0 +1,8 @@ +function A() { + return "a"; +} +const b = "b"; +const c = "c"; +export function d() { + return {c}; +} diff --git a/crates/swc_ecma_transforms_optimization/tests/dce-jsx/spread/output.js b/crates/swc_ecma_transforms_optimization/tests/dce-jsx/spread/output.js new file mode 100644 index 000000000000..a5ee2839c7e8 --- /dev/null +++ b/crates/swc_ecma_transforms_optimization/tests/dce-jsx/spread/output.js @@ -0,0 +1,8 @@ +function A() { + return "a"; +} +const b = "b"; +const c = "c"; +export function d() { + return {c}; +} diff --git a/crates/swc_ecma_transforms_optimization/tests/dce-jsx/var/input.js b/crates/swc_ecma_transforms_optimization/tests/dce-jsx/var/input.js new file mode 100644 index 000000000000..819e09994e12 --- /dev/null +++ b/crates/swc_ecma_transforms_optimization/tests/dce-jsx/var/input.js @@ -0,0 +1,8 @@ +function A() { + return "a"; +} +const b = "b"; +const c = "c"; +export function d() { + return {c}; +} diff --git a/crates/swc_ecma_transforms_optimization/tests/dce-jsx/var/output.js b/crates/swc_ecma_transforms_optimization/tests/dce-jsx/var/output.js new file mode 100644 index 000000000000..819e09994e12 --- /dev/null +++ b/crates/swc_ecma_transforms_optimization/tests/dce-jsx/var/output.js @@ -0,0 +1,8 @@ +function A() { + return "a"; +} +const b = "b"; +const c = "c"; +export function d() { + return {c}; +} diff --git a/crates/swc_ecma_transforms_optimization/tests/fixture.rs b/crates/swc_ecma_transforms_optimization/tests/fixture.rs index 3576f0fa1b44..9ecb1adb07f0 100644 --- a/crates/swc_ecma_transforms_optimization/tests/fixture.rs +++ b/crates/swc_ecma_transforms_optimization/tests/fixture.rs @@ -54,6 +54,23 @@ fn dce_repeated(input: PathBuf) { ); } +#[testing::fixture("tests/dce-jsx/**/input.js")] +fn dce_jsx(input: PathBuf) { + let output = input.with_file_name("output.js"); + + test_fixture( + Syntax::Es(EsSyntax { + decorators: true, + jsx: true, + ..Default::default() + }), + &|t| chain!(remover(t), dce(Default::default(), Mark::new())), + &input, + &output, + Default::default(), + ); +} + #[testing::fixture("tests/expr-simplifier/**/input.js")] fn expr(input: PathBuf) { let output = input.with_file_name("output.js"); diff --git a/crates/swc_ecma_usage_analyzer/src/alias/mod.rs b/crates/swc_ecma_usage_analyzer/src/alias/mod.rs index bc7db73f0aba..37b4ef6e3e3c 100644 --- a/crates/swc_ecma_usage_analyzer/src/alias/mod.rs +++ b/crates/swc_ecma_usage_analyzer/src/alias/mod.rs @@ -4,7 +4,7 @@ use rustc_hash::FxHashSet; use swc_common::{collections::AHashSet, SyntaxContext}; use swc_ecma_ast::*; use swc_ecma_utils::{collect_decls, BindingCollector}; -use swc_ecma_visit::{standard_only_visit, Visit, VisitWith}; +use swc_ecma_visit::{noop_visit_type, Visit, VisitWith}; pub use self::ctx::Ctx; use crate::{marks::Marks, util::is_global_var_with_pure_property_access}; @@ -120,7 +120,7 @@ impl InfectionCollector<'_> { } impl Visit for InfectionCollector<'_> { - standard_only_visit!(); + noop_visit_type!(fail); fn visit_bin_expr(&mut self, e: &BinExpr) { match e.op { diff --git a/crates/swc_ecma_usage_analyzer/src/analyzer/mod.rs b/crates/swc_ecma_usage_analyzer/src/analyzer/mod.rs index 37f8ffc70bf7..277bf157f6d7 100644 --- a/crates/swc_ecma_usage_analyzer/src/analyzer/mod.rs +++ b/crates/swc_ecma_usage_analyzer/src/analyzer/mod.rs @@ -1,7 +1,7 @@ use swc_common::{collections::AHashMap, SyntaxContext}; use swc_ecma_ast::*; use swc_ecma_utils::{find_pat_ids, ExprCtx, ExprExt, IsEmpty, StmtExt}; -use swc_ecma_visit::{standard_only_visit, Visit, VisitWith}; +use swc_ecma_visit::{noop_visit_type, Visit, VisitWith}; use swc_timer::timer; pub use self::ctx::Ctx; @@ -215,7 +215,7 @@ impl Visit for UsageAnalyzer where S: Storage, { - standard_only_visit!(); + noop_visit_type!(fail); fn visit_array_lit(&mut self, n: &ArrayLit) { let ctx = Ctx { @@ -896,6 +896,24 @@ where self.declare_decl(&n.local, true, None, false); } + #[cfg_attr(feature = "debug", tracing::instrument(skip_all))] + fn visit_jsx_element_name(&mut self, n: &JSXElementName) { + let ctx = Ctx { + in_pat_of_var_decl: false, + in_pat_of_param: false, + in_catch_param: false, + var_decl_kind_of_pat: None, + in_pat_of_var_decl_with_init: false, + ..self.ctx + }; + + n.visit_children_with(&mut *self.with_ctx(ctx)); + + if let JSXElementName::Ident(i) = n { + self.with_ctx(ctx).report_usage(i); + } + } + #[cfg_attr(feature = "debug", tracing::instrument(skip(self, e)))] fn visit_member_expr(&mut self, e: &MemberExpr) { { diff --git a/crates/swc_ecma_utils/src/constructor.rs b/crates/swc_ecma_utils/src/constructor.rs index eb29cc90e6ae..6c988bc79ea1 100644 --- a/crates/swc_ecma_utils/src/constructor.rs +++ b/crates/swc_ecma_utils/src/constructor.rs @@ -3,7 +3,7 @@ use std::iter; use swc_common::{util::take::Take, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_visit::{ - standard_only_fold, standard_only_visit_mut, Fold, FoldWith, VisitMut, VisitMutWith, + noop_visit_mut_type, standard_only_fold, Fold, FoldWith, VisitMut, VisitMutWith, }; use crate::{prepend_stmts, ExprFactory}; @@ -119,7 +119,7 @@ struct ExprInjector<'a> { } impl VisitMut for ExprInjector<'_> { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_class(&mut self, c: &mut Class) { c.super_class.visit_mut_with(self); diff --git a/crates/swc_ecma_utils/src/function/fn_env_hoister.rs b/crates/swc_ecma_utils/src/function/fn_env_hoister.rs index f81db6181897..32add81df5ae 100644 --- a/crates/swc_ecma_utils/src/function/fn_env_hoister.rs +++ b/crates/swc_ecma_utils/src/function/fn_env_hoister.rs @@ -4,7 +4,7 @@ use indexmap::IndexMap; use swc_atoms::JsWord; use swc_common::{util::take::Take, Span, Spanned, SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; -use swc_ecma_visit::{standard_only_visit_mut, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; use crate::ExprFactory; @@ -281,7 +281,7 @@ impl FnEnvHoister { } impl VisitMut for FnEnvHoister { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_assign_target_pat(&mut self, n: &mut AssignTargetPat) { let in_pat = self.in_pat; @@ -603,7 +603,7 @@ struct InitThis<'a> { // babel is skip function and class property impl<'a> VisitMut for InitThis<'a> { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_class(&mut self, _: &mut Class) {} diff --git a/crates/swc_ecma_utils/src/lib.rs b/crates/swc_ecma_utils/src/lib.rs index 2830ef30d77d..859372c1295f 100644 --- a/crates/swc_ecma_utils/src/lib.rs +++ b/crates/swc_ecma_utils/src/lib.rs @@ -22,8 +22,8 @@ use swc_common::{ }; use swc_ecma_ast::*; use swc_ecma_visit::{ - noop_visit_mut_type, noop_visit_type, standard_only_visit_mut, visit_mut_obj_and_computed, - visit_obj_and_computed, Visit, VisitMut, VisitMutWith, VisitWith, + noop_visit_mut_type, noop_visit_type, visit_mut_obj_and_computed, visit_obj_and_computed, + Visit, VisitMut, VisitMutWith, VisitWith, }; use tracing::trace; @@ -2678,7 +2678,7 @@ pub struct IdentReplacer<'a> { } impl VisitMut for IdentReplacer<'_> { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); visit_mut_obj_and_computed!(); @@ -2958,7 +2958,7 @@ impl<'a> Remapper<'a> { } impl VisitMut for Remapper<'_> { - standard_only_visit_mut!(); + noop_visit_mut_type!(fail); fn visit_mut_ident(&mut self, i: &mut Ident) { if let Some(new_ctxt) = self.vars.get(&i.to_id()).copied() { @@ -2983,10 +2983,6 @@ impl VisitMut for IdentRenamer<'_> { visit_mut_obj_and_computed!(); - fn visit_mut_jsx_member_expr(&mut self, n: &mut JSXMemberExpr) { - n.obj.visit_mut_with(self); - } - fn visit_mut_export_named_specifier(&mut self, node: &mut ExportNamedSpecifier) { if node.exported.is_some() { node.orig.visit_mut_children_with(self); diff --git a/crates/swc_ecma_utils/src/var.rs b/crates/swc_ecma_utils/src/var.rs index 9585d270bc03..ea000b1d0658 100644 --- a/crates/swc_ecma_utils/src/var.rs +++ b/crates/swc_ecma_utils/src/var.rs @@ -1,5 +1,5 @@ use swc_ecma_ast::*; -use swc_ecma_visit::{standard_only_visit, Visit, VisitWith}; +use swc_ecma_visit::{noop_visit_type, Visit, VisitWith}; use crate::ident::IdentLike; @@ -10,7 +10,7 @@ pub struct VarCollector<'a, I: IdentLike> { } impl<'a, I: IdentLike> Visit for VarCollector<'a, I> { - standard_only_visit!(); + noop_visit_type!(fail); fn visit_arrow_expr(&mut self, _: &ArrowExpr) {} diff --git a/crates/swc_ecma_visit/src/lib.rs b/crates/swc_ecma_visit/src/lib.rs index 54297af2dc76..afd92289d4d4 100644 --- a/crates/swc_ecma_visit/src/lib.rs +++ b/crates/swc_ecma_visit/src/lib.rs @@ -352,7 +352,6 @@ macro_rules! noop_fold_type { noop_fold_type!(fold_ts_enum_member, TsEnumMember); noop_fold_type!(fold_ts_enum_member_id, TsEnumMemberId); noop_fold_type!(fold_ts_expr_with_type_args, TsExprWithTypeArgs); - noop_fold_type!(fold_ts_external_module_ref, TsExternalModuleRef); noop_fold_type!(fold_ts_fn_or_constructor_type, TsFnOrConstructorType); noop_fold_type!(fold_ts_fn_param, TsFnParam); noop_fold_type!(fold_ts_fn_type, TsFnType); @@ -410,8 +409,66 @@ macro_rules! noop_fold_type { /// Note: Ignoring more types is not considered as a breaking change. #[macro_export] macro_rules! noop_visit_type { - ($name:ident, $N:tt) => { - fn $name(&mut self, _: &$crate::swc_ecma_ast::$N) {} + (fail) => { + noop_visit_type!(visit_accessibility, Accessibility, fail); + noop_visit_type!(visit_true_plus_minus, TruePlusMinus, fail); + noop_visit_type!(visit_ts_array_type, TsArrayType, fail); + noop_visit_type!(visit_ts_call_signature_decl, TsCallSignatureDecl, fail); + noop_visit_type!(visit_ts_conditional_type, TsConditionalType, fail); + noop_visit_type!( + visit_ts_construct_signature_decl, + TsConstructSignatureDecl, + fail + ); + noop_visit_type!(visit_ts_constructor_type, TsConstructorType, fail); + noop_visit_type!(visit_ts_entity_name, TsEntityName, fail); + noop_visit_type!(visit_ts_expr_with_type_args, TsExprWithTypeArgs, fail); + noop_visit_type!(visit_ts_fn_or_constructor_type, TsFnOrConstructorType, fail); + noop_visit_type!(visit_ts_fn_param, TsFnParam, fail); + noop_visit_type!(visit_ts_fn_type, TsFnType, fail); + noop_visit_type!(visit_ts_import_type, TsImportType, fail); + noop_visit_type!(visit_ts_index_signature, TsIndexSignature, fail); + noop_visit_type!(visit_ts_indexed_access_type, TsIndexedAccessType, fail); + noop_visit_type!(visit_ts_infer_type, TsInferType, fail); + noop_visit_type!(visit_ts_interface_body, TsInterfaceBody, fail); + noop_visit_type!(visit_ts_interface_decl, TsInterfaceDecl, fail); + noop_visit_type!(visit_ts_intersection_type, TsIntersectionType, fail); + noop_visit_type!(visit_ts_keyword_type, TsKeywordType, fail); + noop_visit_type!(visit_ts_keyword_type_kind, TsKeywordTypeKind, fail); + noop_visit_type!(visit_ts_mapped_type, TsMappedType, fail); + noop_visit_type!(visit_ts_method_signature, TsMethodSignature, fail); + noop_visit_type!(visit_ts_optional_type, TsOptionalType, fail); + noop_visit_type!(visit_ts_parenthesized_type, TsParenthesizedType, fail); + noop_visit_type!(visit_ts_property_signature, TsPropertySignature, fail); + noop_visit_type!(visit_ts_qualified_name, TsQualifiedName, fail); + noop_visit_type!(visit_ts_rest_type, TsRestType, fail); + noop_visit_type!(visit_ts_this_type, TsThisType, fail); + noop_visit_type!(visit_ts_this_type_or_ident, TsThisTypeOrIdent, fail); + noop_visit_type!(visit_ts_tuple_type, TsTupleType, fail); + noop_visit_type!(visit_ts_type, TsType, fail); + noop_visit_type!(visit_ts_type_alias_decl, TsTypeAliasDecl, fail); + noop_visit_type!(visit_ts_type_ann, TsTypeAnn, fail); + noop_visit_type!(visit_ts_type_element, TsTypeElement, fail); + noop_visit_type!(visit_ts_type_lit, TsTypeLit, fail); + noop_visit_type!(visit_ts_type_operator, TsTypeOperator, fail); + noop_visit_type!(visit_ts_type_operator_op, TsTypeOperatorOp, fail); + noop_visit_type!(visit_ts_type_param, TsTypeParam, fail); + noop_visit_type!(visit_ts_type_param_decl, TsTypeParamDecl, fail); + noop_visit_type!( + visit_ts_type_param_instantiation, + TsTypeParamInstantiation, + fail + ); + noop_visit_type!(visit_ts_type_predicate, TsTypePredicate, fail); + noop_visit_type!(visit_ts_type_query, TsTypeQuery, fail); + noop_visit_type!(visit_ts_type_query_expr, TsTypeQueryExpr, fail); + noop_visit_type!(visit_ts_type_ref, TsTypeRef, fail); + noop_visit_type!( + visit_ts_union_or_intersection_type, + TsUnionOrIntersectionType, + fail + ); + noop_visit_type!(visit_ts_union_type, TsUnionType, fail); }; () => { noop_visit_type!(visit_accessibility, Accessibility); @@ -423,7 +480,6 @@ macro_rules! noop_visit_type { noop_visit_type!(visit_ts_constructor_type, TsConstructorType); noop_visit_type!(visit_ts_entity_name, TsEntityName); noop_visit_type!(visit_ts_expr_with_type_args, TsExprWithTypeArgs); - noop_visit_type!(visit_ts_external_module_ref, TsExternalModuleRef); noop_visit_type!(visit_ts_fn_or_constructor_type, TsFnOrConstructorType); noop_visit_type!(visit_ts_fn_param, TsFnParam); noop_visit_type!(visit_ts_fn_type, TsFnType); @@ -438,7 +494,6 @@ macro_rules! noop_visit_type { noop_visit_type!(visit_ts_keyword_type_kind, TsKeywordTypeKind); noop_visit_type!(visit_ts_mapped_type, TsMappedType); noop_visit_type!(visit_ts_method_signature, TsMethodSignature); - noop_visit_type!(visit_ts_module_ref, TsModuleRef); noop_visit_type!(visit_ts_optional_type, TsOptionalType); noop_visit_type!(visit_ts_parenthesized_type, TsParenthesizedType); noop_visit_type!(visit_ts_property_signature, TsPropertySignature); @@ -467,15 +522,37 @@ macro_rules! noop_visit_type { ); noop_visit_type!(visit_ts_union_type, TsUnionType); }; + + ($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(); + } + }; + ($name:ident, $N:tt) => { + fn $name(&mut self, _: &$crate::swc_ecma_ast::$N) {} + }; } /// NOT A PUBLIC API #[doc(hidden)] -#[inline(always)] +#[cfg_attr(not(debug_assertions), inline(always))] pub fn fail_not_standard() { unsafe { debug_unreachable::debug_unreachable!( - "This visitor supports only standard ECMAScript types" + "This visitor supports only standard ECMAScript types. This method fails for \ + optimization purpose." + ) + } +} + +/// NOT A PUBLIC API +#[doc(hidden)] +#[cfg_attr(not(debug_assertions), inline(always))] +pub fn fail_no_typescript() { + unsafe { + debug_unreachable::debug_unreachable!( + "This visitor does not support typescript. This method fails for optimization purpose." ) } } @@ -703,8 +780,70 @@ macro_rules! standard_only_visit_mut { /// Note: Ignoring more types is not considered as a breaking change. #[macro_export] macro_rules! noop_visit_mut_type { - ($name:ident, $N:ident) => { - fn $name(&mut self, _: &mut $crate::swc_ecma_ast::$N) {} + (fail) => { + noop_visit_mut_type!(visit_mut_accessibility, Accessibility, fail); + noop_visit_mut_type!(visit_mut_true_plus_minus, TruePlusMinus, fail); + noop_visit_mut_type!(visit_mut_ts_array_type, TsArrayType, fail); + noop_visit_mut_type!(visit_mut_ts_call_signature_decl, TsCallSignatureDecl, fail); + noop_visit_mut_type!(visit_mut_ts_conditional_type, TsConditionalType, fail); + noop_visit_mut_type!( + visit_mut_ts_construct_signature_decl, + TsConstructSignatureDecl, + fail + ); + noop_visit_mut_type!(visit_mut_ts_constructor_type, TsConstructorType, fail); + noop_visit_mut_type!(visit_mut_ts_entity_name, TsEntityName, fail); + noop_visit_mut_type!(visit_mut_ts_expr_with_type_args, TsExprWithTypeArgs, fail); + noop_visit_mut_type!( + visit_mut_ts_fn_or_constructor_type, + TsFnOrConstructorType, + fail + ); + noop_visit_mut_type!(visit_mut_ts_fn_param, TsFnParam, fail); + noop_visit_mut_type!(visit_mut_ts_fn_type, TsFnType, fail); + noop_visit_mut_type!(visit_mut_ts_import_type, TsImportType, fail); + noop_visit_mut_type!(visit_mut_ts_index_signature, TsIndexSignature, fail); + noop_visit_mut_type!(visit_mut_ts_indexed_access_type, TsIndexedAccessType, fail); + noop_visit_mut_type!(visit_mut_ts_infer_type, TsInferType, fail); + noop_visit_mut_type!(visit_mut_ts_interface_body, TsInterfaceBody, fail); + noop_visit_mut_type!(visit_mut_ts_interface_decl, TsInterfaceDecl, fail); + noop_visit_mut_type!(visit_mut_ts_intersection_type, TsIntersectionType, fail); + noop_visit_mut_type!(visit_mut_ts_keyword_type, TsKeywordType, fail); + noop_visit_mut_type!(visit_mut_ts_keyword_type_kind, TsKeywordTypeKind, fail); + noop_visit_mut_type!(visit_mut_ts_mapped_type, TsMappedType, fail); + noop_visit_mut_type!(visit_mut_ts_method_signature, TsMethodSignature, fail); + noop_visit_mut_type!(visit_mut_ts_optional_type, TsOptionalType, fail); + noop_visit_mut_type!(visit_mut_ts_parenthesized_type, TsParenthesizedType, fail); + noop_visit_mut_type!(visit_mut_ts_property_signature, TsPropertySignature, fail); + noop_visit_mut_type!(visit_mut_ts_qualified_name, TsQualifiedName, fail); + noop_visit_mut_type!(visit_mut_ts_rest_type, TsRestType, fail); + noop_visit_mut_type!(visit_mut_ts_this_type, TsThisType, fail); + noop_visit_mut_type!(visit_mut_ts_this_type_or_ident, TsThisTypeOrIdent, fail); + noop_visit_mut_type!(visit_mut_ts_tuple_type, TsTupleType, fail); + noop_visit_mut_type!(visit_mut_ts_type, TsType, fail); + noop_visit_mut_type!(visit_mut_ts_type_alias_decl, TsTypeAliasDecl, fail); + noop_visit_mut_type!(visit_mut_ts_type_ann, TsTypeAnn, fail); + noop_visit_mut_type!(visit_mut_ts_type_element, TsTypeElement, fail); + noop_visit_mut_type!(visit_mut_ts_type_lit, TsTypeLit, fail); + noop_visit_mut_type!(visit_mut_ts_type_operator, TsTypeOperator, fail); + noop_visit_mut_type!(visit_mut_ts_type_operator_op, TsTypeOperatorOp, fail); + noop_visit_mut_type!(visit_mut_ts_type_param, TsTypeParam, fail); + noop_visit_mut_type!(visit_mut_ts_type_param_decl, TsTypeParamDecl, fail); + noop_visit_mut_type!( + visit_mut_ts_type_param_instantiation, + TsTypeParamInstantiation, + fail + ); + noop_visit_mut_type!(visit_mut_ts_type_predicate, TsTypePredicate, fail); + noop_visit_mut_type!(visit_mut_ts_type_query, TsTypeQuery, fail); + noop_visit_mut_type!(visit_mut_ts_type_query_expr, TsTypeQueryExpr, fail); + noop_visit_mut_type!(visit_mut_ts_type_ref, TsTypeRef, fail); + noop_visit_mut_type!( + visit_mut_ts_union_or_intersection_type, + TsUnionOrIntersectionType, + fail + ); + noop_visit_mut_type!(visit_mut_ts_union_type, TsUnionType, fail); }; () => { noop_visit_mut_type!(visit_mut_accessibility, Accessibility); @@ -719,7 +858,6 @@ macro_rules! noop_visit_mut_type { noop_visit_mut_type!(visit_mut_ts_constructor_type, TsConstructorType); noop_visit_mut_type!(visit_mut_ts_entity_name, TsEntityName); noop_visit_mut_type!(visit_mut_ts_expr_with_type_args, TsExprWithTypeArgs); - noop_visit_mut_type!(visit_mut_ts_external_module_ref, TsExternalModuleRef); noop_visit_mut_type!(visit_mut_ts_fn_or_constructor_type, TsFnOrConstructorType); noop_visit_mut_type!(visit_mut_ts_fn_param, TsFnParam); noop_visit_mut_type!(visit_mut_ts_fn_type, TsFnType); @@ -734,7 +872,6 @@ macro_rules! noop_visit_mut_type { noop_visit_mut_type!(visit_mut_ts_keyword_type_kind, TsKeywordTypeKind); noop_visit_mut_type!(visit_mut_ts_mapped_type, TsMappedType); noop_visit_mut_type!(visit_mut_ts_method_signature, TsMethodSignature); - noop_visit_mut_type!(visit_mut_ts_module_ref, TsModuleRef); noop_visit_mut_type!(visit_mut_ts_optional_type, TsOptionalType); noop_visit_mut_type!(visit_mut_ts_parenthesized_type, TsParenthesizedType); noop_visit_mut_type!(visit_mut_ts_property_signature, TsPropertySignature); @@ -766,20 +903,33 @@ macro_rules! noop_visit_mut_type { ); noop_visit_mut_type!(visit_mut_ts_union_type, TsUnionType); }; + + ($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(); + } + }; + ($name:ident, $N:ident) => { + fn $name(&mut self, _: &mut $crate::swc_ecma_ast::$N) {} + }; } #[macro_export] macro_rules! visit_obj_and_computed { () => { - fn visit_member_expr(&mut self, n: &$crate::swc_ecma_ast::MemberExpr) { - n.obj.visit_with(self); - if let $crate::swc_ecma_ast::MemberProp::Computed(c) = &n.prop { + fn visit_member_prop(&mut self, n: &$crate::swc_ecma_ast::MemberProp) { + if let $crate::swc_ecma_ast::MemberProp::Computed(c) = n { c.visit_with(self); } } - fn visit_super_prop_expr(&mut self, n: &$crate::swc_ecma_ast::SuperPropExpr) { - if let $crate::swc_ecma_ast::SuperProp::Computed(c) = &n.prop { + fn visit_jsx_member_expr(&mut self, n: &$crate::swc_ecma_ast::JSXMemberExpr) { + n.obj.visit_with(self); + } + + fn visit_super_prop(&mut self, n: &$crate::swc_ecma_ast::SuperProp) { + if let $crate::swc_ecma_ast::SuperProp::Computed(c) = n { c.visit_with(self); } } @@ -789,15 +939,18 @@ macro_rules! visit_obj_and_computed { #[macro_export] macro_rules! visit_mut_obj_and_computed { () => { - fn visit_mut_member_expr(&mut self, n: &mut $crate::swc_ecma_ast::MemberExpr) { - n.obj.visit_mut_with(self); - if let $crate::swc_ecma_ast::MemberProp::Computed(c) = &mut n.prop { + fn visit_mut_member_prop(&mut self, n: &mut $crate::swc_ecma_ast::MemberProp) { + if let $crate::swc_ecma_ast::MemberProp::Computed(c) = n { c.visit_mut_with(self); } } - fn visit_mut_super_prop_expr(&mut self, n: &mut $crate::swc_ecma_ast::SuperPropExpr) { - if let $crate::swc_ecma_ast::SuperProp::Computed(c) = &mut n.prop { + fn visit_mut_jsx_member_expr(&mut self, n: &mut $crate::swc_ecma_ast::JSXMemberExpr) { + n.obj.visit_mut_with(self); + } + + fn visit_mut_super_prop(&mut self, n: &mut $crate::swc_ecma_ast::SuperProp) { + if let $crate::swc_ecma_ast::SuperProp::Computed(c) = n { c.visit_mut_with(self); } }