@mirascript/bindings 0.1.90 → 0.1.92

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mirascript/bindings",
3
- "version": "0.1.90",
3
+ "version": "0.1.92",
4
4
  "author": "CloudPSS",
5
5
  "license": "MIT",
6
6
  "description": "MiraScript compiler bindings",
@@ -32,12 +32,17 @@
32
32
  }
33
33
  },
34
34
  "dependencies": {
35
- "@mirascript/napi": "~0.1.90",
36
- "@mirascript/wasm": "~0.1.90"
35
+ "@mirascript/napi": "~0.1.92",
36
+ "@mirascript/wasm": "~0.1.92"
37
+ },
38
+ "devDependencies": {
39
+ "ava": "^8.0.1",
40
+ "c8": "^12.0.0"
37
41
  },
38
42
  "scripts": {
39
43
  "watch": "pnpm build --watch",
40
44
  "build": "pnpm clean && tsc",
45
+ "test": "c8 ava",
41
46
  "clean": "rimraf dist"
42
47
  }
43
48
  }
package/tests/index.ts ADDED
@@ -0,0 +1,51 @@
1
+ import test from 'ava';
2
+
3
+ import * as bindings from '../dist/index.js';
4
+ import * as napi from '../dist/napi.js';
5
+ import * as wasm from '../dist/wasm.js';
6
+
7
+ test('loadModule', async (t) => {
8
+ const module = await bindings.loadModule();
9
+ t.truthy(module);
10
+ t.truthy(module.compileSync);
11
+
12
+ const moduleNapi = await napi.loadModule();
13
+ t.truthy(moduleNapi);
14
+ t.truthy(moduleNapi.compile);
15
+ t.truthy(moduleNapi.compileSync);
16
+ t.truthy(moduleNapi.JsCompileResult);
17
+
18
+ const moduleWasm = await wasm.loadModule();
19
+ t.truthy(moduleWasm);
20
+ t.truthy(moduleWasm.compileSync);
21
+ t.truthy(moduleWasm.createConfig);
22
+ t.truthy(moduleWasm.formatSync);
23
+ t.truthy(moduleWasm.wasm);
24
+ });
25
+
26
+ test('getModule', async (t) => {
27
+ for (const module of [bindings, napi, wasm]) {
28
+ const loaded = await module.loadModule();
29
+ const gotten = module.getModule();
30
+ t.is(loaded, gotten);
31
+ }
32
+ });
33
+
34
+ test('WASM range formatting preserves template literal content', async (t) => {
35
+ const module = await wasm.loadModule();
36
+ const expression = 'if active { "活跃" } else { "非活跃" }';
37
+ for (const source of [`<p>状态: \${\n ${expression}\n}</p>`, `<p>状态: \${\n\n ${expression}\n}</p>`]) {
38
+ const start = source.indexOf(expression);
39
+ const result = module.formatSync(source, { input_mode: 'Template', trivia: true }, undefined, [
40
+ { start, end: start + expression.length },
41
+ ]);
42
+ t.deepEqual(result.edits, []);
43
+ }
44
+ });
45
+
46
+ test('WASM document formatting trims a single content line', async (t) => {
47
+ const module = await wasm.loadModule();
48
+ const source = ' \n \n[1,2]\n \n';
49
+ const result = module.formatSync(source, { input_mode: 'Script', trivia: true });
50
+ t.deepEqual(result.edits, [{ start: 0, end: source.length, text: '[1, 2]' }]);
51
+ });
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "../../../tsconfig.scripts.json"
3
+ }