-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Switch from TS to JS #4000
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch from TS to JS #4000
Conversation
d9936fe
to
250c9e7
Compare
f7683a8
to
20f8f7f
Compare
Some updates
This is the final step that should be taken. @LeaVerou, could you elaborate a bit? Do we want to check JS files using the TS compiler and show errors? Should it work the same way the |
- Restore `tsconfig.json` but allow implicit `any` - Add the `typecheck` NPM script - Adjust the build script (use `tsconfig.json` and remove redundant code)
7676335
to
03733d1
Compare
may I ask why the Prism project is moving from TS to JS? It'd be great to have reasoning in the PR body since JSDoc is considered less ergonomic than Typescript. |
Some more updates:
Now, all JS files (except |
Please note that there has never been a released Prism version using TS, so the Prism project is not moving to JS, it is simply not moving to TS. A past maintainer rewrote the codebase to use TS as it would help him move faster, and I agreed in the interest of making progress. Since he left and I took over again (with my apprentice @DmitrySharabin's help) we really gave TS a good shot since the v2 codebase was already using it and it was cheaper than switching at that point. However, the DX has been a constant uphill battle, and we found we were spending more time dealing with TS than actually making progress on v2. Besides the sheer time spent jumping through TS hoops to simply express how things worked, hoops that provided absolutely no benefit in terms of finding bugs more easily, there were also the pointless TS assertions for obvious (to a human) things that added noise all over the codebase. Go through the code this PR removes (e.g. in the grammar files) for many samples of this. TS is fantastic for getting folks from classical strongly typed / statically typed languages into JS. But for JS-native folks, it means that many of the dynamic coding and metaprogramming paradigms that JS allows (and that Prism takes good advantage of) are very challenging to express in TS. Additionally, Prism is the type of project where performance can be critical, so there is an advantage to avoiding such heavy abstractions unless absolutely necessary. Staying closer to the metal (at least as much as one can be with JS) allows to better optimize highlighting. Do note that using JS doesn't mean the project is untyped, or that all types are now defined in JSDoc. JSDoc is used for simple types, whereas complex types are defined in If you're a TS user, you could help by trying out this PR and reporting back on the experience! |
All issues with types (which appeared after allowing TS checking of JS files) are now fixed. If we still had a CI task for checking types, we would pass it. That means the changes in this PR don't make the codebase worse than it was before. I think the PR is ready for review. |
@DmitrySharabin I just went through the PR, though not very deeply. All LGTM, except the comment I left: why do we still need a build step given that lazy grammars are (supposed to be) evaluated when they're first used? That's the whole point of lazy grammars — otherwise they're not saving anything if we pre-build them. |
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.
I haven't looked super deeply, but LGTM from a quick skim. We can fix any issues as they come up. Let's land this baby and kill TS with 🔥 ! Thanks for the hard work @DmitrySharabin!
(thinking @getify would approve of the spirit of this PR 😀)
Seconded 😃 |
nicely done! 💯 |
Summary
build
script to build types (.d.ts
files)components.js
fromcomponents.json
, import attributes are used to read the JSON file directlytsconfig.json
files are removedpackage.json
adjusted accordingly (no more script for checking TS)Prism
v2
can still be used in the same way asv1
. To see it in action (with files from this PR), go to: https://codepen.io/dmitrysharabin/pen/QwjqywJ?editors=1000