Skip to content

Commit 5c7ab17

Browse files
committed
wip
1 parent 1c5bec8 commit 5c7ab17

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed

crates/swc_ecma_lints/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ testing = { version = "15.0.0", path = "../testing" }
4141

4242
[features]
4343
non_critical_lints = []
44+
unknown = ["swc_ecma_ast/unknown", "swc_ecma_visit/unknown", "swc_ecma_utils/unknown"]
4445

4546

4647
[[bench]]

crates/swc_ecma_utils/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ bench = false
1818
[features]
1919
# Process in parallel.
2020
concurrent = ["swc_common/concurrent", "par-core/parallel"]
21+
unknown = ["swc_ecma_ast/unknown", "swc_ecma_visit/unknown"]
2122

2223
[dependencies]
2324
indexmap = { workspace = true }

crates/swc_ecma_utils/src/function/fn_env_hoister.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,8 @@ impl VisitMut for FnEnvHoister {
393393
e.visit_mut_children_with(self);
394394
return;
395395
}
396+
#[cfg(feature = "unknown")]
397+
_ => return,
396398
};
397399
if !self.super_disabled {
398400
if let SimpleAssignTarget::SuperProp(super_prop) = &mut *expr {
@@ -462,7 +464,9 @@ impl VisitMut for FnEnvHoister {
462464
..Default::default()
463465
}
464466
.into();
465-
}
467+
},
468+
#[cfg(feature = "unknown")]
469+
_ => ()
466470
}
467471
}
468472
}
@@ -508,6 +512,8 @@ impl VisitMut for FnEnvHoister {
508512

509513
*e = call.call_fn(*span, new_args);
510514
}
515+
#[cfg(feature = "unknown")]
516+
_ => ()
511517
}
512518
};
513519
}
@@ -559,6 +565,8 @@ impl VisitMut for FnEnvHoister {
559565
.into()
560566
};
561567
}
568+
#[cfg(feature = "unknown")]
569+
_ => ()
562570
},
563571
_ => e.visit_mut_children_with(self),
564572
}

crates/swc_ecma_utils/src/lib.rs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ impl StmtOrModuleItem for ModuleItem {
237237
match self {
238238
ModuleItem::ModuleDecl(v) => Err(v),
239239
ModuleItem::Stmt(v) => Ok(v),
240+
#[cfg(feature = "unknown")]
241+
_ => panic!("unable to access unknown nodes")
240242
}
241243
}
242244

@@ -245,6 +247,8 @@ impl StmtOrModuleItem for ModuleItem {
245247
match self {
246248
ModuleItem::ModuleDecl(v) => Err(v),
247249
ModuleItem::Stmt(v) => Ok(v),
250+
#[cfg(feature = "unknown")]
251+
_ => panic!("unable to access unknown nodes")
248252
}
249253
}
250254

@@ -253,6 +257,8 @@ impl StmtOrModuleItem for ModuleItem {
253257
match self {
254258
ModuleItem::ModuleDecl(v) => Err(v),
255259
ModuleItem::Stmt(v) => Ok(v),
260+
#[cfg(feature = "unknown")]
261+
_ => panic!("unable to access unknown nodes")
256262
}
257263
}
258264

@@ -1199,6 +1205,8 @@ impl Visit for LiteralVisitor {
11991205
}
12001206
PropName::BigInt(_) => self.is_lit = false,
12011207
PropName::Computed(..) => self.is_lit = false,
1208+
#[cfg(feature = "unknown")]
1209+
_ => (),
12021210
}
12031211
}
12041212

@@ -1260,6 +1268,8 @@ pub fn is_simple_pure_member_expr(m: &MemberExpr, pure_getters: bool) -> bool {
12601268
MemberProp::Computed(c) => {
12611269
is_simple_pure_expr(&c.expr, pure_getters) && is_simple_pure_expr(&m.obj, pure_getters)
12621270
}
1271+
#[cfg(feature = "unknown")]
1272+
_ => false
12631273
}
12641274
}
12651275

@@ -1423,6 +1433,8 @@ pub fn prop_name_to_expr(p: PropName) -> Expr {
14231433
PropName::Num(n) => Lit::Num(n).into(),
14241434
PropName::BigInt(b) => Lit::BigInt(b).into(),
14251435
PropName::Computed(c) => *c.expr,
1436+
#[cfg(feature = "unknown")]
1437+
_ => panic!("unable to access unknown nodes")
14261438
}
14271439
}
14281440
/// Similar to `prop_name_to_expr`, but used for value position.
@@ -1440,6 +1452,8 @@ pub fn prop_name_to_expr_value(p: PropName) -> Expr {
14401452
PropName::Num(n) => Lit::Num(n).into(),
14411453
PropName::BigInt(b) => Lit::BigInt(b).into(),
14421454
PropName::Computed(c) => *c.expr,
1455+
#[cfg(feature = "unknown")]
1456+
_ => panic!("unable to access unknown nodes")
14431457
}
14441458
}
14451459

@@ -1459,6 +1473,8 @@ pub fn prop_name_to_member_prop(prop_name: PropName) -> MemberProp {
14591473
span: DUMMY_SP,
14601474
expr: b.into(),
14611475
}),
1476+
#[cfg(feature = "unknown")]
1477+
_ => panic!("unable to access unknown nodes")
14621478
}
14631479
}
14641480

@@ -1930,11 +1946,15 @@ impl ExprCtx {
19301946
Prop::Assign(..) => {
19311947
unreachable!("assign property in object literal is not a valid syntax")
19321948
}
1949+
#[cfg(feature = "unknown")]
1950+
_ => true,
19331951
},
19341952
PropOrSpread::Spread(SpreadElement { .. }) => {
19351953
has_spread = true;
19361954
true
1937-
}
1955+
},
1956+
#[cfg(feature = "unknown")]
1957+
_ => true,
19381958
});
19391959

19401960
if has_spread {
@@ -1962,6 +1982,8 @@ impl ExprCtx {
19621982
"assign property in object literal is not a valid syntax"
19631983
)
19641984
}
1985+
#[cfg(feature = "unknown")]
1986+
_ => panic!("unable to access unknown nodes")
19651987
},
19661988
_ => unreachable!(),
19671989
})
@@ -2007,6 +2029,8 @@ impl ExprCtx {
20072029
Expr::OptChain(..) => to.push(Box::new(expr)),
20082030

20092031
Expr::Invalid(..) => unreachable!(),
2032+
#[cfg(feature = "unknown")]
2033+
_ => to.push(Box::new(expr)),
20102034
}
20112035
}
20122036
}
@@ -2021,6 +2045,8 @@ pub fn prop_name_eq(p: &PropName, key: &str) -> bool {
20212045
Expr::Lit(Lit::Str(Str { value, .. })) => *value == *key,
20222046
_ => false,
20232047
},
2048+
#[cfg(feature = "unknown")]
2049+
_ => false,
20242050
}
20252051
}
20262052

@@ -2364,6 +2390,8 @@ impl VisitMut for IdentRenamer<'_> {
23642390
}
23652391
}
23662392
ModuleExportName::Str(_) => {}
2393+
#[cfg(feature = "unknown")]
2394+
_ => {},
23672395
}
23682396
}
23692397

@@ -2515,6 +2543,8 @@ where
25152543
JSXElementName::Ident(ident) => ident.into(),
25162544
JSXElementName::JSXMemberExpr(expr) => Box::new(expr).into(),
25172545
JSXElementName::JSXNamespacedName(..) => unimplemented!(),
2546+
#[cfg(feature = "unknown")]
2547+
_ => return,
25182548
}
25192549
}
25202550
}
@@ -2949,6 +2979,8 @@ fn cast_to_bool(expr: &Expr, ctx: ExprCtx) -> (Purity, BoolValue) {
29492979
Lit::Null(..) => false,
29502980
Lit::Regex(..) => true,
29512981
Lit::JSXText(..) => unreachable!("as_bool() for JSXText"),
2982+
#[cfg(feature = "unknown")]
2983+
_ => return (Pure, Unknown),
29522984
}),
29532985
);
29542986
}
@@ -3506,6 +3538,8 @@ fn may_have_side_effects(expr: &Expr, ctx: ExprCtx) -> bool {
35063538
}) => true,
35073539
_ => false,
35083540
},
3541+
#[cfg(feature = "unknown")]
3542+
_ => true,
35093543
};
35103544
if obj.props.iter().any(can_have_side_effect) {
35113545
return true;
@@ -3517,6 +3551,8 @@ fn may_have_side_effects(expr: &Expr, ctx: ExprCtx) -> bool {
35173551
match prop {
35183552
MemberProp::Computed(c) => c.expr.may_have_side_effects(ctx),
35193553
MemberProp::Ident(_) | MemberProp::PrivateName(_) => false,
3554+
#[cfg(feature = "unknown")]
3555+
_ => true,
35203556
}
35213557
}
35223558

@@ -3590,9 +3626,13 @@ fn may_have_side_effects(expr: &Expr, ctx: ExprCtx) -> bool {
35903626
_ => false,
35913627
},
35923628
Prop::Assign(_) => true,
3629+
#[cfg(feature = "unknown")]
3630+
_ => true,
35933631
},
35943632
// may trigger getter
35953633
PropOrSpread::Spread(_) => true,
3634+
#[cfg(feature = "unknown")]
3635+
_ => true,
35963636
}),
35973637

35983638
Expr::JSXMember(..)
@@ -3608,6 +3648,8 @@ fn may_have_side_effects(expr: &Expr, ctx: ExprCtx) -> bool {
36083648
| Expr::TsSatisfies(TsSatisfiesExpr { ref expr, .. }) => expr.may_have_side_effects(ctx),
36093649

36103650
Expr::Invalid(..) => true,
3651+
#[cfg(feature = "unknown")]
3652+
_ => true,
36113653
}
36123654
}
36133655

0 commit comments

Comments
 (0)