From 334c4095bbb4f87fdb22a1c90e6fa247f2a6e526 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 30 Apr 2013 22:43:51 -0700 Subject: [PATCH] Write empty object values on same line as keys --- spec/stdlib/cson-spec.coffee | 2 ++ src/stdlib/cson.coffee | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/spec/stdlib/cson-spec.coffee b/spec/stdlib/cson-spec.coffee index bee9e2032..6ec3ec12a 100644 --- a/spec/stdlib/cson-spec.coffee +++ b/spec/stdlib/cson-spec.coffee @@ -73,6 +73,8 @@ describe "CSON", -> it "returns formatted CSON", -> expect(CSON.stringify(a: {b: 'c'})).toBe "'a':\n 'b': 'c'" + expect(CSON.stringify(a:{})).toBe "'a': {}" + expect(CSON.stringify(a:[])).toBe "'a': []" describe "when converting back to an object", -> it "produces the original object", -> diff --git a/src/stdlib/cson.coffee b/src/stdlib/cson.coffee index 5b8527d75..6d703d578 100644 --- a/src/stdlib/cson.coffee +++ b/src/stdlib/cson.coffee @@ -94,7 +94,10 @@ module.exports = else if _.isArray(value) cson += " #{@stringifyArray(value, indentLevel)}" else if _.isObject(value) - cson += "\n#{@stringifyObject(value, indentLevel + 2)}" + if _.isEmpty(value) + cson += ' {}' + else + cson += "\n#{@stringifyObject(value, indentLevel + 2)}" else throw new Error("Unrecognized value type for key: #{key} with value: #{value}") prefix = '\n'