Our source maps rely on output trees from transformation having location values from the input tree nodes. As we've moved to use parseStatement and parseExpression extensively, more and more trees have no locations. It turns out that entire source files can disappear. Well ok, I found one somewhat trivial case where the entire file disappears. A file with this source
import 'foo.js';
generates no output tree with input locations.
To add more locations when using parseStatement and parseExpression is rather disruptive to the source. These two clever 'functions' make creating parse trees look like parsing source. Adding an argument to set location would make them much less clever.
The most straight forward fix is to have a function like tree.relocate(location); which attaches SourceRange info to a tree. This however would be impure, it would mutate the tree slightly. To add the location without mutation would require -- as far as I can tell -- reconstructing the tree nodes.
Any ideas or opinions?
jjb