Skip to content

Commit

Permalink
Fix corner case with if-then expression (#83)
Browse files Browse the repository at this point in the history
* Fix corner case with if-then expression

* 0.3.2

* Bump mo-fmt
  • Loading branch information
rvanasa authored Jan 30, 2023
1 parent 1d240e0 commit 7866aac
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prettier-plugin-motoko",
"version": "0.3.1",
"version": "0.3.2",
"description": "A code formatter for the Motoko smart contract language.",
"main": "lib/environments/node.js",
"browser": "lib/environments/web.js",
Expand Down
14 changes: 7 additions & 7 deletions packages/mo-fmt/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/mo-fmt/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mo-fmt",
"version": "0.3.1",
"version": "0.3.2",
"description": "An easy-to-use Motoko formatter command.",
"main": "src/cli.js",
"bin": {
Expand All @@ -21,7 +21,7 @@
"commander": "^9.4.0",
"fast-glob": "^3.2.11",
"prettier": "^2.7",
"prettier-plugin-motoko": "^0.3.1"
"prettier-plugin-motoko": "^0.3.2"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^22.0.2",
Expand Down
3 changes: 3 additions & 0 deletions src/printers/motoko-tt-ast/spaceConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ const spaceConfig: SpaceConfig = {
['Delim', '_', 'line'],
// ['Delim', 'Line', 'nil'],

// if-then expressions
[{ left: tokenEquals('if'), main: '_' }, 'Paren', 'space'],

// unary operators
[tokenEquals('#'), 'Ident', 'keep'],
[tokenEquals('+'), '_', 'keep'],
Expand Down
7 changes: 7 additions & 0 deletions tests/formatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,13 @@ describe('Motoko formatter', () => {
expect(format('{\n// }\n}\nA\n')).toStrictEqual('{\n // }\n};\nA;\n');
});

test('conditional parentheses', () => {
expect(format('if a b')).toStrictEqual('if a b\n');
expect(format('if (a) b')).toStrictEqual('if (a) b\n');
expect(format('if a (b)')).toStrictEqual('if a (b)\n');
expect(format('if (a) (b)')).toStrictEqual('if (a) (b)\n');
});

// test('generate diff files from compiler tests', () => {
// for (const extension of ['mo', 'did']) {
// let preOutput = '';
Expand Down

0 comments on commit 7866aac

Please sign in to comment.