question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for source maps

See original GitHub issue

Hi 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:open
  • Created 8 years ago
  • Reactions:6
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
RyanZimcommented, Oct 26, 2016

Thanks for chiming in @sitegui

As things stand now, I would be in favor of closing this.

  • @sitegui has found a solution that works for him.
  • Someone would need to write the EJS minifier; unless we have a volunteer for that, there is no point discussing 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.

0reactions
v4dkoucommented, Dec 22, 2020

From what I see, to implement source maps, we need to pass this.currentLine to the compiled __append in the scanLine 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

Read more comments on GitHub >

github_iconTop Results From Across the Web

source-map-support - npm
Fixes stack traces for files with source maps. ... Start using source-map-support in your project by running `npm i source-map-support`.
Read more >
evanw/node-source-map-support - GitHub
This module provides source map support for stack traces in node via the V8 stack trace API. It uses the source-map module to...
Read more >
Is there source map support for typescript in node / nodemon?
My tsconfig has sourceMap set to true and the *.map.js files are generated. When I execute my transpiled *.js JavaScript files via node...
Read more >
Source maps in Node.js. Supporting the many flavors of…
Adding support for the Source Map V3 format to Node.js was an important step towards better supporting the alternate flavors of JavaScript ...
Read more >
Use a source map — Firefox Source Docs documentation
Use a source map¶ · sources are often combined and minified to make delivering them from the server more efficient. · JavaScript running...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found