From 0278b626b90349007ef4201a2d9208d48902116d Mon Sep 17 00:00:00 2001 From: riflowth Date: Sat, 11 May 2024 12:52:53 +0700 Subject: [PATCH] fix: setter decorator not working --- package.json | 2 +- src/TSLombok.ts | 26 ++++++++++----------- src/generator/decorators/SetterDecorator.ts | 2 +- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 9c1bfb7..33b6e70 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "tslombok", "description": "Lombok for TypeScript", - "version": "1.2.0", + "version": "1.2.6", "author": "Krid Heprakhone ", "homepage": "https://github.com/vectier/tslombok", "bugs": "https://github.com/vectier/tslombok/issues", diff --git a/src/TSLombok.ts b/src/TSLombok.ts index 88ddd73..3b61849 100644 --- a/src/TSLombok.ts +++ b/src/TSLombok.ts @@ -18,18 +18,16 @@ export const Getter = (target: Object, propertyKey: string | Symbol): void => { }); }; -export const Setter = (...params: unknown[]): PropertyDecorator => { - return (target: Object, propertyKey: string | Symbol): void => { - if (typeof propertyKey === 'symbol') propertyKey.toString(); - const propertyName = propertyKey as string; - const methodName = `set${capitalize(propertyName)}`; +export const Setter = (target: Object, propertyKey: string | Symbol): void => { + if (typeof propertyKey === 'symbol') propertyKey.toString(); + const propertyName = propertyKey as string; + const methodName = `set${capitalize(propertyName)}`; - // Define setter method to the target class prototype, - // that set a given value to their own property instance - Object.defineProperty(target, methodName, { - value: function (value: unknown) { - this[propertyName] = value; - }, - }); - }; -} + // Define setter method to the target class prototype, + // that set a given value to their own property instance + Object.defineProperty(target, methodName, { + value: function (value: unknown) { + this[propertyName] = value; + }, + }); +}; diff --git a/src/generator/decorators/SetterDecorator.ts b/src/generator/decorators/SetterDecorator.ts index 0e34d99..4b258ae 100644 --- a/src/generator/decorators/SetterDecorator.ts +++ b/src/generator/decorators/SetterDecorator.ts @@ -10,7 +10,7 @@ export class SetterDecorator implements MethodGeneratorDecorator { public createMethodSignature(propertyName: string, returnType: TypeNode): MethodSignature { return factory.createMethodSignature( undefined, // No need to have a modifer for interface in declaration merging - `get${capitalize(propertyName)}`, + `set${capitalize(propertyName)}`, undefined, undefined, [factory.createParameterDeclaration(