MCPcopy Create free account
hub / github.com/CoderLine/alphaTab / createNodeFromSource

Function createNodeFromSource

packages/transpiler/src/BuilderHelpers.ts:25–40  ·  view source on GitHub ↗
(source: string, kind: ts.SyntaxKind)

Source from the content-addressed store, hash-verified

23}
24
25export 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
42function findNode(node: ts.Node, kind: ts.SyntaxKind): ts.Node | null {
43 if (node.kind === kind) {

Callers 7

generateToJsonBodyFunction · 0.90
createToJsonMethodFunction · 0.90
generateFromJsonBodyFunction · 0.90
createFromJsonMethodFunction · 0.90
generateSetPropertyBodyFunction · 0.90
createSetPropertyMethodFunction · 0.90

Calls 2

findNodeFunction · 0.85
markNodeSynthesizedFunction · 0.85

Tested by

no test coverage detected