Add support for evaluating basic typescript#82
Add support for evaluating basic typescript#82TikiTDO wants to merge 1 commit intokentcdodds:mainfrom
Conversation
Codecov Report
@@ Coverage Diff @@
## master #82 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 4 4
Lines 106 106
Branches 22 22
=========================================
Hits 106 106
Continue to review full report at Codecov.
|
|
Hi @TikiTDO, Thanks for this. We used to transform the code (using babel), but it ended up causing issues. I can't remember what they were though. It was years ago. I guess I'm willing to merge this if you're willing to help maintain things if it breaks something 😬 |
|
@kentcdodds how about the idea of making this an babel option for this plugin? I hit a few problems with this patch myself (it worked for node 14, but did not work for node 10 due to how modules are handled), so I don't think it would be easy to get it working generically. However, if we add a way tell babel what options to use when parsing the code then it would be be possible to adapt it to any particular environment by letting the users enable the set of plugins that work for them. |
|
That would be fine with me. Got any ideas? |
What: Allows preval to parse typescript (and potentially any dialect supported by babel with some extra work)
Why: Preval currently chokes on typescript.
This PR serves as a proof-of-concept to show that a TS file can be transformed into plain JS before being handed off the the
require-from-stringhelper.This could be generalized with a more extensive set of transformers, or potentially even a babel option for the plugin to allow an arbitrary set of extra plugins.
How: Check for typescript files when parsing a
@prevaltagged file, and optionally parse it with the typescript transformer enabled.Note, this example only handled the file comment approach, since that code already used babel for parsing the input file. Expanding this it to support the other three approaches would require some changes to use babel handlers such as transformFileSync or transformSync