Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

feat(rome_js_parser, rome_js_formatter): support using and await using declaration #4737

Merged
merged 11 commits into from
Aug 7, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ impl Rule for UseSingleVarDeclarator {
semicolon_token,
} = node.as_fields();

let JsVariableDeclarationFields { kind, declarators } = declaration.ok()?.as_fields();
let JsVariableDeclarationFields {
await_token: _,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this token should be added to the rule’s state, so it can be preserved in the fixer action. I had actually made this change here: main...arendjr:rome-tools:using-proposal#diff-b62c2afc841e799795a6707e4bcdf0f415da3b3183303b3a8507d844f546d455R41

Copy link
Contributor Author

@nissy-dev nissy-dev Aug 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pointing! I will create a separate PR for some fixes in Linter.

kind,
declarators,
} = declaration.ok()?.as_fields();

let kind = kind.ok()?;

Expand Down Expand Up @@ -194,10 +198,13 @@ impl Rule for UseSingleVarDeclarator {
)
};

let mut builder = make::js_variable_statement(make::js_variable_declaration(
kind,
make::js_variable_declarator_list([declarator], []),
));
let mut builder = make::js_variable_statement(
make::js_variable_declaration(
kind,
make::js_variable_declarator_list([declarator], []),
)
.build(),
);

let semicolon_token = if index + 1 == declarators_len {
last_semicolon_token
Expand Down
70 changes: 54 additions & 16 deletions crates/rome_js_factory/src/generated/node_factory.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 18 additions & 4 deletions crates/rome_js_factory/src/generated/syntax_factory.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,31 @@ pub(crate) struct FormatJsForVariableDeclaration;
impl FormatNodeRule<JsForVariableDeclaration> for FormatJsForVariableDeclaration {
fn fmt_fields(&self, node: &JsForVariableDeclaration, f: &mut JsFormatter) -> FormatResult<()> {
let JsForVariableDeclarationFields {
await_token,
kind_token,
declarator,
} = node.as_fields();

write![
f,
[group(&format_args![
kind_token.format(),
space(),
declarator.format()
])]
]
if let Some(await_token) = await_token {
write![
f,
[group(&format_args![
await_token.format(),
space(),
kind_token.format(),
space(),
declarator.format()
])]
]
} else {
write![
f,
[group(&format_args![
kind_token.format(),
space(),
declarator.format()
])]
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,32 @@ pub(crate) struct FormatJsVariableDeclaration;

impl FormatNodeRule<JsVariableDeclaration> for FormatJsVariableDeclaration {
fn fmt_fields(&self, node: &JsVariableDeclaration, f: &mut JsFormatter) -> FormatResult<()> {
let JsVariableDeclarationFields { kind, declarators } = node.as_fields();
let JsVariableDeclarationFields {
await_token,
kind,
declarators,
} = node.as_fields();

write!(
f,
[group(&format_args![
kind.format(),
space(),
declarators.format()
])]
)
if let Some(await_token) = await_token {
write![
f,
[group(&format_args![
await_token.format(),
space(),
kind.format(),
space(),
declarators.format()
])]
]
} else {
write![
f,
[group(&format_args![
kind.format(),
space(),
declarators.format()
])]
]
}
}
}

This file was deleted.

Loading
Loading