@wasm-fmt/dart_fmt 0.2.0 → 0.3.0

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/dart_fmt.js CHANGED
@@ -1,10 +1,8 @@
1
+ /* @ts-self-types="./dart_fmt.d.ts" */
1
2
  import { format as dart_fmt, instantiate, invoke } from "./dart_fmt.mjs";
2
3
 
3
4
  let wasm;
4
5
 
5
- function get_imports() {}
6
- function init_memory() {}
7
-
8
6
  function normalize(module) {
9
7
  if (!(module instanceof WebAssembly.Module)) {
10
8
  return new WebAssembly.Module(module);
@@ -18,7 +16,6 @@ export default async function (input) {
18
16
  if (typeof input === "undefined") {
19
17
  input = new URL("dart_fmt.wasm", import.meta.url);
20
18
  }
21
- const imports = get_imports();
22
19
 
23
20
  if (
24
21
  typeof input === "string" ||
@@ -28,8 +25,6 @@ export default async function (input) {
28
25
  input = fetch(input);
29
26
  }
30
27
 
31
- init_memory(imports);
32
-
33
28
  wasm = await load(await input)
34
29
  .then(normalize)
35
30
  .then(instantiate);
@@ -67,18 +62,16 @@ export function format(source, filename = "stdin.dart", config = {}) {
67
62
  if (config.line_width) {
68
63
  options.pageWidth = config.line_width;
69
64
  }
70
- if (options.line_ending === "crlf") {
65
+ if (config.line_ending === "crlf") {
71
66
  options.lineEnding = "\r\n";
72
67
  }
73
- if(options.language_version) {
74
- options.languageVersion = options.language_version;
68
+ if (config.language_version) {
69
+ options.languageVersion = config.language_version;
75
70
  }
76
71
 
77
72
  const result = dart_fmt(source, filename, JSON.stringify(options));
78
- const err = result[0] === "x";
79
- const output = result.slice(1);
80
- if (err) {
81
- throw new Error(output);
73
+ if (result.success) {
74
+ return result.code;
82
75
  }
83
- return output;
76
+ throw new Error(result.error);
84
77
  }