Title: Do not check in the `transpileModule` API · Issue #50699 · microsoft/TypeScript · GitHub
Open Graph Title: Do not check in the `transpileModule` API · Issue #50699 · microsoft/TypeScript
X Title: Do not check in the `transpileModule` API · Issue #50699 · microsoft/TypeScript
Description: Suggestion 🔍 Search Terms transpileModule skip typechecking no typechecking Semi-related issues found: Skip typechecking; only emit (support --transpileOnly in tsc, re-open of #4176) #29651 [FEATURE REQUEST] Please supply a minified vers...
Open Graph Description: Suggestion 🔍 Search Terms transpileModule skip typechecking no typechecking Semi-related issues found: Skip typechecking; only emit (support --transpileOnly in tsc, re-open of #4176) #29651 [FEATUR...
X Description: Suggestion 🔍 Search Terms transpileModule skip typechecking no typechecking Semi-related issues found: Skip typechecking; only emit (support --transpileOnly in tsc, re-open of #4176) #29651 [FEATUR...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/50699
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Do not check in the `transpileModule` API","articleBody":"# Suggestion\r\n\r\n\u003c!--\r\n Please fill in each section completely. Thank you!\r\n--\u003e\r\n\r\n## 🔍 Search Terms\r\n\r\n\u003c!--\r\n 💡 Did you know? TypeScript has over 2,000 open suggestions!\r\n 🔎 Please search thoroughly before logging new feature requests as most common ideas already have a proposal in progress.\r\n The \"Common Feature Requests\" section of the FAQ lists many popular requests: https://github.com/Microsoft/TypeScript/wiki/FAQ#common-feature-requests\r\n\r\n Replace the text below:\r\n--\u003e\r\n\r\n- `transpileModule`\r\n- `skip typechecking`\r\n- `no typechecking`\r\n\r\nSemi-related issues found:\r\n\r\n- Skip typechecking; only emit (support --transpileOnly in tsc, re-open of #4176) #29651\r\n- [FEATURE REQUEST] Please supply a minified version with only transpilation functionality #9245\r\n- Allow transformers to run without type-checking #41986\r\n\r\n## ✅ Viability Checklist\r\n\r\n\u003c!--\r\n Suggestions that don't meet all these criteria are very, very unlikely to be accepted.\r\n We always recommend reviewing the TypeScript design goals before investing time writing\r\n a proposal for ideas outside the scope of the project.\r\n--\u003e\r\n\r\nMy suggestion meets these guidelines:\r\n\r\n- [x] This wouldn't be a breaking change in existing TypeScript/JavaScript code\r\n- [x] This wouldn't change the runtime behavior of existing JavaScript code\r\n- [x] This could be implemented without emitting different JS based on the types of the expressions\r\n- [x] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)\r\n- [x] This feature would agree with the rest of [TypeScript's Design Goals](https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals).\r\n\r\n## ⭐ Suggestion\r\n\r\n\u003c!-- A summary of what you'd like to see added or changed --\u003e\r\n\r\nModify the `transpileModule` API to mostly do the following:\r\n\r\n- Parses a source string\r\n- Runs the corresponding transforms to get to the target ES version\r\n- Emits a resulting string with a sourceMap string\r\n\r\nThe API itself would be unchanged but would be guaranteed to not hit the type-checker if a certain set of compatible compiler options is set. (deoptimizing options TBD)\r\n\r\nAchieving this without modifying TypeScript is currently not possible with the current TypeScript API: there is currently no way to just apply the transforms without running the checker as a `Program` has to be created in the process.\r\n\r\nAlternatively, if changing `transpileModule` is not possible we would be interested in exposing more minimal API primitives so we could build up this API ourselves:\r\n\r\n- A public `Printer` API that can issue sourcemaps\r\n- A way to run transforms on TS ASTs without the need to build up a `Program` (and run the checker...)\r\n\r\n## 📃 Motivating Example\r\n\r\n\u003c!--\r\n If you were announcing this feature in a blog post, what's a short explanation that shows\r\n a developer why this feature improves the language?\r\n--\u003e\r\n\r\nIn our build system, for certain workflows, we introduced a new build mode that runs `transpileModule` instead of compiling and type-checking the full project. `transpileModule` is run on a per-file basis as we are reading files into our build stream, meaning there are no inter-file ordering dependencies.\r\n\r\n\u003cdetails\u003e\r\n\u003csummary\u003eApproximative `transpileModule` API usage\u003c/summary\u003e\r\n\r\n```ts\r\nconst result = ts.transpileModule(tsFileStr, {\r\n compilerOptions, // \u003c- with an ESNext target\r\n reportDiagnostics: true,\r\n moduleName: tsFilePath,\r\n fileName: tsFilePath,\r\n});\r\nif (result.diagnostics) {\r\n // report syntax errors\r\n if (result.diagnostics.length \u003e 0) {\r\n return;\r\n }\r\n}\r\nconst jsFilePath = tsFilePath.replace(/\\.tsx?$/, \".js\");\r\nconst jsFileStr = result.outputText;\r\nconst sourceMapPath = jsFilePath + \".map\";\r\nconst sourceMapStr = result.sourceMapText;\r\n// ...\r\n```\r\n\r\n\u003c/details\u003e\r\n\r\nWith this new mode, we managed to get 4x faster than an equivalent fully-typechecked build! This is an amazing speedup that is appreciated for running common workflows (while VSCode continues to type-check things in the editor).\r\n\r\nWe are still trying to get faster: most of the time is now spent type-checking inside `transpileModule`, as seen in the CPU flamecharts.\r\n\r\n\r\n\r\nWe researched using alternative build tools such as [swc](https://swc.rs) or [esbuild](https://esbuild.github.io) but using their transpile API alone in our setup is not significantly better than using `transpileModule`! (I could do a writeup on this if anyone is interested in that research) However, those other tools do tend to get really fast when they are run standalone and handle file I/O but unfortunately this does not fit our use case.\r\n\r\nAt this point, a pure js-based transform might be the better option and simply using the TypeScript compiler infrastructure would make sense since all the tools to create a relatively fast module type-stripping system should be there but are not exposed through the current API.\r\n\r\n## 💻 Use Cases\r\n\r\n\u003c!--\r\n What do you want to use this for?\r\n What shortcomings exist with current approaches?\r\n What workarounds are you using in the meantime?\r\n--\u003e\r\n\r\nOur goal is to be able to keep `transpileModule` and have it go faster if the options don't require checking:\r\n\r\n```ts\r\n// ✅ doesn't require checking, fast path:\r\nts.transpileModule(tsFileStr, {\r\n compilerOptions: {\r\n target: \"esnext\",\r\n },\r\n});\r\n\r\n// ❌ requires checking, slow path:\r\nts.transpileModule(\"class c { @x f: string };\", {\r\n compilerOptions: {\r\n target: \"esnext\",\r\n emitDecoratorMetadata: true,\r\n noEmitHelpers: true,\r\n },\r\n});\r\n// emits with some type system info:\r\nclass c { f }\r\n__decorate([], x, __metadata(\"design:type\", String), c.prototype, \"f\", void 0);\r\n```\r\n\r\nBy avoiding type-checking code paths when possible (deoptimizing options TBD), we could speed things up significantly again for the users of `transpileModule`.\r\n\r\nIn the future, it could also be the base to then introduce a `tsc` flag for fast unchecked builds as suggested in #29651.This would permit `tsc` to be significantly faster if opted into with the flag.\r\n\r\n### Deoptimizing options\r\n\r\nThis is a temporary list that we intend to build up over time:\r\n\r\n- `emitDecoratorMetadata`\r\n- ... TBD ...\r\n\r\n---\r\n\r\nIf you can provide some guidance on whether this would be a good thing to change/fix, along with any implementation constraints/tips, I would be happy to attempt an implementation.\r\n","author":{"url":"https://github.com/rricard","@type":"Person","name":"rricard"},"datePublished":"2022-09-09T09:40:10.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":10},"url":"https://github.com/50699/TypeScript/issues/50699"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:5e6bae0e-8735-be0d-db3e-95cc7659a324 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9808:3EF61D:36CEE87:4D2E4AB:6A5F9ADE |
| html-safe-nonce | 29971fab58e6e381af418462ab9617fb29038474b6367a73e162dd2db0e487fc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5ODA4OjNFRjYxRDozNkNFRTg3OjREMkU0QUI6NkE1RjlBREUiLCJ2aXNpdG9yX2lkIjoiMTk3ODEyNjc2MjgxNjU0MzQ1NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a36043f1804201b64ff7492e25618357d9392b19dcf59f1fe95b31310569491b |
| hovercard-subject-tag | issue:1367563682 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/50699/issue_layout |
| twitter:image | https://opengraph.githubassets.com/85d5b728dae9fce2fadf5bda839ce18c50f756b9bbb1c2e0308fb0073a9bea6d/microsoft/TypeScript/issues/50699 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/85d5b728dae9fce2fadf5bda839ce18c50f756b9bbb1c2e0308fb0073a9bea6d/microsoft/TypeScript/issues/50699 |
| og:image:alt | Suggestion 🔍 Search Terms transpileModule skip typechecking no typechecking Semi-related issues found: Skip typechecking; only emit (support --transpileOnly in tsc, re-open of #4176) #29651 [FEATUR... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | rricard |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9353cc7b48460319d80daeeb399e4919b4abcfe6f78d37c7b457924d164a40b1 |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 755d210ae728fcf699d7ab1cdd9866592be6ad35 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width