Skip to content

Commit

Permalink
refactor: optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
lddubeau committed Jul 4, 2018
1 parent 3852e64 commit 52151e0
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions lib/saxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1015,13 +1015,14 @@ ${XML_NAMESPACE}.`);
return;
}

const { tags } = this;
// first make sure that the closing tag actually exists.
// <a><b></c></b></a> will close everything, otherwise.
let t = this.tags.length;
let t = tags.length;
const { tagName } = this;
const closeTo = tagName;
while (t--) {
const close = this.tags[t];
const close = tags[t];
if (close.name !== closeTo) {
this.fail("Unexpected close tag");
}
Expand All @@ -1031,19 +1032,17 @@ ${XML_NAMESPACE}.`);
}

if (t < 0) {
this.fail(`Unmatched closing tag: ${this.tagName}`);
this.textNode += `</${this.tagName}>`;
this.fail(`Unmatched closing tag: ${tagName}`);
this.textNode += `</${tagName}>`;
this.state = S_TEXT;
return;
}
this.tagName = tagName;
let s = this.tags.length;
while (s-- > t) {
const tag = this.tag = this.tags.pop();
this.tagName = this.tag.name;
this.emitNode("onclosetag", this.tagName);
const tag = this.tag = tags.pop();
this.emitNode("onclosetag", tag.name);

const parent = this.tags[this.tags.length - 1] || this;
const parent = tags[tags.length - 1] || this;
if (this.opt.xmlns && tag.ns !== parent.ns) {
// remove namespace bindings introduced by tag
for (const p of Object.keys(tag.ns)) {
Expand Down

0 comments on commit 52151e0

Please sign in to comment.