Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ impl<'a, 'b> SimpleArgument<'a, 'b> {
Self::from(&computed_expression.expression).is_simple_impl(depth)
&& Self::from(&computed_expression.object).is_simple_impl(depth)
}
// In Prettier's default `typescript` parser (typescript-estree) AST,
// `this.#v` is a `MemberExpression` with a `PrivateIdentifier` property.
// In oxc's AST, it's a separate type.
// The private field name is always simple, so only check the object.
// https://github.com/prettier/prettier/blob/093745f0ec429d3db47c1edd823357e0ef24e226/src/language-js/utilities/index.js#L643-L648
Expression::PrivateFieldExpression(private_field) => {
Self::from(&private_field.object).is_simple_impl(depth)
}
Expression::NewExpression(expr) => {
Self::is_simple_call_like(&expr.callee, &expr.arguments, depth)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Private field access should not force multi-line call arguments
class Foo {
#t: NodeJS.Timeout | undefined = undefined;
#v: number;

constructor(v: number) {
this.#v = v;
}

start() {
this.#t = setInterval(() => {
console.log();
}, this.#v);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
source: crates/oxc_formatter/tests/fixtures/mod.rs
---
==================== Input ====================
// Private field access should not force multi-line call arguments
class Foo {
#t: NodeJS.Timeout | undefined = undefined;
#v: number;

constructor(v: number) {
this.#v = v;
}

start() {
this.#t = setInterval(() => {
console.log();
}, this.#v);
}
}

==================== Output ====================
------------------
{ printWidth: 80 }
------------------
// Private field access should not force multi-line call arguments
class Foo {
#t: NodeJS.Timeout | undefined = undefined;
#v: number;

constructor(v: number) {
this.#v = v;
}

start() {
this.#t = setInterval(() => {
console.log();
}, this.#v);
}
}

-------------------
{ printWidth: 100 }
-------------------
// Private field access should not force multi-line call arguments
class Foo {
#t: NodeJS.Timeout | undefined = undefined;
#v: number;

constructor(v: number) {
this.#v = v;
}

start() {
this.#t = setInterval(() => {
console.log();
}, this.#v);
}
}

===================== End =====================
Loading