* @static
(tex: string)
| 76 | * @static |
| 77 | */ |
| 78 | function parseTex(tex: string): Score { |
| 79 | const importer: AlphaTexImporter = new AlphaTexImporter(); |
| 80 | importer.logErrors = true; |
| 81 | importer.initFromString(tex, new Settings()); |
| 82 | try { |
| 83 | return importer.readScore(); |
| 84 | } catch (e) { |
| 85 | const x = (e as Error).cause instanceof AlphaTexErrorWithDiagnostics ? (e as Error).cause : e; |
| 86 | if (x instanceof AlphaTexErrorWithDiagnostics) { |
| 87 | const withDiag = x as AlphaTexErrorWithDiagnostics; |
| 88 | if (e instanceof UnsupportedFormatError) { |
| 89 | throw new UnsupportedFormatError(withDiag.toString()); |
| 90 | } else { |
| 91 | throw new Error(`${withDiag.toString()}`); |
| 92 | } |
| 93 | } |
| 94 | throw e; |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | // as we often add tests here for new alphaTex features, this helper |
| 99 | // directly allows testing the exporter via a roundtrip comparison |
no test coverage detected