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
16 changes: 6 additions & 10 deletions crates/oxc_formatter/src/write/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1477,27 +1477,23 @@ impl<'a> Format<'a> for FormatTSSignature<'a, '_> {
}
}
Semicolons::AsNeeded => {
let TSSignature::TSPropertySignature(property) = self.signature.as_ref() else {
return;
};

let has_no_type_annotation = property.type_annotation.is_none();

// Needs semicolon anyway when:
// 1. It's a non-computed property signature with type annotation followed by
// a call signature that has type parameters
// e.g for: `a: string; <T>() => void`
// 2. It's a non-computed property signature without type annotation followed by
// a call signature or method signature
// e.g for: `a; () => void` or `a; method(): void`
let needs_semicolon = !property.computed
let needs_semicolon = matches!(
self.signature.as_ref(), TSSignature::TSPropertySignature(property) if !property.computed
&& self.next_signature.is_some_and(|signature| match signature.as_ref() {
TSSignature::TSCallSignatureDeclaration(call) => {
has_no_type_annotation || call.type_parameters.is_some()
property.type_annotation.is_none() || call.type_parameters.is_some()
}
TSSignature::TSMethodSignature(_) => has_no_type_annotation,
TSSignature::TSMethodSignature(_) => property.type_annotation.is_none(),
_ => false,
});
})
);

if needs_semicolon {
write!(f, [";"]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ export interface MethodSignatures {
(arg: string): void;
(arg: number): null;
}

export type MethodSignaturesAndPropertyOnSameLine =
| { json(): never; ok: false }
| { json(): Promise<any>; ok: true }
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export interface MethodSignatures {
(arg: number): null;
}

export type MethodSignaturesAndPropertyOnSameLine =
| { json(): never; ok: false }
| { json(): Promise<any>; ok: true }

==================== Output ====================
-------------------------------
{ printWidth: 80, semi: false }
Expand All @@ -16,6 +20,10 @@ export interface MethodSignatures {
(arg: number): null
}

export type MethodSignaturesAndPropertyOnSameLine =
| { json(): never; ok: false }
| { json(): Promise<any>; ok: true }

--------------------------------
{ printWidth: 100, semi: false }
--------------------------------
Expand All @@ -24,6 +32,10 @@ export interface MethodSignatures {
(arg: number): null
}

export type MethodSignaturesAndPropertyOnSameLine =
| { json(): never; ok: false }
| { json(): Promise<any>; ok: true }

------------------------------
{ printWidth: 80, semi: true }
------------------------------
Expand All @@ -32,6 +44,10 @@ export interface MethodSignatures {
(arg: number): null;
}

export type MethodSignaturesAndPropertyOnSameLine =
| { json(): never; ok: false }
| { json(): Promise<any>; ok: true };

-------------------------------
{ printWidth: 100, semi: true }
-------------------------------
Expand All @@ -40,4 +56,8 @@ export interface MethodSignatures {
(arg: number): null;
}

export type MethodSignaturesAndPropertyOnSameLine =
| { json(): never; ok: false }
| { json(): Promise<any>; ok: true };

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