-
-
Notifications
You must be signed in to change notification settings - Fork 538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove span
field from BindingPattern
#3900
Comments
@rzvxa Rather than hard-coding logic into codegen for this, could we add a i.e. remove the pub struct BindingPattern<'a> {
#[span] // Get `span` from `kind`
pub kind: BindingPatternKind<'a>,
pub type_annotation: Option<Box<'a, TSTypeAnnotation<'a>>>,
pub optional: bool,
} I think it's ideal if the codegen contains as little "special case" logic as possible - better in my view if the AST types themselves are the single source of truth, and the codegen just acts on this information. #3882 (if it's merged) adds ability to introduce extra attributes on types for passing information to the codegen - just add |
So what would it look like? something like this: #[visited_node]
#[derive(Debug, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[cfg_attr(feature = "serialize", serde(rename_all = "camelCase"))]
pub struct BindingPattern<'a> {
// serde(flatten) the attributes because estree has no `BindingPattern`
#[cfg_attr(feature = "serialize", serde(flatten))]
#[cfg_attr(
feature = "serialize",
tsify(type = "(BindingIdentifier | ObjectPattern | ArrayPattern | AssignmentPattern)")
)]
#[span]
pub kind: BindingPatternKind<'a>,
pub type_annotation: Option<Box<'a, TSTypeAnnotation<'a>>>,
pub optional: bool,
} |
Yes, exactly like that. |
Orthogonal to this, but we can also add #[visited_node]
#[derive(Debug, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(rename_all = "camelCase")]
pub struct BindingPattern<'a> {
// serde(flatten) the attributes because estree has no `BindingPattern`
#[serde(flatten)]
#[tsify(type = "(BindingIdentifier | ObjectPattern | ArrayPattern | AssignmentPattern)")]
#[span]
pub kind: BindingPatternKind<'a>,
pub type_annotation: Option<Box<'a, TSTypeAnnotation<'a>>>,
pub optional: bool,
} |
Then I think it is time we rename the #[ast_node(
visitable,
scope(ScopeFlags::Top),
strict_if(self.source_type.is_strict() || self.directives.iter().any(Directive::is_use_strict))
)]
#[derive(Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))]
pub struct Program<'a> {
#[cfg_attr(feature = "serialize", serde(flatten))]
pub span: Span,
pub source_type: SourceType,
pub directives: Vec<'a, Directive<'a>>,
pub hashbang: Option<Hashbang<'a>>,
pub body: Vec<'a, Statement<'a>>,
pub scope_id: Cell<Option<ScopeId>>,
} I mean if we want to have some nodes that are visitable and some that aren't, This is the way to go. |
Yes, I tend to agree with you. As as style nit, I'd prefer if we bust out scope-related stuff in // Before
#[ast_node(
visitable,
scope(ScopeFlags::Top),
strict_if(self.source_type.is_strict() || self.directives.iter().any(Directive::is_use_strict))
)] // After
#[ast_node(visit)]
#[scope(
flags(ScopeFlags::Top)),
strict_if(self.source_type.is_strict() || self.directives.iter().any(Directive::is_use_strict)),
)] NB: I have avoided using the name |
Closed by #3899. |
#3855 added a
span
field toBindingPattern
. There's good reason for doing this - simplifying codegen-ingGetSpan
impls. But it's not ideal as it's duplicate information (BindingPatternKind
already has a span) and requires keeping the 2 in sync if you changeBindingPatternKind
in a transform.Once
GetSpan
codegen is merged, see if can find another way, and remove this field again.The text was updated successfully, but these errors were encountered: