developit / htm

Hyperscript Tagged Markup: JSX alternative using standard tagged templates, with compiler support.
Apache License 2.0
8.73k stars 170 forks source link

Is something like "__source" supported? #184

Closed voxpelli closed 3 years ago

voxpelli commented 4 years ago

I'm looking at https://babeljs.io/docs/en/babel-plugin-transform-react-jsx-source and the, for debugging, useful __source property it adds.

Is there something like that in htm? Otherwise: Is it something you would like to have added?

developit commented 3 years ago

This would only really be possible to add to the JSX transform, and I believe that's already supported - just placing the plugin you linked to before babel-plugin-transfrom-jsx-to-htm in your Babel config should make it work.

As for HTM itself, there's no good way to get that information, since HTM isn't executed at build time like JSX is. A library could check the stack (new Error().stack or similar) within its h() function and get the bundle (final, not source) for any HTM fragment, but it's likely impossible to obtain accurate line/column info.