Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions lib/parser/pbxproj.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,47 @@ function peg$parse(input, options) {
peg$c6 = function() { return Object.create(null) },
peg$c7 = function(list) {
var returnObject = list[0][0];
for(var i = 1; i < list.length; i++){

for (var i = 1; i < list.length; i++) {
Comment thread
GitToTheHub marked this conversation as resolved.
var another = list[i][0];
returnObject = Object.assign(returnObject, another);

/*
* Ensure previously parsed section entries are not lost
*
* Example:
*
* If "returnObject" contains:
*
* {
* PBXTargetDependency: {
* 'A': {},
* 'A_comment': 'PBXTargetDependency'
* }
* }
*
* And "another" contains:
*
* {
* PBXTargetDependency: {
* 'B': {},
* 'B_comment': 'PBXTargetDependency'
* }
* }
*
* Using "Object.assign(returnObject, another)" would lose
* "A" as it would replace the entire PBXTargetDependency.
*
* Instead, we will merge each top-level property of the
* objects, if it exists and is an object else add.
*/
for (var key in another) {
returnObject[key] = (
returnObject[key] &&
another[key] &&
typeof returnObject[key] === 'object' &&
typeof another[key] === 'object'
) ? Object.assign(returnObject[key], another[key]) : another[key];
}
}
return returnObject;
},
Expand Down
54 changes: 40 additions & 14 deletions lib/parser/pbxproj.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,6 @@
under the License.
*/

{
function merge_obj(obj, secondObj) {
if (!obj)
return secondObj;

for(var i in secondObj)
obj[i] = merge_obj(obj[i], secondObj[i]);

return obj;
}
}

/*
* Project: point of entry from pbxproj file
*/
Expand Down Expand Up @@ -60,9 +48,47 @@ AssignmentList
= _ list:((a:Assignment / d:DelimitedSection) _)+
{
var returnObject = list[0][0];
for(var i = 1; i < list.length; i++){

for (var i = 1; i < list.length; i++) {
var another = list[i][0];
returnObject = merge_obj(returnObject, another);

/*
* Ensure previously parsed section entries are not lost
*
* Example:
*
* If "returnObject" contains:
*
* {
* PBXTargetDependency: {
* 'A': {},
* 'A_comment': 'PBXTargetDependency'
* }
* }
*
* And "another" contains:
*
* {
* PBXTargetDependency: {
* 'B': {},
* 'B_comment': 'PBXTargetDependency'
* }
* }
*
* Using "Object.assign(returnObject, another)" would lose
* "A" as it would replace the entire PBXTargetDependency.
*
* Instead, we will merge each top-level property of the
* objects, if it exists and is an object else add.
*/
for (var key in another) {
returnObject[key] = (
returnObject[key] &&
another[key] &&
typeof returnObject[key] === 'object' &&
typeof another[key] === 'object'
) ? Object.assign(returnObject[key], another[key]) : another[key];
}
}
return returnObject;
}
Expand Down
Loading