Skip to content

Commit

Permalink
finish writing method parser
Browse files Browse the repository at this point in the history
  • Loading branch information
zianksm committed Dec 11, 2022
1 parent 181b9bb commit c8acc36
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
output.ts
output.js
dist/
12 changes: 6 additions & 6 deletions src/implementation/javascript/assembler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class JavascriptMethodAssembler {
return literal;
}
private getStartingParam() {
return " (";
return "(";
}

public build(Tree: Tree) {
Expand Down Expand Up @@ -115,7 +115,7 @@ export class JavascriptMethodAssembler {
params = params.concat(literal[i].concat(COMMA, SPACE));
}

return params.concat(CLOSE_PAR, SPACE);
return params.concat(CLOSE_PAR);
}

private parseInput(value: iochild[]) {
Expand All @@ -134,9 +134,8 @@ export class JavascriptMethodAssembler {
const inputName = this.determineInputName(input).name;

input.inferredTypes = inputType;
const inputLiteral = inputName.concat(COLON, SPACE, inputType);

return inputLiteral;
return inputName;
}

private writeOutput(value: iochild[]) {
Expand Down Expand Up @@ -168,12 +167,13 @@ export class JavascriptMethodAssembler {
this.docGen.generateJsDoc(fnObj);

const signature = FORMAT_LINE.concat(
SPACE,
fnObj.jsDoc,
FORMAT_LINE,
ASYNC,
SPACE,
fnObj.name,
fnObj.attributes.inputs.literals as string,
this.determineOutput(fnObj),
// this.determineOutput(fnObj),
// function implementation will starts here
SPACE,
OPEN_BRACE,
Expand Down
7 changes: 4 additions & 3 deletions src/implementation/javascript/js-doc-generator.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { FORMAT_LINE } from "../token";
import { Branch, iochild } from "../type-mapping";

export class DocGen {
private generateParam(fragment: iochild) {
return `* @param {${fragment.inferredTypes}} ${fragment.name}\n`;
return `${FORMAT_LINE}* @param {${fragment.inferredTypes}} ${fragment.name}\n`;
}

private generateOutput(fragments: string[]) {
return `* @returns {${fragments}}\n`;
return `${FORMAT_LINE}* @returns {${fragments}}\n`;
}

// TODO : make method to concat multiple jsdoc literals into 1 for that tree branch
Expand Down Expand Up @@ -39,6 +40,6 @@ export class DocGen {
}

private buildJsDoc(branch: Branch) {
branch.jsDoc = `/**\n ${branch.attributes.inputs.jsDoc} ${branch.attributes.outputs.jsDoc} */`;
branch.jsDoc = `/**\n ${branch.attributes.inputs.jsDoc} ${branch.attributes.outputs.jsDoc} ${FORMAT_LINE}*/\n`;
}
}
2 changes: 1 addition & 1 deletion test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ const abi = fs.readFileSync("./abi/auctions/auction.json");
const writer = new Writer();
const output = writer.write("test", abi.toString("utf-8"), { lang: "js" });

fs.writeFileSync("./output.ts", output);
fs.writeFileSync("./output.js", output);

0 comments on commit c8acc36

Please sign in to comment.