Skip to content

Commit

Permalink
fix(codegen): Emit this parameters of class methods (#8834)
Browse files Browse the repository at this point in the history
Co-authored-by: MichaelMitchell-at <=>
  • Loading branch information
MichaelMitchell-at authored Feb 2, 2025
1 parent 5788ac0 commit 0928a19
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
15 changes: 11 additions & 4 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,8 +767,8 @@ impl Gen for Function<'_> {
this_param.print(p, ctx);
if !self.params.is_empty() || self.params.rest.is_some() {
p.print_str(",");
p.print_soft_space();
}
p.print_soft_space();
}
self.params.print(p, ctx);
p.print_ascii_byte(b')');
Expand Down Expand Up @@ -2675,6 +2675,13 @@ impl Gen for MethodDefinition<'_> {
type_parameters.print(p, ctx);
}
p.print_ascii_byte(b'(');
if let Some(this_param) = &self.value.this_param {
this_param.print(p, ctx);
if !self.value.params.is_empty() || self.value.params.rest.is_some() {
p.print_str(",");
p.print_soft_space();
}
}
self.value.params.print(p, ctx);
p.print_ascii_byte(b')');
if let Some(return_type) = &self.value.return_type {
Expand Down Expand Up @@ -3365,8 +3372,8 @@ impl Gen for TSFunctionType<'_> {
this_param.print(p, ctx);
if !self.params.is_empty() || self.params.rest.is_some() {
p.print_str(",");
p.print_soft_space();
}
p.print_soft_space();
}
self.params.print(p, ctx);
p.print_str(")");
Expand Down Expand Up @@ -3401,8 +3408,8 @@ impl Gen for TSSignature<'_> {
this_param.print(p, ctx);
if !signature.params.is_empty() || signature.params.rest.is_some() {
p.print_str(",");
p.print_soft_space();
}
p.print_soft_space();
}
signature.params.print(p, ctx);
p.print_str(")");
Expand Down Expand Up @@ -3460,8 +3467,8 @@ impl Gen for TSSignature<'_> {
this_param.print(p, ctx);
if !signature.params.is_empty() || signature.params.rest.is_some() {
p.print_str(",");
p.print_soft_space();
}
p.print_soft_space();
}
signature.params.print(p, ctx);
p.print_str(")");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { AExtend, BExtend, Type, CImplements1, CImplements2, CType, ThisType1, ThisType2, Unused } from 'mod';
import { AExtend, BExtend, Type, CImplements1, CImplements2, CType, ThisType1, ThisType2, ThisType3, Unused } from 'mod';

export interface A extends AExtend<Type> {}
export class B extends BExtend<Type> {}
export class C implements CImplements1<CType>, CImplements2<CType> {}
export function foo(this: ThisType1): void {}
export const bar: (this: ThisType2) => void = function() {}
export class D { method(this: ThisType1): void { } }
export function foo(this: ThisType2): void {}
export const bar: (this: ThisType3) => void = function() {}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ input_file: crates/oxc_isolated_declarations/tests/fixtures/eliminate-imports.ts
```
==================== .D.TS ====================
import { AExtend, BExtend, Type, CImplements1, CImplements2, CType, ThisType1, ThisType2 } from "mod";
import { AExtend, BExtend, Type, CImplements1, CImplements2, CType, ThisType1, ThisType2, ThisType3 } from "mod";
export interface A extends AExtend<Type> {}
export declare class B extends BExtend<Type> {}
export declare class C implements CImplements1<CType>, CImplements2<CType> {}
export declare function foo(this: ThisType1 ): void;
export declare const bar: (this: ThisType2 ) => void;
export declare class D {
method(this: ThisType1): void;
}
export declare function foo(this: ThisType2): void;
export declare const bar: (this: ThisType3) => void;
import { type InferType1, type InferType2 } from "infer";
export type F<X extends InferType1> = X extends infer U extends InferType2 ? U : never;
export { Unused } from "./unused";

0 comments on commit 0928a19

Please sign in to comment.