Stuli1 While they work on figuring that out, I've switched over to using state machine or equivalent globals in my JS, since doing one-line JS with inline PHP doesn't disrupt the rest of the JS block:
<script type="text/javascript">G3.registerObject("relatedTypes", [<?php foreach (array_values($relatedTypes) as $rType): ?>{ ... },<?php endforeach; ?>]);</script>
It's not perfect, but it gets me around the issue for now.