Skip to content

Commit

Permalink
Fix obscure lexer corner case (#75)
Browse files Browse the repository at this point in the history
* Fix obscure lexer corner case

* Test keep-space for obscure corner case

* 0.2.5

* Bump mo-fmt dependency
  • Loading branch information
rvanasa authored Dec 19, 2022
1 parent 18a3cbd commit 0c646e7
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 14 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.2.4",
"version": "0.2.5",
"description": "A code formatter for the Motoko smart contract language.",
"main": "lib/environments/node.js",
"browser": "lib/environments/web.js",
Expand Down
18 changes: 9 additions & 9 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.2.4",
"version": "0.2.5",
"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.2.4"
"prettier-plugin-motoko": "^0.2.5"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^22.0.2",
Expand Down
11 changes: 11 additions & 0 deletions src/printers/motoko-tt-ast/spaceConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,17 @@ const spaceConfig: SpaceConfig = {
['Open', '_', 'nil'],
['_', 'Close', 'nil'],

// identifier after float in exponential notation (fixes #74)
[
token(
(token) =>
token.token_type === 'Literal' &&
/\.[a-z]/i.test(token.data[0]),
),
'Ident',
'keep',
],

// default
['_', '_', 'space'],
],
Expand Down
5 changes: 5 additions & 0 deletions tests/formatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ describe('Motoko formatter', () => {
// );
// });

test('identifier tokens', ()=>{
expect(format('x.0.e0x')).toStrictEqual('x.0.e0x\n');
expect(format('x.0.e0 x')).toStrictEqual('x.0.e0 x\n');
})

test('array indexing line break', () => {
expect(format(`${'x'.repeat(80)}[0]`)).toStrictEqual(
`${'x'.repeat(80)}[0];\n`,
Expand Down

0 comments on commit 0c646e7

Please sign in to comment.