Skip to content

Commit

Permalink
yeehaw
Browse files Browse the repository at this point in the history
  • Loading branch information
kevaundray committed Sep 15, 2023
1 parent 435c6ab commit 181196d
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from '@esm-bundle/chai';
import { initialiseResolver } from "@noir-lang/source-resolver";
import { initializeResolver } from "@noir-lang/source-resolver";
import newCompiler, {
compile,
init_log_level as compilerLogLevel
Expand Down Expand Up @@ -66,7 +66,7 @@ test_cases.forEach((testInfo) => {

expect(noir_source).to.be.a.string;

initialiseResolver((id: String) => {
initializeResolver((id: String) => {
console.log("Resolving:", id);
return noir_source;
});
Expand Down
10 changes: 5 additions & 5 deletions compiler/source-resolver/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ export let read_file = function (source_id: any): string {
if (typeof result === "string") {
return result;
} else {
throw new Error("Noir source resolver funtion MUST return String synchronously. Are you trying to return anything else, eg. `Promise`?");
throw new Error("Noir source resolver function MUST return String synchronously. Are you trying to return anything else, eg. `Promise`?");
}
} else {
throw new Error('Not yet initialised. Use initialiseResolver(() => string)');
throw new Error('Not yet initialized. Use initializeResolver(() => string)');
}

};

function initialise(noir_resolver: (source_id: String) => string): (source_id: String) => string {
function initialize(noir_resolver: (source_id: String) => string): (source_id: String) => string {

if (typeof noir_resolver === "function") {
return noir_resolver;
Expand All @@ -26,6 +26,6 @@ function initialise(noir_resolver: (source_id: String) => string): (source_id: S
}
}

export function initialiseResolver(resolver: (source_id: String) => string): void {
resolveFunction = initialise(resolver);
export function initializeResolver(resolver: (source_id: String) => string): void {
resolveFunction = initialize(resolver);
}
6 changes: 3 additions & 3 deletions compiler/source-resolver/src/index_node.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/// <reference types="node" />

import { initialiseResolver, read_file } from './index.js';
import { initializeResolver, read_file } from './index.js';

initialiseResolver((source_id: String) => {
initializeResolver((source_id: String) => {
let fileContent = "";
try {
const fs = require("fs");
Expand All @@ -15,6 +15,6 @@ initialiseResolver((source_id: String) => {
return fileContent;
});

export { initialiseResolver, read_file };
export { initializeResolver, read_file };


10 changes: 5 additions & 5 deletions compiler/source-resolver/test/cjs_initialization.test.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const test = require('ava');

const { initialiseResolver, read_file } = require("../lib-node/index_node.js");
const { initializeResolver, read_file } = require("../lib-node/index_node.js");

test('It reads file from file system within read_file using default implementation.', t => {

Expand All @@ -14,7 +14,7 @@ test('It calls function from initializer within read_file function.', t => {

const RESULT_RESPONSE = "TEST";

initialiseResolver((source) => {
initializeResolver((source) => {
return source;
});

Expand All @@ -28,22 +28,22 @@ test('It communicates error when resolver returns non-String to read_file functi

const RESULT_RESPONSE = "TEST";

initialiseResolver((source) => {
initializeResolver((source) => {
return Promise.resolve(source);
});

const error = t.throws(() => {
read_file(RESULT_RESPONSE);
}, { instanceOf: Error });

t.is(error.message, 'Noir source resolver funtion MUST return String synchronously. Are you trying to return anything else, eg. `Promise`?');
t.is(error.message, 'Noir source resolver function MUST return String synchronously. Are you trying to return anything else, eg. `Promise`?');

});

test('It communicates error when resolver is initialized to anything but a function.', t => {

const error = t.throws(() => {
initialiseResolver(null);
initializeResolver(null);
}, { instanceOf: Error });

t.is(error.message, 'Provided Noir Resolver is not a function, hint: use function(module_id) => NoirSource as second parameter');
Expand Down
14 changes: 7 additions & 7 deletions compiler/source-resolver/test/esm_initialization.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@
*/
import test from 'ava';

import { initialiseResolver, read_file } from "../lib-node/index.js";
import { initializeResolver, read_file } from "../lib-node/index.js";

test('It communicates error when read_file was called before initialiseResolver.', t => {
test('It communicates error when read_file was called before initializeResolver.', t => {

const error = t.throws(() => {
const readResult = read_file("./package.json");
}, { instanceOf: Error });

t.is(error.message, 'Not yet initialised. Use initialiseResolver(() => string)');
t.is(error.message, 'Not yet initialized. Use initializeResolver(() => string)');

});

test('It calls function from initializer within read_file function.', t => {

const RESULT_RESPONSE = "TEST";

initialiseResolver((source) => {
initializeResolver((source) => {
return source;
});

Expand All @@ -35,22 +35,22 @@ test('It communicates error when resolver returns non-String to read_file functi

const RESULT_RESPONSE = "TEST";

initialiseResolver((source) => {
initializeResolver((source) => {
return Promise.resolve(source);
});

const error = t.throws(() => {
read_file(RESULT_RESPONSE);
}, { instanceOf: Error });

t.is(error.message, 'Noir source resolver funtion MUST return String synchronously. Are you trying to return anything else, eg. `Promise`?');
t.is(error.message, 'Noir source resolver function MUST return String synchronously. Are you trying to return anything else, eg. `Promise`?');

});

test('It communicates error when resolver is initialized to anything but a function.', t => {

const error = t.throws(() => {
initialiseResolver(null);
initializeResolver(null);
}, { instanceOf: Error });

t.is(error.message, 'Provided Noir Resolver is not a function, hint: use function(module_id) => NoirSource as second parameter');
Expand Down
2 changes: 1 addition & 1 deletion compiler/source-resolver/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export declare let read_file: (source_id: any) => string;
export declare function initialiseResolver(resolver: (source_id: String) => string): void;
export declare function initializeResolver(resolver: (source_id: String) => string): void;
4 changes: 2 additions & 2 deletions compiler/source-resolver/types/index_node.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { initialiseResolver, read_file } from './index.js';
export { initialiseResolver, read_file };
import { initializeResolver, read_file } from './index.js';
export { initializeResolver, read_file };
4 changes: 2 additions & 2 deletions compiler/wasm/test/shared.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { initialiseResolver } from "@noir-lang/source-resolver";
import { initializeResolver } from "@noir-lang/source-resolver";
import { compile } from "@noir-lang/noir_wasm";

export const noirSourcePath = "../../noir-script/src/main.nr";
Expand All @@ -8,7 +8,7 @@ export const nargoArtifactPath =
export async function compileNoirSource(noir_source: string): Promise<any> {
console.log("Compiling Noir source...");

initialiseResolver((id: String) => {
initializeResolver((id: String) => {
console.log(`Resolving source ${id}`);

const source = noir_source;
Expand Down

0 comments on commit 181196d

Please sign in to comment.