Skip to content

Commit 03b1c46

Browse files
authored
Merge pull request nfarina#73 from roobscoob/patch-1
Allow for construction of XmlElements outside of a parse context
2 parents f9d4d32 + edda9af commit 03b1c46

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/xmldoc.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,14 @@
2525
* behaves like an XmlElement by inheriting its attributes and functions.
2626
*/
2727

28-
function XmlElement(tag) {
28+
function XmlElement(tag, parserIn) {
2929
// Capture the parser object off of the XmlDocument delegate
30-
var parser = delegates[delegates.length - 1].parser;
30+
var delegate = delegates[delegates.length - 1];
31+
var parser = parserIn;
32+
33+
if (delegate) {
34+
parser = delegate.parser;
35+
}
3136

3237
this.name = tag.name;
3338
this.attr = tag.attributes;
@@ -37,10 +42,10 @@
3742
this.lastChild = null;
3843

3944
// Assign parse information
40-
this.line = parser.line;
41-
this.column = parser.column;
42-
this.position = parser.position;
43-
this.startTagPosition = parser.startTagPosition;
45+
this.line = parser?.line;
46+
this.column = parser?.column;
47+
this.position = parser?.position;
48+
this.startTagPosition = parser?.startTagPosition;
4449
}
4550

4651
// Private methods

0 commit comments

Comments
 (0)