Add support for source maps
See original GitHub issueHi all,
In PR #56, it was discussed one can modify the EJS source before handing it to ejs.compile()
.
It works, but has the downside of making the extended error messages (with EJS source and line numbers) hard to read, since all source will probably be presented as one line.
Another solution is to minify the render()
's output, but this may be too expensive. In my benchmarks, using html-minifier, it takes more than 100ms (for my use case, that’s too much).
But I think offering HTML minification as part of EJS is not the way to go either, since it would bloat this wonderful module too much and would not solve the underlying problem with pre-processed source.
What if EJS could accept a source map as part of the compilation and use it to report the right line number and original source? This way, HTML minification could be part of another module, separating concerns.
I’d like to hear you position on this issue: do you think this module should accommodate this use case?
Best regards, Guilherme
Issue Analytics
- State:
- Created 8 years ago
- Reactions:6
- Comments:12 (2 by maintainers)
Top GitHub Comments
Thanks for chiming in @sitegui
As things stand now, I would be in favor of closing this.
@TimothyGu If you feel that line-number error mapping should/could be rewritten, that should be a separate issue. “If it ain’t broke, don’t fix it!” IMO, though.
If someone has something else to add to this discussion, please do so, otherwise, I will probably close in few days.
From what I see, to implement source maps, we need to pass
this.currentLine
to the compiled__append
in thescanLine
method. Then if we extend this__append
method to store an association between the source line number and output lines range, we’ll get something like a source map.https://github.com/mde/ejs/blob/main/lib/ejs.js#L885 https://github.com/mde/ejs/blob/main/lib/ejs.js#L827