Skip to content

Commit

Permalink
refactor: pass the actual tag to onclosetag
Browse files Browse the repository at this point in the history
BREAKING CHANGE:

Sax was only passing the tag name. We pass the whole object.
  • Loading branch information
lddubeau committed Jul 23, 2018
1 parent 2d4ce0f commit 7020e64
Show file tree
Hide file tree
Showing 37 changed files with 572 additions and 79 deletions.
2 changes: 1 addition & 1 deletion lib/saxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1856,7 +1856,7 @@ ${JSON.stringify(this.tagName)}.`);
let s = this.tags.length;
while (s-- > t) {
const tag = this.tag = tags.pop();
this.emitNode("onclosetag", tag.name);
this.emitNode("onclosetag", tag);
}
if (t === 0) {
this.inRoot = false;
Expand Down
18 changes: 17 additions & 1 deletion test/attribute-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,23 @@ require(".").test({
],
[
"closetag",
"root",
{
name: "root",
prefix: "",
local: "root",
uri: "",
attributes: {
length: {
name: "length",
value: "12345",
prefix: "",
local: "length",
uri: "",
},
},
ns: {},
isSelfClosing: false,
},
],
],
opt: {
Expand Down
8 changes: 4 additions & 4 deletions test/attribute-no-space.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require(".").test({
["opentagstart", { name: "root", attributes: {} }],
["error", "undefined:1:20: no whitespace between attributes."],
["opentag", { name: "root", attributes: { attr1: "first", attr2: "second" }, isSelfClosing: true }],
["closetag", "root"],
["closetag", { name: "root", attributes: { attr1: "first", attr2: "second" }, isSelfClosing: true }],
],
opt: { },
});
Expand All @@ -20,7 +20,7 @@ require(".").test({
expect: [
["opentagstart", { name: "root", attributes: {} }],
["opentag", { name: "root", attributes: { attr1: "first", attr2: "second" }, isSelfClosing: true }],
["closetag", "root"],
["closetag", { name: "root", attributes: { attr1: "first", attr2: "second" }, isSelfClosing: true }],
],
opt: { },
});
Expand All @@ -32,7 +32,7 @@ require(".").test({
expect: [
["opentagstart", { name: "root", attributes: {} }],
["opentag", { name: "root", attributes: { attr1: "first", attr2: "second" }, isSelfClosing: true }],
["closetag", "root"],
["closetag", { name: "root", attributes: { attr1: "first", attr2: "second" }, isSelfClosing: true }],
],
opt: { },
});
Expand All @@ -44,7 +44,7 @@ require(".").test({
expect: [
["opentagstart", { name: "root", attributes: {} }],
["opentag", { name: "root", attributes: { attr1: "first", attr2: "second" }, isSelfClosing: true }],
["closetag", "root"],
["closetag", { name: "root", attributes: { attr1: "first", attr2: "second" }, isSelfClosing: true }],
],
opt: { },
});
18 changes: 17 additions & 1 deletion test/attribute-unquoted.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,23 @@ require(".").test({
uri: "",
isSelfClosing: false,
}],
["closetag", "root"],
["closetag", {
name: "root",
attributes: {
length: {
name: "length",
value: "12345",
prefix: "",
local: "length",
uri: "",
},
},
ns: {},
prefix: "",
local: "root",
uri: "",
isSelfClosing: false,
}],
["end", undefined],
["ready", undefined],
],
Expand Down
6 changes: 3 additions & 3 deletions test/bad-entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require(".").test({
["opentag", { name: "r", attributes: {}, isSelfClosing: false }],
["error", "undefined:1:5: malformed character entity."],
["text", "&;"],
["closetag", "r"],
["closetag", { name: "r", attributes: {}, isSelfClosing: false }],
],
});

Expand All @@ -20,7 +20,7 @@ require(".").test({
["opentag", { name: "r", attributes: {}, isSelfClosing: false }],
["error", "undefined:1:6: malformed character entity."],
["text", "&#;"],
["closetag", "r"],
["closetag", { name: "r", attributes: {}, isSelfClosing: false }],
],
});

Expand All @@ -32,6 +32,6 @@ require(".").test({
["opentag", { name: "r", attributes: {}, isSelfClosing: false }],
["error", "undefined:1:7: malformed character entity."],
["text", "&#x;"],
["closetag", "r"],
["closetag", { name: "r", attributes: {}, isSelfClosing: false }],
],
});
8 changes: 4 additions & 4 deletions test/bom.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require(".").test({
expect: [
["opentagstart", { name: "P", attributes: {} }],
["opentag", { name: "P", attributes: {}, isSelfClosing: false }],
["closetag", "P"],
["closetag", { name: "P", attributes: {}, isSelfClosing: false }],
],
});

Expand All @@ -19,7 +19,7 @@ require(".").test({
["opentagstart", { name: "P", attributes: {} }],
["opentag", { name: "P", attributes: { BOM: "\uFEFF" }, isSelfClosing: false }],
["text", "\uFEFFStarts and ends with BOM\uFEFF"],
["closetag", "P"],
["closetag", { name: "P", attributes: { BOM: "\uFEFF" }, isSelfClosing: false }],
],
});

Expand All @@ -32,7 +32,7 @@ require(".").test({
["text", "\uFEFF"],
["opentagstart", { name: "P", attributes: {} }],
["opentag", { name: "P", attributes: {}, isSelfClosing: false }],
["closetag", "P"],
["closetag", { name: "P", attributes: {}, isSelfClosing: false }],
],
});

Expand All @@ -45,6 +45,6 @@ require(".").test({
["text", "\uFEFF"],
["opentagstart", { name: "P", attributes: {} }],
["opentag", { name: "P", attributes: {}, isSelfClosing: false }],
["closetag", "P"],
["closetag", { name: "P", attributes: {}, isSelfClosing: false }],
],
});
2 changes: 1 addition & 1 deletion test/cdata-chunked.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require(".").test({
["opentagstart", { name: "r", attributes: {} }],
["opentag", { name: "r", attributes: {}, isSelfClosing: false }],
["cdata", " this is character data  "],
["closetag", "r"],
["closetag", { name: "r", attributes: {}, isSelfClosing: false }],
],
fn(parser) {
parser.write("<r><![CDATA[ this is ").write("character data  ")
Expand Down
2 changes: 1 addition & 1 deletion test/cdata-end-split.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require(".").test({
["opentagstart", { name: "r", attributes: {} }],
["opentag", { name: "r", attributes: {}, isSelfClosing: false }],
["cdata", " this is "],
["closetag", "r"],
["closetag", { name: "r", attributes: {}, isSelfClosing: false }],
],
fn(parser) {
parser.write("<r><![CDATA[ this is ]")
Expand Down
4 changes: 2 additions & 2 deletions test/cdata-fake-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require(".").test({
["opentagstart", { name: "r", attributes: {} }],
["opentag", { name: "r", attributes: {}, isSelfClosing: false }],
["cdata", "[[[[[[[[]]]]]]]]"],
["closetag", "r"],
["closetag", { name: "r", attributes: {}, isSelfClosing: false }],
],
fn(parser) {
const x = "<r><![CDATA[[[[[[[[[]]]]]]]]]]></r>";
Expand All @@ -23,7 +23,7 @@ require(".").test({
["opentagstart", { name: "r", attributes: {} }],
["opentag", { name: "r", attributes: {}, isSelfClosing: false }],
["cdata", "[[[[[[[[]]]]]]]]"],
["closetag", "r"],
["closetag", { name: "r", attributes: {}, isSelfClosing: false }],
],
xml: "<r><![CDATA[[[[[[[[[]]]]]]]]]]></r>",
});
2 changes: 1 addition & 1 deletion test/cdata-multiple.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require(".").test({
["opentag", { name: "r", attributes: {}, isSelfClosing: false }],
["cdata", " this is "],
["cdata", "character data  "],
["closetag", "r"],
["closetag", { name: "r", attributes: {}, isSelfClosing: false }],
],
fn(parser) {
parser.write("<r><![CDATA[ this is ]]>").write("<![CDA")
Expand Down
2 changes: 1 addition & 1 deletion test/cdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ require(".").test({
["opentag", { name: "r", attributes: {}, isSelfClosing: false }],
["cdata", " this is character data  "],
["cdata", ""],
["closetag", "r"],
["closetag", { name: "r", attributes: {}, isSelfClosing: false }],
],
});
2 changes: 1 addition & 1 deletion test/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ require(".").test({
["opentag", { name: "r", attributes: {}, isSelfClosing: false }],
["comment", "foo"],
["comment", ""],
["closetag", "r"],
["closetag", { name: "r", attributes: {}, isSelfClosing: false }],
],
});
2 changes: 1 addition & 1 deletion test/cyrillic.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ require(".").test({
["opentagstart", { name: "Р", attributes: {} }],
["opentag", { name: "Р", attributes: {}, isSelfClosing: false }],
["text", "тест"],
["closetag", "Р"],
["closetag", { name: "Р", attributes: {}, isSelfClosing: false }],
],
});
6 changes: 5 additions & 1 deletion test/duplicate-attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ require(".").test({
attributes: { id: "there" },
isSelfClosing: false,
}],
["closetag", "span"],
["closetag", {
name: "span",
attributes: { id: "there" },
isSelfClosing: false,
}],
],
opt: {},
});
2 changes: 1 addition & 1 deletion test/emoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require(".").test({
["opentagstart", { name: "a", attributes: {} }],
["opentag", { name: "a", attributes: {}, isSelfClosing: false }],
["text", "\ud83d\udd25"],
["closetag", "a"],
["closetag", { name: "a", attributes: {}, isSelfClosing: false }],
],
opt: {},
});
2 changes: 1 addition & 1 deletion test/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ require(".").test({
["opentagstart", { name: "r", attributes: {} }],
["opentag", { name: "r", attributes: {}, isSelfClosing: false }],
["text", "& < > >"],
["closetag", "r"],
["closetag", { name: "r", attributes: {}, isSelfClosing: false }],
],
});
2 changes: 1 addition & 1 deletion test/entity-nan.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ require(".").test({
["opentag", { name: "r", attributes: {}, isSelfClosing: false }],
["error", "undefined:1:9: malformed character entity."],
["text", "&#NaN;"],
["closetag", "r"],
["closetag", { name: "r", attributes: {}, isSelfClosing: false }],
],
});
16 changes: 8 additions & 8 deletions test/issue-23.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,29 @@ require(".").test({
["opentagstart", { name: "bodyCrc", attributes: {} }],
["opentag", { name: "bodyCrc", attributes: {}, isSelfClosing: false }],
["text", "653724009"],
["closetag", "bodyCrc"],
["closetag", { name: "bodyCrc", attributes: {}, isSelfClosing: false }],
["opentagstart", { name: "column", attributes: {} }],
["opentag", { name: "column", attributes: {}, isSelfClosing: false }],
["text", "-1"],
["closetag", "column"],
["closetag", { name: "column", attributes: {}, isSelfClosing: false }],
["opentagstart", { name: "id", attributes: {} }],
["opentag", { name: "id", attributes: {}, isSelfClosing: false }],
["text", "01pG0000002KoSUIA0"],
["closetag", "id"],
["closetag", { name: "id", attributes: {}, isSelfClosing: false }],
["opentagstart", { name: "line", attributes: {} }],
["opentag", { name: "line", attributes: {}, isSelfClosing: false }],
["text", "-1"],
["closetag", "line"],
["closetag", { name: "line", attributes: {}, isSelfClosing: false }],
["opentagstart", { name: "name", attributes: {} }],
["opentag", { name: "name", attributes: {}, isSelfClosing: false }],
["text", "CalendarController"],
["closetag", "name"],
["closetag", { name: "name", attributes: {}, isSelfClosing: false }],
["opentagstart", { name: "success", attributes: {} }],
["opentag", { name: "success", attributes: {}, isSelfClosing: false }],
["text", "true"],
["closetag", "success"],
["closetag", "result"],
["closetag", "compileClassesResponse"],
["closetag", { name: "success", attributes: {}, isSelfClosing: false }],
["closetag", { name: "result", attributes: {}, isSelfClosing: false }],
["closetag", { name: "compileClassesResponse", attributes: {}, isSelfClosing: false }],
],
opt: {},
});
4 changes: 2 additions & 2 deletions test/issue-33.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ require(".").test({
["text", "\n"],
["opentagstart", { name: "data", attributes: {} }],
["opentag", { name: "data", attributes: {}, isSelfClosing: true }],
["closetag", "data"],
["closetag", { name: "data", attributes: {}, isSelfClosing: true }],
["text", "\n"],
["closetag", "xml"],
["closetag", { name: "xml", attributes: {}, isSelfClosing: false }],
],
opt: {},
});
2 changes: 1 addition & 1 deletion test/issue-35.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require(".").test({
["opentagstart", { name: "xml", attributes: {} }],
["opentag", { name: "xml", attributes: {}, isSelfClosing: false }],
["text", "\r\r\n"],
["closetag", "xml"],
["closetag", { name: "xml", attributes: {}, isSelfClosing: false }],
],
opt: {},
});
2 changes: 1 addition & 1 deletion test/issue-47.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require(".").test({
expect: [
["opentagstart", { name: "a", attributes: {} }],
["opentag", { name: "a", attributes: { href: "query.svc?x=1&y=2&z=3" }, isSelfClosing: true }],
["closetag", "a"],
["closetag", { name: "a", attributes: { href: "query.svc?x=1&y=2&z=3" }, isSelfClosing: true }],
],
opt: {},
});
2 changes: 1 addition & 1 deletion test/issue-84.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require(".").test({
["opentag", { name: "xml", attributes: {}, isSelfClosing: false }],
["processinginstruction", { target: "has", body: "unbalanced \"quotes" }],
["text", "body"],
["closetag", "xml"],
["closetag", { name: "xml", attributes: {}, isSelfClosing: false }],
],
opt: {},
});
6 changes: 5 additions & 1 deletion test/issue-86.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ require(".").test({
],
[
"closetag",
"root",
{
name: "root",
attributes: {},
isSelfClosing: false,
},
],
[
"error",
Expand Down
26 changes: 24 additions & 2 deletions test/opentagstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,23 @@ require(".").test({
],
[
"closetag",
"root",
{
name: "root",
prefix: "",
local: "root",
uri: "",
attributes: {
length: {
name: "length",
value: "12345",
prefix: "",
local: "length",
uri: "",
},
},
ns: {},
isSelfClosing: false,
},
],
],
opt: {
Expand Down Expand Up @@ -65,7 +81,13 @@ require(".").test({
],
[
"closetag",
"root",
{
name: "root",
attributes: {
length: "12345",
},
isSelfClosing: false,
},
],
],
});
Loading

0 comments on commit 7020e64

Please sign in to comment.