[Pkg-javascript-commits] [ltx] 312/469: Cleaned up parse.js

Jonas Smedegaard dr at jones.dk
Wed Aug 31 13:03:20 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 e5e2b1351641cc0d3f1c64651f72c441613caaf4
Author: Lloyd Watkin <lloyd at evilprofessor.co.uk>
Date:   Sun Feb 16 20:17:10 2014 +0000

    Cleaned up parse.js
---
 lib/parse.js | 52 +++++++++++++++++++++++++++-------------------------
 1 file changed, 27 insertions(+), 25 deletions(-)

diff --git a/lib/parse.js b/lib/parse.js
index b11d41d..915bfef 100644
--- a/lib/parse.js
+++ b/lib/parse.js
@@ -16,16 +16,17 @@ var saxParsers = [
 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
+        }
     }
 })
 
@@ -33,12 +34,13 @@ var element = require('./element')
 
 exports.Parser = function(saxParser) {
     events.EventEmitter.call(this)
-    var that = this
+    var self = this
 
-    var parserMod = saxParser || exports.bestSaxParser
-    if (!parserMod)
-    throw new Error('No SAX parser available')
-    this.parser = new parserMod()
+    var ParserMod = saxParser || exports.bestSaxParser
+    if (!ParserMod) {
+        throw new Error('No SAX parser available')
+    }
+    this.parser = new ParserMod()
 
     var el
     this.parser.addListener('startElement', function(name, attrs) {
@@ -50,24 +52,23 @@ exports.Parser = function(saxParser) {
         }
     })
     this.parser.addListener('endElement', function(name) {
-        if (!el) {
-            /* Err */
-        } else if (el && name == el.name) {
-            if (el.parent)
+        if (el && (name === el.name)) {
+            if (el.parent) {
                 el = el.parent
-            else if (!that.tree) {
-                that.tree = el
+            } 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) {
-    that.error = e
-    that.emit('error', e)
+        self.error = e
+        self.emit('error', e)
     })
 }
 util.inherits(exports.Parser, events.EventEmitter)
@@ -80,10 +81,11 @@ 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'))
+        }
     }
 }
 

-- 
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