3 ms·
> Rather than manipulating the AST, Bublé manipulates the source code directly, using the AST as a guide – so there's no costly code generation step at the end.
by pgz 10y ago
> Rather than manipulating the AST, Bublé manipulates the source code directly, using the AST as a guide – so there's no costly code generation step at the end.
Is that really good idea when looking at the possibility of introducing bugs in the transpiler?
- rtpg 10y agoit sounds like they're still generating an AST, but replacing AST nodes directly through the code string. It's definitely trickier but I think it's possible to do this in a clean way if the changes are just "replace this AST node with this other AST node". You know the text boundaries, and the output is context free so...
- rich_harris 10y ago> Is that really good idea when looking at the possibility of introducing bugs in the transpiler? That's what a test suite is for :)
- aspiringuser 10y agoSurely the AST is still produced? Acorn is the parser I assume?
- rich_harris 10y agoCorrect – Acorn is a truly wonderful library
- Touche 10y agoHey Rich, I wish some time you would write more about magic-string and what makes it special. You say "no costly code generation step", but what makes codegen costly compared to what you're doing in magic-string?
- rich_harris 10y agoI plan to write about this in the near future (in fact I'm writing slides for a talk on it this week) – essentially, codegen is more costly because a) you have to generate the entire program, rather than just modifying the nodes that have changed, b) your code generator needs to know about every single node type, and c) you have to keep track of state (e.g indentation levels).