Skip to content

Commit d30a59b

Browse files
committed
Fixing reported issue jsonata-js#547. Added unit test coverage.
1 parent 964f420 commit d30a59b

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

src/jsonata.js

+20-18
Original file line numberDiff line numberDiff line change
@@ -931,24 +931,26 @@ var jsonata = (function() {
931931
};
932932
}
933933

934-
var entry = {data: item, exprIndex: pairIndex};
935-
if (groups.hasOwnProperty(key)) {
936-
// a value already exists in this slot
937-
if(groups[key].exprIndex !== pairIndex) {
938-
// this key has been generated by another expression in this group
939-
// when multiple key expressions evaluate to the same key, then error D1009 must be thrown
940-
throw {
941-
code: "D1009",
942-
stack: (new Error()).stack,
943-
position: expr.position,
944-
value: key
945-
};
946-
}
934+
if (key !== undefined) {
935+
var entry = {data: item, exprIndex: pairIndex};
936+
if (groups.hasOwnProperty(key)) {
937+
// a value already exists in this slot
938+
if(groups[key].exprIndex !== pairIndex) {
939+
// this key has been generated by another expression in this group
940+
// when multiple key expressions evaluate to the same key, then error D1009 must be thrown
941+
throw {
942+
code: "D1009",
943+
stack: (new Error()).stack,
944+
position: expr.position,
945+
value: key
946+
};
947+
}
947948

948-
// append it as an array
949-
groups[key].data = fn.append(groups[key].data, item);
950-
} else {
951-
groups[key] = entry;
949+
// append it as an array
950+
groups[key].data = fn.append(groups[key].data, item);
951+
} else {
952+
groups[key] = entry;
953+
}
952954
}
953955
}
954956
}
@@ -965,7 +967,7 @@ var jsonata = (function() {
965967
env = createFrameFromTuple(environment, tuple);
966968
}
967969
var value = yield * evaluate(expr.lhs[entry.exprIndex][1], context, env);
968-
if(typeof value !== 'undefined' && key !== 'undefined') {
970+
if(typeof value !== 'undefined') {
969971
result[key] = value;
970972
}
971973
}

0 commit comments

Comments
 (0)