Hi @jypre I’m afraid that is a lot of code to read. Is there any chance you can reduce it to a minimal test case?
JS errors are, by definition, a bug in the core. It is not supposed to be possible to induce a red screen of embarrassment purely in wikitext so it would be worth chasing this down.