@noir-lang/noir_wasm 0.24.0-722dc96.nightly → 0.24.0-9544813.nightly

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.
Binary file
package/dist/node/main.js CHANGED
@@ -18,12 +18,6 @@ heap.push(undefined, null, true, false);
18
18
 
19
19
  function getObject(idx) { return heap[idx]; }
20
20
 
21
- function _assertBoolean(n) {
22
- if (typeof(n) !== 'boolean') {
23
- throw new Error('expected a boolean argument');
24
- }
25
- }
26
-
27
21
  let heap_next = heap.length;
28
22
 
29
23
  function dropObject(idx) {
@@ -61,8 +55,6 @@ function addHeapObject(obj) {
61
55
  const idx = heap_next;
62
56
  heap_next = heap[idx];
63
57
 
64
- if (typeof(heap_next) !== 'number') throw new Error('corrupt heap');
65
-
66
58
  heap[idx] = obj;
67
59
  return idx;
68
60
  }
@@ -86,8 +78,6 @@ const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
86
78
 
87
79
  function passStringToWasm0(arg, malloc, realloc) {
88
80
 
89
- if (typeof(arg) !== 'string') throw new Error('expected a string argument');
90
-
91
81
  if (realloc === undefined) {
92
82
  const buf = cachedTextEncoder.encode(arg);
93
83
  const ptr = malloc(buf.length) >>> 0;
@@ -116,7 +106,7 @@ function passStringToWasm0(arg, malloc, realloc) {
116
106
  ptr = realloc(ptr, len, len = offset + arg.length * 3) >>> 0;
117
107
  const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
118
108
  const ret = encodeString(arg, view);
119
- if (ret.read !== arg.length) throw new Error('failed to pass whole string');
109
+
120
110
  offset += ret.written;
121
111
  }
122
112
 
@@ -208,33 +198,22 @@ function _assertClass(instance, klass) {
208
198
  }
209
199
  return instance.ptr;
210
200
  }
211
-
212
- function _assertNum(n) {
213
- if (typeof(n) !== 'number') throw new Error('expected a number argument');
214
- }
215
201
  /**
216
202
  * This is a method that exposes the same API as `compile`
217
203
  * But uses the Context based APi internally
218
204
  * @param {string} entry_point
219
- * @param {boolean | undefined} contracts
220
205
  * @param {DependencyGraph | undefined} dependency_graph
221
206
  * @param {PathToFileSourceMap} file_source_map
222
- * @returns {CompileResult}
207
+ * @returns {ProgramCompileResult}
223
208
  */
224
- module.exports.compile_ = function(entry_point, contracts, dependency_graph, file_source_map) {
209
+ module.exports.compile_program_ = function(entry_point, dependency_graph, file_source_map) {
225
210
  try {
226
211
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
227
212
  const ptr0 = passStringToWasm0(entry_point, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
228
213
  const len0 = WASM_VECTOR_LEN;
229
- if (!isLikeNone(contracts)) {
230
- _assertBoolean(contracts);
231
- }
232
214
  _assertClass(file_source_map, PathToFileSourceMap);
233
- if (file_source_map.__wbg_ptr === 0) {
234
- throw new Error('Attempt to use a moved value');
235
- }
236
215
  var ptr1 = file_source_map.__destroy_into_raw();
237
- wasm.compile_(retptr, ptr0, len0, isLikeNone(contracts) ? 0xFFFFFF : contracts ? 1 : 0, isLikeNone(dependency_graph) ? 0 : addHeapObject(dependency_graph), ptr1);
216
+ wasm.compile_program_(retptr, ptr0, len0, isLikeNone(dependency_graph) ? 0 : addHeapObject(dependency_graph), ptr1);
238
217
  var r0 = getInt32Memory0()[retptr / 4 + 0];
239
218
  var r1 = getInt32Memory0()[retptr / 4 + 1];
240
219
  var r2 = getInt32Memory0()[retptr / 4 + 2];
@@ -247,42 +226,74 @@ module.exports.compile_ = function(entry_point, contracts, dependency_graph, fil
247
226
  }
248
227
  };
249
228
 
250
- function logError(f, args) {
229
+ /**
230
+ * This is a method that exposes the same API as `compile`
231
+ * But uses the Context based APi internally
232
+ * @param {string} entry_point
233
+ * @param {DependencyGraph | undefined} dependency_graph
234
+ * @param {PathToFileSourceMap} file_source_map
235
+ * @returns {ContractCompileResult}
236
+ */
237
+ module.exports.compile_contract_ = function(entry_point, dependency_graph, file_source_map) {
251
238
  try {
252
- return f.apply(this, args);
253
- } catch (e) {
254
- let error = (function () {
255
- try {
256
- return e instanceof Error ? `${e.message}\n\nStack:\n${e.stack}` : e.toString();
257
- } catch(_) {
258
- return "<failed to stringify thrown value>";
259
- }
260
- }());
261
- console.error("wasm-bindgen: imported JS function that was not marked as `catch` threw an error:", error);
262
- throw e;
239
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
240
+ const ptr0 = passStringToWasm0(entry_point, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
241
+ const len0 = WASM_VECTOR_LEN;
242
+ _assertClass(file_source_map, PathToFileSourceMap);
243
+ var ptr1 = file_source_map.__destroy_into_raw();
244
+ wasm.compile_contract_(retptr, ptr0, len0, isLikeNone(dependency_graph) ? 0 : addHeapObject(dependency_graph), ptr1);
245
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
246
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
247
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
248
+ if (r2) {
249
+ throw takeObject(r1);
250
+ }
251
+ return takeObject(r0);
252
+ } finally {
253
+ wasm.__wbindgen_add_to_stack_pointer(16);
263
254
  }
264
- }
255
+ };
256
+
265
257
  /**
266
258
  * @param {string} entry_point
267
- * @param {boolean | undefined} contracts
268
259
  * @param {DependencyGraph | undefined} dependency_graph
269
260
  * @param {PathToFileSourceMap} file_source_map
270
- * @returns {CompileResult}
261
+ * @returns {ProgramCompileResult}
271
262
  */
272
- module.exports.compile = function(entry_point, contracts, dependency_graph, file_source_map) {
263
+ module.exports.compile_program = function(entry_point, dependency_graph, file_source_map) {
273
264
  try {
274
265
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
275
266
  const ptr0 = passStringToWasm0(entry_point, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
276
267
  const len0 = WASM_VECTOR_LEN;
277
- if (!isLikeNone(contracts)) {
278
- _assertBoolean(contracts);
279
- }
280
268
  _assertClass(file_source_map, PathToFileSourceMap);
281
- if (file_source_map.__wbg_ptr === 0) {
282
- throw new Error('Attempt to use a moved value');
269
+ var ptr1 = file_source_map.__destroy_into_raw();
270
+ wasm.compile_program(retptr, ptr0, len0, isLikeNone(dependency_graph) ? 0 : addHeapObject(dependency_graph), ptr1);
271
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
272
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
273
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
274
+ if (r2) {
275
+ throw takeObject(r1);
283
276
  }
277
+ return takeObject(r0);
278
+ } finally {
279
+ wasm.__wbindgen_add_to_stack_pointer(16);
280
+ }
281
+ };
282
+
283
+ /**
284
+ * @param {string} entry_point
285
+ * @param {DependencyGraph | undefined} dependency_graph
286
+ * @param {PathToFileSourceMap} file_source_map
287
+ * @returns {ContractCompileResult}
288
+ */
289
+ module.exports.compile_contract = function(entry_point, dependency_graph, file_source_map) {
290
+ try {
291
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
292
+ const ptr0 = passStringToWasm0(entry_point, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
293
+ const len0 = WASM_VECTOR_LEN;
294
+ _assertClass(file_source_map, PathToFileSourceMap);
284
295
  var ptr1 = file_source_map.__destroy_into_raw();
285
- wasm.compile(retptr, ptr0, len0, isLikeNone(contracts) ? 0xFFFFFF : contracts ? 1 : 0, isLikeNone(dependency_graph) ? 0 : addHeapObject(dependency_graph), ptr1);
296
+ wasm.compile_contract(retptr, ptr0, len0, isLikeNone(dependency_graph) ? 0 : addHeapObject(dependency_graph), ptr1);
286
297
  var r0 = getInt32Memory0()[retptr / 4 + 0];
287
298
  var r1 = getInt32Memory0()[retptr / 4 + 1];
288
299
  var r2 = getInt32Memory0()[retptr / 4 + 2];
@@ -296,10 +307,10 @@ module.exports.compile = function(entry_point, contracts, dependency_graph, file
296
307
  };
297
308
 
298
309
  /**
299
- * @param {string} filter
310
+ * @param {string} level
300
311
  */
301
- module.exports.init_log_level = function(filter) {
302
- const ptr0 = passStringToWasm0(filter, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
312
+ module.exports.init_log_level = function(level) {
313
+ const ptr0 = passStringToWasm0(level, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
303
314
  const len0 = WASM_VECTOR_LEN;
304
315
  wasm.init_log_level(ptr0, len0);
305
316
  };
@@ -350,9 +361,6 @@ class CompilerContext {
350
361
  */
351
362
  constructor(source_map) {
352
363
  _assertClass(source_map, PathToFileSourceMap);
353
- if (source_map.__wbg_ptr === 0) {
354
- throw new Error('Attempt to use a moved value');
355
- }
356
364
  var ptr0 = source_map.__destroy_into_raw();
357
365
  const ret = wasm.compilercontext_new(ptr0);
358
366
  return CompilerContext.__wrap(ret);
@@ -362,8 +370,6 @@ class CompilerContext {
362
370
  * @returns {CrateId}
363
371
  */
364
372
  process_root_crate(path_to_crate) {
365
- if (this.__wbg_ptr == 0) throw new Error('Attempt to use a moved value');
366
- _assertNum(this.__wbg_ptr);
367
373
  const ptr0 = passStringToWasm0(path_to_crate, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
368
374
  const len0 = WASM_VECTOR_LEN;
369
375
  const ret = wasm.compilercontext_process_root_crate(this.__wbg_ptr, ptr0, len0);
@@ -374,8 +380,6 @@ class CompilerContext {
374
380
  * @returns {CrateId}
375
381
  */
376
382
  process_dependency_crate(path_to_crate) {
377
- if (this.__wbg_ptr == 0) throw new Error('Attempt to use a moved value');
378
- _assertNum(this.__wbg_ptr);
379
383
  const ptr0 = passStringToWasm0(path_to_crate, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
380
384
  const len0 = WASM_VECTOR_LEN;
381
385
  const ret = wasm.compilercontext_process_dependency_crate(this.__wbg_ptr, ptr0, len0);
@@ -388,19 +392,11 @@ class CompilerContext {
388
392
  */
389
393
  add_dependency_edge(crate_name, from, to) {
390
394
  try {
391
- if (this.__wbg_ptr == 0) throw new Error('Attempt to use a moved value');
392
395
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
393
- _assertNum(this.__wbg_ptr);
394
396
  const ptr0 = passStringToWasm0(crate_name, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
395
397
  const len0 = WASM_VECTOR_LEN;
396
398
  _assertClass(from, CrateId);
397
- if (from.__wbg_ptr === 0) {
398
- throw new Error('Attempt to use a moved value');
399
- }
400
399
  _assertClass(to, CrateId);
401
- if (to.__wbg_ptr === 0) {
402
- throw new Error('Attempt to use a moved value');
403
- }
404
400
  wasm.compilercontext_add_dependency_edge(retptr, this.__wbg_ptr, ptr0, len0, from.__wbg_ptr, to.__wbg_ptr);
405
401
  var r0 = getInt32Memory0()[retptr / 4 + 0];
406
402
  var r1 = getInt32Memory0()[retptr / 4 + 1];
@@ -413,15 +409,12 @@ class CompilerContext {
413
409
  }
414
410
  /**
415
411
  * @param {number} program_width
416
- * @returns {CompileResult}
412
+ * @returns {ProgramCompileResult}
417
413
  */
418
414
  compile_program(program_width) {
419
415
  try {
420
- if (this.__wbg_ptr == 0) throw new Error('Attempt to use a moved value');
421
416
  const ptr = this.__destroy_into_raw();
422
417
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
423
- _assertNum(ptr);
424
- _assertNum(program_width);
425
418
  wasm.compilercontext_compile_program(retptr, ptr, program_width);
426
419
  var r0 = getInt32Memory0()[retptr / 4 + 0];
427
420
  var r1 = getInt32Memory0()[retptr / 4 + 1];
@@ -436,15 +429,12 @@ class CompilerContext {
436
429
  }
437
430
  /**
438
431
  * @param {number} program_width
439
- * @returns {CompileResult}
432
+ * @returns {ContractCompileResult}
440
433
  */
441
434
  compile_contract(program_width) {
442
435
  try {
443
- if (this.__wbg_ptr == 0) throw new Error('Attempt to use a moved value');
444
436
  const ptr = this.__destroy_into_raw();
445
437
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
446
- _assertNum(ptr);
447
- _assertNum(program_width);
448
438
  wasm.compilercontext_compile_contract(retptr, ptr, program_width);
449
439
  var r0 = getInt32Memory0()[retptr / 4 + 0];
450
440
  var r1 = getInt32Memory0()[retptr / 4 + 1];
@@ -463,10 +453,6 @@ module.exports.CompilerContext = CompilerContext;
463
453
  */
464
454
  class CrateId {
465
455
 
466
- constructor() {
467
- throw new Error('cannot invoke `new` directly');
468
- }
469
-
470
456
  static __wrap(ptr) {
471
457
  ptr = ptr >>> 0;
472
458
  const obj = Object.create(CrateId.prototype);
@@ -523,8 +509,6 @@ class PathToFileSourceMap {
523
509
  * @returns {boolean}
524
510
  */
525
511
  add_source_code(path, source_code) {
526
- if (this.__wbg_ptr == 0) throw new Error('Attempt to use a moved value');
527
- _assertNum(this.__wbg_ptr);
528
512
  const ptr0 = passStringToWasm0(path, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
529
513
  const len0 = WASM_VECTOR_LEN;
530
514
  const ptr1 = passStringToWasm0(source_code, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
@@ -535,40 +519,39 @@ class PathToFileSourceMap {
535
519
  }
536
520
  module.exports.PathToFileSourceMap = PathToFileSourceMap;
537
521
 
522
+ module.exports.__wbindgen_object_drop_ref = function(arg0) {
523
+ takeObject(arg0);
524
+ };
525
+
538
526
  module.exports.__wbindgen_is_undefined = function(arg0) {
539
527
  const ret = getObject(arg0) === undefined;
540
- _assertBoolean(ret);
541
528
  return ret;
542
529
  };
543
530
 
544
- module.exports.__wbindgen_object_drop_ref = function(arg0) {
545
- takeObject(arg0);
546
- };
547
-
548
- module.exports.__wbg_constructor_05d6d198f3477d6f = function() { return logError(function () {
531
+ module.exports.__wbg_constructor_05d6d198f3477d6f = function() {
549
532
  const ret = new Object();
550
533
  return addHeapObject(ret);
551
- }, arguments) };
534
+ };
552
535
 
553
- module.exports.__wbg_constructor_e8767839abf8a966 = function() { return logError(function (arg0) {
536
+ module.exports.__wbg_constructor_e8767839abf8a966 = function(arg0) {
554
537
  const ret = new Error(takeObject(arg0));
555
538
  return addHeapObject(ret);
556
- }, arguments) };
539
+ };
557
540
 
558
- module.exports.__wbg_new_abda76e883ba8a5f = function() { return logError(function () {
541
+ module.exports.__wbg_new_abda76e883ba8a5f = function() {
559
542
  const ret = new Error();
560
543
  return addHeapObject(ret);
561
- }, arguments) };
544
+ };
562
545
 
563
- module.exports.__wbg_stack_658279fe44541cf6 = function() { return logError(function (arg0, arg1) {
546
+ module.exports.__wbg_stack_658279fe44541cf6 = function(arg0, arg1) {
564
547
  const ret = getObject(arg1).stack;
565
548
  const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
566
549
  const len1 = WASM_VECTOR_LEN;
567
550
  getInt32Memory0()[arg0 / 4 + 1] = len1;
568
551
  getInt32Memory0()[arg0 / 4 + 0] = ptr1;
569
- }, arguments) };
552
+ };
570
553
 
571
- module.exports.__wbg_error_f851667af71bcfc6 = function() { return logError(function (arg0, arg1) {
554
+ module.exports.__wbg_error_f851667af71bcfc6 = function(arg0, arg1) {
572
555
  let deferred0_0;
573
556
  let deferred0_1;
574
557
  try {
@@ -578,52 +561,44 @@ module.exports.__wbg_error_f851667af71bcfc6 = function() { return logError(funct
578
561
  } finally {
579
562
  wasm.__wbindgen_export_2(deferred0_0, deferred0_1);
580
563
  }
581
- }, arguments) };
564
+ };
582
565
 
583
566
  module.exports.__wbindgen_string_new = function(arg0, arg1) {
584
567
  const ret = getStringFromWasm0(arg0, arg1);
585
568
  return addHeapObject(ret);
586
569
  };
587
570
 
588
- module.exports.__wbg_debug_e3f6a1578e6d45ca = function() { return logError(function (arg0) {
571
+ module.exports.__wbg_debug_e3f6a1578e6d45ca = function(arg0) {
589
572
  console.debug(getObject(arg0));
590
- }, arguments) };
573
+ };
591
574
 
592
- module.exports.__wbg_debug_efabe4eb183aa5d4 = function() { return logError(function (arg0, arg1, arg2, arg3) {
575
+ module.exports.__wbg_debug_efabe4eb183aa5d4 = function(arg0, arg1, arg2, arg3) {
593
576
  console.debug(getObject(arg0), getObject(arg1), getObject(arg2), getObject(arg3));
594
- }, arguments) };
577
+ };
595
578
 
596
- module.exports.__wbg_error_a7e23606158b68b9 = function() { return logError(function (arg0) {
579
+ module.exports.__wbg_error_a7e23606158b68b9 = function(arg0) {
597
580
  console.error(getObject(arg0));
598
- }, arguments) };
581
+ };
599
582
 
600
- module.exports.__wbg_error_50f42b952a595a23 = function() { return logError(function (arg0, arg1, arg2, arg3) {
583
+ module.exports.__wbg_error_50f42b952a595a23 = function(arg0, arg1, arg2, arg3) {
601
584
  console.error(getObject(arg0), getObject(arg1), getObject(arg2), getObject(arg3));
602
- }, arguments) };
585
+ };
603
586
 
604
- module.exports.__wbg_info_05db236d79f1b785 = function() { return logError(function (arg0) {
587
+ module.exports.__wbg_info_05db236d79f1b785 = function(arg0) {
605
588
  console.info(getObject(arg0));
606
- }, arguments) };
589
+ };
607
590
 
608
- module.exports.__wbg_info_24d8f53d98f12b95 = function() { return logError(function (arg0, arg1, arg2, arg3) {
591
+ module.exports.__wbg_info_24d8f53d98f12b95 = function(arg0, arg1, arg2, arg3) {
609
592
  console.info(getObject(arg0), getObject(arg1), getObject(arg2), getObject(arg3));
610
- }, arguments) };
611
-
612
- module.exports.__wbg_log_dc06ec929fc95a20 = function() { return logError(function (arg0) {
613
- console.log(getObject(arg0));
614
- }, arguments) };
615
-
616
- module.exports.__wbg_log_2f6947e39440ae3b = function() { return logError(function (arg0, arg1, arg2, arg3, arg4) {
617
- console.log(getObject(arg0), getObject(arg1), getObject(arg2), getObject(arg3), getObject(arg4));
618
- }, arguments) };
593
+ };
619
594
 
620
- module.exports.__wbg_warn_9bdd743e9f5fe1e0 = function() { return logError(function (arg0) {
595
+ module.exports.__wbg_warn_9bdd743e9f5fe1e0 = function(arg0) {
621
596
  console.warn(getObject(arg0));
622
- }, arguments) };
597
+ };
623
598
 
624
- module.exports.__wbg_warn_8342bfbc6028193a = function() { return logError(function (arg0, arg1, arg2, arg3) {
599
+ module.exports.__wbg_warn_8342bfbc6028193a = function(arg0, arg1, arg2, arg3) {
625
600
  console.warn(getObject(arg0), getObject(arg1), getObject(arg2), getObject(arg3));
626
- }, arguments) };
601
+ };
627
602
 
628
603
  module.exports.__wbindgen_string_get = function(arg0, arg1) {
629
604
  const obj = getObject(arg1);
@@ -646,7 +621,6 @@ module.exports.__wbg_stringify_d06ad2addc54d51e = function() { return handleErro
646
621
 
647
622
  module.exports.__wbg_set_07da13cc24b69217 = function() { return handleError(function (arg0, arg1, arg2) {
648
623
  const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
649
- _assertBoolean(ret);
650
624
  return ret;
651
625
  }, arguments) };
652
626
 
@@ -1237,18 +1211,54 @@ class NoirWasmCompiler {
1237
1211
  /**
1238
1212
  * Compile EntryPoint
1239
1213
  */
1214
+ async compile_program() {
1215
+ console.log(`Compiling at ${this.#package.getEntryPointPath()}`);
1216
+ if (this.#package.getType() !== 'bin') {
1217
+ throw new Error(`Expected to find package type "bin" but found ${this.#package.getType()}`);
1218
+ }
1219
+ await this.#dependencyManager.resolveDependencies();
1220
+ this.#debugLog(`Dependencies: ${this.#dependencyManager.getPackageNames().join(', ')}`);
1221
+ try {
1222
+ const entrypoint = this.#package.getEntryPointPath();
1223
+ const deps = {
1224
+ /* eslint-disable camelcase */
1225
+ root_dependencies: this.#dependencyManager.getEntrypointDependencies(),
1226
+ library_dependencies: this.#dependencyManager.getLibraryDependencies(),
1227
+ /* eslint-enable camelcase */
1228
+ };
1229
+ const packageSources = await this.#package.getSources(this.#fm);
1230
+ const librarySources = (await Promise.all(this.#dependencyManager
1231
+ .getLibraries()
1232
+ .map(async ([alias, library]) => await library.package.getSources(this.#fm, alias)))).flat();
1233
+ [...packageSources, ...librarySources].forEach((sourceFile) => {
1234
+ this.#debugLog(`Adding source ${sourceFile.path}`);
1235
+ this.#sourceMap.add_source_code(sourceFile.path, sourceFile.source);
1236
+ });
1237
+ const result = this.#wasmCompiler.compile_program(entrypoint, deps, this.#sourceMap);
1238
+ return result;
1239
+ }
1240
+ catch (err) {
1241
+ if (err instanceof Error && err.name === 'CompileError') {
1242
+ const logs = await this.#processCompileError(err);
1243
+ for (const log of logs) {
1244
+ this.#log(log);
1245
+ }
1246
+ throw new Error(logs.join('\n'));
1247
+ }
1248
+ throw err;
1249
+ }
1250
+ }
1240
1251
  /**
1241
1252
  * Compile EntryPoint
1242
1253
  */
1243
- async compile() {
1254
+ async compile_contract() {
1244
1255
  console.log(`Compiling at ${this.#package.getEntryPointPath()}`);
1245
- if (!(this.#package.getType() === 'contract' || this.#package.getType() === 'bin')) {
1246
- throw new Error(`Only supports compiling "contract" and "bin" package types (${this.#package.getType()})`);
1256
+ if (this.#package.getType() !== 'contract') {
1257
+ throw new Error(`Expected to find package type "contract" but found ${this.#package.getType()}`);
1247
1258
  }
1248
1259
  await this.#dependencyManager.resolveDependencies();
1249
1260
  this.#debugLog(`Dependencies: ${this.#dependencyManager.getPackageNames().join(', ')}`);
1250
1261
  try {
1251
- const isContract = this.#package.getType() === 'contract';
1252
1262
  const entrypoint = this.#package.getEntryPointPath();
1253
1263
  const deps = {
1254
1264
  /* eslint-disable camelcase */
@@ -1264,10 +1274,7 @@ class NoirWasmCompiler {
1264
1274
  this.#debugLog(`Adding source ${sourceFile.path}`);
1265
1275
  this.#sourceMap.add_source_code(sourceFile.path, sourceFile.source);
1266
1276
  });
1267
- const result = this.#wasmCompiler.compile(entrypoint, isContract, deps, this.#sourceMap);
1268
- if ((isContract && !('contract' in result)) || (!isContract && !('program' in result))) {
1269
- throw new Error('Invalid compilation result');
1270
- }
1277
+ const result = this.#wasmCompiler.compile_contract(entrypoint, deps, this.#sourceMap);
1271
1278
  return result;
1272
1279
  }
1273
1280
  catch (err) {
@@ -1396,7 +1403,7 @@ class Package {
1396
1403
  * Gets this package's dependencies.
1397
1404
  */
1398
1405
  getDependencies() {
1399
- return this.#config.dependencies;
1406
+ return this.#config.dependencies ?? {};
1400
1407
  }
1401
1408
  /**
1402
1409
  * Gets this package's sources.
@@ -12816,7 +12823,7 @@ var exports = __webpack_exports__;
12816
12823
  \***********************/
12817
12824
 
12818
12825
  Object.defineProperty(exports, "__esModule", ({ value: true }));
12819
- exports.inflateDebugSymbols = exports.createFileManager = exports.compile = void 0;
12826
+ exports.inflateDebugSymbols = exports.createFileManager = exports.compile_contract = exports.compile_program = exports.compile = void 0;
12820
12827
  const nodejs_file_manager_1 = __webpack_require__(/*! ./noir/file-manager/nodejs-file-manager */ "./src/noir/file-manager/nodejs-file-manager.ts");
12821
12828
  const noir_wasm_compiler_1 = __webpack_require__(/*! ./noir/noir-wasm-compiler */ "./src/noir/noir-wasm-compiler.ts");
12822
12829
  const debug_1 = __webpack_require__(/*! ./noir/debug */ "./src/noir/debug.ts");
@@ -12833,30 +12840,71 @@ Object.defineProperty(exports, "inflateDebugSymbols", ({ enumerable: true, get:
12833
12840
  * ```typescript
12834
12841
  * // Node.js
12835
12842
  *
12836
- * import { compile, createFileManager } from '@noir-lang/noir_wasm';
12843
+ * import { compile_program, createFileManager } from '@noir-lang/noir_wasm';
12837
12844
  *
12838
12845
  * const fm = createFileManager(myProjectPath);
12839
- * const myCompiledCode = await compile(fm);
12846
+ * const myCompiledCode = await compile_program(fm);
12840
12847
  * ```
12841
12848
  *
12842
12849
  * ```typescript
12843
12850
  * // Browser
12844
12851
  *
12845
- * import { compile, createFileManager } from '@noir-lang/noir_wasm';
12852
+ * import { compile_program, createFileManager } from '@noir-lang/noir_wasm';
12846
12853
  *
12847
12854
  * const fm = createFileManager('/');
12848
12855
  * for (const path of files) {
12849
12856
  * await fm.writeFile(path, await getFileAsStream(path));
12850
12857
  * }
12851
- * const myCompiledCode = await compile(fm);
12858
+ * const myCompiledCode = await compile_program(fm);
12852
12859
  * ```
12853
12860
  */
12854
- async function compile(fileManager, projectPath, logFn, debugLogFn) {
12861
+ async function compile_program(fileManager, projectPath, logFn, debugLogFn) {
12862
+ const compiler = await setup_compiler(fileManager, projectPath, logFn, debugLogFn);
12863
+ return await compiler.compile_program();
12864
+ }
12865
+ exports.compile = compile_program;
12866
+ exports.compile_program = compile_program;
12867
+ /**
12868
+ * Compiles a Noir project
12869
+ *
12870
+ * @param fileManager - The file manager to use
12871
+ * @param projectPath - The path to the project inside the file manager. Defaults to the root of the file manager
12872
+ * @param logFn - A logging function. If not provided, console.log will be used
12873
+ * @param debugLogFn - A debug logging function. If not provided, logFn will be used
12874
+ *
12875
+ * @example
12876
+ * ```typescript
12877
+ * // Node.js
12878
+ *
12879
+ * import { compile_contract, createFileManager } from '@noir-lang/noir_wasm';
12880
+ *
12881
+ * const fm = createFileManager(myProjectPath);
12882
+ * const myCompiledCode = await compile_contract(fm);
12883
+ * ```
12884
+ *
12885
+ * ```typescript
12886
+ * // Browser
12887
+ *
12888
+ * import { compile_contract, createFileManager } from '@noir-lang/noir_wasm';
12889
+ *
12890
+ * const fm = createFileManager('/');
12891
+ * for (const path of files) {
12892
+ * await fm.writeFile(path, await getFileAsStream(path));
12893
+ * }
12894
+ * const myCompiledCode = await compile_contract(fm);
12895
+ * ```
12896
+ */
12897
+ async function compile_contract(fileManager, projectPath, logFn, debugLogFn) {
12898
+ const compiler = await setup_compiler(fileManager, projectPath, logFn, debugLogFn);
12899
+ return await compiler.compile_contract();
12900
+ }
12901
+ exports.compile_contract = compile_contract;
12902
+ async function setup_compiler(fileManager, projectPath, logFn, debugLogFn) {
12855
12903
  if (logFn && !debugLogFn) {
12856
12904
  debugLogFn = logFn;
12857
12905
  }
12858
12906
  const cjs = await __webpack_require__(/*! ../build/cjs */ "./build/cjs/index.js");
12859
- const compiler = await noir_wasm_compiler_1.NoirWasmCompiler.new(fileManager, projectPath ?? fileManager.getDataDir(), cjs, new cjs.PathToFileSourceMap(), {
12907
+ return await noir_wasm_compiler_1.NoirWasmCompiler.new(fileManager, projectPath ?? fileManager.getDataDir(), cjs, new cjs.PathToFileSourceMap(), {
12860
12908
  log: logFn ??
12861
12909
  function (msg, data) {
12862
12910
  if (data) {
@@ -12876,9 +12924,7 @@ async function compile(fileManager, projectPath, logFn, debugLogFn) {
12876
12924
  }
12877
12925
  },
12878
12926
  });
12879
- return await compiler.compile();
12880
12927
  }
12881
- exports.compile = compile;
12882
12928
  const createFileManager = nodejs_file_manager_1.createNodejsFileManager;
12883
12929
  exports.createFileManager = createFileManager;
12884
12930