Skip to content
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

fix(pretty-printer): support AstTypedParameter AST node #1347

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- 'The "remainder" field can only be the last field:' inspection now shows location: PR [#1300](https://github.com/tact-lang/tact/pull/1300)
- Forbid "remainder" field at the middle of a contract storage: PR [#1301](https://github.com/tact-lang/tact/pull/1301)
- Forbid the `override` modifier for functions without the corresponding super-function: PR [#1302](https://github.com/tact-lang/tact/pull/1302)
- Support `AstDestructMapping`, `AstDestructEnd`, and `AstTypedParameter` AST nodes in pretty printer: PR [#1347](https://github.com/tact-lang/tact/pull/1347)

### Docs

Expand Down
34 changes: 25 additions & 9 deletions src/prettyPrinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,28 @@ export const ppAstStatementDestruct: Printer<A.AstStatementDestruct> =
);
};

export const ppAstDestructMapping: Printer<A.AstDestructMapping> =
anton-trunov marked this conversation as resolved.
Show resolved Hide resolved
({ field, name }) =>
(c) => {
return c.row(
field.text === name.text
? ppAstId(name)
: `${ppAstId(field)}: ${ppAstId(name)}`,
);
};

export const ppAstDestructEnd: Printer<A.AstDestructEnd> =
anton-trunov marked this conversation as resolved.
Show resolved Hide resolved
({ ignoreUnspecifiedFields }) =>
(c) => {
return c.row(ignoreUnspecifiedFields ? ", .." : "");
};

export const ppTypedParameter: Printer<A.AstTypedParameter> =
({ name, type }) =>
(c) => {
return c.row(`${ppAstId(name)}: ${ppAstType(type)}`);
};

export const ppAstStatementBlock: Printer<A.AstStatementBlock> =
({ statements }) =>
(c) =>
Expand Down Expand Up @@ -874,15 +896,6 @@ export const ppAstNode: Printer<A.AstNode> = makeVisitor<A.AstNode>()({
bounced_message_type: exprNode(ppAstType),
struct_field_initializer: exprNode(ppAstStructFieldInit),
struct_field_value: exprNode(ppAstStructFieldValue),
destruct_mapping: () => {
throw new Error("Not implemented");
},
typed_parameter: () => {
throw new Error("Not implemented");
},
destruct_end: () => {
throw new Error("Not implemented");
},

module: ppAstModule,
struct_decl: ppAstStruct,
Expand Down Expand Up @@ -914,8 +927,11 @@ export const ppAstNode: Printer<A.AstNode> = makeVisitor<A.AstNode>()({
import: ppAstImport,
func_id: exprNode(ppAstFuncId),
statement_destruct: ppAstStatementDestruct,
destruct_mapping: ppAstDestructMapping,
destruct_end: ppAstDestructEnd,
function_attribute: exprNode(ppAstFunctionAttribute),
asm_function_def: ppAstAsmFunctionDef,
typed_parameter: ppTypedParameter,
});

/**
Expand Down
Loading