Skip to content

Commit 0928a19

Browse files
fix(codegen): Emit this parameters of class methods (#8834)
Co-authored-by: MichaelMitchell-at <=>
1 parent 5788ac0 commit 0928a19

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

crates/oxc_codegen/src/gen.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -767,8 +767,8 @@ impl Gen for Function<'_> {
767767
this_param.print(p, ctx);
768768
if !self.params.is_empty() || self.params.rest.is_some() {
769769
p.print_str(",");
770+
p.print_soft_space();
770771
}
771-
p.print_soft_space();
772772
}
773773
self.params.print(p, ctx);
774774
p.print_ascii_byte(b')');
@@ -2675,6 +2675,13 @@ impl Gen for MethodDefinition<'_> {
26752675
type_parameters.print(p, ctx);
26762676
}
26772677
p.print_ascii_byte(b'(');
2678+
if let Some(this_param) = &self.value.this_param {
2679+
this_param.print(p, ctx);
2680+
if !self.value.params.is_empty() || self.value.params.rest.is_some() {
2681+
p.print_str(",");
2682+
p.print_soft_space();
2683+
}
2684+
}
26782685
self.value.params.print(p, ctx);
26792686
p.print_ascii_byte(b')');
26802687
if let Some(return_type) = &self.value.return_type {
@@ -3365,8 +3372,8 @@ impl Gen for TSFunctionType<'_> {
33653372
this_param.print(p, ctx);
33663373
if !self.params.is_empty() || self.params.rest.is_some() {
33673374
p.print_str(",");
3375+
p.print_soft_space();
33683376
}
3369-
p.print_soft_space();
33703377
}
33713378
self.params.print(p, ctx);
33723379
p.print_str(")");
@@ -3401,8 +3408,8 @@ impl Gen for TSSignature<'_> {
34013408
this_param.print(p, ctx);
34023409
if !signature.params.is_empty() || signature.params.rest.is_some() {
34033410
p.print_str(",");
3411+
p.print_soft_space();
34043412
}
3405-
p.print_soft_space();
34063413
}
34073414
signature.params.print(p, ctx);
34083415
p.print_str(")");
@@ -3460,8 +3467,8 @@ impl Gen for TSSignature<'_> {
34603467
this_param.print(p, ctx);
34613468
if !signature.params.is_empty() || signature.params.rest.is_some() {
34623469
p.print_str(",");
3470+
p.print_soft_space();
34633471
}
3464-
p.print_soft_space();
34653472
}
34663473
signature.params.print(p, ctx);
34673474
p.print_str(")");

crates/oxc_isolated_declarations/tests/fixtures/eliminate-imports.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { AExtend, BExtend, Type, CImplements1, CImplements2, CType, ThisType1, ThisType2, Unused } from 'mod';
1+
import { AExtend, BExtend, Type, CImplements1, CImplements2, CType, ThisType1, ThisType2, ThisType3, Unused } from 'mod';
22

33
export interface A extends AExtend<Type> {}
44
export class B extends BExtend<Type> {}
55
export class C implements CImplements1<CType>, CImplements2<CType> {}
6-
export function foo(this: ThisType1): void {}
7-
export const bar: (this: ThisType2) => void = function() {}
6+
export class D { method(this: ThisType1): void { } }
7+
export function foo(this: ThisType2): void {}
8+
export const bar: (this: ThisType3) => void = function() {}
89

910
import { type InferType1, type InferType2 } from 'infer';
1011

crates/oxc_isolated_declarations/tests/snapshots/eliminate-imports.snap

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ input_file: crates/oxc_isolated_declarations/tests/fixtures/eliminate-imports.ts
55
```
66
==================== .D.TS ====================
77
8-
import { AExtend, BExtend, Type, CImplements1, CImplements2, CType, ThisType1, ThisType2 } from "mod";
8+
import { AExtend, BExtend, Type, CImplements1, CImplements2, CType, ThisType1, ThisType2, ThisType3 } from "mod";
99
export interface A extends AExtend<Type> {}
1010
export declare class B extends BExtend<Type> {}
1111
export declare class C implements CImplements1<CType>, CImplements2<CType> {}
12-
export declare function foo(this: ThisType1 ): void;
13-
export declare const bar: (this: ThisType2 ) => void;
12+
export declare class D {
13+
method(this: ThisType1): void;
14+
}
15+
export declare function foo(this: ThisType2): void;
16+
export declare const bar: (this: ThisType3) => void;
1417
import { type InferType1, type InferType2 } from "infer";
1518
export type F<X extends InferType1> = X extends infer U extends InferType2 ? U : never;
1619
export { Unused } from "./unused";

0 commit comments

Comments
 (0)