Skip to content

Commit

Permalink
getDecorators too
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaKGoldberg committed Sep 7, 2023
1 parent 3095a14 commit d6b5f18
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/usage/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,25 @@ export function identifierToKeywordKind(
}

/**
* Supports TypeScript<4.8 versions that don't have identifierToKeywordKind.
* Supports TypeScript<4.8 versions that don't have canHaveDecorators.
*/
export function canHaveDecorators(node: ts.Node): node is ts.HasDecorators {
return "canHaveDecorators" in ts
? ts.canHaveDecorators(node)
: "decorators" in node;
}

type NodeWithDecorators = ts.HasDecorators & {
decorators: readonly ts.Decorator[] | undefined;
};

/**
* Supports TypeScript<4.8 versions that don't have getDecorators.
*/
export function getDecorators(
node: ts.HasDecorators,
): readonly ts.Decorator[] | undefined {
return "getDecorators" in ts
? ts.getDecorators(node)
: (node as NodeWithDecorators).decorators;
}

0 comments on commit d6b5f18

Please sign in to comment.