Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint with tabs & enable strict mode #90

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions .eslintrc.js
@@ -0,0 +1,24 @@
"use strict";

module.exports = {
"env": {
"node": true,
"es6": true,
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 6,
},
"rules": {
"indent": [ "error", "tab" ],
"strict": ["error", "global"],
"no-redeclare": [ "warn" ],
"no-unused-vars": [ "warn", { "args": "none" } ],
"no-cond-assign": 0,
// "no-unreachable": [ "error" ],
"linebreak-style": [ "error", "unix" ],
// "semi": [ "error", "always" ],
// "comma-dangle": [ "error", "always-multiline" ],
// "no-console": [ "error" ],
}
};
82 changes: 42 additions & 40 deletions lib/dom-parser.js
@@ -1,3 +1,5 @@
"use strict";

function DOMParser(options){
this.options = options ||{locator:{}};
}
Expand All @@ -10,7 +12,7 @@ DOMParser.prototype.parseFromString = function(source,mimeType){
var locator = options.locator;
var defaultNSMap = options.xmlns||{};
var isHTML = /\/x?html?$/.test(mimeType);//mimeType.toLowerCase().indexOf('html') > -1;
var entityMap = isHTML?htmlEntity.entityMap:{'lt':'<','gt':'>','amp':'&','quot':'"','apos':"'"};
var entityMap = isHTML?htmlEntity.entityMap:{'lt':'<','gt':'>','amp':'&','quot':'"','apos':"'"};
if(locator){
domBuilder.setDocumentLocator(locator)
}
Expand Down Expand Up @@ -64,7 +66,7 @@ function buildErrorHandler(errorImpl,domBuilder,locator){
* @link http://www.saxproject.org/apidoc/org/xml/sax/helpers/DefaultHandler.html
*/
function DOMHandler() {
this.cdata = false;
this.cdata = false;
}
function position(locator,node){
node.lineNumber = locator.lineNumber;
Expand All @@ -76,28 +78,28 @@ function position(locator,node){
*/
DOMHandler.prototype = {
startDocument : function() {
this.doc = new DOMImplementation().createDocument(null, null, null);
if (this.locator) {
this.doc.documentURI = this.locator.systemId;
}
this.doc = new DOMImplementation().createDocument(null, null, null);
if (this.locator) {
this.doc.documentURI = this.locator.systemId;
}
},
startElement:function(namespaceURI, localName, qName, attrs) {
var doc = this.doc;
var el = doc.createElementNS(namespaceURI, qName||localName);
var len = attrs.length;
appendElement(this, el);
this.currentElement = el;
var el = doc.createElementNS(namespaceURI, qName||localName);
var len = attrs.length;
appendElement(this, el);
this.currentElement = el;

this.locator && position(this.locator,el)
for (var i = 0 ; i < len; i++) {
var namespaceURI = attrs.getURI(i);
var value = attrs.getValue(i);
var qName = attrs.getQName(i);
this.locator && position(this.locator,el);
for (var i = 0 ; i < len; i++) {
var namespaceURI = attrs.getURI(i);
var value = attrs.getValue(i);
var qName = attrs.getQName(i);
var attr = doc.createAttributeNS(namespaceURI, qName);
this.locator &&position(attrs.getLocator(i),attr);
attr.value = attr.nodeValue = value;
el.setAttributeNode(attr)
}
el.setAttributeNode(attr);
}
},
endElement:function(namespaceURI, localName, qName) {
var current = this.currentElement
Expand All @@ -109,9 +111,9 @@ DOMHandler.prototype = {
endPrefixMapping:function(prefix) {
},
processingInstruction:function(target, data) {
var ins = this.doc.createProcessingInstruction(target, data);
this.locator && position(this.locator,ins)
appendElement(this, ins);
var ins = this.doc.createProcessingInstruction(target, data);
this.locator && position(this.locator,ins)
appendElement(this, ins);
},
ignorableWhitespace:function(ch, start, length) {
},
Expand Down Expand Up @@ -139,33 +141,33 @@ DOMHandler.prototype = {
this.doc.normalize();
},
setDocumentLocator:function (locator) {
if(this.locator = locator){// && !('lineNumber' in locator)){
locator.lineNumber = 0;
}
if(this.locator = locator){// && !('lineNumber' in locator)){
locator.lineNumber = 0;
}
},
//LexicalHandler
comment:function(chars, start, length) {
chars = _toString.apply(this,arguments)
var comm = this.doc.createComment(chars);
this.locator && position(this.locator,comm)
appendElement(this, comm);
var comm = this.doc.createComment(chars);
this.locator && position(this.locator,comm)
appendElement(this, comm);
},

startCDATA:function() {
//used in characters() methods
this.cdata = true;
//used in characters() methods
this.cdata = true;
},
endCDATA:function() {
this.cdata = false;
this.cdata = false;
},

startDTD:function(name, publicId, systemId) {
var impl = this.doc.implementation;
if (impl && impl.createDocumentType) {
var dt = impl.createDocumentType(name, publicId, systemId);
this.locator && position(this.locator,dt)
appendElement(this, dt);
}
if (impl && impl.createDocumentType) {
var dt = impl.createDocumentType(name, publicId, systemId);
this.locator && position(this.locator,dt)
appendElement(this, dt);
}
},
/**
* @see org.xml.sax.ErrorHandler
Expand All @@ -179,7 +181,7 @@ DOMHandler.prototype = {
},
fatalError:function(error) {
console.error('[xmldom fatalError]\t'+error,_locator(this.locator));
throw error;
throw error;
}
}
function _locator(l){
Expand Down Expand Up @@ -235,11 +237,11 @@ function _toString(chars,start,length){

/* Private static helpers treated below as private instance methods, so don't need to add these to the public API; we might use a Relator to also get rid of non-standard public properties */
function appendElement (hander,node) {
if (!hander.currentElement) {
hander.doc.appendChild(node);
} else {
hander.currentElement.appendChild(node);
}
if (!hander.currentElement) {
hander.doc.appendChild(node);
} else {
hander.currentElement.appendChild(node);
}
}//appendChild and setAttributeNS are preformance key

//if(typeof require == 'function'){
Expand Down