fn validate_custom(ctx: &Context, node: NodePtr) -> Result<(), ValidationError> {
    match &node.get(ctx) {
        Node::MemberExpression(MemberExpression {
            range: _,
            property,
            object: _,
            computed,
        })
        | Node::OptionalMemberExpression(OptionalMemberExpression {
            range: _,
            property,
            object: _,
            computed,
            optional: _,
        }) => {
            if *computed {
                property.validate_child(ctx, node, &[NodeVariant::Expression])?;
            } else {
                property.validate_child(ctx, node, &[NodeVariant::Identifier])?;
            }
        }

        Node::Property(Property {
            range: _,
            key,
            value,
            kind,
            computed,
            method,
            shorthand,
        }) => {
            if *computed && *shorthand {
                return Err(ValidationError {
                    node,
                    message: "Property cannot be computed and shorthand".to_string(),
                });
            }
            if !*computed {
                key.validate_child(ctx, node, &[NodeVariant::Identifier, NodeVariant::Literal])?;
            }
            if *method {
                value.validate_child(ctx, node, &[NodeVariant::FunctionExpression])?;
            }
            if *kind == PropertyKind::Get || *kind == PropertyKind::Set {
                value.validate_child(ctx, node, &[NodeVariant::FunctionExpression])?;
            }
        }

        _ => {}
    }
    Ok(())
}
/// Custom validation function for constraints which can't be expressed
/// using just the inheritance structure in Node.
Custom validation function for constraints which can't be expressed
using just the inheritance structure in Node.
Custom validation function for constraints which can ' t be expressed using just the inheritance structure in Node .
fn validate_custom(ctx: &Context, node: NodePtr) -> Result<(), ValidationError> {
    match &node.get(ctx) {
        Node::MemberExpression(MemberExpression {
            range: _,
            property,
            object: _,
            computed,
        })
        | Node::OptionalMemberExpression(OptionalMemberExpression {
            range: _,
            property,
            object: _,
            computed,
            optional: _,
        }) => {
            if *computed {
                property.validate_child(ctx, node, &[NodeVariant::Expression])?;
            } else {
                property.validate_child(ctx, node, &[NodeVariant::Identifier])?;
            }
        }
        Node::Property(Property {
            range: _,
            key,
            value,
            kind,
            computed,
            method,
            shorthand,
        }) => {
            if *computed && *shorthand {
                return Err(ValidationError {
                    node,
                    message: "Property cannot be computed and shorthand".to_string(),
                });
            }
            if !*computed {
                key.validate_child(ctx, node, &[NodeVariant::Identifier, NodeVariant::Literal])?;
            }
            if *method {
                value.validate_child(ctx, node, &[NodeVariant::FunctionExpression])?;
            }
            if *kind == PropertyKind::Get || *kind == PropertyKind::Set {
                value.validate_child(ctx, node, &[NodeVariant::FunctionExpression])?;
            }
        }
        _ => {}
    }
    Ok(())
}
fn validate_custom ( ctx : & Context , node : NodePtr ) -> Result < ( ) , ValidationError > { match & node . get ( ctx ) { Node :: MemberExpression ( MemberExpression { range : _ , property , object : _ , computed , } ) | Node :: OptionalMemberExpression ( OptionalMemberExpression { range : _ , property , object : _ , computed , optional : _ , } ) => { if * computed { property . validate_child ( ctx , node , & [ NodeVariant :: Expression ] ) ? ; } else { property . validate_child ( ctx , node , & [ NodeVariant :: Identifier ] ) ? ; } } Node :: Property ( Property { range : _ , key , value , kind , computed , method , shorthand , } ) => { if * computed && * shorthand { return Err ( ValidationError { node , message : " " . to_string ( ) , } ) ; } if ! * computed { key . validate_child ( ctx , node , & [ NodeVariant :: Identifier , NodeVariant :: Literal ] ) ? ; } if * method { value . validate_child ( ctx , node , & [ NodeVariant :: FunctionExpression ] ) ? ; } if * kind == PropertyKind :: Get || * kind == PropertyKind :: Set { value . validate_child ( ctx , node , & [ NodeVariant :: FunctionExpression ] ) ? ; } } _ => { } } Ok ( ( ) ) }
Custom validation function for constraints which can't be expressed
using just the inheritance structure in Node.
Custom validation function for constraints which can ' t be expressed using just the inheritance structure in Node .
ctx
&Context
node
NodePtr
ctx
&Context
node
NodePtr