From 9962c2f768e70f0397e61a9580b9f163fed0cc01 Mon Sep 17 00:00:00 2001 From: liam humphreys Date: Thu, 18 Jul 2019 11:08:34 +0100 Subject: [PATCH] support variable declarations without expressions --- src/nodes.js | 3 +-- src/nodes/variable-declaration.js | 13 +++++-------- src/nodes/variable-declaration.spec.js | 3 ++- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/nodes.js b/src/nodes.js index e14d490..baf1113 100644 --- a/src/nodes.js +++ b/src/nodes.js @@ -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"); diff --git a/src/nodes/variable-declaration.js b/src/nodes/variable-declaration.js index 4521e1a..1abe0a2 100644 --- a/src/nodes/variable-declaration.js +++ b/src/nodes/variable-declaration.js @@ -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]); }; diff --git a/src/nodes/variable-declaration.spec.js b/src/nodes/variable-declaration.spec.js index 8e564e8..a42d009 100644 --- a/src/nodes/variable-declaration.spec.js +++ b/src/nodes/variable-declaration.spec.js @@ -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()); });