[Pkg-javascript-commits] [ltx] 302/469: Code tidy

Jonas Smedegaard dr at jones.dk
Wed Aug 31 13:03:19 UTC 2016


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository ltx.

commit 2c29af200e6bb2e93445e734f8b4044a2d8add40
Author: Lloyd Watkin <lloyd at evilprofessor.co.uk>
Date:   Sun Feb 16 18:56:28 2014 +0000

    Code tidy
---
 lib/parse.js | 62 ++++++++++++++++++++++++++++++++++++++----------------------
 1 file changed, 39 insertions(+), 23 deletions(-)

diff --git a/lib/parse.js b/lib/parse.js
index af17af8..d940ff6 100644
--- a/lib/parse.js
+++ b/lib/parse.js
@@ -5,19 +5,28 @@ var events = require('events')
 exports.availableSaxParsers = []
 
 exports.bestSaxParser = null
-['./sax_expat.js', './sax_ltx.js', /*'./sax_easysax.js', './sax_node-xml.js',*/ './sax_saxjs.js'].forEach(function(modName) {
+
+var saxParsers = [
+    './sax_expat.js',
+    './sax_ltx.js',
+    /*'./sax_easysax.js', './sax_node-xml.js',*/
+    './sax_saxjs.js'
+]
+
+saxParsers.forEach(function(modName) {
     var mod
     try {
-	mod = require(modName)
+        mod = require(modName)
     } catch (e) {
-	/* Silently missing libraries drop for debug:
-	console.error(e.stack || e)
-	 */
+        /* Silently missing libraries drop for debug:
+        console.error(e.stack || e)
+         */
     }
     if (mod) {
-	exports.availableSaxParsers.push(mod)
-	if (!exports.bestSaxParser)
-	    exports.bestSaxParser = mod
+        exports.availableSaxParsers.push(mod)
+        if (!exports.bestSaxParser) {
+            exports.bestSaxParser = mod
+        }
     }
 })
 
@@ -26,8 +35,10 @@ exports.Parser = function(saxParser) {
     var self = this
 
     var parserMod = saxParser || exports.bestSaxParser
-    if (!parserMod)
-	throw new Error('No SAX parser available')
+    if (!parserMod) {
+    	throw new Error('No SAX parser available')
+    }
+
     this.parser = new parserMod()
 
     var el
@@ -42,24 +53,26 @@ exports.Parser = function(saxParser) {
     this.parser.addListener('endElement', function(name) {
         if (!el) {
             /* Err */
-        } else if (el && name == el.name) {
-            if (el.parent)
+        } else if (el && (name === el.name)) {
+            if (el.parent) {
                 el = el.parent
-            else if (!self.tree) {
+            } else if (!self.tree) {
                 self.tree = el
                 el = undefined
             }
         }
     })
     this.parser.addListener('text', function(str) {
-        if (el)
+        if (el) {
             el.t(str)
+        }
     })
     this.parser.addListener('error', function(e) {
-	self.error = e
-	self.emit('error', e)
+        self.error = e
+        self.emit('error', e)
     })
 }
+
 util.inherits(exports.Parser, events.EventEmitter)
 
 exports.Parser.prototype.write = function(data) {
@@ -70,16 +83,18 @@ exports.Parser.prototype.end = function(data) {
     this.parser.end(data)
 
     if (!this.error) {
-	if (this.tree)
-	    this.emit('tree', this.tree)
-	else
-	    this.emit('error', new Error('Incomplete document'))
+        if (this.tree) {
+            this.emit('tree', this.tree)
+        } else {
+            this.emit('error', new Error('Incomplete document'))
+        }
     }
 }
 
 exports.parse = function(data, saxParser) {
     var p = new exports.Parser(saxParser)
-    var result = null, error = null
+    var result = null
+      , error = null
 
     p.on('tree', function(tree) {
         result = tree
@@ -91,8 +106,9 @@ exports.parse = function(data, saxParser) {
     p.write(data)
     p.end()
 
-    if (error)
+    if (error) {
         throw error
-    else
+    } else {
         return result
+    }
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/ltx.git



More information about the Pkg-javascript-commits mailing list