Skip to content

Commit

Permalink
Code style
Browse files Browse the repository at this point in the history
  • Loading branch information
hyf0 committed Nov 19, 2022
1 parent 4952c38 commit 952af6e
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions crates/swc_ecma_utils/src/lib.rs
Expand Up @@ -1376,21 +1376,31 @@ pub trait ExprExt {
}
Expr::Object(obj) => {
let can_have_side_effect = |prop: &PropOrSpread| match prop {
PropOrSpread::Spread(_) => true,
PropOrSpread::Prop(prop) => match prop.as_ref() {
Prop::Shorthand(i) => i.sym == js_word!("__proto__"),
Prop::KeyValue(KeyValueProp { key, .. }) => match key {
PropName::Ident(i) => i.sym == js_word!("__proto__"),
PropName::Str(s) => s.value == js_word!("__proto__"),
PropName::Computed(_) => true,
PropOrSpread::Spread(_) | PropOrSpread::Prop(prop) => {
match prop.as_ref() {
Prop::Getter(_)
| Prop::Setter(_)
| Prop::Method(_)
| Prop::Shorthand(Ident {
sym: js_word!("__proto__"),
..
})
| Prop::KeyValue(KeyValueProp {
key:
PropName::Ident(Ident {
sym: js_word!("__proto__"),
..
})
| PropName::Str(Str {
value: js_word!("__proto__"),
..
})
| PropName::Computed(_),
..
}) => true,
_ => false,
},
Prop::Getter(..) | Prop::Setter(..) => true,
Prop::Method(_) => true,
Prop::Assign(_) => {
unreachable!("This is **invalid** for object literal")
}
},
}
};
if obj.props.iter().any(can_have_side_effect) {
return true;
Expand Down

0 comments on commit 952af6e

Please sign in to comment.