-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Support pulling type information directly from .wasm
modules
#39784
Conversation
@typescript-bot pack this |
Heya @weswigham, I've started to run the tarball bundle task on this PR at 0f6b16e. You can monitor the build here. |
Hey @weswigham, I've packed this into an installable tgz. You can install it for testing by referencing it in your
and then running |
This would be amazing to have, especially for AssemblyScript users, but also anyone importing Wasm with type declarations. This would help reduce the barrier of entry for people wanting to try WebAssembly. What would it do to existing JS projects that rely on |
Related: #31713 |
|
||
|
||
//// [wasmImportsSimple.js] | ||
import * as mod from "test.wasm"; |
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.
The emitted module specifier doesn’t look right.
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.
The test harness strips the leading /.lib/
because it's on the real disk from the host machine (and has the corresponding full, real path) - it only does this in the test harness~
@typescript-bot pack this |
Heya @weswigham, I've started to run the tarball bundle task on this PR at 0f6b16e. You can monitor the build here. |
Hey @weswigham, I've packed this into an installable tgz. You can install it for testing by referencing it in your
and then running |
Is it possible to extends this possibility to a set of public APIs that allow custom file types (e.g. CSS Modules, GraphQL, ...) to be able to generate in-memory declarations and join the incremental building / watch mode building? Does this PR copy the |
This experiment is pretty old, so I'm going to close it to reduce the number of open PRs. |
To better support
wasm
modules under node's--experimental-wasm-modules
flag.In this PR, I add a new
experimentalWasmModules
typescript flag, which allows one to import.wasm
files directly in TS code without us issuing an error (this is only supported at runtime innode
using the node flag mentioned above). When enabled, we parse the contents of referenced.wasm
files for their exported function names and types, and generate a declaration file on-the-fly in memory for it based on those types (and that declaration file is what we then bind/check against).This is still very much a limited experiment, with only a small subset of possible features implemented thus far, but is far enough along to be able to show some new behavior:
In the above, on the left, I'm watch-rebuilding an
assemblyscript
program into awasm
module. On the right, I'm consuming that module in the editor, and getting live updates (with auto imports) as the backing.wasm
module updates. Repo available here.In any case, this should be a complete enough implementation to be able to gauge interest in the feature.
TODO:
readFile
compiler API so it can more easily returnUInt8Array
instances, rather thanstring
s (since wasm file contents are most definitely not strings). (You'll note that right now I have a separate host API call for it, which is very painful). Pretty much our entire file pipeline is geared for strings only (especially in the language service) - this is probably the biggest practical blocker for this..wasm
files (and introduce more early sanity checks on index bounds).wasm
imports when building the program (wasm files may import other wasm (or JS?) files - while this has no bearing on the types of the exports, it may result in the inclusion of more files in the program (which may in turn impact declaration emit))i32
/i64
/f32
/f64
subtypes ofnumber
and strongly check that the inputs/outputs of awasm
module are bounds-checkeddeclaration: true
is set.wasm
parsing/tree reuse in the language service (I had to wholly disable incremental LS operations on wasm files to get the LS to function, since they both need nonstring file reads, and are not updatable with the normal incremental parser)