Skip to content

Commit 9cc7c02

Browse files
Getting rid of the moronic ExprContext.node.
1 parent dd96572 commit 9cc7c02

16 files changed

+158
-159
lines changed

src/dom/functions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ const XML11_TAGNAME_REGEXP = new RegExp(`^(${XML11_NAME})`);
3232
const XML11_ATTRIBUTE_REGEXP = new RegExp(XML11_ATTRIBUTE, 'g');
3333

3434
// Wrapper around DOM methods so we can condense their invocations.
35-
export function domGetAttribute(node: any, name: any) {
36-
return node.getAttribute(name);
35+
export function domGetAttributeValue(node: any, name: any) {
36+
return node.getAttributeValue(name);
3737
}
3838

3939
export function domSetAttribute(node: any, name: any, value: any) {

src/dom/xml-functions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
DOM_ELEMENT_NODE,
1010
DOM_TEXT_NODE
1111
} from '../constants';
12-
import { domGetAttribute } from './functions';
12+
import { domGetAttributeValue } from './functions';
1313
import { XNode } from './xnode';
1414

1515
// Returns the text value of a node; for nodes without children this
@@ -144,7 +144,7 @@ export function xmlGetAttribute(node: XNode, name: string) {
144144
// TODO(mesch): This should not be necessary if the DOM is working
145145
// correctly. The DOM is responsible for resolving entities, not the
146146
// application.
147-
const value = domGetAttribute(node, name);
147+
const value = domGetAttributeValue(node, name);
148148
if (value) {
149149
return he.decode(value);
150150
}

src/dom/xnode.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ export class XNode {
1313
childNodes: XNode[];
1414
nodeType: any;
1515
nodeName: string;
16-
nodeValue: string;
16+
nodeValue: any;
1717
transformedNodeType: any;
1818
transformedNodeName: string;
19-
transformedNodeValue: string;
19+
transformedNodeValue: any;
2020
ownerDocument: any;
2121
namespaceURI: any;
2222
prefix: any;
@@ -278,7 +278,7 @@ export class XNode {
278278
this.attributes.push(XNode.create(DOM_ATTRIBUTE_NODE, name, value, this, namespace));
279279
}
280280

281-
getAttribute(name: any) {
281+
getAttributeValue(name: any): any {
282282
for (let i = 0; i < this.attributes.length; ++i) {
283283
if (this.attributes[i].nodeName == name) {
284284
return this.attributes[i].nodeValue;
@@ -414,7 +414,7 @@ export class XNode {
414414
domTraverseElements(
415415
this,
416416
(node: any) => {
417-
if (node.getAttribute('id') == id) {
417+
if (node.getAttributeValue('id') == id) {
418418
ret = node;
419419
return false;
420420
}

src/xpath/expr-context.ts

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ import { TOK_NUMBER } from "./tokens";
5858
import { XNode } from "../dom";
5959

6060
export class ExprContext {
61-
node: XNode;
62-
position: any;
63-
nodelist: any;
61+
position: number;
62+
nodelist: XNode[];
6463
variables: any;
6564
parent: any;
6665
caseInsensitive: any;
@@ -70,18 +69,16 @@ export class ExprContext {
7069
root: any;
7170

7271
constructor(
73-
node: any,
74-
opt_position?: any,
75-
opt_nodelist?: any,
72+
nodelist: any[],
73+
opt_position?: number,
7674
opt_parent?: any,
7775
opt_caseInsensitive?: any,
7876
opt_ignoreAttributesWithoutValue?: any,
7977
opt_returnOnFirstMatch?: any,
8078
opt_ignoreNonElementNodesForNTA?: any
8179
) {
82-
this.node = node;
80+
this.nodelist = nodelist;
8381
this.position = opt_position || 0;
84-
this.nodelist = opt_nodelist || [node];
8582
this.variables = {};
8683
this.parent = opt_parent || null;
8784
this.caseInsensitive = opt_caseInsensitive || false;
@@ -90,22 +87,21 @@ export class ExprContext {
9087
this.ignoreNonElementNodesForNTA = opt_ignoreNonElementNodesForNTA || false;
9188
if (opt_parent) {
9289
this.root = opt_parent.root;
93-
} else if (this.node.nodeType == DOM_DOCUMENT_NODE) {
90+
} else if (this.nodelist[this.position].nodeType == DOM_DOCUMENT_NODE) {
9491
// NOTE(mesch): DOM Spec stipulates that the ownerDocument of a
9592
// document is null. Our root, however is the document that we are
9693
// processing, so the initial context is created from its document
9794
// node, which case we must handle here explcitly.
98-
this.root = node;
95+
this.root = this.nodelist[this.position];
9996
} else {
100-
this.root = node.ownerDocument;
97+
this.root = this.nodelist[this.position].ownerDocument;
10198
}
10299
}
103100

104-
clone(opt_node?: any, opt_position?: any, opt_nodelist?: any[]) {
101+
clone(opt_nodelist?: any[], opt_position?: any) {
105102
return new ExprContext(
106-
opt_node || this.node,
107-
typeof opt_position != 'undefined' ? opt_position : this.position,
108103
opt_nodelist || this.nodelist,
104+
typeof opt_position != 'undefined' ? opt_position : this.position,
109105
this,
110106
this.caseInsensitive,
111107
this.ignoreAttributesWithoutValue,
@@ -146,8 +142,7 @@ export class ExprContext {
146142
}
147143
}
148144

149-
setNode(position) {
150-
this.node = this.nodelist[position];
145+
setNode(position: number) {
151146
this.position = position;
152147
}
153148

0 commit comments

Comments
 (0)