Commit 18db860
committed
Port JavaScript runtime to TypeScript
This commit ports the JavaScript runtime to TypeScript.
The main work of this commit is to port the KaitaiStream.js to
KaitaiStream.ts. This was pretty much straight search-and-replace task
to map the previously prototype-based class definition to a TypeScript
class definition.
Only in one case, the mapping was not straigtforward: The
deprecated `readBitsInt` was previously set to the exact same function
instance as `readBitsIntBE`. This is not possible in TypeScript.
Instead, this `readBitsInt` is now implemented as a separate function
which simply forwards all calls to `readBitsIntBE`.
This commit does not yet add types to the class member and function
arguments. I am planning to add strict types in a follow-up commit.
To compile the TypeScript file to a JavaScript file, this commit uses
rollup.js. I would have prefered to directly use the TypeScript
compiler, however the TypeScript compiler's UMD loader is missing the
"global" fallback in case no module loader is available.
Usually, I would put the "Kaitaistream.js" into the .gitignore because
it is a generated file. However, doing so would break the existing
super-project structure, because the `run-javascript` script inside the
`tests` repository does not actually build the JavaScript runtime but
only links it1 parent ba12384 commit 18db860
File tree
9 files changed
+1859
-842
lines changed9 files changed
+1859
-842
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
0 commit comments