xmldom icon indicating copy to clipboard operation
xmldom copied to clipboard

Convert four assignment statements to the usage of compound operators

Open elfring opened this issue 4 years ago • 0 comments

:eyes: Some source code analysis tools can help to find opportunities for improving software components. :thought_balloon: I propose to increase the usage of compound operators accordingly.

diff --git a/lib/dom-parser.js b/lib/dom-parser.js
index 94769a2..0116519 100644
--- a/lib/dom-parser.js
+++ b/lib/dom-parser.js
@@ -90,7 +90,7 @@ DOMParser.prototype.parseFromString = function(source,mimeType){
 	if(isHTML){
 		defaultNSMap[''] = NAMESPACE.HTML;
 	}
-	defaultNSMap.xml = defaultNSMap.xml || NAMESPACE.XML;
+	defaultNSMap.xml ||= NAMESPACE.XML;
 	var normalize = options.normalizeLineEndings || normalizeLineEndings;
 	if (source && typeof source === 'string') {
 		sax.parse(
@@ -112,7 +112,7 @@ function buildErrorHandler(errorImpl,domBuilder,locator){
 	}
 	var errorHandler = {}
 	var isCallback = errorImpl instanceof Function;
-	locator = locator||{}
+	locator ||= {}
 	function build(key){
 		var fn = errorImpl[key];
 		if(!fn && isCallback){
diff --git a/lib/dom.js b/lib/dom.js
index 99064f9..553cd2c 100644
--- a/lib/dom.js
+++ b/lib/dom.js
@@ -138,7 +138,7 @@ function DOMException(code, message) {
 		if(Error.captureStackTrace) Error.captureStackTrace(this, DOMException);
 	}
 	error.code = code;
-	if(message) this.message = this.message + ": " + message;
+	if(message) this.message += ": " + message;
 	return error;
 };
 DOMException.prototype = Error.prototype;
diff --git a/test/get-test-parser.js b/test/get-test-parser.js
index 59bdbd9..216ae6f 100644
--- a/test/get-test-parser.js
+++ b/test/get-test-parser.js
@@ -26,8 +26,7 @@ const { DOMParser } = require('../lib/dom-parser')
  * @returns {{parser: DOMParser, errors: Partial<Record<ErrorLevel, string[]>>}}
  */
 function getTestParser({ errorHandler, errors = {}, locator = {} } = {}) {
-	errorHandler =
-		errorHandler ||
+	errorHandler ||=
 		((key, msg) => {
 			if (!errors[key]) errors[key] = []
 			errors[key].push(msg)

elfring avatar Dec 15 '21 19:12 elfring