fn fold_pat(&mut self, mut p: Pat) -> Pat {
        p = p.fold_children_with(self);

        if self.in_lhs_of_var {
            match &mut p {
                Pat::Ident(name) => {
                    if self.should_remove(name.id.to_id()) {
                        self.state.should_run_again = true;
                        tracing::trace!(
                            "Dropping var `{}{:?}` because it should be removed",
                            name.id.sym,
                            name.id.span.ctxt
                        );

                        return Pat::Invalid(Invalid { span: DUMMY_SP });
                    }
                }
                Pat::Array(arr) => {
                    if !arr.elems.is_empty() {
                        arr.elems.retain(|e| !matches!(e, Some(Pat::Invalid(..))));

                        if arr.elems.is_empty() {
                            return Pat::Invalid(Invalid { span: DUMMY_SP });
                        }
                    }
                }
                Pat::Object(obj) => {
                    if !obj.props.is_empty() {
                        obj.props = take(&mut obj.props)
                            .into_iter()
                            .filter_map(|prop| match prop {
                                ObjectPatProp::KeyValue(prop) => {
                                    if prop.value.is_invalid() {
                                        None
                                    } else {
                                        Some(ObjectPatProp::KeyValue(prop))
                                    }
                                }
                                ObjectPatProp::Assign(prop) => {
                                    if self.should_remove(prop.key.to_id()) {
                                        self.mark_as_candidate(prop.value);

                                        None
                                    } else {
                                        Some(ObjectPatProp::Assign(prop))
                                    }
                                }
                                ObjectPatProp::Rest(prop) => {
                                    if prop.arg.is_invalid() {
                                        None
                                    } else {
                                        Some(ObjectPatProp::Rest(prop))
                                    }
                                }
                            })
                            .collect();

                        if obj.props.is_empty() {
                            return Pat::Invalid(Invalid { span: DUMMY_SP });
                        }
                    }
                }
                Pat::Rest(rest) => {
                    if rest.arg.is_invalid() {
                        return Pat::Invalid(Invalid { span: DUMMY_SP });
                    }
                }
                _ => {}
            }
        }

        p
    }
/// This methods returns [Pat::Invalid] if the pattern should be removed.
This methods returns [Pat::Invalid] if the pattern should be removed.
This methods returns [ Pat :: Invalid ] if the pattern should be removed .
fn fold_pat(&mut self, mut p: Pat) -> Pat {
        p = p.fold_children_with(self);
        if self.in_lhs_of_var {
            match &mut p {
                Pat::Ident(name) => {
                    if self.should_remove(name.id.to_id()) {
                        self.state.should_run_again = true;
                        tracing::trace!(
                            "Dropping var `{}{:?}` because it should be removed",
                            name.id.sym,
                            name.id.span.ctxt
                        );
                        return Pat::Invalid(Invalid { span: DUMMY_SP });
                    }
                }
                Pat::Array(arr) => {
                    if !arr.elems.is_empty() {
                        arr.elems.retain(|e| !matches!(e, Some(Pat::Invalid(..))));
                        if arr.elems.is_empty() {
                            return Pat::Invalid(Invalid { span: DUMMY_SP });
                        }
                    }
                }
                Pat::Object(obj) => {
                    if !obj.props.is_empty() {
                        obj.props = take(&mut obj.props)
                            .into_iter()
                            .filter_map(|prop| match prop {
                                ObjectPatProp::KeyValue(prop) => {
                                    if prop.value.is_invalid() {
                                        None
                                    } else {
                                        Some(ObjectPatProp::KeyValue(prop))
                                    }
                                }
                                ObjectPatProp::Assign(prop) => {
                                    if self.should_remove(prop.key.to_id()) {
                                        self.mark_as_candidate(prop.value);
                                        None
                                    } else {
                                        Some(ObjectPatProp::Assign(prop))
                                    }
                                }
                                ObjectPatProp::Rest(prop) => {
                                    if prop.arg.is_invalid() {
                                        None
                                    } else {
                                        Some(ObjectPatProp::Rest(prop))
                                    }
                                }
                            })
                            .collect();
                        if obj.props.is_empty() {
                            return Pat::Invalid(Invalid { span: DUMMY_SP });
                        }
                    }
                }
                Pat::Rest(rest) => {
                    if rest.arg.is_invalid() {
                        return Pat::Invalid(Invalid { span: DUMMY_SP });
                    }
                }
                _ => {}
            }
        }
        p
    }
fn fold_pat ( & mut self , mut p : Pat ) -> Pat { p = p . fold_children_with ( self ) ; if self . in_lhs_of_var { match & mut p { Pat :: Ident ( name ) => { if self . should_remove ( name . id . to_id ( ) ) { self . state . should_run_again = true ; tracing :: trace ! ( " " name id sym name id span ctxt ) ; return Pat :: Invalid ( Invalid { span : DUMMY_SP } ) ; } } Pat :: Array ( arr ) => { if ! arr . elems . is_empty ( ) { arr . elems . retain ( | e | ! matches ! ( e Some ( Pat Invalid ( ) ) ) ) ; if arr . elems . is_empty ( ) { return Pat :: Invalid ( Invalid { span : DUMMY_SP } ) ; } } } Pat :: Object ( obj ) => { if ! obj . props . is_empty ( ) { obj . props = take ( & mut obj . props ) . into_iter ( ) . filter_map ( | prop | match prop { ObjectPatProp :: KeyValue ( prop ) => { if prop . value . is_invalid ( ) { None } else { Some ( ObjectPatProp :: KeyValue ( prop ) ) } } ObjectPatProp :: Assign ( prop ) => { if self . should_remove ( prop . key . to_id ( ) ) { self . mark_as_candidate ( prop . value ) ; None } else { Some ( ObjectPatProp :: Assign ( prop ) ) } } ObjectPatProp :: Rest ( prop ) => { if prop . arg . is_invalid ( ) { None } else { Some ( ObjectPatProp :: Rest ( prop ) ) } } } ) . collect ( ) ; if obj . props . is_empty ( ) { return Pat :: Invalid ( Invalid { span : DUMMY_SP } ) ; } } } Pat :: Rest ( rest ) => { if rest . arg . is_invalid ( ) { return Pat :: Invalid ( Invalid { span : DUMMY_SP } ) ; } } _ => { } } } p }
This methods returns [Pat::Invalid] if the pattern should be removed.
This methods returns [ Pat :: Invalid ] if the pattern should be removed .
&mut self
p
Pat
&mut self
p
Pat