MCPcopy Index your code
hub / github.com/CoderLine/alphaTab / rewriteBody

Function rewriteBody

packages/tooling/src/vite.plugin.transform.ts:65–95  ·  view source on GitHub ↗
(body: Statement[], ms: MagicString)

Source from the content-addressed store, hash-verified

63}
64
65function rewriteBody(body: Statement[], ms: MagicString): void {
66 let open: { id: string; lastStmtEnd: number } | null = null;
67
68 for (const stmt of body) {
69 if (isElementStyleHelperUsing(stmt)) {
70 if (open) {
71 ms.appendLeft(open.lastStmtEnd, ` } finally { ${open.id}?.[Symbol.dispose]?.(); }`);
72 }
73
74 const idNode = stmt.declarations[0].id;
75 if (idNode.type !== 'Identifier') {
76 // destructured `using` is not supported.
77 open = null;
78 continue;
79 }
80 const name = (idNode as IdentifierName).name;
81
82 // `using` is 5 chars; replace with `const`
83 ms.update(stmt.start, stmt.start + 5, 'const');
84 ms.appendLeft(stmt.end, ' try {');
85
86 open = { id: name, lastStmtEnd: stmt.end };
87 } else if (open) {
88 open.lastStmtEnd = stmt.end;
89 }
90 }
91
92 if (open) {
93 ms.appendLeft(open.lastStmtEnd, ` } finally { ${open.id}?.[Symbol.dispose]?.(); }`);
94 }
95}
96
97function isElementStyleHelperUsing(
98 stmt: Statement

Callers 1

handlerFunction · 0.85

Calls 2

updateMethod · 0.65

Tested by

no test coverage detected