Skip to content

Commit

Permalink
Remove JSDoc type annotations in TS files (rustwasm#4187)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment authored Oct 12, 2024
1 parent 4c2e923 commit ec6b042
Show file tree
Hide file tree
Showing 16 changed files with 33 additions and 73 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
* String enums now generate private TypeScript types but only if used.
[#4174](https://github.com/rustwasm/wasm-bindgen/pull/4174)

* Remove unnecessary JSDoc type annotations from generated `.d.ts` files
[#4187](https://github.com/rustwasm/wasm-bindgen/pull/4187)

### Fixed

* Fixed methods with `self: &Self` consuming the object.
Expand Down
15 changes: 8 additions & 7 deletions crates/cli-support/src/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2712,7 +2712,7 @@ __wbg_set_wasm(wasm);"
match &export.kind {
AuxExportKind::Function(name) => {
if let Some(ts_sig) = ts_sig {
self.typescript.push_str(&js_docs);
self.typescript.push_str(&ts_docs);
self.typescript.push_str("export function ");
self.typescript.push_str(name);
self.typescript.push_str(ts_sig);
Expand All @@ -2730,7 +2730,7 @@ __wbg_set_wasm(wasm);"
}

exported.has_constructor = true;
exported.push(&js_docs, "constructor", "", &code, ts_sig);
exported.push("constructor", "", &js_docs, &code, &ts_docs, ts_sig);
}
AuxExportKind::Method {
class,
Expand Down Expand Up @@ -2783,7 +2783,7 @@ __wbg_set_wasm(wasm);"
}
};

exported.push(&js_docs, name, &prefix, &code, ts);
exported.push(name, &prefix, &js_docs, &code, &ts_docs, ts);
}
}
}
Expand Down Expand Up @@ -4287,20 +4287,21 @@ fn property_accessor(name: &str) -> String {
impl ExportedClass {
fn push(
&mut self,
docs: &str,
function_name: &str,
function_prefix: &str,
js_docs: &str,
js: &str,
ts_docs: &str,
ts: Option<&str>,
) {
self.contents.push_str(docs);
self.contents.push_str(js_docs);
self.contents.push_str(function_prefix);
self.contents.push_str(function_name);
self.contents.push_str(js);
self.contents.push('\n');
if let Some(ts) = ts {
if !docs.is_empty() {
for line in docs.lines() {
if !ts_docs.is_empty() {
for line in ts_docs.lines() {
self.typescript.push_str(" ");
self.typescript.push_str(line);
self.typescript.push('\n');
Expand Down
10 changes: 0 additions & 10 deletions crates/cli/tests/reference/add.d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
/* tslint:disable */
/* eslint-disable */
/**
* @param {number} a
* @param {number} b
* @returns {number}
*/
export function add_u32(a: number, b: number): number;
/**
* @param {number} a
* @param {number} b
* @returns {number}
*/
export function add_i32(a: number, b: number): number;
3 changes: 0 additions & 3 deletions crates/cli/tests/reference/async-number.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* tslint:disable */
/* eslint-disable */
/**
* @returns {Promise<number>}
*/
export function foo(): Promise<number>;
3 changes: 0 additions & 3 deletions crates/cli/tests/reference/async-void.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* tslint:disable */
/* eslint-disable */
/**
* @returns {Promise<void>}
*/
export function foo(): Promise<void>;
3 changes: 0 additions & 3 deletions crates/cli/tests/reference/builder.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,5 @@
/* eslint-disable */
export class ClassBuilder {
free(): void;
/**
* @returns {ClassBuilder}
*/
static builder(): ClassBuilder;
}
16 changes: 0 additions & 16 deletions crates/cli/tests/reference/enums.d.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
/* tslint:disable */
/* eslint-disable */
/**
* @param {Color} color
* @returns {Color}
*/
export function enum_echo(color: Color): Color;
/**
* @param {Color | undefined} [color]
* @returns {Color | undefined}
*/
export function option_enum_echo(color?: Color): Color | undefined;
/**
* @param {Color} color
* @returns {ColorName}
*/
export function get_name(color: Color): ColorName;
/**
* @param {ColorName | undefined} [color]
* @returns {ColorName | undefined}
*/
export function option_string_enum_echo(color?: ColorName): ColorName | undefined;
/**
* A color.
Expand Down
8 changes: 0 additions & 8 deletions crates/cli/tests/reference/pointers.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
/* tslint:disable */
/* eslint-disable */
/**
* @param {number} input
* @returns {number}
*/
export function const_pointer(input: number): number;
/**
* @param {number} input
* @returns {number}
*/
export function mut_pointer(input: number): number;
11 changes: 0 additions & 11 deletions crates/cli/tests/reference/raw.d.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
/* tslint:disable */
/* eslint-disable */
/**
* @param {number} test
* @returns {number}
*/
export function test1(test: number): number;
export class Test {
free(): void;
/**
* @param {number} test
* @returns {Test}
*/
static test1(test: number): Test;
/**
* @param {number} test
*/
test2(test: number): void;
}
3 changes: 0 additions & 3 deletions crates/cli/tests/reference/result-string.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* tslint:disable */
/* eslint-disable */
/**
* @returns {string}
*/
export function exported(): string;
4 changes: 4 additions & 0 deletions crates/cli/tests/reference/skip-jsdoc.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
* @returns to whence I came
*/
export function docme(arg: number): number;
/**
* Regular documentation.
*/
export function i_has_docs(arg: number): number;
10 changes: 10 additions & 0 deletions crates/cli/tests/reference/skip-jsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@ export function docme(arg) {
return ret >>> 0;
}

/**
* Regular documentation.
* @param {number} arg
* @returns {number}
*/
export function i_has_docs(arg) {
const ret = wasm.i_has_docs(arg);
return ret >>> 0;
}

6 changes: 6 additions & 0 deletions crates/cli/tests/reference/skip-jsdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ use wasm_bindgen::prelude::*;
pub fn docme(arg: u32) -> u32 {
arg + 1
}

/// Regular documentation.
#[wasm_bindgen]
pub fn i_has_docs(arg: u32) -> u32 {
arg + 1
}
2 changes: 2 additions & 0 deletions crates/cli/tests/reference/skip-jsdoc.wat
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
(module $reference_test.wasm
(type (;0;) (func (param i32) (result i32)))
(func $docme (;0;) (type 0) (param i32) (result i32))
(func $i_has_docs (;1;) (type 0) (param i32) (result i32))
(memory (;0;) 17)
(export "memory" (memory 0))
(export "docme" (func $docme))
(export "i_has_docs" (func $i_has_docs))
(@custom "target_features" (after code) "\02+\0fmutable-globals+\08sign-ext")
)

3 changes: 0 additions & 3 deletions crates/cli/tests/reference/string-arg.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* tslint:disable */
/* eslint-disable */
/**
* @param {string} a
*/
export function foo(a: string): void;
6 changes: 0 additions & 6 deletions crates/cli/tests/reference/web-sys.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
/* tslint:disable */
/* eslint-disable */
/**
* @returns {URL}
*/
export function get_url(): URL;
/**
* @returns {MediaSourceEnum}
*/
export function get_media_source(): MediaSourceEnum;
/**
*The `MediaSourceEnum` enum.
Expand Down

0 comments on commit ec6b042

Please sign in to comment.