@wasm-fmt/dart_fmt 0.1.1 → 0.1.2

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 CHANGED
@@ -29,8 +29,26 @@ console.log(formatted);
29
29
 
30
30
  For Vite users:
31
31
 
32
+ Add `"@wasm-fmt/dart_fmt"` to `optimizeDeps.exclude` in your vite config:
33
+
34
+ ```JSON
35
+ {
36
+ "optimizeDeps": {
37
+ "exclude": ["@wasm-fmt/dart_fmt"]
38
+ }
39
+ }
40
+ ```
41
+
42
+ <details>
43
+ <summary>
44
+ If you cannot change the vite config, you can use another import entry
45
+
46
+ </summary>
47
+
32
48
  ```JavaScript
33
49
  import init, { format } from "@wasm-fmt/dart_fmt/vite";
34
50
 
35
51
  // ...
36
52
  ```
53
+
54
+ </details>
package/dart_fmt.js CHANGED
@@ -1,22 +1,10 @@
1
- import { instantiate } from "./dart_fmt.mjs";
1
+ import { format as dart_fmt, instantiate, invoke } from "./dart_fmt.mjs";
2
2
 
3
3
  let wasm;
4
4
 
5
5
  function get_imports() {}
6
6
  function init_memory() {}
7
7
 
8
- // export function initSync(module) {
9
- // if (wasm !== undefined) return wasm;
10
-
11
- // const imports = get_imports();
12
-
13
- // init_memory(imports);
14
-
15
- // module = normalize(module);
16
-
17
- // return (wasm = instantiate(module));
18
- // }
19
-
20
8
  function normalize(module) {
21
9
  if (!(module instanceof WebAssembly.Module)) {
22
10
  return new WebAssembly.Module(module);
@@ -42,9 +30,13 @@ export default async function (input) {
42
30
 
43
31
  init_memory(imports);
44
32
 
45
- return (wasm = await load(await input)
33
+ wasm = await load(await input)
46
34
  .then(normalize)
47
- .then(instantiate));
35
+ .then(instantiate);
36
+
37
+ invoke(wasm);
38
+
39
+ return wasm;
48
40
  }
49
41
 
50
42
  async function load(module) {
@@ -70,43 +62,7 @@ async function load(module) {
70
62
  return module;
71
63
  }
72
64
 
73
- function stringFromDartString(string) {
74
- const totalLength = wasm.exports.$stringLength(string);
75
- let result = "";
76
- let index = 0;
77
- while (index < totalLength) {
78
- let chunkLength = Math.min(totalLength - index, 0xffff);
79
- const array = new Array(chunkLength);
80
- for (let i = 0; i < chunkLength; i++) {
81
- array[i] = wasm.exports.$stringRead(string, index++);
82
- }
83
- result += String.fromCharCode(...array);
84
- }
85
- return result;
86
- }
87
-
88
- function stringToDartString(string) {
89
- const length = string.length;
90
- let range = 0;
91
- for (let i = 0; i < length; i++) {
92
- range |= string.codePointAt(i);
93
- }
94
- if (range < 256) {
95
- const dartString = wasm.exports.$stringAllocate1(length);
96
- for (let i = 0; i < length; i++) {
97
- wasm.exports.$stringWrite1(dartString, i, string.codePointAt(i));
98
- }
99
- return dartString;
100
- } else {
101
- const dartString = wasm.exports.$stringAllocate2(length);
102
- for (let i = 0; i < length; i++) {
103
- wasm.exports.$stringWrite2(dartString, i, string.charCodeAt(i));
104
- }
105
- return dartString;
106
- }
107
- }
108
-
109
- export function format(source, filename, config = {}) {
65
+ export function format(source, filename = "stdin.dart", config = {}) {
110
66
  const options = { lineEnding: "\n" };
111
67
  if (config.line_width) {
112
68
  options.pageWidth = config.line_width;
@@ -115,13 +71,11 @@ export function format(source, filename, config = {}) {
115
71
  options.lineEnding = "\r\n";
116
72
  }
117
73
 
118
- const sourceString = stringToDartString(source);
119
- const filenameString = stringToDartString(filename);
120
- const configString = stringToDartString(JSON.stringify(options));
121
- const result = wasm.exports.format(
122
- sourceString,
123
- filenameString,
124
- configString,
125
- );
126
- return stringFromDartString(result);
74
+ const result = dart_fmt(source, filename, JSON.stringify(options));
75
+ const err = result[0] === "x";
76
+ const output = result.slice(1);
77
+ if (err) {
78
+ throw new Error(output);
79
+ }
80
+ return output;
127
81
  }
package/dart_fmt.mjs CHANGED
@@ -1,4 +1,3 @@
1
- let buildArgsList;
2
1
 
3
2
  // `modulePromise` is a promise to the `WebAssembly.module` object to be
4
3
  // instantiated.
@@ -10,42 +9,6 @@ let buildArgsList;
10
9
  export const instantiate = async (modulePromise, importObjectPromise) => {
11
10
  let dartInstance;
12
11
 
13
- function stringFromDartString(string) {
14
- const totalLength = dartInstance.exports.$stringLength(string);
15
- let result = '';
16
- let index = 0;
17
- while (index < totalLength) {
18
- let chunkLength = Math.min(totalLength - index, 0xFFFF);
19
- const array = new Array(chunkLength);
20
- for (let i = 0; i < chunkLength; i++) {
21
- array[i] = dartInstance.exports.$stringRead(string, index++);
22
- }
23
- result += String.fromCharCode(...array);
24
- }
25
- return result;
26
- }
27
-
28
- function stringToDartString(string) {
29
- const length = string.length;
30
- let range = 0;
31
- for (let i = 0; i < length; i++) {
32
- range |= string.codePointAt(i);
33
- }
34
- if (range < 256) {
35
- const dartString = dartInstance.exports.$stringAllocate1(length);
36
- for (let i = 0; i < length; i++) {
37
- dartInstance.exports.$stringWrite1(dartString, i, string.codePointAt(i));
38
- }
39
- return dartString;
40
- } else {
41
- const dartString = dartInstance.exports.$stringAllocate2(length);
42
- for (let i = 0; i < length; i++) {
43
- dartInstance.exports.$stringWrite2(dartString, i, string.charCodeAt(i));
44
- }
45
- return dartString;
46
- }
47
- }
48
-
49
12
  // Prints to the console
50
13
  function printToConsole(value) {
51
14
  if (typeof dartPrint == "function") {
@@ -67,43 +30,36 @@ export const instantiate = async (modulePromise, importObjectPromise) => {
67
30
  // Converts a Dart List to a JS array. Any Dart objects will be converted, but
68
31
  // this will be cheap for JSValues.
69
32
  function arrayFromDartList(constructor, list) {
70
- const length = dartInstance.exports.$listLength(list);
71
- const array = new constructor(length);
72
- for (let i = 0; i < length; i++) {
73
- array[i] = dartInstance.exports.$listRead(list, i);
74
- }
75
- return array;
76
- }
77
-
78
- buildArgsList = function(list) {
79
- const dartList = dartInstance.exports.$makeStringList();
80
- for (let i = 0; i < list.length; i++) {
81
- dartInstance.exports.$listAdd(dartList, stringToDartString(list[i]));
82
- }
83
- return dartList;
33
+ const exports = dartInstance.exports;
34
+ const read = exports.$listRead;
35
+ const length = exports.$listLength(list);
36
+ const array = new constructor(length);
37
+ for (let i = 0; i < length; i++) {
38
+ array[i] = read(list, i);
39
+ }
40
+ return array;
84
41
  }
85
42
 
86
43
  // A special symbol attached to functions that wrap Dart functions.
87
44
  const jsWrappedDartFunctionSymbol = Symbol("JSWrappedDartFunction");
88
45
 
89
46
  function finalizeWrapper(dartFunction, wrapped) {
90
- wrapped.dartFunction = dartFunction;
91
- wrapped[jsWrappedDartFunctionSymbol] = true;
92
- return wrapped;
47
+ wrapped.dartFunction = dartFunction;
48
+ wrapped[jsWrappedDartFunctionSymbol] = true;
49
+ return wrapped;
93
50
  }
94
51
 
95
52
  // Imports
96
53
  const dart2wasm = {
97
54
 
98
- _48: v => stringToDartString(v.toString()),
99
- _62: s => {
100
- const jsSource = stringFromDartString(s);
101
- if (!/^\s*[+-]?(?:Infinity|NaN|(?:\.\d+|\d+(?:\.\d*)?)(?:[eE][+-]?\d+)?)\s*$/.test(jsSource)) {
55
+ _49: v => v.toString(),
56
+ _64: s => {
57
+ if (!/^\s*[+-]?(?:Infinity|NaN|(?:\.\d+|\d+(?:\.\d*)?)(?:[eE][+-]?\d+)?)\s*$/.test(s)) {
102
58
  return NaN;
103
59
  }
104
- return parseFloat(jsSource);
60
+ return parseFloat(s);
105
61
  },
106
- _63: () => {
62
+ _65: () => {
107
63
  let stackString = new Error().stack.toString();
108
64
  let frames = stackString.split('\n');
109
65
  let drop = 2;
@@ -112,136 +68,242 @@ _63: () => {
112
68
  }
113
69
  return frames.slice(drop).join('\n');
114
70
  },
115
- _67: () => {
71
+ _69: () => {
116
72
  // On browsers return `globalThis.location.href`
117
73
  if (globalThis.location != null) {
118
- return stringToDartString(globalThis.location.href);
74
+ return globalThis.location.href;
119
75
  }
120
76
  return null;
121
77
  },
122
- _68: () => {
123
- return typeof process != undefined &&
78
+ _70: () => {
79
+ return typeof process != "undefined" &&
124
80
  Object.prototype.toString.call(process) == "[object process]" &&
125
81
  process.platform == "win32"
126
82
  },
127
- _72: s => stringToDartString(JSON.stringify(stringFromDartString(s))),
128
- _73: s => printToConsole(stringFromDartString(s)),
129
- _91: (c) =>
83
+ _85: s => JSON.stringify(s),
84
+ _86: s => printToConsole(s),
85
+ _87: a => a.join(''),
86
+ _90: (s, t) => s.split(t),
87
+ _91: s => s.toLowerCase(),
88
+ _92: s => s.toUpperCase(),
89
+ _93: s => s.trim(),
90
+ _95: s => s.trimRight(),
91
+ _97: (s, p, i) => s.indexOf(p, i),
92
+ _98: (s, p, i) => s.lastIndexOf(p, i),
93
+ _100: Object.is,
94
+ _101: s => s.toUpperCase(),
95
+ _102: s => s.toLowerCase(),
96
+ _103: (a, i) => a.push(i),
97
+ _113: (a, b) => a == b ? 0 : (a > b ? 1 : -1),
98
+ _114: a => a.length,
99
+ _116: (a, i) => a[i],
100
+ _117: (a, i, v) => a[i] = v,
101
+ _120: (o, start, length) => new Uint8Array(o.buffer, o.byteOffset + start, length),
102
+ _121: (o, start, length) => new Int8Array(o.buffer, o.byteOffset + start, length),
103
+ _122: (o, start, length) => new Uint8ClampedArray(o.buffer, o.byteOffset + start, length),
104
+ _123: (o, start, length) => new Uint16Array(o.buffer, o.byteOffset + start, length),
105
+ _124: (o, start, length) => new Int16Array(o.buffer, o.byteOffset + start, length),
106
+ _125: (o, start, length) => new Uint32Array(o.buffer, o.byteOffset + start, length),
107
+ _126: (o, start, length) => new Int32Array(o.buffer, o.byteOffset + start, length),
108
+ _129: (o, start, length) => new Float32Array(o.buffer, o.byteOffset + start, length),
109
+ _130: (o, start, length) => new Float64Array(o.buffer, o.byteOffset + start, length),
110
+ _133: (o) => new DataView(o.buffer, o.byteOffset, o.byteLength),
111
+ _137: Function.prototype.call.bind(Object.getOwnPropertyDescriptor(DataView.prototype, 'byteLength').get),
112
+ _138: (b, o) => new DataView(b, o),
113
+ _140: Function.prototype.call.bind(DataView.prototype.getUint8),
114
+ _141: Function.prototype.call.bind(DataView.prototype.setUint8),
115
+ _142: Function.prototype.call.bind(DataView.prototype.getInt8),
116
+ _143: Function.prototype.call.bind(DataView.prototype.setInt8),
117
+ _144: Function.prototype.call.bind(DataView.prototype.getUint16),
118
+ _145: Function.prototype.call.bind(DataView.prototype.setUint16),
119
+ _146: Function.prototype.call.bind(DataView.prototype.getInt16),
120
+ _147: Function.prototype.call.bind(DataView.prototype.setInt16),
121
+ _148: Function.prototype.call.bind(DataView.prototype.getUint32),
122
+ _149: Function.prototype.call.bind(DataView.prototype.setUint32),
123
+ _150: Function.prototype.call.bind(DataView.prototype.getInt32),
124
+ _151: Function.prototype.call.bind(DataView.prototype.setInt32),
125
+ _156: Function.prototype.call.bind(DataView.prototype.getFloat32),
126
+ _157: Function.prototype.call.bind(DataView.prototype.setFloat32),
127
+ _158: Function.prototype.call.bind(DataView.prototype.getFloat64),
128
+ _159: Function.prototype.call.bind(DataView.prototype.setFloat64),
129
+ _165: x0 => format = x0,
130
+ _166: f => finalizeWrapper(f, function(x0,x1,x2) { return dartInstance.exports._166(f,arguments.length,x0,x1,x2) }),
131
+ _184: (c) =>
130
132
  queueMicrotask(() => dartInstance.exports.$invokeCallback(c)),
131
- _93: (a, i) => a.push(i),
132
- _103: (a, b) => a == b ? 0 : (a > b ? 1 : -1),
133
- _104: a => a.length,
134
- _106: (a, i) => a[i],
135
- _107: (a, i, v) => a[i] = v,
136
- _109: a => a.join(''),
137
- _112: (s, t) => s.split(t),
138
- _113: s => s.toLowerCase(),
139
- _114: s => s.toUpperCase(),
140
- _115: s => s.trim(),
141
- _117: s => s.trimRight(),
142
- _119: (s, p, i) => s.indexOf(p, i),
143
- _120: (s, p, i) => s.lastIndexOf(p, i),
144
- _122: (o, start, length) => new Uint8Array(o.buffer, o.byteOffset + start, length),
145
- _123: (o, start, length) => new Int8Array(o.buffer, o.byteOffset + start, length),
146
- _124: (o, start, length) => new Uint8ClampedArray(o.buffer, o.byteOffset + start, length),
147
- _125: (o, start, length) => new Uint16Array(o.buffer, o.byteOffset + start, length),
148
- _126: (o, start, length) => new Int16Array(o.buffer, o.byteOffset + start, length),
149
- _127: (o, start, length) => new Uint32Array(o.buffer, o.byteOffset + start, length),
150
- _128: (o, start, length) => new Int32Array(o.buffer, o.byteOffset + start, length),
151
- _131: (o, start, length) => new Float32Array(o.buffer, o.byteOffset + start, length),
152
- _132: (o, start, length) => new Float64Array(o.buffer, o.byteOffset + start, length),
153
- _133: Object.is,
154
- _136: (o) => new DataView(o.buffer, o.byteOffset, o.byteLength),
155
- _140: Function.prototype.call.bind(Object.getOwnPropertyDescriptor(DataView.prototype, 'byteLength').get),
156
- _141: (b, o) => new DataView(b, o),
157
- _143: Function.prototype.call.bind(DataView.prototype.getUint8),
158
- _144: Function.prototype.call.bind(DataView.prototype.setUint8),
159
- _145: Function.prototype.call.bind(DataView.prototype.getInt8),
160
- _146: Function.prototype.call.bind(DataView.prototype.setInt8),
161
- _147: Function.prototype.call.bind(DataView.prototype.getUint16),
162
- _148: Function.prototype.call.bind(DataView.prototype.setUint16),
163
- _149: Function.prototype.call.bind(DataView.prototype.getInt16),
164
- _150: Function.prototype.call.bind(DataView.prototype.setInt16),
165
- _151: Function.prototype.call.bind(DataView.prototype.getUint32),
166
- _152: Function.prototype.call.bind(DataView.prototype.setUint32),
167
- _153: Function.prototype.call.bind(DataView.prototype.getInt32),
168
- _154: Function.prototype.call.bind(DataView.prototype.setInt32),
169
- _159: Function.prototype.call.bind(DataView.prototype.getFloat32),
170
- _160: Function.prototype.call.bind(DataView.prototype.setFloat32),
171
- _161: Function.prototype.call.bind(DataView.prototype.getFloat64),
172
- _162: Function.prototype.call.bind(DataView.prototype.setFloat64),
173
- _168: s => stringToDartString(stringFromDartString(s).toUpperCase()),
174
- _169: s => stringToDartString(stringFromDartString(s).toLowerCase()),
175
- _171: (s, m) => {
133
+ _187: (s, m) => {
176
134
  try {
177
135
  return new RegExp(s, m);
178
136
  } catch (e) {
179
137
  return String(e);
180
138
  }
181
139
  },
182
- _172: (x0,x1) => x0.exec(x1),
183
- _173: (x0,x1) => x0.test(x1),
184
- _174: (x0,x1) => x0.exec(x1),
185
- _175: (x0,x1) => x0.exec(x1),
186
- _176: x0 => x0.pop(),
187
- _182: o => o === undefined,
188
- _183: o => typeof o === 'boolean',
189
- _184: o => typeof o === 'number',
190
- _186: o => typeof o === 'string',
191
- _189: o => o instanceof Int8Array,
192
- _190: o => o instanceof Uint8Array,
193
- _191: o => o instanceof Uint8ClampedArray,
194
- _192: o => o instanceof Int16Array,
195
- _193: o => o instanceof Uint16Array,
196
- _194: o => o instanceof Int32Array,
197
- _195: o => o instanceof Uint32Array,
198
- _196: o => o instanceof Float32Array,
199
- _197: o => o instanceof Float64Array,
200
- _198: o => o instanceof ArrayBuffer,
201
- _199: o => o instanceof DataView,
202
- _200: o => o instanceof Array,
203
- _201: o => typeof o === 'function' && o[jsWrappedDartFunctionSymbol] === true,
204
- _204: o => o instanceof RegExp,
205
- _205: (l, r) => l === r,
206
- _206: o => o,
207
- _207: o => o,
208
- _208: o => o,
209
- _209: b => !!b,
210
- _210: o => o.length,
211
- _213: (o, i) => o[i],
212
- _214: f => f.dartFunction,
213
- _215: l => arrayFromDartList(Int8Array, l),
214
- _216: l => arrayFromDartList(Uint8Array, l),
215
- _217: l => arrayFromDartList(Uint8ClampedArray, l),
216
- _218: l => arrayFromDartList(Int16Array, l),
217
- _219: l => arrayFromDartList(Uint16Array, l),
218
- _220: l => arrayFromDartList(Int32Array, l),
219
- _221: l => arrayFromDartList(Uint32Array, l),
220
- _222: l => arrayFromDartList(Float32Array, l),
221
- _223: l => arrayFromDartList(Float64Array, l),
222
- _224: (data, length) => {
140
+ _188: (x0,x1) => x0.exec(x1),
141
+ _189: (x0,x1) => x0.test(x1),
142
+ _190: (x0,x1) => x0.exec(x1),
143
+ _191: (x0,x1) => x0.exec(x1),
144
+ _192: x0 => x0.pop(),
145
+ _198: o => o === undefined,
146
+ _199: o => typeof o === 'boolean',
147
+ _200: o => typeof o === 'number',
148
+ _202: o => typeof o === 'string',
149
+ _205: o => o instanceof Int8Array,
150
+ _206: o => o instanceof Uint8Array,
151
+ _207: o => o instanceof Uint8ClampedArray,
152
+ _208: o => o instanceof Int16Array,
153
+ _209: o => o instanceof Uint16Array,
154
+ _210: o => o instanceof Int32Array,
155
+ _211: o => o instanceof Uint32Array,
156
+ _212: o => o instanceof Float32Array,
157
+ _213: o => o instanceof Float64Array,
158
+ _214: o => o instanceof ArrayBuffer,
159
+ _215: o => o instanceof DataView,
160
+ _216: o => o instanceof Array,
161
+ _217: o => typeof o === 'function' && o[jsWrappedDartFunctionSymbol] === true,
162
+ _220: o => o instanceof RegExp,
163
+ _221: (l, r) => l === r,
164
+ _222: o => o,
165
+ _223: o => o,
166
+ _224: o => o,
167
+ _225: b => !!b,
168
+ _226: o => o.length,
169
+ _229: (o, i) => o[i],
170
+ _230: f => f.dartFunction,
171
+ _231: l => arrayFromDartList(Int8Array, l),
172
+ _232: (data, length) => {
173
+ const jsBytes = new Uint8Array(length);
174
+ const getByte = dartInstance.exports.$uint8ListGet;
175
+ for (let i = 0; i < length; i++) {
176
+ jsBytes[i] = getByte(data, i);
177
+ }
178
+ return jsBytes;
179
+ },
180
+ _233: l => arrayFromDartList(Uint8ClampedArray, l),
181
+ _234: l => arrayFromDartList(Int16Array, l),
182
+ _235: l => arrayFromDartList(Uint16Array, l),
183
+ _236: l => arrayFromDartList(Int32Array, l),
184
+ _237: l => arrayFromDartList(Uint32Array, l),
185
+ _238: l => arrayFromDartList(Float32Array, l),
186
+ _239: l => arrayFromDartList(Float64Array, l),
187
+ _240: (data, length) => {
188
+ const read = dartInstance.exports.$byteDataGetUint8;
223
189
  const view = new DataView(new ArrayBuffer(length));
224
190
  for (let i = 0; i < length; i++) {
225
- view.setUint8(i, dartInstance.exports.$byteDataGetUint8(data, i));
191
+ view.setUint8(i, read(data, i));
226
192
  }
227
193
  return view;
228
194
  },
229
- _225: l => arrayFromDartList(Array, l),
230
- _226: stringFromDartString,
231
- _227: stringToDartString,
232
- _230: l => new Array(l),
233
- _234: (o, p) => o[p],
234
- _238: o => String(o),
235
- _243: x0 => x0.index,
236
- _245: x0 => x0.length,
237
- _247: (x0,x1) => x0[x1],
238
- _249: (x0,x1) => x0.exec(x1),
239
- _251: x0 => x0.flags,
240
- _252: x0 => x0.multiline,
241
- _253: x0 => x0.ignoreCase,
242
- _254: x0 => x0.unicode,
243
- _255: x0 => x0.dotAll,
244
- _256: (x0,x1) => x0.lastIndex = x1
195
+ _241: l => arrayFromDartList(Array, l),
196
+ _242: (s, length) => {
197
+ if (length == 0) return '';
198
+
199
+ const read = dartInstance.exports.$stringRead1;
200
+ let result = '';
201
+ let index = 0;
202
+ const chunkLength = Math.min(length - index, 500);
203
+ let array = new Array(chunkLength);
204
+ while (index < length) {
205
+ const newChunkLength = Math.min(length - index, 500);
206
+ for (let i = 0; i < newChunkLength; i++) {
207
+ array[i] = read(s, index++);
208
+ }
209
+ if (newChunkLength < chunkLength) {
210
+ array = array.slice(0, newChunkLength);
211
+ }
212
+ result += String.fromCharCode(...array);
213
+ }
214
+ return result;
215
+ }
216
+ ,
217
+ _243: (s, length) => {
218
+ if (length == 0) return '';
219
+
220
+ const read = dartInstance.exports.$stringRead2;
221
+ let result = '';
222
+ let index = 0;
223
+ const chunkLength = Math.min(length - index, 500);
224
+ let array = new Array(chunkLength);
225
+ while (index < length) {
226
+ const newChunkLength = Math.min(length - index, 500);
227
+ for (let i = 0; i < newChunkLength; i++) {
228
+ array[i] = read(s, index++);
229
+ }
230
+ if (newChunkLength < chunkLength) {
231
+ array = array.slice(0, newChunkLength);
232
+ }
233
+ result += String.fromCharCode(...array);
234
+ }
235
+ return result;
236
+ }
237
+ ,
238
+ _244: (s) => {
239
+ let length = s.length;
240
+ let range = 0;
241
+ for (let i = 0; i < length; i++) {
242
+ range |= s.codePointAt(i);
243
+ }
244
+ const exports = dartInstance.exports;
245
+ if (range < 256) {
246
+ if (length <= 10) {
247
+ if (length == 1) {
248
+ return exports.$stringAllocate1_1(s.codePointAt(0));
249
+ }
250
+ if (length == 2) {
251
+ return exports.$stringAllocate1_2(s.codePointAt(0), s.codePointAt(1));
252
+ }
253
+ if (length == 3) {
254
+ return exports.$stringAllocate1_3(s.codePointAt(0), s.codePointAt(1), s.codePointAt(2));
255
+ }
256
+ if (length == 4) {
257
+ return exports.$stringAllocate1_4(s.codePointAt(0), s.codePointAt(1), s.codePointAt(2), s.codePointAt(3));
258
+ }
259
+ if (length == 5) {
260
+ return exports.$stringAllocate1_5(s.codePointAt(0), s.codePointAt(1), s.codePointAt(2), s.codePointAt(3), s.codePointAt(4));
261
+ }
262
+ if (length == 6) {
263
+ return exports.$stringAllocate1_6(s.codePointAt(0), s.codePointAt(1), s.codePointAt(2), s.codePointAt(3), s.codePointAt(4), s.codePointAt(5));
264
+ }
265
+ if (length == 7) {
266
+ return exports.$stringAllocate1_7(s.codePointAt(0), s.codePointAt(1), s.codePointAt(2), s.codePointAt(3), s.codePointAt(4), s.codePointAt(5), s.codePointAt(6));
267
+ }
268
+ if (length == 8) {
269
+ return exports.$stringAllocate1_8(s.codePointAt(0), s.codePointAt(1), s.codePointAt(2), s.codePointAt(3), s.codePointAt(4), s.codePointAt(5), s.codePointAt(6), s.codePointAt(7));
270
+ }
271
+ if (length == 9) {
272
+ return exports.$stringAllocate1_9(s.codePointAt(0), s.codePointAt(1), s.codePointAt(2), s.codePointAt(3), s.codePointAt(4), s.codePointAt(5), s.codePointAt(6), s.codePointAt(7), s.codePointAt(8));
273
+ }
274
+ if (length == 10) {
275
+ return exports.$stringAllocate1_10(s.codePointAt(0), s.codePointAt(1), s.codePointAt(2), s.codePointAt(3), s.codePointAt(4), s.codePointAt(5), s.codePointAt(6), s.codePointAt(7), s.codePointAt(8), s.codePointAt(9));
276
+ }
277
+ }
278
+ const dartString = exports.$stringAllocate1(length);
279
+ const write = exports.$stringWrite1;
280
+ for (let i = 0; i < length; i++) {
281
+ write(dartString, i, s.codePointAt(i));
282
+ }
283
+ return dartString;
284
+ } else {
285
+ const dartString = exports.$stringAllocate2(length);
286
+ const write = exports.$stringWrite2;
287
+ for (let i = 0; i < length; i++) {
288
+ write(dartString, i, s.charCodeAt(i));
289
+ }
290
+ return dartString;
291
+ }
292
+ }
293
+ ,
294
+ _247: l => new Array(l),
295
+ _251: (o, p) => o[p],
296
+ _255: o => String(o),
297
+ _260: x0 => x0.index,
298
+ _262: x0 => x0.length,
299
+ _264: (x0,x1) => x0[x1],
300
+ _265: (x0,x1) => x0.exec(x1),
301
+ _267: x0 => x0.flags,
302
+ _268: x0 => x0.multiline,
303
+ _269: x0 => x0.ignoreCase,
304
+ _270: x0 => x0.unicode,
305
+ _271: x0 => x0.dotAll,
306
+ _272: (x0,x1) => x0.lastIndex = x1
245
307
  };
246
308
 
247
309
  const baseImports = {
@@ -265,7 +327,7 @@ _256: (x0,x1) => x0.lastIndex = x1
265
327
  "concat": (s1, s2) => s1 + s2,
266
328
  "equals": (s1, s2) => s1 === s2,
267
329
  "fromCharCode": (i) => String.fromCharCode(i),
268
- "length": (s) => s.length,
330
+ "length": (s) => s?.length||0,
269
331
  "substring": (s, a, b) => s.substring(a, b),
270
332
  };
271
333
 
@@ -282,8 +344,8 @@ _256: (x0,x1) => x0.lastIndex = x1
282
344
  // `moduleInstance` is the instantiated dart2wasm module
283
345
  // `args` are any arguments that should be passed into the main function.
284
346
  export const invoke = (moduleInstance, ...args) => {
285
- const dartMain = moduleInstance.exports.$getMain();
286
- const dartArgs = buildArgsList(args);
287
- moduleInstance.exports.$invokeMain(dartMain, dartArgs);
347
+ moduleInstance.exports.$invokeMain(args);
288
348
  }
289
349
 
350
+
351
+ export let format;
package/dart_fmt.wasm CHANGED
Binary file