Comparing version 5.3.2 to 5.4.0
@@ -9,2 +9,6 @@ # Changelog | ||
# 5.4.0 | ||
* `CHORE`: configure hooks only if actually used [5ab3e2ee](https://github.com/nikku/saxen/commit/066e712dd89f15f913387b40f0198575e1083d2f) | ||
# 5.3.1 | ||
@@ -11,0 +15,0 @@ |
@@ -5,6 +5,7 @@ { | ||
"scripts": { | ||
"all": "run-s lint test-coverage", | ||
"all": "run-s lint test-coverage test-perf", | ||
"lint": "eslint parser.js test/*.js", | ||
"test": "mocha test/index.js", | ||
"test-coverage": "NO_PERF=1 nyc --check-coverage --statements 95 npm test" | ||
"test-coverage": "NO_PERF=1 nyc --check-coverage --statements 95 npm test", | ||
"test-perf": "node test/perf" | ||
}, | ||
@@ -17,3 +18,3 @@ "keywords": [ | ||
], | ||
"version": "5.3.2", | ||
"version": "5.4.0", | ||
"main": "./parser.js", | ||
@@ -49,4 +50,5 @@ "bugs": { | ||
"npm-run-all": "^4.1.1", | ||
"nyc": "^11.3.0" | ||
"nyc": "^11.3.0", | ||
"table": "^4.0.2" | ||
} | ||
} |
107
parser.js
@@ -5,8 +5,4 @@ 'use strict'; | ||
function hasProperty(o, prop) { | ||
return Object.prototype.hasOwnProperty.call(o, prop); | ||
} | ||
var decodeEntities = require('./decode'); | ||
var fromCharCode = String.fromCharCode; | ||
var XSI_URI = 'http://www.w3.org/2001/XMLSchema-instance'; | ||
@@ -16,15 +12,2 @@ var XSI_PREFIX = 'xsi'; | ||
var SPECIAL_CHARS_MAPPING = { | ||
'amp': '&', | ||
'apos': '\'', | ||
'gt': '>', | ||
'lt': '<', | ||
'quot': '"' | ||
}; | ||
// map UPPERCASE variants of supported special chars | ||
Object.keys(SPECIAL_CHARS_MAPPING).forEach(function(k) { | ||
SPECIAL_CHARS_MAPPING[k.toUpperCase()] = SPECIAL_CHARS_MAPPING[k]; | ||
}); | ||
function error(msg) { | ||
@@ -45,31 +28,2 @@ return new Error(msg); | ||
function replaceEntities(_, d, x, z) { | ||
// reserved names, i.e. | ||
if (z) { | ||
if (hasProperty(SPECIAL_CHARS_MAPPING, z)) { | ||
return SPECIAL_CHARS_MAPPING[z]; | ||
} else { | ||
// fall back to original value | ||
return '&' + z + ';'; | ||
} | ||
} | ||
// decimal encoded char | ||
if (d) { | ||
return fromCharCode(d); | ||
} | ||
// hex encoded char | ||
return fromCharCode(parseInt(x, 16)); | ||
} | ||
function decodeEntities(s) { | ||
if (s.length > 3 && s.indexOf('&') !== -1) { | ||
return s.replace(/&#(\d+);|&#x([0-9a-f]+);|&(\w+);/ig, replaceEntities); | ||
} | ||
return s; | ||
} | ||
function cloneNsMatrix(nsMatrix) { | ||
@@ -105,4 +59,2 @@ var clone = {}, key; | ||
function nullFunc() {} | ||
function throwFunc(err) { | ||
@@ -127,8 +79,8 @@ throw err; | ||
var onText = nullFunc, | ||
onOpenTag = nullFunc, | ||
onCloseTag = nullFunc, | ||
onCDATA = nullFunc, | ||
var onText, | ||
onOpenTag, | ||
onCloseTag, | ||
onCDATA, | ||
onError = throwFunc, | ||
onWarning = nullFunc, | ||
onWarning, | ||
onComment, | ||
@@ -199,2 +151,7 @@ onQuestion, | ||
function handleWarning(err) { | ||
if (!onWarning) { | ||
return; | ||
} | ||
if (!(err instanceof Error)) { | ||
@@ -228,3 +185,2 @@ err = error(err); | ||
case 'cdata': onCDATA = cb; break; | ||
case 'attention': onAttention = cb; break; // <!XXXXX zzzz="eeee"> | ||
@@ -684,5 +640,7 @@ case 'question': onQuestion = cb; break; // <? .... ?> | ||
if (j !== i) { | ||
onText(xml.substring(j, i), decodeEntities); | ||
if (parseStop) { | ||
return; | ||
if (onText) { | ||
onText(xml.substring(j, i), decodeEntities); | ||
if (parseStop) { | ||
return; | ||
} | ||
} | ||
@@ -702,5 +660,7 @@ } | ||
onCDATA(xml.substring(i + 9, j), false); | ||
if (parseStop) { | ||
return; | ||
if (onCDATA) { | ||
onCDATA(xml.substring(i + 9, j)); | ||
if (parseStop) { | ||
return; | ||
} | ||
} | ||
@@ -902,10 +862,12 @@ | ||
if (proxy) { | ||
onOpenTag(elementProxy, decodeEntities, tagEnd, getContext); | ||
} else { | ||
onOpenTag(elementName, getAttrs, decodeEntities, tagEnd, getContext); | ||
} | ||
if (onOpenTag) { | ||
if (proxy) { | ||
onOpenTag(elementProxy, decodeEntities, tagEnd, getContext); | ||
} else { | ||
onOpenTag(elementName, getAttrs, decodeEntities, tagEnd, getContext); | ||
} | ||
if (parseStop) { | ||
return; | ||
if (parseStop) { | ||
return; | ||
} | ||
} | ||
@@ -916,6 +878,9 @@ | ||
if (tagEnd) { | ||
onCloseTag(proxy ? elementProxy : elementName, decodeEntities, tagStart, getContext); | ||
if (parseStop) { | ||
return; | ||
if (onCloseTag) { | ||
onCloseTag(proxy ? elementProxy : elementName, decodeEntities, tagStart, getContext); | ||
if (parseStop) { | ||
return; | ||
} | ||
} | ||
@@ -922,0 +887,0 @@ |
@@ -32,3 +32,3 @@ # `/saxen/` parser <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/5f/Coat_of_arms_of_Saxony.svg/220px-Coat_of_arms_of_Saxony.svg.png" align="right" /> | ||
parser.on('openTag', function(elementName, attrGetter, decodeEntity, selfClosing, getContext) { | ||
parser.on('openTag', function(elementName, attrGetter, decodeEntities, selfClosing, getContext) { | ||
@@ -51,3 +51,3 @@ elementName; | ||
* `openTag(elementName, attrGetter, decodeEntities, selfClosing, contextGetter)` | ||
* `closeTag(elementName, selfClosing, contextGetter)` | ||
* `closeTag(elementName, decodeEntities, selfClosing, contextGetter)` | ||
* `error(err, contextGetter)` | ||
@@ -54,0 +54,0 @@ * `warn(warning, contextGetter)` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30028
6
711