-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Opcodes and Errors classes in generated Typescript code #1100
base: main
Are you sure you want to change the base?
Conversation
…Added opcodes class generation. Added ExitCodes map generation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's either
- add tests with the new functionality, or
- simplify the existing tests using it
|
||
//Opcodes | ||
//So user can use them in sandbox tests | ||
w.append("export abstract class Opcodes {"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TypeScript has enum
syntax for this. abstract class
implies user should inherit from it to get access to its fields, and that's definitely not the way in a language without multiple inheritance.
@@ -272,58 +303,66 @@ export function writeTypescript( | |||
|
|||
if (init) { | |||
w.append( | |||
`static async init(${writeArguments(init.args).join(", ")}) {`, | |||
`static async init<T extends ${abi.name}>(` + | |||
`this: new (address: Address, init?: { code: Cell, data: Cell }) => T,` + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This kind of types is meant to type legacy JS code, not to write or generate novel code.
w.append(`const ${abi.name}_errorMessages: { [key: string]: number } = {`); | ||
w.inIndent(() => { | ||
if (abi.errors) { | ||
Object.entries(abi.errors).forEach(([k, abiError]) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (const [k, abiError] of abi.errors)
would be more readable, concise and performant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@verytactical there is a few of instances of Object.entries(foo).forEach(([k, v]) ...
in the codebase. Could you please open an issue to refactor those?
if (abi.errors) { | ||
Object.entries(abi.errors).forEach(([k, abiError]) => { | ||
const escapedMessage = abiError.message.replaceAll('"', '\\"'); | ||
w.append(` "${escapedMessage}": ${k},`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an indent that doesn't take .inIndent()
state in consideration.
Issue
Closes #1033 .
Checklist
docs/
and made the build locally