@yuku-codegen/wasm 0.5.24 → 0.5.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/index.js +2 -2
- package/package.json +1 -1
- package/yuku-codegen.wasm +0 -0
package/README.md
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
# yuku-codegen
|
|
1
|
+
# @yuku-codegen/wasm
|
|
2
2
|
|
|
3
3
|
The [`yuku-codegen`](https://www.npmjs.com/package/yuku-codegen) code generator
|
|
4
|
-
as a single WebAssembly module. Takes a `Program` from
|
|
4
|
+
as a single WebAssembly module. Takes a `Program` from `@yuku-parser/wasm` and
|
|
5
5
|
returns generated source.
|
|
6
6
|
|
|
7
7
|
## Usage
|
|
8
8
|
|
|
9
9
|
```js
|
|
10
|
-
import { parse } from "yuku-parser
|
|
11
|
-
import { print, strip, minify } from "yuku-codegen
|
|
10
|
+
import { parse } from "@yuku-parser/wasm";
|
|
11
|
+
import { print, strip, minify } from "@yuku-codegen/wasm";
|
|
12
12
|
|
|
13
13
|
const { program } = parse("const x: number = 1", { lang: "ts" });
|
|
14
14
|
|
|
15
15
|
print(program); // formatted source
|
|
16
16
|
strip(program); // TypeScript stripped to JavaScript
|
|
17
|
-
minify(program); // compact
|
|
17
|
+
minify(program); // compact
|
|
18
18
|
```
|
package/index.js
CHANGED
|
@@ -20,12 +20,12 @@ const decoder = new TextDecoder();
|
|
|
20
20
|
|
|
21
21
|
function run(op, program) {
|
|
22
22
|
const ast = new Uint8Array(encode(program, null));
|
|
23
|
-
const inPtr = alloc(ast.length);
|
|
23
|
+
const inPtr = alloc(ast.length || 1);
|
|
24
24
|
// Growing wasm memory detaches memory.buffer, so re-view after every call.
|
|
25
25
|
new Uint8Array(memory.buffer, inPtr, ast.length).set(ast);
|
|
26
26
|
|
|
27
27
|
const ptr = codegen(inPtr, ast.length, op);
|
|
28
|
-
free(inPtr, ast.length);
|
|
28
|
+
free(inPtr, ast.length || 1);
|
|
29
29
|
if (ptr === 0) throw new Error("yuku-codegen-wasm: failed to generate code");
|
|
30
30
|
|
|
31
31
|
const len = new DataView(memory.buffer).getUint32(ptr, true);
|
package/package.json
CHANGED
package/yuku-codegen.wasm
CHANGED
|
Binary file
|