@journeyapps/domparser
Advanced tools
Comparing version 0.3.0 to 0.4.0
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__export(require("./index")); | ||
__exportStar(require("./index"), exports); | ||
//# sourceMappingURL=browser.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DOMParser = void 0; | ||
const XMLError_1 = require("./XMLError"); | ||
@@ -16,11 +17,2 @@ const sax = require("./sax"); | ||
} | ||
function errorFromMessage(message) { | ||
if (typeof message != 'string') { | ||
throw message; | ||
} | ||
var msg = message.split('\n')[0]; | ||
var line = parseInt(getMatch(/Line: (\d+)/, 1, message), 10); | ||
var column = parseInt(getMatch(/Column: (\d+)/, 1, message), 10); | ||
return new XMLError_1.XMLError(msg, { line: line, column: column }); | ||
} | ||
class DOMParser { | ||
@@ -51,15 +43,12 @@ constructor(options) { | ||
const previous = errors[errors.length - 1]; | ||
if (previous && | ||
previous.line == error.line && | ||
previous.column == error.column) { | ||
// We expect the last message to be more informative - drop the previous message | ||
errors.pop(); | ||
errors.push(error); | ||
if (previous && error.startOffset - previous.startOffset <= 2) { | ||
if (previous.message == 'Unexpected close tag') { | ||
// In this case, the new message is likely more informative. | ||
errors.pop(); | ||
errors.push(error); | ||
} | ||
else { | ||
// Keep the previous message | ||
} | ||
} | ||
else if (previous && | ||
previous.message == error.message && | ||
previous.line == error.line) { | ||
// Ignore, even if the columns are different | ||
// Typically the first error will have the most accurate column | ||
} | ||
else { | ||
@@ -70,3 +59,4 @@ errors.push(error); | ||
parser.onerror = function (e) { | ||
var error = XMLError_1.errorFromParser(e, parser); | ||
parser.error = null; // Let the parser continue | ||
const error = XMLError_1.errorFromParser(e, parser, locator); | ||
addUnlessDuplicate(error); | ||
@@ -76,8 +66,21 @@ }; | ||
if (current && current != doc) { | ||
var node = doc.createTextNode(t); | ||
const node = doc.createTextNode(t); | ||
current.appendChild(node); | ||
} | ||
}; | ||
let currentAttributes = {}; | ||
parser.onopentagstart = function (tag) { | ||
currentAttributes = {}; | ||
}; | ||
parser.onattribute = function (attr) { | ||
const name = attr.name; | ||
if (name in currentAttributes) { | ||
addUnlessDuplicate(new XMLError_1.XMLError(`Attribute '${name}' redefined.`, { start: attr.start - 1, end: attr.start + attr.name.length - 1 }, locator)); | ||
} | ||
else { | ||
currentAttributes[name] = true; | ||
} | ||
}; | ||
parser.onopentag = function (node) { | ||
var element = doc.createElementNS(node.uri, node.name); | ||
const element = doc.createElementNS(node.uri, node.name); | ||
element.openStart = parser.startTagPosition - 1; | ||
@@ -89,4 +92,4 @@ element.nameStart = element.openStart + 1; | ||
// We have: parser.line, parser.column, parser.position, parser.startTagPosition | ||
for (var key in node.attributes) { | ||
var attr = node.attributes[key]; | ||
for (let key in node.attributes) { | ||
const attr = node.attributes[key]; | ||
// Attribute nodes seem to be deprecated in general. | ||
@@ -99,3 +102,3 @@ // doc.createAttributeNS does not work for some cases in PhantomJS, e.g. | ||
// The solution is to store the attribute positions on the element node. | ||
var position = { | ||
const position = { | ||
start: attr.start - 1, | ||
@@ -136,3 +139,5 @@ end: attr.end, | ||
catch (err) { | ||
addUnlessDuplicate(errorFromMessage(err.message)); | ||
if (errors.length == 0) { | ||
errors.push(new XMLError_1.XMLError(err.message, { start: 0, end: 5 }, locator)); | ||
} | ||
} | ||
@@ -139,0 +144,0 @@ doc.errors = errors; |
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.XMLSerializer = exports.DOMParser = void 0; | ||
var DOMParser_1 = require("./DOMParser"); | ||
exports.DOMParser = DOMParser_1.DOMParser; | ||
Object.defineProperty(exports, "DOMParser", { enumerable: true, get: function () { return DOMParser_1.DOMParser; } }); | ||
var XMLSerializer_1 = require("./XMLSerializer"); | ||
exports.XMLSerializer = XMLSerializer_1.XMLSerializer; | ||
__export(require("./types")); | ||
Object.defineProperty(exports, "XMLSerializer", { enumerable: true, get: function () { return XMLSerializer_1.XMLSerializer; } }); | ||
__exportStar(require("./types"), exports); | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const xmldom_1 = require("./xmldom"); | ||
__export(require("./index")); | ||
__exportStar(require("./index"), exports); | ||
const xmldom = require('xmldom'); | ||
@@ -9,0 +16,0 @@ xmldom_1.setImplementation(new xmldom.DOMImplementation()); |
@@ -39,3 +39,3 @@ export declare function parser(strict?: boolean, opt?: ParserOptions): SAXParser; | ||
oncomment: string; | ||
onopentagstart: void; | ||
onopentagstart: QualifiedTag; | ||
onattribute: Attribute; | ||
@@ -111,3 +111,3 @@ onopentag: QualifiedTag; | ||
oncomment: (comment: string) => void; | ||
onopentagstart: () => void; | ||
onopentagstart: (node: QualifiedTag) => void; | ||
onattribute: (attr: Attribute) => void; | ||
@@ -404,2 +404,3 @@ onopentag: (node: QualifiedTag) => void; | ||
declare function setBufferLength(length: number): void; | ||
export { SAXParser, SAXStream, QualifiedTag, EVENTS, createStream, ENTITIES, MAX_BUFFER_LENGTH, setBufferLength }; | ||
export { SAXParser, SAXStream, EVENTS, createStream, ENTITIES, MAX_BUFFER_LENGTH, setBufferLength }; | ||
export type { QualifiedTag }; |
"use strict"; | ||
// TypeScript port of https://github.com/isaacs/sax-js | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.setBufferLength = exports.MAX_BUFFER_LENGTH = exports.ENTITIES = exports.createStream = exports.EVENTS = exports.SAXStream = exports.SAXParser = exports.parser = void 0; | ||
let sax = {}; | ||
@@ -5,0 +6,0 @@ function parser(strict, opt) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SlowLocator = void 0; | ||
class SlowLocator { | ||
@@ -4,0 +5,0 @@ constructor(source) { |
@@ -1,8 +0,8 @@ | ||
export { XMLElement } from './XMLElement'; | ||
export type { XMLElement } from './XMLElement'; | ||
export { XMLError } from './XMLError'; | ||
export { XMLDocument } from './XMLDocument'; | ||
export { XMLPosition } from './XMLPosition'; | ||
export { XMLAttribute } from './XMLAttribute'; | ||
export { IterableNodeList } from './IterableNodeList'; | ||
export type { XMLDocument } from './XMLDocument'; | ||
export type { XMLPosition } from './XMLPosition'; | ||
export type { XMLAttribute } from './XMLAttribute'; | ||
export type { IterableNodeList } from './IterableNodeList'; | ||
export * from './XMLNode'; | ||
export * from './DOMImplementation'; |
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.XMLError = void 0; | ||
var XMLError_1 = require("./XMLError"); | ||
exports.XMLError = XMLError_1.XMLError; | ||
__export(require("./XMLNode")); | ||
Object.defineProperty(exports, "XMLError", { enumerable: true, get: function () { return XMLError_1.XMLError; } }); | ||
__exportStar(require("./XMLNode"), exports); | ||
__exportStar(require("./DOMImplementation"), exports); | ||
//# sourceMappingURL=types.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isEqualNode = exports.setParsers = exports.setImplementation = exports.XMLSerializer = exports.DOMParser = exports.implementation = void 0; | ||
let ourDOMParser; | ||
@@ -4,0 +5,0 @@ exports.DOMParser = ourDOMParser; |
import { XMLPosition } from './XMLPosition'; | ||
import { XMLLocator } from './XMLLocator'; | ||
import { SAXParser } from './sax'; | ||
export declare class XMLError implements XMLPosition { | ||
message: string; | ||
line: number; | ||
column: number; | ||
stack?: string; | ||
constructor(message: string | XMLError, position?: XMLPosition); | ||
startOffset: number; | ||
endOffset?: number; | ||
private locator?; | ||
constructor(message: string | XMLError, position: { | ||
start: number; | ||
end: number; | ||
}, locator?: XMLLocator); | ||
get line(): number; | ||
get column(): number; | ||
get startPosition(): XMLPosition; | ||
get endPosition(): XMLPosition; | ||
} | ||
export declare function errorFromParser(error: any, parser: XMLPosition): XMLError; | ||
export declare function errorFromParser(error: any, parser: SAXParser, locator: XMLLocator): XMLError; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.errorFromParser = exports.XMLError = void 0; | ||
class XMLError { | ||
constructor(message, position) { | ||
constructor(message, position, locator) { | ||
if (typeof message == 'string') { | ||
this.message = message; | ||
this.line = position.line; | ||
this.column = position.column; | ||
this.startOffset = position.start; | ||
this.endOffset = position.end; | ||
} | ||
else { | ||
this.message = message.message; | ||
this.line = message.line; | ||
this.column = message.column; | ||
this.startOffset = message.startOffset; | ||
this.endOffset = message.endOffset; | ||
} | ||
this.locator = locator; | ||
} | ||
get line() { | ||
var _a; | ||
if (this.startOffset == null) { | ||
return null; | ||
} | ||
return (_a = this.locator) === null || _a === void 0 ? void 0 : _a.position(this.startOffset).line; | ||
} | ||
get column() { | ||
var _a; | ||
if (this.startOffset == null) { | ||
return null; | ||
} | ||
return (_a = this.locator) === null || _a === void 0 ? void 0 : _a.position(this.startOffset).column; | ||
} | ||
get startPosition() { | ||
var _a; | ||
return (_a = this.locator) === null || _a === void 0 ? void 0 : _a.position(this.startOffset); | ||
} | ||
get endPosition() { | ||
var _a; | ||
return (_a = this.locator) === null || _a === void 0 ? void 0 : _a.position(this.endOffset); | ||
} | ||
} | ||
exports.XMLError = XMLError; | ||
function errorFromParser(error, parser) { | ||
function errorFromParser(error, parser, locator) { | ||
var _a, _b; | ||
// The message is on the first line | ||
@@ -24,5 +49,16 @@ // We could parse the position from the message, but it's easier to get it from the parser | ||
} | ||
return new XMLError(error.message.split('\n')[0], parser); | ||
const message = error.message.split('\n')[0]; | ||
if (message == 'Attribute without value') { | ||
return new XMLError(message, { | ||
start: parser.startAttributePosition - 1, | ||
end: parser.startAttributePosition + ((_b = (_a = parser.attribName) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 1) - 1 | ||
}, locator); | ||
} | ||
else if (message == 'Unexpected close tag' || | ||
/^Unmatched closing tag/.test(message)) { | ||
return new XMLError(message, { start: parser.startTagPosition - 1, end: parser.position }, locator); | ||
} | ||
return new XMLError(message, { start: parser.position - 1, end: parser.position }, locator); | ||
} | ||
exports.errorFromParser = errorFromParser; | ||
//# sourceMappingURL=XMLError.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.XMLLocator = void 0; | ||
class XMLLocator { | ||
@@ -8,3 +9,3 @@ constructor(source) { | ||
} | ||
const lines = source.split('\n').map(line => line.length + 1); | ||
const lines = source.split('\n').map((line) => line.length + 1); | ||
this.cumulative = cumulative(lines); | ||
@@ -11,0 +12,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.NOTATION_NODE = exports.DOCUMENT_FRAGMENT_NODE = exports.DOCUMENT_TYPE_NODE = exports.DOCUMENT_NODE = exports.COMMENT_NODE = exports.PROCESSING_INSTRUCTION_NODE = exports.ENTITY_NODE = exports.ENTITY_REFERENCE_NODE = exports.CDATA_SECTION_NODE = exports.TEXT_NODE = exports.ATTRIBUTE_NODE = exports.ELEMENT_NODE = void 0; | ||
exports.ELEMENT_NODE = 1; | ||
@@ -4,0 +5,0 @@ exports.ATTRIBUTE_NODE = 2; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.XMLSerializer = void 0; | ||
const native = require("./xmldom"); | ||
@@ -4,0 +5,0 @@ const _1 = require("."); |
{ | ||
"name": "@journeyapps/domparser", | ||
"description": "Basic XML DOM parsing", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"license": "MIT", | ||
@@ -24,13 +24,13 @@ "main": "lib/node.js", | ||
"fast-xml-parser": "^3.12.19", | ||
"jasmine": "^3.4.0", | ||
"karma": "^4.2.0", | ||
"jasmine": "~3.4.0", | ||
"karma": "^5.2.2", | ||
"karma-chrome-launcher": "^3.1.0", | ||
"karma-firefox-launcher": "^1.2.0", | ||
"karma-jasmine": "^2.0.1", | ||
"karma-firefox-launcher": "^1.3.0", | ||
"karma-jasmine": "^4.0.1", | ||
"karma-spec-reporter": "^0.0.32", | ||
"karma-typescript": "^4.1.1", | ||
"prettier": "^1.18.2", | ||
"karma-typescript": "^5.1.0", | ||
"prettier": "^2.1.1", | ||
"tap": "^14.6.1", | ||
"ts-node": "^8.3.0", | ||
"typescript": "^3.5.3", | ||
"typescript": "^4.0.2", | ||
"xmldom": "^0.1.27" | ||
@@ -37,0 +37,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
153445
2855