I don't want to build a program that matches what the Emscripten people have made.
So far it sounds like that's
exactly what you want.
That doesn't work from what I heard
It works
impressively well given what an enormous task it is to translate a huge and incredibly complex language like C++ to JavaScript.
Have you even looked at their examples? It's quite amazing what they have managed to get working. And in my opinion it's the only sane way to do what you want; use a real C++ frontend like Clang to generate LLVM IR, then use the LLVM optimizer to speed it up, then write a JavaScript backend to generate the final JS code that must run on the web.
If you have to invent the tokenizer, lexer, parser (AST generator), optimizer and JS backend from scratch/first principles then you are looking at hundreds of man years of work (which is roughly what has already been put into LLVM + Clang + Emscripten).
Just consider the fact that the current C++ language standard/specification is ~1300 pages. You want to write a program that tackles that
on your own? And then on top of that you want to implement the entire C++ standard library + STL on your own (you'll need it; programs use it). Then you want to write code that translates all that faithfully into working JavaScript.
Good luck.
The Emscripten people have (by using the base that LLVM already built) almost achieved that, but it has taken them years (and many developers during those years).
Throwing your weight behind those projects is really the only realistic way I see towards achieving your goal. Trying to do it alone (in one human lifetime) is just unrealistic on such an enormous scale that it's not even funny.