mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[rust] deny unused fields on non-node structs
Rejects unknown fields during deserialization of helper structs (which don't have a `type` field). This would be super useful for AST `Node` types, too, but that requires implementing a custom deserializer so i'm punting on that for now.
This commit is contained in:
@@ -5,17 +5,20 @@ use serde::ser::{Serializer, SerializeMap};
|
||||
use serde::{Serialize, Deserialize};
|
||||
use crate::{JsValue, Binding, SourceRange};
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct SourceLocation {
|
||||
pub source: Option<String>,
|
||||
pub start: Position,
|
||||
pub end: Position,
|
||||
}
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct Position {
|
||||
pub line: NonZeroU32,
|
||||
pub column: u32,
|
||||
}
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct Function {
|
||||
pub id: Option<Identifier>,
|
||||
pub params: Vec<Pattern>,
|
||||
@@ -32,11 +35,13 @@ pub struct Function {
|
||||
pub range: Option<SourceRange>,
|
||||
}
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct RegExpValue {
|
||||
pub pattern: String,
|
||||
pub flags: String,
|
||||
}
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct TemplateElementValue {
|
||||
pub cooked: Option<String>,
|
||||
pub raw: String,
|
||||
|
||||
@@ -90,6 +90,7 @@ impl Object {
|
||||
|
||||
quote! {
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct #name {
|
||||
#(#fields),*
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user