Skip to content
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 typescript utility types #8

Merged
merged 6 commits into from
Feb 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

- support overloaded functions and methods. #4
- generate js-sys types for corresponding typescript types. #3
- support [typescript utility types](https://www.typescriptlang.org/docs/handbook/utility-types.html) #6

### Fixed

Expand Down
3 changes: 2 additions & 1 deletion ts-bindgen-gen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ The overall flow is:
- Issues with typescript modules and name resolution (e.g. referencing A.B in a typescript module should look for A.B in all ancestors but, as implemented, looks for B in all ancestors).
- Rarely used typescript namespaces are not properly handled yet (they should result in js_namespace attrs in wasm-bindgen) and require special handling in bundling to work (see the [paperjs example](../ts-bindgen/examples/paperjs).
- Improve performance
- Functions passed to js are leaked without interface type support
- Functions don't handle `this` parameters properly

# Needed refactorings

- Codegen is too complex and would be *much* better served by another ir transformation pass to convert to a data representation of the rust code we want to generate and **then** generating a TokenStream more straightforwardly from that representation. This would enable, for example, references to a single generated name instead of hoping to re-generate the same name in multiple places.
- Automatically generate bindings for all [typescript test cases](https://github.com/microsoft/TypeScript/tree/main/tests/baselines/reference) and ensure the generated bindings compile.
- Builtins should not be enums but should configured struct instances.
- The ir transformation pipeline could be better served by something like [frunk::Generic](https://docs.rs/frunk/latest/frunk/generic/index.html).

# License
Expand Down
34 changes: 0 additions & 34 deletions ts-bindgen-gen/src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1155,25 +1155,6 @@ impl<'a, FS: Fs + ?Sized> ToTokens for WithFs<'a, TargetEnrichedType, FS> {
panic!("Intersections must not be empty");
}
}
/*TypeInfo::Mapped {
value_type: Box<TypeInfo>,
},
TypeInfo::LitNumber {
n: f64,
},
TypeInfo::LitString {
s: String,
},
TypeInfo::LitBoolean {
b: bool,
},
TypeInfo::Constructor {
params: Vec<Param>,
return_type: Box<TypeInfo>,
},
TypeInfo::Var {
type_info: Box<TypeInfo>,
},*/
TargetEnrichedTypeInfo::NamespaceImport(NamespaceImport::All { src, .. }) => {
let ns = src.as_path().to_ns_path(*fs, type_name);
if ns.len() == 1 {
Expand Down Expand Up @@ -1343,21 +1324,6 @@ impl ToTokens for TargetEnrichedTypeInfo {
#f
}
}
/*
TargetEnrichedTypeInfo::Constructor {
params: Vec<Param>,
return_type: Box<TypeInfo>,
},
TargetEnrichedTypeInfo::Class(Class {
members: HashMap<String, Member>,
}),
TargetEnrichedTypeInfo::Var {
type_info: Box<TypeInfo>,
},
TargetEnrichedTypeInfo::GenericType {
name: String,
constraint: Box<TypeInfo>,
},*/
TargetEnrichedTypeInfo::NamespaceImport(_) => panic!("namespace import in type info"),
_ => {
quote! {}
Expand Down
Loading