feat(rome_js_syntax): Node factories for unknown nodes
MODIFY
crates/rome_css_factory/src/generated/node_factory.rs
crates/rome_css_factory/src/generated/node_factory.rs
@@ -812,3 +812,10 @@ where
}),
))
}
+pub fn css_unknown<I>(slots: I) -> CssUnknown
+where
+ I: IntoIterator<Item = Option<SyntaxElement>>,
+ I::IntoIter: ExactSizeIterator,
+{
+ CssUnknown::unwrap_cast(SyntaxNode::new_detached(CssSyntaxKind::CSS_UNKNOWN, slots))
+}

MODIFY
crates/rome_js_factory/src/generated/node_factory.rs
crates/rome_js_factory/src/generated/node_factory.rs
@@ -6807,3 +6807,90 @@ where
}),
))
}
+pub fn js_unknown<I>(slots: I) -> JsUnknown
+where
+ I: IntoIterator<Item = Option<SyntaxElement>>,
+ I::IntoIter: ExactSizeIterator,
+{
+ JsUnknown::unwrap_cast(SyntaxNode::new_detached(JsSyntaxKind::JS_UNKNOWN, slots))
+}
+pub fn js_unknown_assignment<I>(slots: I) -> JsUnknownAssignment
+where
+ I: IntoIterator<Item = Option<SyntaxElement>>,
+ I::IntoIter: ExactSizeIterator,
+{
+ JsUnknownAssignment::unwrap_cast(SyntaxNode::new_detached(
+ JsSyntaxKind::JS_UNKNOWN_ASSIGNMENT,
+ slots,
+ ))
+}
+pub fn js_unknown_binding<I>(slots: I) -> JsUnknownBinding
+where
+ I: IntoIterator<Item = Option<SyntaxElement>>,
+ I::IntoIter: ExactSizeIterator,
+{
+ JsUnknownBinding::unwrap_cast(SyntaxNode::new_detached(
+ JsSyntaxKind::JS_UNKNOWN_BINDING,
+ slots,
+ ))
+}
+pub fn js_unknown_expression<I>(slots: I) -> JsUnknownExpression
+where
+ I: IntoIterator<Item = Option<SyntaxElement>>,
+ I::IntoIter: ExactSizeIterator,
+{
+ JsUnknownExpression::unwrap_cast(SyntaxNode::new_detached(
+ JsSyntaxKind::JS_UNKNOWN_EXPRESSION,
+ slots,
+ ))
+}
+pub fn js_unknown_import_assertion_entry<I>(slots: I) -> JsUnknownImportAssertionEntry
+where
+ I: IntoIterator<Item = Option<SyntaxElement>>,
+ I::IntoIter: ExactSizeIterator,
+{
+ JsUnknownImportAssertionEntry::unwrap_cast(SyntaxNode::new_detached(
+ JsSyntaxKind::JS_UNKNOWN_IMPORT_ASSERTION_ENTRY,
+ slots,
+ ))
+}
+pub fn js_unknown_member<I>(slots: I) -> JsUnknownMember
+where
+ I: IntoIterator<Item = Option<SyntaxElement>>,
+ I::IntoIter: ExactSizeIterator,
+{
+ JsUnknownMember::unwrap_cast(SyntaxNode::new_detached(
+ JsSyntaxKind::JS_UNKNOWN_MEMBER,
+ slots,
+ ))
+}
+pub fn js_unknown_named_import_specifier<I>(slots: I) -> JsUnknownNamedImportSpecifier
+where
+ I: IntoIterator<Item = Option<SyntaxElement>>,
+ I::IntoIter: ExactSizeIterator,
+{
+ JsUnknownNamedImportSpecifier::unwrap_cast(SyntaxNode::new_detached(
+ JsSyntaxKind::JS_UNKNOWN_NAMED_IMPORT_SPECIFIER,
+ slots,
+ ))
+}
+pub fn js_unknown_parameter<I>(slots: I) -> JsUnknownParameter
+where
+ I: IntoIterator<Item = Option<SyntaxElement>>,
+ I::IntoIter: ExactSizeIterator,
+{
+ JsUnknownParameter::unwrap_cast(SyntaxNode::new_detached(
+ JsSyntaxKind::JS_UNKNOWN_PARAMETER,
+ slots,
+ ))
+}
+pub fn js_unknown_statement<I>(slots: I) -> JsUnknownStatement
+where
+ I: IntoIterator<Item = Option<SyntaxElement>>,
+ I::IntoIter: ExactSizeIterator,
+{
+ JsUnknownStatement::unwrap_cast(SyntaxNode::new_detached(
+ JsSyntaxKind::JS_UNKNOWN_STATEMENT,
+ slots,
+ ))
+}

MODIFY
crates/rome_json_factory/src/generated/node_factory.rs
crates/rome_json_factory/src/generated/node_factory.rs
@@ -150,3 +150,13 @@ where
}),
))
}
+pub fn json_unknown<I>(slots: I) -> JsonUnknown
+where
+ I: IntoIterator<Item = Option<SyntaxElement>>,
+ I::IntoIter: ExactSizeIterator,
+{
+ JsonUnknown::unwrap_cast(SyntaxNode::new_detached(
+ JsonSyntaxKind::JSON_UNKNOWN,
+ slots,
+ ))
+}

MODIFY
xtask/codegen/src/generate_node_factory.rs
xtask/codegen/src/generate_node_factory.rs
@@ -184,6 +184,25 @@ pub fn generate_node_factory(ast: &AstSrc, language_kind: LanguageKind) -> Resul
}
});
+ let unknowns = ast.unknowns.iter().map(|name| {
+ let unknown_name = format_ident!("{}", name);
+ let kind = format_ident!("{}", to_upper_snake_case(name));
+ let factory_name = format_ident!("{}", to_lower_snake_case(name));
+
+ quote! {
+ pub fn #factory_name<I>(slots: I) -> #unknown_name
+ where
+ I: IntoIterator<Item = Option<SyntaxElement>>,
+ I::IntoIter: ExactSizeIterator,
+ {
+ #unknown_name::unwrap_cast(SyntaxNode::new_detached(
+ #syntax_kind::#kind,
+ slots
+ ))
+ }
+ }
+ });
+
let output = quote! {
#![allow(clippy::redundant_closure)]
#![allow(clippy::too_many_arguments)]
@@ -192,6 +211,7 @@ pub fn generate_node_factory(ast: &AstSrc, language_kind: LanguageKind) -> Resul
#(#nodes)*
#(#lists)*
+ #(#unknowns)*
};
let pretty = xtask::reformat(output)?;

feat(rome_js_syntax): Node factories for unknown nodes (#3033)