Skip to content

Commit d3202fa

Browse files
committed
Add working test use of wasm parser in visual editor
1 parent 6e92655 commit d3202fa

File tree

12 files changed

+623
-12
lines changed

12 files changed

+623
-12
lines changed

apps/vscode-editor/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
"tsconfig": "*",
4444
"typescript": "^4.5.2",
4545
"vite": "^3.0.0",
46-
"vite-plugin-static-copy": "^0.13.0"
46+
"vite-plugin-static-copy": "^0.13.0",
47+
"vite-plugin-top-level-await": "^1.6.0",
48+
"vite-plugin-wasm": "^3.5.0"
4749
}
4850
}

apps/vscode-editor/src/index.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import { editorThemeFromStore } from "./theme";
2929
import "editor-ui/src/styles";
3030
import "./styles.scss"
3131

32+
import main from "./wasm-qmd-parser/";
33+
3234
async function runEditor() {
3335
try {
3436
// init localization
@@ -53,11 +55,14 @@ async function runEditor() {
5355
const root = createRoot(document.getElementById('root')!);
5456
setEditorTheme(editorThemeFromStore(store));
5557
root.render(<App store={store} editorId={editorId} host={host} context={context} request={request}/>);
58+
59+
console.log('hello!!!')
60+
let m = await main();
61+
let parsed = m.parse_qmd("# Hello\n");
62+
console.log('parsed', parsed);
5663
} catch (error) {
57-
console.error(error);
64+
console.error('error',error);
5865
}
5966
}
6067

6168
runEditor();
62-
63-
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<div align="center">
2+
3+
<h1><code>wasm-pack-template</code></h1>
4+
5+
<strong>A template for kick starting a Rust and WebAssembly project using <a href="https://github.com/rustwasm/wasm-pack">wasm-pack</a>.</strong>
6+
7+
<p>
8+
<a href="https://travis-ci.org/rustwasm/wasm-pack-template"><img src="https://img.shields.io/travis/rustwasm/wasm-pack-template.svg?style=flat-square" alt="Build Status" /></a>
9+
</p>
10+
11+
<h3>
12+
<a href="https://rustwasm.github.io/docs/wasm-pack/tutorials/npm-browser-packages/index.html">Tutorial</a>
13+
<span> | </span>
14+
<a href="https://discordapp.com/channels/442252698964721669/443151097398296587">Chat</a>
15+
</h3>
16+
17+
<sub>Built with 🦀🕸 by <a href="https://rustwasm.github.io/">The Rust and WebAssembly Working Group</a></sub>
18+
</div>
19+
20+
## About
21+
22+
[**📚 Read this template tutorial! 📚**][template-docs]
23+
24+
This template is designed for compiling Rust libraries into WebAssembly and
25+
publishing the resulting package to NPM.
26+
27+
Be sure to check out [other `wasm-pack` tutorials online][tutorials] for other
28+
templates and usages of `wasm-pack`.
29+
30+
[tutorials]: https://rustwasm.github.io/docs/wasm-pack/tutorials/index.html
31+
[template-docs]: https://rustwasm.github.io/docs/wasm-pack/tutorials/npm-browser-packages/index.html
32+
33+
## 🚴 Usage
34+
35+
### 🐑 Use `cargo generate` to Clone this Template
36+
37+
[Learn more about `cargo generate` here.](https://github.com/ashleygwilliams/cargo-generate)
38+
39+
```
40+
cargo generate --git https://github.com/rustwasm/wasm-pack-template.git --name my-project
41+
cd my-project
42+
```
43+
44+
### 🛠️ Build with `wasm-pack build`
45+
46+
```
47+
wasm-pack build
48+
```
49+
50+
### 🔬 Test in Headless Browsers with `wasm-pack test`
51+
52+
```
53+
wasm-pack test --headless --firefox
54+
```
55+
56+
### 🎁 Publish to NPM with `wasm-pack publish`
57+
58+
```
59+
wasm-pack publish
60+
```
61+
62+
## 🔋 Batteries Included
63+
64+
* [`wasm-bindgen`](https://github.com/rustwasm/wasm-bindgen) for communicating
65+
between WebAssembly and JavaScript.
66+
* [`console_error_panic_hook`](https://github.com/rustwasm/console_error_panic_hook)
67+
for logging panic messages to the developer console.
68+
* `LICENSE-APACHE` and `LICENSE-MIT`: most Rust projects are licensed this way, so these are included for you
69+
70+
## License
71+
72+
Licensed under either of
73+
74+
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
75+
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
76+
77+
at your option.
78+
79+
### Contribution
80+
81+
Unless you explicitly state otherwise, any contribution intentionally
82+
submitted for inclusion in the work by you, as defined in the Apache-2.0
83+
license, shall be dual licensed as above, without any additional terms or
84+
conditions.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<html>
2+
<head>
3+
<meta charset="utf-8"/>
4+
<title>wasm-qmd-parser</title>
5+
</head>
6+
<script type="module">
7+
import main from "./wasm_qmd_parser.js";
8+
let m = await main();
9+
let parsed = m.parse_qmd("# Hello\n");
10+
console.log(parsed);
11+
</script>
12+
</head>
13+
<body>
14+
</body>
15+
</html>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "wasm-qmd-parser",
3+
"type": "module",
4+
"collaborators": [
5+
"Carlos Scheidegger <carlos.scheidegger@posit.co>"
6+
],
7+
"version": "0.1.0",
8+
"files": [
9+
"wasm_qmd_parser_bg.wasm",
10+
"wasm_qmd_parser.js",
11+
"wasm_qmd_parser.d.ts"
12+
],
13+
"main": "wasm_qmd_parser.js",
14+
"types": "wasm_qmd_parser.d.ts",
15+
"sideEffects": [
16+
"./snippets/*"
17+
]
18+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/* tslint:disable */
2+
/* eslint-disable */
3+
export function run(): void;
4+
export function parse_qmd(input: any): any;
5+
export function greet(): void;
6+
7+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
8+
9+
export interface InitOutput {
10+
readonly memory: WebAssembly.Memory;
11+
readonly parse_qmd: (a: any) => any;
12+
readonly run: () => void;
13+
readonly greet: () => void;
14+
readonly abort: () => void;
15+
readonly calloc: (a: number, b: number) => number;
16+
readonly clock: () => bigint;
17+
readonly fclose: (a: number) => number;
18+
readonly fdopen: (a: number, b: number) => number;
19+
readonly fprintf: (a: number, b: number, c: number) => number;
20+
readonly fputc: (a: number, b: number) => number;
21+
readonly fputs: (a: number, b: number) => number;
22+
readonly free: (a: number) => void;
23+
readonly fwrite: (a: number, b: number, c: number, d: number) => number;
24+
readonly isprint: (a: number) => number;
25+
readonly iswalnum: (a: number) => number;
26+
readonly iswalpha: (a: number) => number;
27+
readonly iswdigit: (a: number) => number;
28+
readonly iswspace: (a: number) => number;
29+
readonly malloc: (a: number) => number;
30+
readonly memcmp: (a: number, b: number, c: number) => number;
31+
readonly memcpy: (a: number, b: number, c: number) => number;
32+
readonly memmove: (a: number, b: number, c: number) => number;
33+
readonly memset: (a: number, b: number, c: number) => number;
34+
readonly realloc: (a: number, b: number) => number;
35+
readonly strncmp: (a: number, b: number, c: number) => number;
36+
readonly towlower: (a: number) => number;
37+
readonly vsnprintf: (a: number, b: number, c: number, d: number) => number;
38+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
39+
readonly __wbindgen_malloc: (a: number, b: number) => number;
40+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
41+
readonly __wbindgen_export_3: WebAssembly.Table;
42+
readonly __wbindgen_start: () => void;
43+
}
44+
45+
export type SyncInitInput = BufferSource | WebAssembly.Module;
46+
/**
47+
* Instantiates the given `module`, which can either be bytes or
48+
* a precompiled `WebAssembly.Module`.
49+
*
50+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
51+
*
52+
* @returns {InitOutput}
53+
*/
54+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
55+
56+
/**
57+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
58+
* for everything else, calls `WebAssembly.instantiate` directly.
59+
*
60+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
61+
*
62+
* @returns {Promise<InitOutput>}
63+
*/
64+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;

0 commit comments

Comments
 (0)