Migrate to TypeScript 6.0, set TypeScript target to ES6 (ES2015 / ECMAScript 2015)#37
Migrate to TypeScript 6.0, set TypeScript target to ES6 (ES2015 / ECMAScript 2015)#37generalmimon wants to merge 3 commits into
Conversation
|
Cc @Azq2, @cherue, @EdJoPaTo, @mfalkvidd |
|
Thanks for including me @generalmimon . I am not 100% sure why I was tagged, but I have probably asked for / discussed es5 support since I use Thingsboard, which is using Nashorn. Nowadays, Thingsboard recommends remote js executor (which is based on nodejs and therefore supports es6) or TBEL which is a fork of MVEL. It would be nice if Kaitai could support generating MVEL code, but since we can use the remote js executor in Thingsboard it should still be possible to use es6 Kaitai anyway. And as you mentioned, we could always stay with an older version of Kaitai or use Babel. The only thing I would add is that it would be nice if this was considered a breaking change and trigger a new version, especially since switching to semver is already being discussed. That way it would be clear which version to stay on. |
|
@mfalkvidd Thank you for your feedback!
Yes, your past pull requests were the reason, because they showed that you care(d) about ES5 compatibility :)
I guess that makes sense. The transition to SemVer is discussed in kaitai-io/kaitai_struct#1293. For now, we plan for 1.x versions to be compatible with 0.x, while 2.x versions will have breaking changes. If we consider this a breaking change, then this PR should go into 2.x, so let me mark this PR as a draft so that we don't accidentally merge it prematurely (as I've done with other PRs containing breaking changes: kaitai-io/kaitai_struct#1288 (comment)). |
|
I'm still working on the ES6 & TypeScript. During some periods, I just don't have enough time to work on it. But yesterday I got back to it again. I can send all my work as a draft PR's. Current progress (very short description): RuntimeDonePackage & Build System
KaitaiStruct
KaitaiStream
Planned
CompilerDone
Planned
CI Systemhttps://github.com/yet-another-org-with-forks/kaitai_struct_tests/tree/typescript_and_esm Done
LOG: https://gist.github.com/Azq2/9203b1b0718693e790fc456f5f874a76 Planned
|
|
And about targets... my opinion:
I think it would be good to align the minimum NodeJS version with TypeScript. For example, the minimum version for TS6 is Node 14: For the ES target, I think ES2022 is a good choice: https://caniuse.com/?search=es2022 Example Gif.js: https://gist.github.com/Azq2/fb3aebd0c0b96c3f73136171c14f048f The current version of the JS compiler uses these features:
All of these features are supported even in legacy NodeJS 12. However, if ES2015 is mandatory, the following can be polyfilled:
The current JavaScriptCompiler can support this without big changes. // Not applicable to the TypeScriptCompiler, since TSC will gracefully downgrade all of these features. |
Keep in mind that a bunch of people are using old tablets in a bunch of places (like wall displays or signs) which don't receive updates anymore. (I have an iOS 12 tablet in use and I know more hobbyists using similar older tech for stuff like that.) Projects that should run there could not use Kaitai Struct output when they require newer JS features. Not sure how many people would need that. Supporting these 10+ years old mobile browsers would be nice. |
This case can be handled with babel & polyfills Fancy fact - 10+ years ago it was 2016, not 2000's.... Most 2016 browsers ES6 capable: https://caniuse.com/?search=ES6 |
|
Another argument for a higher ES version - BigInt was added in ES2020: https://caniuse.com/?search=es2020 // Also, BigInt is one feature that cannot be transpiled to lower targets. It seems sooner or later a choice will have to be made: the future or legacy. |
522b275 to
48bec97
Compare
Related issue: kaitai-io/kaitai_struct#539 See also kaitai-io/kaitai_struct#542 (comment) --- The ECMAScript 5 (ES5) target was deprecated in TypeScript 6.0, see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-6-0.html#deprecated-target-es5 ES6 (ES2015) is now the TypeScript's lowest target. ES6 is widely supported across JavaScript engines, see https://compat-table.github.io/compat-table/es6/ As can be seen from the table and also from https://zoo.js.org/, there are several non-mainstream JS engines that don't support ES6 classes (which is the main feature we need), namely: * Rhino 1.9.0 - see mozilla/rhino#835 and https://github.com/ivankra/javascript-zoo-data/blob/8d76f329c686f006081842b5c5091880e49efd03/compat-table/rhino.json#L400 * Hermes 0.12.0 - see facebook/hermes#685; Hermes 0.13.0 likely already supports them, Hermes V1 (the default `static_h` branch of the https://github.com/facebook/hermes repo; see https://zoo.js.org/#hermes-v1) definitely does, see https://github.com/ivankra/javascript-zoo-data/blob/8d76f329c686f006081842b5c5091880e49efd03/compat-table/hermes_full.json#L381-L404 * Nashorn 15.7 (labeled "JJS 1.8" at https://compat-table.github.io/compat-table/es6/) - see https://github.com/ivankra/javascript-zoo-data/blob/8d76f329c686f006081842b5c5091880e49efd03/compat-table/nashorn.json#L401 and https://bugs.openjdk.org/browse/JDK-8066046 * Duktape 2.7 - apparently abandoned, see https://github.com/svaarala/duktape (last release in February 2022 and no commits since January 2024) I believe it makes sense to leave these rather outdated JavaScript runtimes behind and no longer support them out of the box in future versions of Kaitai Struct. If any of our users use one of the runtimes listed above or another ES5-only runtime, they can continue using existing versions of Kaitai Struct, or use [Babel](https://babeljs.io/) to transpile ES6 code to ES5.
These `Object.setPrototypeOf` calls are now unnecessary, since our TypeScript compilation target is set to ES6. From <https://www.typescriptlang.org/docs/handbook/2/classes.html#inheriting-built-in-types>: > Note: If you don't plan to inherit from built-in types like `Array`, > `Error`, `Map`, etc. or your compilation target is explicitly set to > `ES6`/`ES2015` or above, you may skip this section
48bec97 to
de803c9
Compare
Related issue: kaitai-io/kaitai_struct#539
See also kaitai-io/kaitai_struct#542 (comment)
The ECMAScript 5 (ES5) target was deprecated in TypeScript 6.0, see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-6-0.html#deprecated-target-es5. ES6 (ES2015) is now the TypeScript's lowest target.
ES6 is widely supported across JavaScript engines, see https://compat-table.github.io/compat-table/es6/. As can be seen from this table and also from https://zoo.js.org/, there are several non-mainstream JS engines that don't support ES6 classes (which is the main feature we need), namely:
static_hbranch of the https://github.com/facebook/hermes repo; see https://zoo.js.org/#hermes-v1) definitely does, see https://github.com/ivankra/javascript-zoo-data/blob/8d76f329c686f006081842b5c5091880e49efd03/compat-table/hermes_full.json#L381-L404I believe it makes sense to leave these rather outdated JavaScript runtimes behind and no longer support them out of the box in future versions of Kaitai Struct. If any of our users use one of the runtimes listed above or another ES5-only runtime, they can continue using existing versions of Kaitai Struct, or use Babel to transpile ES6 code to ES5.