(source: string, kind: ts.SyntaxKind)
| 23 | } |
| 24 | |
| 25 | export function createNodeFromSource<T extends ts.Node>(source: string, kind: ts.SyntaxKind): T { |
| 26 | const sourceFile = ts.createSourceFile( |
| 27 | 'temp.ts', |
| 28 | source.trim(), |
| 29 | ts.ScriptTarget.Latest, |
| 30 | /*setParentNodes */ true, |
| 31 | ts.ScriptKind.TS |
| 32 | ); |
| 33 | const node = findNode(sourceFile, kind); |
| 34 | if (!node) { |
| 35 | throw new Error( |
| 36 | `Could not parse TS source to ${ts.SyntaxKind[kind]}, node count was ${sourceFile.getChildCount()}` |
| 37 | ); |
| 38 | } |
| 39 | return markNodeSynthesized(node) as T; |
| 40 | } |
| 41 | |
| 42 | function findNode(node: ts.Node, kind: ts.SyntaxKind): ts.Node | null { |
| 43 | if (node.kind === kind) { |
no test coverage detected