JavaScript[0] isn't what I would call a fast storage repository, but I guess it works out for prototyping.
On the context of porting to C and C++, or make it execute faster, I can see two options with minor rewrites.
Use AssemblyScript and generate native code via WebAssembly AOT compilers.
Try to adapt TypeScript to C++ compiler from Microsoft's MakeCode project.
Implement your own C++ code generator.
It would be much easier than keep using multiple code bases in parallel, plus any memory corruption issues would be most likely bugs on the code generator.
[0] - Yes I know the source code is Typescript.