You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ra...@apache.org on 2018/08/16 14:24:32 UTC
[cordova-common] branch master updated: Simplify some helpers in
util/xml-helpers (#40)
This is an automated email from the ASF dual-hosted git repository.
raphinesse pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-common.git
The following commit(s) were added to refs/heads/master by this push:
new b296be5 Simplify some helpers in util/xml-helpers (#40)
b296be5 is described below
commit b296be547ae6e4afc1bfd7f9fd03f1e6be1f0ba9
Author: Raphael von der GrĂ¼n <ra...@gmail.com>
AuthorDate: Thu Aug 16 16:24:30 2018 +0200
Simplify some helpers in util/xml-helpers (#40)
No functional changes. Just cleanup.
---
src/util/xml-helpers.js | 30 +++++-------------------------
1 file changed, 5 insertions(+), 25 deletions(-)
diff --git a/src/util/xml-helpers.js b/src/util/xml-helpers.js
index b8a03e9..acb610b 100644
--- a/src/util/xml-helpers.js
+++ b/src/util/xml-helpers.js
@@ -137,8 +137,8 @@ module.exports = {
if (!parent) return false;
nodes.forEach(function (node) {
- var matchingKid = null;
- if ((matchingKid = findChild(node, parent)) !== null) {
+ var matchingKid = findChild(node, parent);
+ if (matchingKid !== undefined) {
// stupid elementtree takes an index argument it doesn't use
// and does not conform to the python lib
parent.remove(matchingKid);
@@ -208,32 +208,12 @@ module.exports = {
};
function findChild (node, parent) {
- var matchingKids = parent.findall(node.tag);
- var i;
- var j;
-
- for (i = 0, j = matchingKids.length; i < j; i++) {
- if (module.exports.equalNodes(node, matchingKids[i])) {
- return matchingKids[i];
- }
- }
- return null;
+ const matches = parent.findall(node.tag);
+ return matches.find(m => module.exports.equalNodes(node, m));
}
function uniqueChild (node, parent) {
- var matchingKids = parent.findall(node.tag);
- var i = 0;
-
- if (matchingKids.length === 0) {
- return true;
- } else {
- for (i; i < matchingKids.length; i++) {
- if (module.exports.equalNodes(node, matchingKids[i])) {
- return false;
- }
- }
- return true;
- }
+ return !findChild(node, parent);
}
// Find the index at which to insert an entry. After is a ;-separated priority list
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org