Comments (4)
- Some items have various serde attributes
serde
attributes that change the tagging, flattening. Does Tsify account for these?
Yep, though there's one or two idiosyncrasies (namely rename
directly on a struct - it tends to mess with references to the original name).
Indeed, it's a proc macro. Yeah, all the top level function exports (members of wasm_bindings) are ineligible for the macro form sadly (the tsify crate is in a... complicated state re maintenance - pretty sure I can modify it to work on functions, but that would require depending on a fork :-/), so it's back to typescript_custom_section
for those, looks like this:
#[wasm_bindgen(typescript_custom_section)]
const TYPES: &str = r###"
export function parse_expression(input: string): {Ok: Expression} | {Err: [string, Span]}
export function parse_module(input: string): {Ok: Module} | {Err: [string, Span]}
"###;
The consensus around non-automated use of those is: Good for slowly changing api surfaces; avoid for everything else (because they're susceptible to typedef drift).
Also, one follow-up question:
The direct wasm-bindgen cli calls, those were motivated by problems getting wasm-pack to work correctly, right? If you like, I have a fix for that that I'll cordon off in it's own commit (so we can omit it if necessary).
from ezno.
I see, I will bear that in mind for changes. Can you have separate sections? So that rather than one block, there is one above each function to keep it together?
Good point, yes, that's permitted (I've actually already switched to that in the parser crate, far too difficult to write otherwise).
I can't quite remember but I think I had some issues with wasm-pack. One thing is that using the wasm-bindgen CLI directly I can pin the CLI version so it is the same version as the crate (I have had some problems where the GH actions downloaded a CLI with a new patch which wasn't equal to the one crates dependency and so broke). Is there any benefits to doing it in one with wasm-pack?
Yeah, the big win from wasm-pack is wasm-opt (~30% uncompressed size reduction (negligible compressed). The optimization runs are, like most compilers, pretty variable wrt execution time reductions - I typically see ~10-15% speed boosts). the wasm-pack maintainers have been pretty good about ensuring the bindgen version precisely matches the crate's version (there's a fair amount of careful Cargo.toml parsing involved).
from ezno.
This looks great! Some hopefully helpful information
- Yes, at the moment the
.d.ts
built files are not exported. I can't quite remember, but I think when I tried it last I got an error or something and skipped it, just to get it published. If you don't get an error that is great! - So at the moment there are two exported areas that would need definitions under:
- The type checking, this takes
TypeCheckOptions
and outputs aVec<Diagnostic>
(this type might be lost throughJSValue
annotations). Should be okay to addTsify
(I am correct in thinking this is a proc macro that creates TS definitions from Rust items?) to those definitions that implementserde::Serialize
in the./checker
crate. Additionally thecheck
andbuild
functions (inwasm_bindings
) take a file retrieval function. It is typed in Rust as ajs_sys::Function
, the TS type is(path: string) => string
- Some parser playground things. I think there are two exports
parse_module
andparse_expression
. Both takeParseOption
and they return AST structures (and their many decedents).
- The type checking, this takes
- Serializing (/turning to JSON) in the checker and parser is done under the
serde-serialize
feature flag. I thinkderive(Tsify)
can added under the same conditional attributes - Some items have various serde attributes
serde
attributes that change the tagging, flattening. Does Tsify account for these? - These exports return most things inside the crate. However I think the parser contains
Span
s (positions of where nodes were parsed from the source) and in the the checker, diagnostics have aSpan
which point to the origin of the issue. These come from (my) source-map crate. If you also want to PR that repo to add it to there I will gladly accept! - Didn't know about the macro_rules_attribute crate! This looks amazing and something I was wondering whether it exists (those attributes are getting quite long now in the parser). I didn't think it was possible. Would be excellent if you added that at the same time.
Looking forward to the PR!
from ezno.
The consensus around non-automated use of those is: Good for slowly changing api surfaces; avoid for everything else (because they're susceptible to typedef drift).
I see, I will bear that in mind for changes. Can you have separate sections? So that rather than one block, there is one above each function to keep it together?
The direct wasm-bindgen cli calls, those were motivated by problems getting wasm-pack to work correctly, right? If you like, I have a fix for that that I'll cordon off in it's own commit (so we can omit it if necessary).
I can't quite remember but I think I had some issues with wasm-pack. One thing is that using the wasm-bindgen CLI directly I can pin the CLI version so it is the same version as the crate (I have had some problems where the GH actions downloaded a CLI with a new patch which wasn't equal to the one crates dependency and so broke). Is there any benefits to doing it in one with wasm-pack?
from ezno.
Related Issues (20)
- Implement destructuring assignment (declaration works already)
- feat(ci): auto-fix formatting and linting on new PRs HOT 1
- Improve fuzzing tests HOT 11
- Check using the type annotation for default parameter value and try-catch variable HOT 2
- Is there still a way to convert from OXC parsed AST to Ezno? HOT 1
- Crates in this repository have a different versions HOT 2
- Missing `Console` methods HOT 3
- Class types and class extends
- Allow for more than u16::MAX types HOT 1
- Merge Ezno runtime definitions with existing TS definition files HOT 3
- Narrowing
- Interface extends and type parameters extends
- Closure TDZ HOT 1
- Nominal classes
- `console.log` not variadic HOT 2
- Bug: Unsound checking of function calls with array parameters HOT 3
- `never` type lookup - "Cannot find type never" HOT 4
- Proposal: Support `unknown`, rename `TypeId::ANY_TYPE` -> `TypeId::UNKNOWN_TYPE` HOT 1
- Parsing import meta
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ezno.