Skip to content

Commit cfead2e

Browse files
committed
Remove all the code associated with type checking
1 parent 0617cef commit cfead2e

File tree

3 files changed

+0
-181
lines changed

3 files changed

+0
-181
lines changed

test.js

Lines changed: 0 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,136 +1051,4 @@ describe('xpath', () => {
10511051
assert.strictEqual(xpath.select1('local-name(/book/characters)', doc), 'characters');
10521052
});
10531053
});
1054-
1055-
describe('Node type tests', () => {
1056-
it('should correctly identify a Node of type Element', () => {
1057-
var doc = parseXml('<book />');
1058-
var element = doc.createElement('characters');
1059-
1060-
assert.ok(xpath.isNodeLike(element));
1061-
assert.ok(xpath.isElement(element));
1062-
assert.ok(!xpath.isAttribute(doc));
1063-
});
1064-
1065-
it('should correctly identify a Node of type Attribute', () => {
1066-
var doc = parseXml('<book />');
1067-
var attribute = doc.createAttribute('name');
1068-
1069-
assert.ok(xpath.isNodeLike(attribute));
1070-
assert.ok(xpath.isAttribute(attribute));
1071-
assert.ok(!xpath.isTextNode(attribute));
1072-
});
1073-
1074-
it('should correctly identify a Node of type Text', () => {
1075-
var doc = parseXml('<book />');
1076-
var text = doc.createTextNode('Harry Potter');
1077-
1078-
assert.ok(xpath.isNodeLike(text));
1079-
assert.ok(xpath.isTextNode(text));
1080-
assert.ok(!xpath.isCDATASection(text));
1081-
});
1082-
1083-
it('should correctly identify a Node of type CDATASection', () => {
1084-
var doc = parseXml('<book />');
1085-
var cdata = doc.createCDATASection('Harry Potter');
1086-
1087-
assert.ok(xpath.isNodeLike(cdata));
1088-
assert.ok(xpath.isCDATASection(cdata));
1089-
assert.ok(!xpath.isProcessingInstruction(cdata));
1090-
});
1091-
1092-
it('should correctly identify a Node of type ProcessingInstruction', () => {
1093-
var doc = parseXml('<book />');
1094-
var pi = doc.createProcessingInstruction('xml-stylesheet', 'href="mycss.css" type="text/css"');
1095-
1096-
// This test fails due to a bug in @xmldom/[email protected]
1097-
// assert.ok(xpath.isNodeLike(pi));
1098-
assert.ok(xpath.isProcessingInstruction(pi));
1099-
assert.ok(!xpath.isComment(pi));
1100-
});
1101-
1102-
it('should correctly identify a Node of type Comment', () => {
1103-
var doc = parseXml('<book />');
1104-
var comment = doc.createComment('Harry Potter');
1105-
1106-
assert.ok(xpath.isNodeLike(comment));
1107-
assert.ok(xpath.isComment(comment));
1108-
assert.ok(!xpath.isDocumentNode(comment));
1109-
});
1110-
1111-
it('should correctly identify a Node of type Document', () => {
1112-
var doc = parseXml('<book />');
1113-
1114-
assert.ok(xpath.isNodeLike(doc));
1115-
assert.ok(xpath.isDocumentNode(doc));
1116-
assert.ok(!xpath.isDocumentTypeNode(doc));
1117-
});
1118-
1119-
it('should correctly identify a Node of type DocumentType', () => {
1120-
var doc = parseXml('<book />');
1121-
var doctype = doc.implementation.createDocumentType('book', null, null);
1122-
1123-
assert.ok(xpath.isNodeLike(doctype));
1124-
assert.ok(xpath.isDocumentTypeNode(doctype));
1125-
assert.ok(!xpath.isDocumentFragment(doctype));
1126-
});
1127-
1128-
it('should correctly identify a Node of type DocumentFragment', () => {
1129-
var doc = parseXml('<book />');
1130-
var fragment = doc.createDocumentFragment();
1131-
1132-
assert.ok(xpath.isNodeLike(fragment));
1133-
assert.ok(xpath.isDocumentFragment(fragment));
1134-
assert.ok(!xpath.isElement(fragment));
1135-
});
1136-
1137-
it('should not identify a string as a Node', () => {
1138-
assert.ok(!xpath.isNodeLike('Harry Potter'));
1139-
});
1140-
1141-
it('should not identify a number as a Node', () => {
1142-
assert.ok(!xpath.isNodeLike(45));
1143-
});
1144-
1145-
it('should not identify a boolean as a Node', () => {
1146-
assert.ok(!xpath.isNodeLike(true));
1147-
});
1148-
1149-
it('should not identify null as a Node', () => {
1150-
assert.ok(!xpath.isNodeLike(null));
1151-
});
1152-
1153-
it('should not identify undefined as a Node', () => {
1154-
assert.ok(!xpath.isNodeLike(undefined));
1155-
});
1156-
1157-
it('should not identify an array as a Node', () => {
1158-
assert.ok(!xpath.isNodeLike([]));
1159-
});
1160-
1161-
it('should identify an array of Nodes as such', () => {
1162-
var doc = parseXml('<book />');
1163-
var fragment = doc.createDocumentFragment();
1164-
var nodes = [doc, fragment];
1165-
1166-
assert.ok(xpath.isArrayOfNodes(nodes));
1167-
assert.ok(!xpath.isNodeLike(nodes));
1168-
});
1169-
1170-
it('should not identify an array of non-Nodes as an array of Nodes', () => {
1171-
var nodes = ['Harry Potter', 45];
1172-
1173-
assert.ok(!xpath.isArrayOfNodes(nodes));
1174-
assert.ok(!xpath.isNodeLike(nodes));
1175-
});
1176-
1177-
it('should not identify an array of mixed Nodes and non-Nodes as an array of Nodes', () => {
1178-
var doc = parseXml('<book />');
1179-
var fragment = doc.createDocumentFragment();
1180-
var nodes = [doc, fragment, 'Harry Potter'];
1181-
1182-
assert.ok(!xpath.isArrayOfNodes(nodes));
1183-
assert.ok(!xpath.isNodeLike(nodes));
1184-
});
1185-
});
11861054
});

xpath.d.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,3 @@ export function selectWithResolver(expression: string, node: Node, resolver: XPa
3636
* @return a function with the same signature as `xpath.select`
3737
*/
3838
export function useNamespaces(namespaceMap: Record<string, string>): XPathSelect;
39-
40-
// Type guards to narrow down the type of the selected type of a returned Node object
41-
export function isNodeLike(value: SelectedValue): value is Node;
42-
export function isArrayOfNodes(value: SelectedValue): value is Node[];
43-
export function isElement(value: SelectedValue): value is Element;
44-
export function isAttribute(value: SelectedValue): value is Attr;
45-
export function isTextNode(value: SelectedValue): value is Text;
46-
export function isCDATASection(value: SelectedValue): value is CDATASection;
47-
export function isProcessingInstruction(value: SelectedValue): value is ProcessingInstruction;
48-
export function isComment(value: SelectedValue): value is Comment;
49-
export function isDocumentNode(value: SelectedValue): value is Document;
50-
export function isDocumentTypeNode(value: SelectedValue): value is DocumentType;
51-
export function isDocumentFragment(value: SelectedValue): value is DocumentFragment;

xpath.js

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4898,41 +4898,5 @@ var xpath = (typeof exports === 'undefined') ? {} : exports;
48984898
exports.select1 = function (e, doc) {
48994899
return exports.select(e, doc, true);
49004900
};
4901-
4902-
var isNodeLike = function (value) {
4903-
return value
4904-
&& typeof value.nodeType === "number"
4905-
&& Number.isInteger(value.nodeType)
4906-
&& value.nodeType >= 1
4907-
&& value.nodeType <= 11
4908-
&& typeof value.nodeName === "string";
4909-
};
4910-
4911-
var isArrayOfNodes = function (value) {
4912-
return Array.isArray(value) && value.every(isNodeLike);
4913-
};
4914-
4915-
var isNodeOfType = function (type) {
4916-
return function (value) {
4917-
return isNodeLike(value) && value.nodeType === type;
4918-
};
4919-
};
4920-
4921-
assign(
4922-
exports,
4923-
{
4924-
isNodeLike: isNodeLike,
4925-
isArrayOfNodes: isArrayOfNodes,
4926-
isElement: isNodeOfType(NodeTypes.ELEMENT_NODE),
4927-
isAttribute: isNodeOfType(NodeTypes.ATTRIBUTE_NODE),
4928-
isTextNode: isNodeOfType(NodeTypes.TEXT_NODE),
4929-
isCDATASection: isNodeOfType(NodeTypes.CDATA_SECTION_NODE),
4930-
isProcessingInstruction: isNodeOfType(NodeTypes.PROCESSING_INSTRUCTION_NODE),
4931-
isComment: isNodeOfType(NodeTypes.COMMENT_NODE),
4932-
isDocumentNode: isNodeOfType(NodeTypes.DOCUMENT_NODE),
4933-
isDocumentTypeNode: isNodeOfType(NodeTypes.DOCUMENT_TYPE_NODE),
4934-
isDocumentFragment: isNodeOfType(NodeTypes.DOCUMENT_FRAGMENT_NODE),
4935-
}
4936-
);
49374901
// end non-node wrapper
49384902
})(xpath);

0 commit comments

Comments
 (0)