astring icon indicating copy to clipboard operation
astring copied to clipboard

Add support for JSX

Open wooorm opened this issue 4 years ago • 8 comments

  • Add new JSX export, similar to GENERATOR, with handlers for JSX nodes
  • Add unit tests for JSX nodes
  • Add JSX example

  • I’m a fan of small unit tests over checking whole documents, so I tested the new features with those
  • Types are not tested, and I’m not a TS user, so I didn’t add types for JSX. For reference, if you’re interested, here is an example of how to test types. You could also opt to use JSDoc for typescript if the source is JS, which I quite like, like so. Some complexity with types though is that newer ESTree proposal aren’t typed yet, such as bigint (and I’m not sure where JSX is typed)

wooorm avatar Mar 07 '21 09:03 wooorm

Codecov Report

Merging #480 (8b7f1dd) into master (2dfdef1) will increase coverage by 0.77%. The diff coverage is 99.26%.

:exclamation: Current head 8b7f1dd differs from pull request most recent head 9f1bbaf. Consider uploading reports for the commit 9f1bbaf to get more accurate results Impacted file tree graph

@@            Coverage Diff             @@
##           master     #480      +/-   ##
==========================================
+ Coverage   94.97%   95.74%   +0.77%     
==========================================
  Files           1        1              
  Lines        1134     1270     +136     
==========================================
+ Hits         1077     1216     +139     
+ Misses         57       54       -3     
Impacted Files Coverage Δ
src/astring.js 95.74% <99.26%> (+0.77%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 2dfdef1...9f1bbaf. Read the comment docs.

codecov[bot] avatar Mar 07 '21 09:03 codecov[bot]

Thanks @wooorm for sending this, it looks great! Adding inline comments about what a node does is also a great idea. The reason behind template-based tests is to avoid malformed AST nodes and to ensure that sourcemaps match.

I'll have more time next week-end to apply the remaining changes:

  • [ ] Add template tests
  • [ ] Add TypeScript types
  • [ ] Add generateJsx helper
  • [ ] Update demo with JSX support

Edit: not this one but the next one.

davidbonnet avatar Apr 05 '21 19:04 davidbonnet

here’s a PR somewhere else that types (using JSDoc comments, which I like a lot) these same functions: https://github.com/wooorm/xdm/pull/24, by @ChristianMurphy

wooorm avatar Apr 05 '21 19:04 wooorm

Just a quick note to mention that I haven't forgotten this PR.

davidbonnet avatar Jun 02 '21 12:06 davidbonnet

Let me now if there's anything I could do to unblock it!

wooorm avatar Jun 02 '21 18:06 wooorm

Hi guys, I'm looking to do exactly this! Is there any update on when this will be merged, or can I help in any way?

Adam-Collier avatar Jul 23 '21 10:07 Adam-Collier

Friendly ping!

wooorm avatar Jan 25 '22 12:01 wooorm

@davidbonnet Friendly ping! Anything I can do?

wooorm avatar Oct 12 '22 19:10 wooorm