From 7fd574deb4114f175c0b9fb33a08df20d83a8afd Mon Sep 17 00:00:00 2001 From: Patrick Steele-Idem Date: Tue, 9 Feb 2016 15:20:44 -0700 Subject: [PATCH] Marko v3: Improved code generation for empty objects and arrays --- compiler/CodeGenerator.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/compiler/CodeGenerator.js b/compiler/CodeGenerator.js index fcbb9b271..894770477 100644 --- a/compiler/CodeGenerator.js +++ b/compiler/CodeGenerator.js @@ -522,6 +522,11 @@ class Generator { } else if (value === false) { this.write('false'); } else if (isArray(value)) { + if (value.length === 0) { + this.write('[]'); + return; + } + this.write('[\n'); this.incIndent(); @@ -549,12 +554,16 @@ class Generator { } else if (typeof value === 'number') { this.write(value.toString()); } else if (typeof value === 'object') { + let keys = Object.keys(value); + if (keys.length === 0) { + this.write('{}'); + return; + } + this.incIndent(); this.write('{\n'); this.incIndent(); - let keys = Object.keys(value); - for (let i=0; i