From f074644bc32ae6f3012962686ad70188bf98f61a Mon Sep 17 00:00:00 2001 From: Jan Stepanek Date: Wed, 22 May 2019 09:05:36 +0200 Subject: [PATCH] cr fixes (will be squashed after another cr) --- lib/parser.js | 8 ++++++-- src/parser.coffee | 5 ++++- test/parser.test.coffee | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/parser.js b/lib/parser.js index bed4910f..2b8f88eb 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -170,7 +170,7 @@ })(this); this.saxParser.onclosetag = (function(_this) { return function() { - var base, cdata, emptyStr, key, node, nodeName, obj, objClone, old, ref, s, xpath; + var cdata, emptyStr, key, node, nodeName, obj, objClone, old, s, xpath; obj = stack.pop(); nodeName = obj["#name"]; if (!_this.options.explicitChildren || !_this.options.preserveChildrenOrder) { @@ -197,7 +197,11 @@ } } if (isEmpty(obj)) { - obj = (ref = typeof (base = _this.options).emptyTag === "function" ? base.emptyTag() : void 0) != null ? ref : (_this.options.emptyTag !== '' ? _this.options.emptyTag : emptyStr); + if (typeof _this.options.emptyTag === 'function') { + obj = _this.options.emptyTag(); + } else { + obj = _this.options.emptyTag !== '' ? _this.options.emptyTag : emptyStr; + } } if (_this.options.validator != null) { xpath = "/" + ((function() { diff --git a/src/parser.coffee b/src/parser.coffee index ff640a1e..5ff379fa 100644 --- a/src/parser.coffee +++ b/src/parser.coffee @@ -145,7 +145,10 @@ class exports.Parser extends events.EventEmitter obj = obj[charkey] if (isEmpty obj) - obj = @options.emptyTag?() ? (if @options.emptyTag != '' then @options.emptyTag else emptyStr) + if typeof @options.emptyTag == 'function' + obj = @options.emptyTag() + else + obj = if @options.emptyTag != '' then @options.emptyTag else emptyStr if @options.validator? xpath = "/" + (node["#name"] for node in stack).concat(nodeName).join("/") diff --git a/test/parser.test.coffee b/test/parser.test.coffee index cf3798c1..354bd61f 100644 --- a/test/parser.test.coffee +++ b/test/parser.test.coffee @@ -72,7 +72,7 @@ module.exports = # determine number of items in object equ Object.keys(r.sample.tagcasetest[0]).length, 3) - 'test parse with empty objects and functions': skeleton({emptyTag: ()=> new Object()}, (r)-> + 'test parse with empty objects and functions': skeleton({emptyTag: ()=> ({})}, (r)-> console.log 'Result object: ' + util.inspect r, false, 10 bool = r.sample.emptytestanother[0] is r.sample.emptytest[0] equ bool, false)