Skip to content

Commit

Permalink
Add an isSourceFile() type guard
Browse files Browse the repository at this point in the history
  • Loading branch information
knutwannheden committed Sep 17, 2024
1 parent d197954 commit 4e35a2d
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions openrewrite/src/core/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ const SourceFileSymbol = Symbol('SourceFile');
// This allows using `SourceFile` like a class in certain situations (e.g. `Cursor.firstEnclosing()`)
export const SourceFile = SourceFileSymbol;

export function isSourceFile(tree: any & Tree): tree is SourceFile {
// return 'sourcePath' in tree && 'printer' in tree;
return tree && tree[SourceFileSymbol] === true;
}

export interface SourceFile extends Tree {
[SourceFileSymbol]: true;

Expand Down

0 comments on commit 4e35a2d

Please sign in to comment.