├── .gitignore ├── .prettierignore ├── .prettierrc ├── .travis.yml ├── LICENSE ├── README.md ├── assets ├── asbind-0-1-0.wat ├── asbind-debug-0-1-0.wat ├── asbind.gif ├── asbind.webm ├── markdown-parser-0-1-0.wat └── mdParserScreenshot.png ├── examples ├── browser-sdk │ └── index.html ├── markdown-parser │ ├── assembly │ │ ├── as-mocks-banner.js │ │ ├── code-generator │ │ │ └── code-generator.ts │ │ ├── index.ts │ │ ├── parser │ │ │ ├── ast-node-type.ts │ │ │ ├── ast.ts │ │ │ └── parser.ts │ │ ├── tokenizer │ │ │ ├── token-type.ts │ │ │ ├── token.ts │ │ │ └── tokenizer.ts │ │ ├── tsconfig.json │ │ └── util.ts │ ├── index.css │ ├── index.html │ └── index.js └── quickstart │ ├── browser-puppeteer.js │ ├── browser.html │ ├── browser.js │ ├── nodejs.js │ ├── package-lock.json │ ├── package.json │ ├── path-to-my-wasm.wasm │ └── your-entryfile.ts ├── index.js ├── lib ├── asbind-instance │ ├── asbind-instance.ts │ ├── bind-function.ts │ ├── instantiate.ts │ ├── reserved-export-keys.ts │ └── type-converters.ts ├── lib.ts └── types.ts ├── package-lock.json ├── package.json ├── rollup.config.js ├── rollup.lib.js ├── rollup.markdown-parser.js ├── test ├── .gitignore ├── test-runner.html ├── test-runner.js └── tests │ ├── array │ ├── asc.ts │ └── test.js │ ├── arraybuffer │ ├── asc.ts │ └── test.js │ ├── arraybufferview │ ├── asc.ts │ └── test.js │ ├── custom-type │ ├── asc.ts │ └── test.js │ ├── import-on-prototype │ ├── asc.ts │ └── test.js │ ├── instantiateSync │ ├── asc.ts │ └── test.js │ ├── multifile │ ├── asc.ts │ ├── exports.ts │ ├── imports.ts │ └── test.js │ ├── namespace-import │ ├── asc.ts │ └── test.js │ ├── namespace │ ├── asc.ts │ └── test.js │ ├── pinning │ ├── asc.ts │ ├── config.js │ └── test.js │ ├── strings │ ├── asc.ts │ └── test.js │ ├── tsconfig.json │ ├── unexpected-import │ ├── asc.ts │ └── test.js │ ├── unknown-type │ ├── asc.ts │ └── test.js │ └── unused-import │ ├── asc.ts │ └── test.js ├── transform.ts └── tsconfig.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Project 2 | build/ 3 | dist/ 4 | 5 | # Logs 6 | logs 7 | *.log 8 | npm-debug.log* 9 | yarn-debug.log* 10 | yarn-error.log* 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | 24 | # nyc test coverage 25 | .nyc_output 26 | 27 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 28 | .grunt 29 | 30 | # Bower dependency directory (https://bower.io/) 31 | bower_components 32 | 33 | # node-waf configuration 34 | .lock-wscript 35 | 36 | # Compiled binary addons (https://nodejs.org/api/addons.html) 37 | build/Release 38 | 39 | # Dependency directories 40 | node_modules/ 41 | jspm_packages/ 42 | 43 | # TypeScript v1 declaration files 44 | typings/ 45 | 46 | # Optional npm cache directory 47 | .npm 48 | 49 | # Optional eslint cache 50 | .eslintcache 51 | 52 | # Optional REPL history 53 | .node_repl_history 54 | 55 | # Output of 'npm pack' 56 | *.tgz 57 | 58 | # Yarn Integrity file 59 | .yarn-integrity 60 | 61 | # dotenv environment variables file 62 | .env 63 | 64 | # next.js build output 65 | .next 66 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | test/tests/namespace-import/asc.ts 2 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "none", 3 | "semi": true, 4 | "arrowParens": "avoid", 5 | "printWidth": 80, 6 | "bracketSpacing": true 7 | } -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | notifications: 2 | email: false 3 | language: node_js 4 | node_js: 5 | - "node" 6 | install: 7 | - npm install 8 | script: 9 | - npm run lint:ci 10 | - npm run build 11 | - npm run test 12 | # Commenting for now due to small AS/TS Compiler difference 13 | # Opening a PR as I write this to fix it haha! 14 | # - npm run md:build 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Aaron Turner 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # as-bind 2 | 3 | 4 | 5 | [](https://travis-ci.org/torch2424/as-bind) 6 |  7 |  8 |  9 |  10 | 11 | Isomorphic library to handle passing high-level data structures between AssemblyScript and JavaScript. 🤝🚀 12 | 13 | [Markdown Parser Demo](https://torch2424.github.io/as-bind/) 14 | 15 |  16 | 17 | ## Table of Contents 18 | 19 | - [Features](#features) 20 | - [Installation](#installation) 21 | - [Quick Start](#quick-start) 22 | - [Additional Examples](#additional-examples) 23 | - [Supported Data Types](#supported-data-types) 24 | - [Supported AssemblyScript Runtime Variants](#supported-assemblyscript-runtime-variants) 25 | - [Reference API](#reference-api) 26 | - [Motivation](#motivation) 27 | - [Performance](#performance) 28 | - [Production](#production) 29 | - [Projects using as-bind](#projects-using-as-bind) 30 | - [Contributing](#contributing) 31 | - [License](#license) 32 | 33 | ## Features 34 | 35 | - The library is isomorphic. Meaning it supports both the Browser, and Node! And has ESM, AMD, CommonJS, and IIFE bundles! 🌐 36 | - Wraps around the [AssemblyScript Loader](https://github.com/AssemblyScript/assemblyscript/tree/master/lib/loader). The loader handles all the heavy-lifting of passing data into WebAssembly linear memory. 💪 37 | - Wraps around imported JavaScript functions, and exported AssemblyScript functions of the AssemblyScript Wasm Module. This allows high-level data types to be passed directly to exported AssemblyScript functions! 🤯 38 | - Moves a lot of work to compile-time using [AssemblyScript Transforms](https://www.assemblyscript.org/transforms.html#transforms) and completely avoids module-specific “glue code”. 🏃 39 | - Installable from package managers (npm), with a modern JavaScript API syntax. 📦 40 | - The library is [< 4KB (minified and gzip'd)](https://bundlephobia.com/result?p=as-bind), _including_ the AssemblyScript Loader ! 🌲 41 | - This library is currently (as of January, 2020) the [wasm-bindgen](https://github.com/rustwasm/wasm-bindgen) of AssemblyScript. 😀 42 | 43 | ## Installation 44 | 45 | You can install as-bind in your project by running the following: 46 | 47 | `npm install --save as-bind` 48 | 49 | ## Quick Start 50 | 51 | **1. Compiling your Assemblyscript** 52 | 53 | To enable as-bind for your AssemblyScript Wasm modules, add the as-bind transform when compiling your module: 54 | 55 | `asc your-entryfile.ts --exportRuntime --transform as-bind [...other cli options...]` 56 | 57 | The things to notice are: 58 | 59 | - `--transform as-bind` - This is the as-bind transform that runs at compile time. It embeds all the required type information into the WebAssembly Module. 60 | - `--exportRuntime` - This is required for the AssemblyScript Loader to work properly. It [exposes functions](https://www.assemblyscript.org/garbage-collection.html#runtime-interface) on the module to allocate memory from JavaScript. 61 | 62 | For **optional testing purposes** , let's export an example function we can try in `your-entryfile.ts`: 63 | 64 | ```typescript 65 | export function myExportedFunctionThatTakesAString(value: string): string { 66 | return "AsBind: " + value; 67 | } 68 | ``` 69 | 70 | **2. In your Javascript** 71 | 72 | For **browser** JavaScript. We can do the following: 73 | 74 | ```javascript 75 | // If you are using a Javascript bundler, use the ESM bundle with import syntax 76 | import * as AsBind from "as-bind"; 77 | 78 | // If you are not using a bundler add a 10 | 11 | 12 | 74 |
See the browser console!
75 |