Skip to content

Commit

Permalink
fix: generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Farenheith committed Sep 22, 2024
1 parent ed9e54e commit b4fc751
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,29 @@ export function before() {
return (sf: ts.SourceFile) => {
const visitNode = (node: ts.Node): ts.Node => {
try {
if ((tsBinary.isMethodDeclaration(node)
|| tsBinary.isPropertyDeclaration(node)
|| tsBinary.isClassDeclaration(node))
&& !tsBinary.getDecorators(node)?.length
if (
(tsBinary.isMethodDeclaration(node) ||
tsBinary.isPropertyDeclaration(node) ||
tsBinary.isClassDeclaration(node)) &&
!tsBinary.getDecorators(node)?.length
) {
const decorator = tsBinary.factory.createDecorator(
tsBinary.factory.createPropertyAccessChain(
tsBinary.factory.createCallExpression(
tsBinary.factory.createIdentifier('require'),
undefined,
[
tsBinary.factory.createStringLiteral('nestjs-emitter'),
]
), undefined, 'simpleDecorator'
)
tsBinary.factory.createCallExpression(
tsBinary.factory.createIdentifier('require'),
undefined,
[
tsBinary.factory.createStringLiteral(
'nestjs-emitter/dist/emitter',
),
],
),
);
node = tsBinary.isClassDeclaration(node)
? tsBinary.visitEachChild(node, visitNode, ctx)
: tsBinary.factory.replaceDecoratorsAndModifiers(
node,
[...(node.modifiers ?? []), decorator]
);
: tsBinary.factory.replaceDecoratorsAndModifiers(node, [
...(node.modifiers ?? []),
decorator,
]);
return node;
}
return tsBinary.visitEachChild(node, visitNode, ctx);
Expand Down

0 comments on commit b4fc751

Please sign in to comment.