Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 1 addition & 40 deletions analyzer_playground/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@
<img src="https://img.icons8.com/flat_round/64/000000/play--v1.png" />
</button>
</div>
<!-- Note the usage of `type=module` here as this is an ES6 module -->
<script type="module">
<script>
// Initialize the text editor from text area
var myCodeMirror = CodeMirror.fromTextArea(
document.getElementById("code-editor"),
Expand All @@ -77,45 +76,7 @@
}
);
outputCodeMirror.setValue("// Diagnostics output\n")
// Use ES module import syntax to import functionality from the module
// that we have compiled.
//
// Note that the `default` import is an initialization function which
// will "boot" the module and make it ready to use. Currently browsers
// don't support natively imported WebAssembly as an ES module, but
// eventually the manual initialization won't be required!
import init, { analyze } from "https://cdn.jsdelivr.net/gh/nestdotland/analyzer/analyzer_wasm/pkg/nest_analyzer_wasm.js";
async function run() {
// First up we need to actually load the wasm file, so we use the
// default export to inform it where the wasm file is located on the
// server, and then we wait on the returned promise to wait for the
// wasm to be loaded.
//
// It may look like this: `await init('./pkg/without_a_bundler_bg.wasm');`,
// but there is also a handy default inside `init` function, which uses
// `import.meta` to locate the wasm file relatively to js file.
//
// Note that instead of a string you can also pass in any of the
// following things:
//
// * `WebAssembly.Module`
//
// * `ArrayBuffer`
//
// * `Response`
//
// * `Promise` which returns any of the above, e.g. `fetch("./path/to/wasm")`
//
// This gives you complete control over how the module is loaded
// and compiled.
//
// Also note that the promise, when resolved, yields the wasm module's
// exports which is the same as importing the `*_bg` module in other
// modes
await init();

// And afterwards we can use all the functionality defined in wasm.
const result = analyze(myCodeMirror.getValue());
fetch('/api', {
method: 'post',
body: myCodeMirror.getValue()
Expand Down