| 123 | }; |
| 124 | |
| 125 | const getLanguageParserSingleton = async () => { |
| 126 | if (!languageParserSingleton) { |
| 127 | // Assign only after init() succeeds. Otherwise a failed init would leave an |
| 128 | // uninitialized parser cached for the rest of the worker's lifetime, so |
| 129 | // every subsequent file would throw "not initialized" and silently lose |
| 130 | // compression. Keeping the singleton null lets the next call retry init. |
| 131 | const parser = new LanguageParser(); |
| 132 | await parser.init(); |
| 133 | languageParserSingleton = parser; |
| 134 | } |
| 135 | return languageParserSingleton; |
| 136 | }; |
| 137 | /** |
| 138 | * Clean up the language parser singleton by deleting all loaded parsers |
| 139 | */ |