|
17 | 17 | under the License. |
18 | 18 | */ |
19 | 19 |
|
20 | | -{ |
21 | | - function merge_obj(obj, secondObj) { |
22 | | - if (!obj) |
23 | | - return secondObj; |
24 | | - |
25 | | - for(var i in secondObj) |
26 | | - obj[i] = merge_obj(obj[i], secondObj[i]); |
27 | | - |
28 | | - return obj; |
29 | | - } |
30 | | -} |
31 | | - |
32 | 20 | /* |
33 | 21 | * Project: point of entry from pbxproj file |
34 | 22 | */ |
@@ -60,9 +48,47 @@ AssignmentList |
60 | 48 | = _ list:((a:Assignment / d:DelimitedSection) _)+ |
61 | 49 | { |
62 | 50 | var returnObject = list[0][0]; |
63 | | - for(var i = 1; i < list.length; i++){ |
| 51 | + |
| 52 | + for (var i = 1; i < list.length; i++) { |
64 | 53 | var another = list[i][0]; |
65 | | - returnObject = merge_obj(returnObject, another); |
| 54 | + |
| 55 | + /* |
| 56 | + * Ensure previously parsed section entries are not lost |
| 57 | + * |
| 58 | + * Example: |
| 59 | + * |
| 60 | + * If "returnObject" contains: |
| 61 | + * |
| 62 | + * { |
| 63 | + * PBXTargetDependency: { |
| 64 | + * 'A': {}, |
| 65 | + * 'A_comment': 'PBXTargetDependency' |
| 66 | + * } |
| 67 | + * } |
| 68 | + * |
| 69 | + * And "another" contains: |
| 70 | + * |
| 71 | + * { |
| 72 | + * PBXTargetDependency: { |
| 73 | + * 'B': {}, |
| 74 | + * 'B_comment': 'PBXTargetDependency' |
| 75 | + * } |
| 76 | + * } |
| 77 | + * |
| 78 | + * Using "Object.assign(returnObject, another)" would lose |
| 79 | + * "A" as it would replace the entire PBXTargetDependency. |
| 80 | + * |
| 81 | + * Instead, we will merge each top-level property of the |
| 82 | + * objects, if it exists and is an object else add. |
| 83 | + */ |
| 84 | + for (var key in another) { |
| 85 | + returnObject[key] = ( |
| 86 | + returnObject[key] && |
| 87 | + another[key] && |
| 88 | + typeof returnObject[key] === 'object' && |
| 89 | + typeof another[key] === 'object' |
| 90 | + ) ? Object.assign(returnObject[key], another[key]) : another[key]; |
| 91 | + } |
66 | 92 | } |
67 | 93 | return returnObject; |
68 | 94 | } |
|
0 commit comments