-
-
Notifications
You must be signed in to change notification settings - Fork 540
swc transpiler and new --transpiler option to use third-party transpilers #1160
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
2e0d478
to
1551509
Compare
Codecov Report
|
- rename from ts-node/compilers/swc to ts-node/compiler/swc-experimental - add @swc/wasm fallback when @swc/core is not installed or available - expand TSCommon to include all api surface used by ts-node; use TSCommon consistently (should be extracted to a different PR) - ts-node's compiler loading logic detects a createTypescriptCompiler function and will invoke it to get instance of compiler - fix ts-node's sourcemap comment appender to work even when TS compiler does not append a sourcemap comment. swc does not append such a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From someone fairly unfamiliar with ts-node's architecture, looks good! As a user, I would definitely want a warning for ts-node failing to use the specified compiler.
src/compilers/swc.ts
Outdated
targetMapping.set(/* ts.ScriptTarget.ES2019 */ 6, 'es2019') | ||
targetMapping.set(/* ts.ScriptTarget.ES2020 */ 7, 'es2019') | ||
targetMapping.set(/* ts.ScriptTarget.ESNext */ 99, 'es2019') | ||
targetMapping.set(/* ts.ScriptTarget.Latest */ 99, 'es2019') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
99 is set twice - intentional?
Thinking about this, I see some problems:
Given the above problems, perhaps it is better to introduce a proper
|
It shortens |
When using yarn one should use Thanks for the 3x launch time improvement ! |
Implements #779
Usage information is at the top of this description. Below are design questions and development to-dos.
Usage
Gotchas
swc uses a different helpers library,
@swc/helpers
instead oftslib
. If you haveimportHelpers
enabled, you will also need to install@swc/helpers
in all the places where you would normally installtslib
. When in doubt, there is no harm installing both.Implementation notes, design questions
This is incomplete. To be a proper drop-in compiler I think it will need to implement additional parts of the<--this much has been implemented.TsCommon
interface. It can pull these fromrequire('typescript')
But ideally our
compiler
option supports composable compilers, so you can specify"compiler": ["ntypescript", "ts-node/compilers/swc"]
and the swc wrapper will defer tontypescript
for things it does not implement itself. This has not been implemented yet.Still, it might be cool for users to specify
"transpileOnly": true, "compiler": "ts-node/compilers/swc"
and get a performance boost.Other compilers: (note they are only worth considering if they're noticeably faster than
ts.transpileModule
)Configuration with options: bike-shedding
How should we allow passing configuration options to the transpiler?
TODO
https://yarnpkg.com/configuration/manifest/#peerDependenciesMeta
https://blog.npmjs.org/post/186983646370/npm-cli-roadmap-summer-2019
@swc/wasm
vs@swc/core
)transpileOnly
turned off, since you won't get the speed benefit ofswc
?warn whenInstead, I've switched to a proper transpiler API that does not need to mimic TS compiler APIcreateTypescriptCompiler
is misspelled by detecting when compiler instance doesn't have well-known compiler APIs such astranspileModule
orcreateProgram