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

Invalid d.ts produced after 0.2.56 upgrade #1926

Closed
TomCrypto opened this issue Dec 21, 2019 · 1 comment · Fixed by #1945
Closed

Invalid d.ts produced after 0.2.56 upgrade #1926

TomCrypto opened this issue Dec 21, 2019 · 1 comment · Fixed by #1945
Labels

Comments

@TomCrypto
Copy link

Describe the Bug

After upgrading to 0.2.56, there are errors in the generated crate.d.ts (not the _bg one) that are due to invalid generated typescript.

Steps to Reproduce

  1. Use the https://github.com/rustwasm/wasm-pack-template or whatever to create a new project
  2. Insert the following test case
#[wasm_bindgen]
pub struct Foo {}

#[wasm_bindgen]
impl Foo {
    pub fn test1(&mut self) -> bool {
        true
    }

    pub fn test2(&mut self, _foo: f32) {
        return;
    }
}

Expected Behavior

The expected (and generated as of 0.2.55) d.ts looked like this:

export class Foo {
  free(): void;
/**
* @returns {boolean} 
*/
  test1(): boolean;
/**
* @param {number} _foo 
*/
  test2(_foo: number): void;
}

Actual Behavior

When using wasm-bindgen 0.2.56 instead, the following invalid typescript is generated instead:

export class Foo {
  free(): void;
/**
* @returns {bool} 
*/
  test1(): bool;
/**
* @param {number} this.ptr 
*/
  test2(this.ptr: number): void;
}

Additional Context

There might be other regressions; these are just the ones that I immediately found in my wasm project.

@alexcrichton
Copy link
Contributor

Thanks for the report here! Indeed bool -> boolean was one glaring error, and I can see where the other is coming from (the this.ptr weirdness), I'll try to work on a fix soon!

alexcrichton added a commit to alexcrichton/wasm-bindgen that referenced this issue Jan 7, 2020
This commit updates how TypeScript signature are generated from adapters
in wasm-bindgen. A richer set of `AdapterType` types are now stored
which record information about optional types and such. These direct
`AdapterType` values are then used to calculate the TypeScript
signature, rather than following the instructions in an adapter function
(which only works anyway for wasm-bindgen generated adapters).

This should be more robust since it reads the actual true signature of
the adapter to generate the TypeScript signature, rather than attempting
to ad-hoc-ly infer it from the various instructions, which was already
broken.

A number of refactorings were involved here, but the main pieces are:

* The `AdapterType` type is a bit more rich now to describe more
  Rust-like types.
* The `TypescriptArg` structure is now gone and instead return values
  are directly inferred from type signatures of adapters.
* The `typescript_{required,optional}` methods are no longer needed.
* The return of `JsBuilder::process` was enhanced to return more values,
  rather than storing some return values on the structure itself.

Closes rustwasm#1926
alexcrichton added a commit to alexcrichton/wasm-bindgen that referenced this issue Jan 7, 2020
This commit updates how TypeScript signature are generated from adapters
in wasm-bindgen. A richer set of `AdapterType` types are now stored
which record information about optional types and such. These direct
`AdapterType` values are then used to calculate the TypeScript
signature, rather than following the instructions in an adapter function
(which only works anyway for wasm-bindgen generated adapters).

This should be more robust since it reads the actual true signature of
the adapter to generate the TypeScript signature, rather than attempting
to ad-hoc-ly infer it from the various instructions, which was already
broken.

A number of refactorings were involved here, but the main pieces are:

* The `AdapterType` type is a bit more rich now to describe more
  Rust-like types.
* The `TypescriptArg` structure is now gone and instead return values
  are directly inferred from type signatures of adapters.
* The `typescript_{required,optional}` methods are no longer needed.
* The return of `JsBuilder::process` was enhanced to return more values,
  rather than storing some return values on the structure itself.

Closes rustwasm#1926
alexcrichton added a commit to alexcrichton/wasm-bindgen that referenced this issue Jan 7, 2020
This commit updates how TypeScript signature are generated from adapters
in wasm-bindgen. A richer set of `AdapterType` types are now stored
which record information about optional types and such. These direct
`AdapterType` values are then used to calculate the TypeScript
signature, rather than following the instructions in an adapter function
(which only works anyway for wasm-bindgen generated adapters).

This should be more robust since it reads the actual true signature of
the adapter to generate the TypeScript signature, rather than attempting
to ad-hoc-ly infer it from the various instructions, which was already
broken.

A number of refactorings were involved here, but the main pieces are:

* The `AdapterType` type is a bit more rich now to describe more
  Rust-like types.
* The `TypescriptArg` structure is now gone and instead return values
  are directly inferred from type signatures of adapters.
* The `typescript_{required,optional}` methods are no longer needed.
* The return of `JsBuilder::process` was enhanced to return more values,
  rather than storing some return values on the structure itself.

Closes rustwasm#1926
alexcrichton added a commit that referenced this issue Jan 7, 2020
)

This commit updates how TypeScript signature are generated from adapters
in wasm-bindgen. A richer set of `AdapterType` types are now stored
which record information about optional types and such. These direct
`AdapterType` values are then used to calculate the TypeScript
signature, rather than following the instructions in an adapter function
(which only works anyway for wasm-bindgen generated adapters).

This should be more robust since it reads the actual true signature of
the adapter to generate the TypeScript signature, rather than attempting
to ad-hoc-ly infer it from the various instructions, which was already
broken.

A number of refactorings were involved here, but the main pieces are:

* The `AdapterType` type is a bit more rich now to describe more
  Rust-like types.
* The `TypescriptArg` structure is now gone and instead return values
  are directly inferred from type signatures of adapters.
* The `typescript_{required,optional}` methods are no longer needed.
* The return of `JsBuilder::process` was enhanced to return more values,
  rather than storing some return values on the structure itself.

Closes #1926
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants