mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
feat(prettier): format for((let) of .. (#1429)
This commit is contained in:
parent
3c567d6549
commit
18fa8e45a4
2 changed files with 40 additions and 6 deletions
|
|
@ -243,7 +243,45 @@ impl<'a> Format<'a> for ForOfStatement<'a> {
|
|||
parts.push(ss!(" await"));
|
||||
}
|
||||
parts.push(ss!(" ("));
|
||||
parts.push(format!(p, self.left));
|
||||
|
||||
// for ((async) of []);
|
||||
// for ((let) of []);
|
||||
// for ((let.a) of []);
|
||||
let mut should_hug = false;
|
||||
if let ForStatementLeft::AssignmentTarget(AssignmentTarget::SimpleAssignmentTarget(
|
||||
target,
|
||||
)) = &self.left
|
||||
{
|
||||
if let SimpleAssignmentTarget::AssignmentTargetIdentifier(ident) = target {
|
||||
if ident.name == "let" {
|
||||
should_hug = true;
|
||||
}
|
||||
if ident.name == "async" && !self.r#await {
|
||||
should_hug = true;
|
||||
}
|
||||
}
|
||||
if let SimpleAssignmentTarget::MemberAssignmentTarget(member_expr) = target {
|
||||
let object = match &**member_expr {
|
||||
MemberExpression::ComputedMemberExpression(e) => Some(&e.object),
|
||||
MemberExpression::StaticMemberExpression(e) => Some(&e.object),
|
||||
MemberExpression::PrivateFieldExpression(e) => None,
|
||||
};
|
||||
if let Some(Expression::Identifier(ident)) = object {
|
||||
if ident.name == "let" {
|
||||
should_hug = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if should_hug {
|
||||
parts.push(ss!("("));
|
||||
parts.push(format!(p, self.left));
|
||||
parts.push(ss!(")"));
|
||||
} else {
|
||||
parts.push(format!(p, self.left));
|
||||
}
|
||||
|
||||
parts.push(ss!(" of "));
|
||||
parts.push(format!(p, self.right));
|
||||
parts.push(ss!(")"));
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
Compatibility: 119/838 (14.20%)
|
||||
Compatibility: 121/838 (14.44%)
|
||||
|
||||
# Failed
|
||||
|
||||
|
|
@ -476,9 +476,6 @@ Compatibility: 119/838 (14.20%)
|
|||
### for-await
|
||||
* for-await/for-await.js
|
||||
|
||||
### for-of
|
||||
* for-of/async-identifier.js
|
||||
|
||||
### function
|
||||
* function/function_expression.js
|
||||
* function/issue-10277.js
|
||||
|
|
@ -514,7 +511,6 @@ Compatibility: 119/838 (14.20%)
|
|||
* generator/function-name-starts-with-get.js
|
||||
|
||||
### identifier/for-of
|
||||
* identifier/for-of/await.js
|
||||
* identifier/for-of/let.js
|
||||
|
||||
### identifier/parentheses
|
||||
|
|
|
|||
Loading…
Reference in a new issue