Skip to content

Commit

Permalink
refactor: remove startTagPosition
Browse files Browse the repository at this point in the history
`startTagPosition` is part of the API of sax but was removed from the API when
saxes was forked. Its only remaining use was to produce padding when running
into an error case. This would allow producing a more representative text node
but accurrate data after an error is not part of saxes' contract. So the padding
has been removed and `startTagPosition` too.
  • Loading branch information
lddubeau committed Aug 16, 2018
1 parent bb337e4 commit 2363ff8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
12 changes: 1 addition & 11 deletions lib/saxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,6 @@ class SaxesParser {
this.ns = Object.assign({}, rootNS);
}

this.startTagPosition = undefined;

this.trackPosition = this.opt.position !== false;
if (this.trackPosition) {
/** The line number the parser is currently looking at. */
Expand Down Expand Up @@ -629,7 +627,6 @@ class SaxesParser {
}
if (c === LESS) {
this.state = S_OPEN_WAKA;
this.startTagPosition = this.position;
}
else {
// have to process this as a text node.
Expand Down Expand Up @@ -678,7 +675,6 @@ class SaxesParser {
switch (c) {
case LESS:
this.state = S_OPEN_WAKA;
this.startTagPosition = this.position;
break;
case AMP:
this.state = S_ENTITY;
Expand Down Expand Up @@ -714,17 +710,11 @@ class SaxesParser {
this.state = S_PI;
this.piTarget = this.piBody = "";
break;
default: {
default:
this.fail("disallowed characer in tag name.");
// if there was some whitespace, then add that in.
const pad = (this.startTagPosition + 1 < this.position) ?
new Array(this.position - this.startTagPosition).join(" ") :
"";
this.textNode += `<${pad}${String.fromCodePoint(c)}`;
this.state = S_TEXT;
this.xmlDeclPossible = false;
}
}
}
}

Expand Down
16 changes: 8 additions & 8 deletions test/parser-position.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ describe("parser position", () => {
testPosition(
"with single chunk",
["<div>abcdefgh</div>"], [
["opentagstart", { position: 5, startTagPosition: 1 }],
["opentag", { position: 5, startTagPosition: 1 }],
["text", { position: 19, startTagPosition: 14 }],
["closetag", { position: 19, startTagPosition: 14 }],
["opentagstart", { position: 5 }],
["opentag", { position: 5 }],
["text", { position: 19 }],
["closetag", { position: 19 }],
]);

testPosition(
"with multiple chunks",
["<div>abcde", "fgh</div>"], [
["opentagstart", { position: 5, startTagPosition: 1 }],
["opentag", { position: 5, startTagPosition: 1 }],
["text", { position: 19, startTagPosition: 14 }],
["closetag", { position: 19, startTagPosition: 14 }],
["opentagstart", { position: 5 }],
["opentag", { position: 5 }],
["text", { position: 19 }],
["closetag", { position: 19 }],
]);

test({
Expand Down

0 comments on commit 2363ff8

Please sign in to comment.