-
-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Source maps #73
Comments
Sorry, I don't know much about source maps or how they work. Could you explain how piping Eta's output into sourcemap-aware tooling would work? |
Generally, the way source maps work for minified JS, for instance, is that minifiers produce source maps that contain associations between source AST and the resulting AST, which allows you to backtrack from line/column position in the output file back to where it came from.
Tools like Sentry use that to allow you to capture errors in minified JS in production and unravel them in your IDE. For HTML/CSS, I would expect being able to take linter's messages (line/col position) and use source maps from Eta to find the part of the template that resulted in this erroneous string. For HTML, for instance, that would allow us to quickly catch unclosed tags, invalid doctypes, unnecessary whitespace, etc. |
@v4dkou Sorry for getting back so late, do you know exactly what we would need to implement for this? If this requires another library, we should probably make it a plugin, |
@shadowtime2000 We'd need to extend the compilation sequence with template source line/column numbers, so that running the compiled template could yield the source map along with the rendered string. Here's a description of a solution for source maps in EJS for reference. Libraries are not related to the concept of source mapping, unless someone would like to have it adhere to some specific format, but as this feature would incur a performance penalty, I agree that creating a plugin is the best course of action. However, I don't think the current API with Perhaps we should allow extending the generated function string during it's compilation rather than applying custom functions afterwards? If you see a way to extend the function string with metainfo using the current API, I'd like to discuss it and implement a plugin myself. |
@v4dkou What do you mean by this? I am a little confused by what you mean. |
@shadowtime2000 Right now the function that gets compiled from a string, can only be manipulated through a This prevents me from developing a plugin that adds custom AST handlers (such as Source mapping). If Eta had a hook between the AstObject buffer and the string compilation, one could add their own handlers inside the compiled function (take a look at compile-string.ts, lines 73-109). If this hook receives data about the Eta compilation process, current line in the original template string, AstObjects, etc. (metainfo), I could write a plugin that injects a "collect line number associations" function to store source line positions and resulting line positions for text injected into the template. |
@v4dkou Sorry 😅, still a little confused by what you mean by this. Do you mean like allowing just dropping in a new compile to string function? |
@shadowtime2000 No worries 😄 Dropping in a new compile to string would work, but that's cumbersome to use. So whenever |
@v4dkou What you are proposing would have some more runtime overhead though, as far as I can see. Any other way that could be done? |
Is your feature request related to a problem? Please describe.
It would be useful if we could pipe Eta's output into sourcemap-aware tooling to associate things like rendered HTML linting errors with the template source code.
Describe the solution you'd like
I'd like to be able to produce a sourcemap file along with the rendered template string.
Describe alternatives you've considered
Right now I am working on a project that uses EJS, and I need to figure out a way to have transient error mapping.
Alternatives I've considered:
Additional context
Similar issue for EJS
mde/ejs#123
The text was updated successfully, but these errors were encountered: