()
| 26 | * statement before the next match. |
| 27 | */ |
| 28 | export function elementStyleUsingPlugin(): Plugin { |
| 29 | return { |
| 30 | name: 'alphatab:lower-element-style-using', |
| 31 | enforce: 'pre', |
| 32 | transform: { |
| 33 | filter: { id: /\.tsx?$/ }, |
| 34 | handler(code, id) { |
| 35 | if (!code.includes('ElementStyleHelper')) { |
| 36 | return null; |
| 37 | } |
| 38 | |
| 39 | const program = parseAst( |
| 40 | code, |
| 41 | { lang: id.endsWith('.tsx') ? 'tsx' : 'ts', sourceType: 'module' }, |
| 42 | id |
| 43 | ); |
| 44 | |
| 45 | const ms = new MagicString(code); |
| 46 | walk(program, node => { |
| 47 | if (node.type === 'BlockStatement' || node.type === 'Program') { |
| 48 | rewriteBody((node as BlockStatement | Program).body as Statement[], ms); |
| 49 | } |
| 50 | }); |
| 51 | |
| 52 | if (!ms.hasChanged()) { |
| 53 | return null; |
| 54 | } |
| 55 | |
| 56 | return { |
| 57 | code: ms.toString(), |
| 58 | map: ms.generateMap({ hires: 'boundary', source: id }) |
| 59 | }; |
| 60 | } |
| 61 | } |
| 62 | }; |
| 63 | } |
| 64 | |
| 65 | function rewriteBody(body: Statement[], ms: MagicString): void { |
| 66 | let open: { id: string; lastStmtEnd: number } | null = null; |
no outgoing calls
no test coverage detected