You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Getting the no-modules TypeScript *.d.ts Files Working (#2396)
* In NoModule builds, switched "export" keyword to "declare" in d.ts file.
This aims to be the first step at getting the d.ts file working. The reason for this is that the TypeScript (3.8.3)
compiler ignores "declare" statements if it sees "export" statements. Not sure if that's a bug in TypeScript.
Either way, all I really did here was scan through all changes to `self.typescript` and see if it could add an "export".
The only big wild-card I found was the `typescript_custom_sections`, which I think exists just to let `wasm_buildgen`
annotations to add extra typescript to the document?
* Trying to putting the generated methods into a `wasm_bindgen` namespace.
This is a bit crude, basically anything before the "init" block is put in this namespace.
Hopefully this works in general. I'm not 100% sure yet.
* Fixed a typo in the comments.
* In NoModules d.ts files `init()` is renamed to `wasm_bindgen()`.
Based on the output JavaScript this seems to be how it works.
* Realized that the function declarations couldn't also have `declare`s.
Then traced through the other instances where I'd switched `export` to `declare` and switched them over if they were going to end up in the same `wasm_bindgen` namespace.
* Realized there was a nice no_modules() method.
* Removing the extra spaces at the end of the .d.ts files.
* Realized that can leave the `export` in the namespace declaration.
* Adding tests for the no-modules target.
I'm hoping that `run.sh` is what the CI runs.
* Tried to get the no-modules TypeScript tests to build against actual TypeScript.
So now the `*.d.ts` files will actually be build against (modified) `*.ts` files. This should be a better check than only verifying TypeScript doesn't fail when given just the `*.d.ts` files (what it did before).
Note that the `*.ts` files are generated from the `*.ts` files in `src` using some fairly simple Regular Expressions.
This skips checking the `typescript_tests_bg.wasm.d.ts` file, as I have no experience using that.
* Adding more info about the testing changes in run.sh.
# Then create copies of the TypeScript tests used on "--target web" (i.e. those in ./src) but adjust them to work with "--target no-modules".
36
+
# Store the new generated test files under "src_no_modules".
37
+
rm -rf src_no_modules
38
+
mkdir src_no_modules
39
+
cd src
40
+
forfilenamein*.ts;do
41
+
if grep -q "_bg.wasm""$filename"
42
+
then
43
+
# I am unsure how to import or test the "*_bg.wasm" file.
44
+
# So any test file that includes those is currently being skipped.
45
+
echo"Ignoring $filename as it uses the *.wasm.d.ts file."
46
+
else
47
+
path="../src_no_modules/$filename"
48
+
# Copy over every line EXCEPT for the import statements (since "no-modules" has no modules to import).
49
+
grep -v -w "import""$filename">"$path"
50
+
# Then replace all of the instances of "wbg" (the namespace all the tests use to import the *.d.ts files from "--target web") with "wasm_bindgen" (the namespace the `no-modules` *.d.ts files use).
51
+
sed -i "s/wbg\./wasm_bindgen./g""$path"
52
+
sed -i "s/wbg /wasm_bindgen /g""$path"
53
+
sed -i "s/wbg\[/wasm_bindgen[/g""$path"
54
+
fi
55
+
done
56
+
cd ..
57
+
58
+
# Then try to build the typescript in the src_no_modules folder against the pkg/no_modules build.
0 commit comments