mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
feat(prettier): transform expression to identifier in PropertyKey (#1398)
This commit is contained in:
parent
fb7cdc6687
commit
75eb708526
2 changed files with 16 additions and 4 deletions
|
|
@ -1305,7 +1305,21 @@ impl<'a> Format<'a> for PropertyKey<'a> {
|
|||
match self {
|
||||
PropertyKey::Identifier(ident) => ident.format(p),
|
||||
PropertyKey::PrivateIdentifier(ident) => ident.format(p),
|
||||
PropertyKey::Expression(expr) => expr.format(p),
|
||||
PropertyKey::Expression(expr) => match expr {
|
||||
Expression::StringLiteral(literal) => {
|
||||
let expr = format!(p, literal);
|
||||
let value = literal.value.as_bytes();
|
||||
if !&value[0].is_ascii_digit() && !value.contains(&b'_') {
|
||||
p.str(&literal.value)
|
||||
} else {
|
||||
literal.format(p)
|
||||
}
|
||||
}
|
||||
Expression::Identifier(ident) => {
|
||||
array!(p, ss!("["), ident.format(p), ss!("]"))
|
||||
}
|
||||
_ => expr.format(p),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
Compatibility: 81/881 (9.19%)
|
||||
Compatibility: 83/881 (9.42%)
|
||||
|
||||
# Failed
|
||||
|
||||
|
|
@ -803,7 +803,6 @@ Compatibility: 81/881 (9.19%)
|
|||
|
||||
### object-prop-break-in
|
||||
* object-prop-break-in/comment.js
|
||||
* object-prop-break-in/long-value.js
|
||||
* object-prop-break-in/short-keys.js
|
||||
* object-prop-break-in/test.js
|
||||
|
||||
|
|
@ -1076,7 +1075,6 @@ Compatibility: 81/881 (9.19%)
|
|||
|
||||
### unicode
|
||||
* unicode/combining-characters.js
|
||||
* unicode/keys.js
|
||||
* unicode/nbsp-jsx.js
|
||||
|
||||
### update-expression
|
||||
|
|
|
|||
Loading…
Reference in a new issue