Skip to content

Commit

Permalink
support variable declarations without expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
Angry-Potato committed Jul 18, 2019
1 parent d9ebd19 commit 9962c2f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
3 changes: 1 addition & 2 deletions src/nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ const isVariableDeclaration = node =>
node.mods &&
node.typeParams &&
node.vars &&
node.typeConstraints &&
node.expr;
node.typeConstraints;

const isName = node => node.hasOwnProperty("name");

Expand Down
13 changes: 5 additions & 8 deletions src/nodes/variable-declaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@ module.exports = (path, opts, print) => {
? concat([...path.map(print, "mods"), " "])
: "";

return concat([
prefix,
varType,
...path.map(print, "vars"),
" = ",
path.call(print, "expr"),
hardline
]);
const expr = node.expr
? concat([" = ", path.call(print, "expr"), hardline])
: "";

return concat([prefix, varType, ...path.map(print, "vars"), expr]);
};
3 changes: 2 additions & 1 deletion src/nodes/variable-declaration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ describe("variable-declaration", () => {

test("standard declarations", () =>
expect(`val a = 1
var b = 1`).toMatchFormat());
var b = 1
val c: Int`).toMatchFormat());
});

0 comments on commit 9962c2f

Please sign in to comment.