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

Commit

Permalink
feat(rome_js_parser, rome_js_formatter): support using and `await u…
Browse files Browse the repository at this point in the history
…sing` declaration (#4737)

* feat: update CST defination

* feat: support using and await using declaration for parser

* feat: support using declaration for formatter

* fix regression

* update snapshot

* fix: update parser logic with reference to ecma spec

* fix: update parser logic to pass more prettier tests

* fix: update comments

* fix: update logic
  • Loading branch information
nissy-dev authored Aug 7, 2023
1 parent 222968c commit d25b06d
Show file tree
Hide file tree
Showing 174 changed files with 3,986 additions and 2,567 deletions.
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: _,
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

0 comments on commit d25b06d

Please sign in to comment.