-
Notifications
You must be signed in to change notification settings - Fork 866
TypeScript Core #8861
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
Open
chharvey
wants to merge
4
commits into
WebAssembly:main
Choose a base branch
from
chharvey:feat/ts-core
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
TypeScript Core #8861
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # EditorConfig: https://EditorConfig.org | ||
|
|
||
| root = true | ||
|
|
||
| [*] | ||
| charset = utf-8 | ||
| end_of_line = lf | ||
| indent_size = tab | ||
| indent_style = tab | ||
| insert_final_newline = true | ||
| max_line_length = off | ||
| trim_trailing_whitespace = true | ||
|
|
||
| [**/*.json] | ||
| indent_size = 2 | ||
| indent_style = space |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # dependency directories | ||
| node_modules/ | ||
|
|
||
| # built files | ||
| build/ | ||
|
|
||
| # compiled TypeScript | ||
| dist/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,176 @@ | ||
| # Binaryen.TS | ||
| Binaryen API ported to TypeScript for use in the browser and in Node.JS. | ||
|
|
||
| ## How To Use | ||
| ```zsh | ||
| $ npm install binaryen.ts | ||
| ``` | ||
| ```ts | ||
| import * as binaryen from "binaryen.ts"; | ||
|
|
||
| const mod: binaryen.Module = new binaryen.Module(); | ||
|
|
||
| mod.functions.add("add", binaryen.createType([binaryen.i32, binaryen.i32]), binaryen.i32, [binaryen.i32], (() => { | ||
| const {block, local, i32} = mod.wasm; | ||
| const param0: binaryen.ExpressionRef = local.get(0, binaryen.i32); | ||
| const param1: binaryen.ExpressionRef = local.get(1, binaryen.i32); | ||
| const result: binaryen.ExpressionRef = i32.add(param0, param1); | ||
| return block(null, [ | ||
| local.set(2, result), | ||
| local.get(2, binaryen.i32), | ||
| ], binaryen.i32); | ||
| })()); | ||
| mod.exports.addFunction("add", "add"); | ||
| mod.optimize(); | ||
| if (!mod.validate()) { | ||
| throw new Error("Invalid WebAssembly module."); | ||
| } | ||
|
|
||
| const textData = mod.emitText(); | ||
| const wasmData = mod.emitBinary() as Uint8Array<ArrayBuffer>; | ||
| const compiled = new WebAssembly.Module(wasmData); | ||
| const instance = new WebAssembly.Instance(compiled, {}); | ||
|
|
||
| console.log(instance.exports.add(41, 1)); // 42 | ||
| ``` | ||
|
|
||
| ## How to Contribute | ||
| Contributions are welcome! | ||
| Make sure you have [Git](https://git-scm.com/) and [Node (and NPM)](https://nodejs.org/) installed on your machine, | ||
| and have already cloned the **WebAssembly/binaryen** repo. | ||
|
|
||
| From the repo’s root: | ||
| ```zsh | ||
| $ cd ./ts/ | ||
| $ npm ci | ||
| $ npm run prepublishOnly # gets the package in working order | ||
| ``` | ||
|
|
||
| ### Pipeline | ||
| #### Set Up the Emscripten Build | ||
| You’ll need to do this whenever pulling changes from the C++ repo. | ||
| ```zsh | ||
| $ npm run make # emits Emscripten builds to ./build/ | ||
| ``` | ||
|
|
||
| #### Develop in TypeScript | ||
| The core of this project is written in [TS](https://www.typescriptlang.org/), best paired with a powerful editor and some nice extensions. | ||
| ```zsh | ||
| $ npm run compile # emits javascript output to ./dist/ | ||
| ``` | ||
| Don’t put anything important in `./dist/`, as it gets deleted and rebuilt each time. | ||
|
|
||
| Before committing, ensure only the best code quality by running [ESLint](https://eslint.org/). | ||
| ```zsh | ||
| $ npm run lint # reports linter errors & warnings | ||
| $ npm run lint -- --fix # tries to auto-fix problems (some may need manual fixing) | ||
| ``` | ||
|
|
||
| Use [Conventional Commits](https://www.conventionalcommits.org/) commit message format. | ||
| Messages should be in the present tense / command tense. | ||
| ```zsh | ||
| $ git commit -m "feat: add a new feature" | ||
| $ git commit -m "feat!: add a new breaking feature" # API consumers need to know about these | ||
| $ git commit -m "fix: fix a bug" | ||
| $ git commit -m "refactor: reorganize code" | ||
| $ git commit -m "lint: fix a coding style issue" | ||
| $ git commit -m "docs: update documentation" | ||
| $ git commit -m "test: add/update tests" | ||
| $ git commit -m "build: make a change related to the package build system" | ||
| ``` | ||
|
|
||
| #### Update Docs | ||
| Generated documentation is built with [TypeDoc](https://typedoc.org/), a tool that parses comments in the TS source files and produces beautiful HTML. | ||
|
|
||
| After developing and updating doc-comments, regenerate docs and view them locally in your browser. | ||
| ```zsh | ||
| $ npm run docs # builds a static site to ../docs/binaryen.ts/ | ||
| $ open ../docs/binaryen.ts/index.html | ||
| ``` | ||
| Don’t put anything important in `../docs/`. | ||
|
|
||
| Documentation is hosted online via GitHub Pages at <https://chharvey.github.io/binaryen/binaryen.ts/>, | ||
| and will be moved to <https://webassembly.github.io/binaryen/binaryen.ts/> once this fork is merged in. | ||
|
|
||
| Upon every release, public docs should be redeployed via updating the `gh-pages` branch. On that branch, the `../docs/` folder is checked in. | ||
| You need to switch to that branch, merge in your changes, rebuild the docs, then commit and push. | ||
| ```zsh | ||
| $ git switch gh-pages | ||
| $ git merge --no-commit main | ||
| $ npm run docs | ||
| $ git add ../docs/binaryen.ts/ | ||
| $ git merge --continue | ||
| $ git push | ||
| ``` | ||
|
|
||
| #### Run Tests | ||
| The test suite is still in progress, migrating from `../test/binaryen.js/`. | ||
| The new test suite uses the Node v22+ test runner. | ||
| ```zsh | ||
| $ npm run test | ||
| ``` | ||
|
|
||
| #### Bundle | ||
| TypeScript only compiles the source files to `./dist/`. | ||
| After that we may need a bundler to optimize and minify it into a prepackaged file, | ||
| which will be able to target different platforms so that it can be used by consumers. | ||
|
|
||
| TODO: more details | ||
|
|
||
| #### Build and Push | ||
| Before pushing, rebuild the entire project to catch any errors. | ||
| ```zsh | ||
| $ npm run build | ||
|
|
||
| # if all goes well… | ||
|
|
||
| $ git push | ||
| ``` | ||
|
|
||
| #### Publish | ||
| TODO: this section | ||
|
|
||
| ### File Inventory | ||
| - `README.md`: *you are here* | ||
|
|
||
| - `.editorconfig`, `.gitignore`: standard repo files | ||
|
|
||
| - `package{,-lock}.json`: Node package & npm registry details | ||
|
|
||
| - `node_modules/` *(gitignored)*: npm dependencies | ||
|
|
||
| - `tsconfig.json`: TypeScript configuration | ||
|
|
||
| - `eslint.config.js`: JS/TS coding style conventions | ||
|
|
||
| - `typedoc.config.js`: documentation generator configuration | ||
|
|
||
| - `build/` *(gitignored)*: output of **Emscripten**; this is imported by the `src/` library | ||
|
|
||
| - `src/`: human-written source code | ||
|
|
||
| - `binaryen.ts`: the entrypoint; exports everything available to consumers | ||
|
|
||
| - `-pre.ts`: artifacts provided by Emscripten | ||
|
|
||
| - `-utils.ts`: internal tools | ||
|
|
||
| - `{constants,globals}.ts`: top-level exported globals | ||
|
|
||
| - `-deprecations.ts`: everything deprecated, all in one place | ||
|
|
||
| - `classes/`: all the modular code | ||
|
|
||
| - `{TypeBuilder,ExpressionRunner,Relooper}.ts`: Binaryen tools | ||
|
|
||
| - `module/`: Module and related classes | ||
|
|
||
| - `expression/`: Expression info classes, and source for WASM expression generation | ||
|
|
||
| - `services/`: namespace-like, stateless classes | ||
|
|
||
| - `dist/` *(gitignored)*: output of **tsc**; this gets bundled and published to NPM for consumers | ||
|
|
||
| - `docs/`: documentation assets | ||
|
|
||
| - `../docs/binaryen.ts/` *(gitignored)*: output of **typedoc**; hosted online |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we need extended exported symbols? I haven't seen them being used. Also js-bindings works without all of them normally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of these symbols aren't needed in this PR but they will be needed in future code migration (example links below are from #8826):
outwill be used in emitAsmJSerr, looks like it's not used in the TS anywherestackSave,stackRestore, andstackAllocwill be needed in utilitiesUTF8ToString,stringToAscii, andstringToUTF8OnStackfor anything using javascript strings (e.g. parseText)The reason the JS bindings work without them is because the current post.js file is appended to (i think) the WASM bindings before Emscripten processes them; that's the
--post-jsflag given on line 562. that's why the JS code is able to access the symbols in Emscripten's codebase without being exported. but now that the Emscripten build happens before callingawait Binaryen(), we need those symbols exported on the object, so they need to be added toEXPORTED_RUNTIME_METHODS. (see the comment in binaryen_js.d.ts