Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent removing decorators on classes #108

Merged
merged 3 commits into from
Dec 17, 2024

Conversation

FredericEspiau
Copy link
Contributor

Prevents removing decorators on exported classes that won't be exported anymore

Case

@firstDecorator
@secondDecorator(() => [WithArgument])
export default class C {}
const c = new C();
console.log(c);

Before

class C {}
const c = new C();
console.log(c);

After

@firstDecorator
@secondDecorator(() => [WithArgument])
class C {}
const c = new C();
console.log(c);

Copy link
Contributor

@kazushisan kazushisan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the patch

const syntaxList = node?.getChildren()[syntaxListIndex];

if (!syntaxList) {
throw new Error('Syntaxlist missing');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new Error('Syntaxlist missing');
throw new Error('sytaxList missing');

or maybe syntax list [nit]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

const syntaxListIndex = node
.getChildren()
.findIndex((n) => n.kind === ts.SyntaxKind.SyntaxList);

const syntaxList = node.getChildren()[syntaxListIndex];
const syntaxList = node?.getChildren()[syntaxListIndex];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const syntaxList = node?.getChildren()[syntaxListIndex];
const syntaxList = node.getChildren()[syntaxListIndex];

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good one, done

Comment on lines 299 to 301
export class A {}
const a = new A();
console.log(a);`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export class A {}
const a = new A();
console.log(a);`,
export class A {}

can you remove the class instance and console.log from the added test cases to keep it lean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes you're right, done

@kazushisan kazushisan added the bug Something isn't working label Dec 16, 2024
Copy link
Contributor

@kazushisan kazushisan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@kazushisan kazushisan merged commit 6ed047a into line:main Dec 17, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants