xslt-processor 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +165 -0
- package/README.md +29 -2
- package/constants.js.map +1 -0
- package/dom/functions.d.ts +15 -0
- package/{src/dom → dom}/functions.js +88 -43
- package/dom/functions.js.map +1 -0
- package/{src/dom → dom}/index.d.ts +1 -0
- package/{src/dom → dom}/index.js +1 -0
- package/dom/index.js.map +1 -0
- package/{src/dom → dom}/util.d.ts +0 -21
- package/dom/util.js +175 -0
- package/dom/util.js.map +1 -0
- package/{src/dom → dom}/xdocument.d.ts +3 -2
- package/dom/xdocument.js +71 -0
- package/dom/xdocument.js.map +1 -0
- package/dom/xml-functions.d.ts +46 -0
- package/dom/xml-functions.js +317 -0
- package/dom/xml-functions.js.map +1 -0
- package/{src/dom → dom}/xmltoken.js +25 -25
- package/dom/xmltoken.js.map +1 -0
- package/dom/xnode.d.ts +62 -0
- package/{src/dom → dom}/xnode.js +144 -91
- package/dom/xnode.js.map +1 -0
- package/index.d.ts +4 -4
- package/index.js +6 -5
- package/index.js.map +1 -1
- package/package.json +31 -10
- package/umd/constants.d.ts +8 -0
- package/umd/dom/functions.d.ts +15 -0
- package/umd/dom/index.d.ts +4 -0
- package/umd/dom/util.d.ts +26 -0
- package/umd/dom/xdocument.d.ts +16 -0
- package/umd/dom/xml-functions.d.ts +46 -0
- package/umd/dom/xmltoken.d.ts +12 -0
- package/umd/dom/xnode.d.ts +62 -0
- package/umd/index.d.ts +4 -0
- package/{src → umd}/xpath/expr-context.d.ts +6 -7
- package/umd/xpath/expressions/function-call-expr.d.ts +49 -0
- package/{src → umd}/xpath/expressions/location-expr.d.ts +1 -1
- package/{src → umd}/xpath/expressions/step-expr.d.ts +1 -1
- package/umd/xpath/node-test-element-or-attribute.d.ts +5 -0
- package/{src → umd}/xpath/node-test-name.d.ts +1 -1
- package/{src → umd}/xpath/xpath.d.ts +12 -5
- package/umd/xslt-processor.js +16 -0
- package/umd/xslt-processor.js.map +1 -0
- package/umd/xslt.d.ts +133 -0
- package/xpath/expr-context.d.ts +26 -0
- package/{src/xpath → xpath}/expr-context.js +41 -42
- package/xpath/expr-context.js.map +1 -0
- package/xpath/expressions/binary-expr.d.ts +10 -0
- package/{src/xpath → xpath}/expressions/binary-expr.js +65 -47
- package/xpath/expressions/binary-expr.js.map +1 -0
- package/xpath/expressions/expression.d.ts +4 -0
- package/xpath/expressions/expression.js +10 -0
- package/xpath/expressions/expression.js.map +1 -0
- package/xpath/expressions/filter-expr.d.ts +9 -0
- package/xpath/expressions/filter-expr.js +53 -0
- package/xpath/expressions/filter-expr.js.map +1 -0
- package/xpath/expressions/function-call-expr.d.ts +49 -0
- package/{src/xpath → xpath}/expressions/function-call-expr.js +160 -155
- package/xpath/expressions/function-call-expr.js.map +1 -0
- package/xpath/expressions/index.d.ts +13 -0
- package/xpath/expressions/index.js.map +1 -0
- package/xpath/expressions/literal-expr.d.ts +7 -0
- package/xpath/expressions/literal-expr.js +34 -0
- package/xpath/expressions/literal-expr.js.map +1 -0
- package/xpath/expressions/location-expr.d.ts +14 -0
- package/xpath/expressions/location-expr.js +94 -0
- package/xpath/expressions/location-expr.js.map +1 -0
- package/xpath/expressions/number-expr.d.ts +7 -0
- package/xpath/expressions/number-expr.js +34 -0
- package/xpath/expressions/number-expr.js.map +1 -0
- package/xpath/expressions/path-expr.d.ts +9 -0
- package/xpath/expressions/path-expr.js +52 -0
- package/xpath/expressions/path-expr.js.map +1 -0
- package/xpath/expressions/predicate-expr.d.ts +8 -0
- package/xpath/expressions/predicate-expr.js +43 -0
- package/xpath/expressions/predicate-expr.js.map +1 -0
- package/xpath/expressions/step-expr.d.ts +14 -0
- package/{src/xpath → xpath}/expressions/step-expr.js +68 -51
- package/xpath/expressions/step-expr.js.map +1 -0
- package/xpath/expressions/token-expr.d.ts +7 -0
- package/xpath/expressions/token-expr.js +34 -0
- package/xpath/expressions/token-expr.js.map +1 -0
- package/xpath/expressions/unary-minus-expr.d.ts +8 -0
- package/xpath/expressions/unary-minus-expr.js +34 -0
- package/xpath/expressions/unary-minus-expr.js.map +1 -0
- package/xpath/expressions/union-expr.d.ts +9 -0
- package/xpath/expressions/union-expr.js +51 -0
- package/xpath/expressions/union-expr.js.map +1 -0
- package/xpath/expressions/variable-expr.d.ts +7 -0
- package/xpath/expressions/variable-expr.js +33 -0
- package/xpath/expressions/variable-expr.js.map +1 -0
- package/xpath/index.d.ts +9 -0
- package/xpath/index.js.map +1 -0
- package/xpath/node-test-any.d.ts +5 -0
- package/xpath/node-test-any.js +15 -0
- package/xpath/node-test-any.js.map +1 -0
- package/{src/xpath/node-test-element-or-attribute.d.ts → xpath/node-test-comment.d.ts} +1 -1
- package/xpath/node-test-comment.js +15 -0
- package/xpath/node-test-comment.js.map +1 -0
- package/xpath/node-test-element-or-attribute.d.ts +5 -0
- package/xpath/node-test-element-or-attribute.js +16 -0
- package/xpath/node-test-element-or-attribute.js.map +1 -0
- package/xpath/node-test-name.d.ts +8 -0
- package/xpath/node-test-name.js +22 -0
- package/xpath/node-test-name.js.map +1 -0
- package/xpath/node-test-nc.d.ts +7 -0
- package/xpath/node-test-nc.js +17 -0
- package/xpath/node-test-nc.js.map +1 -0
- package/xpath/node-test-pi.d.ts +6 -0
- package/{src/xpath → xpath}/node-test-pi.js +8 -7
- package/xpath/node-test-pi.js.map +1 -0
- package/xpath/node-test-text.d.ts +4 -0
- package/xpath/node-test-text.js +15 -0
- package/xpath/node-test-text.js.map +1 -0
- package/xpath/tokens.d.ts +231 -0
- package/{src/xpath → xpath}/tokens.js +5 -5
- package/xpath/tokens.js.map +1 -0
- package/xpath/values/boolean-value.d.ts +9 -0
- package/xpath/values/boolean-value.js +24 -0
- package/xpath/values/boolean-value.js.map +1 -0
- package/xpath/values/index.d.ts +4 -0
- package/xpath/values/index.js.map +1 -0
- package/xpath/values/node-set-value.d.ts +9 -0
- package/xpath/values/node-set-value.js +28 -0
- package/xpath/values/node-set-value.js.map +1 -0
- package/xpath/values/number-value.d.ts +9 -0
- package/xpath/values/number-value.js +24 -0
- package/xpath/values/number-value.js.map +1 -0
- package/xpath/values/string-value.d.ts +9 -0
- package/{src/xpath → xpath}/values/string-value.js +12 -11
- package/xpath/values/string-value.js.map +1 -0
- package/xpath/xpath-grammar-rules.d.ts +68 -0
- package/xpath/xpath-grammar-rules.js.map +1 -0
- package/xpath/xpath.d.ts +105 -0
- package/{src/xpath → xpath}/xpath.js +267 -266
- package/xpath/xpath.js.map +1 -0
- package/xpathdebug.d.ts +2 -0
- package/{src/xpathdebug.js → xpathdebug.js} +48 -48
- package/xpathdebug.js.map +1 -0
- package/xslt.d.ts +133 -0
- package/xslt.js +643 -0
- package/xslt.js.map +1 -0
- package/src/constants.js.map +0 -1
- package/src/dom/functions.d.ts +0 -3
- package/src/dom/functions.js.map +0 -1
- package/src/dom/index.js.map +0 -1
- package/src/dom/util.js +0 -338
- package/src/dom/util.js.map +0 -1
- package/src/dom/xdocument.js +0 -47
- package/src/dom/xdocument.js.map +0 -1
- package/src/dom/xmltoken.js.map +0 -1
- package/src/dom/xnode.d.ts +0 -38
- package/src/dom/xnode.js.map +0 -1
- package/src/xpath/expr-context.js.map +0 -1
- package/src/xpath/expressions/binary-expr.js.map +0 -1
- package/src/xpath/expressions/expression.js +0 -7
- package/src/xpath/expressions/expression.js.map +0 -1
- package/src/xpath/expressions/filter-expr.js +0 -35
- package/src/xpath/expressions/filter-expr.js.map +0 -1
- package/src/xpath/expressions/function-call-expr.d.ts +0 -49
- package/src/xpath/expressions/function-call-expr.js.map +0 -1
- package/src/xpath/expressions/index.js.map +0 -1
- package/src/xpath/expressions/literal-expr.js +0 -16
- package/src/xpath/expressions/literal-expr.js.map +0 -1
- package/src/xpath/expressions/location-expr.js +0 -76
- package/src/xpath/expressions/location-expr.js.map +0 -1
- package/src/xpath/expressions/number-expr.js +0 -16
- package/src/xpath/expressions/number-expr.js.map +0 -1
- package/src/xpath/expressions/path-expr.js +0 -36
- package/src/xpath/expressions/path-expr.js.map +0 -1
- package/src/xpath/expressions/predicate-expr.js +0 -25
- package/src/xpath/expressions/predicate-expr.js.map +0 -1
- package/src/xpath/expressions/step-expr.js.map +0 -1
- package/src/xpath/expressions/token-expr.js +0 -16
- package/src/xpath/expressions/token-expr.js.map +0 -1
- package/src/xpath/expressions/unary-minus-expr.js +0 -16
- package/src/xpath/expressions/unary-minus-expr.js.map +0 -1
- package/src/xpath/expressions/union-expr.js +0 -32
- package/src/xpath/expressions/union-expr.js.map +0 -1
- package/src/xpath/expressions/variable-expr.js +0 -15
- package/src/xpath/expressions/variable-expr.js.map +0 -1
- package/src/xpath/index.js.map +0 -1
- package/src/xpath/node-test-any.js +0 -14
- package/src/xpath/node-test-any.js.map +0 -1
- package/src/xpath/node-test-comment.js +0 -12
- package/src/xpath/node-test-comment.js.map +0 -1
- package/src/xpath/node-test-element-or-attribute.js +0 -12
- package/src/xpath/node-test-element-or-attribute.js.map +0 -1
- package/src/xpath/node-test-name.js +0 -23
- package/src/xpath/node-test-name.js.map +0 -1
- package/src/xpath/node-test-nc.js +0 -16
- package/src/xpath/node-test-nc.js.map +0 -1
- package/src/xpath/node-test-pi.js.map +0 -1
- package/src/xpath/node-test-text.js +0 -12
- package/src/xpath/node-test-text.js.map +0 -1
- package/src/xpath/tokens.js.map +0 -1
- package/src/xpath/values/boolean-value.js +0 -23
- package/src/xpath/values/boolean-value.js.map +0 -1
- package/src/xpath/values/index.js.map +0 -1
- package/src/xpath/values/node-set-value.js +0 -27
- package/src/xpath/values/node-set-value.js.map +0 -1
- package/src/xpath/values/number-value.js +0 -23
- package/src/xpath/values/number-value.js.map +0 -1
- package/src/xpath/values/string-value.js.map +0 -1
- package/src/xpath/xpath-grammar-rules.js.map +0 -1
- package/src/xpath/xpath.js.map +0 -1
- package/src/xpathdebug.js.map +0 -1
- package/src/xslt.d.ts +0 -68
- package/src/xslt.js +0 -619
- package/src/xslt.js.map +0 -1
- package/xslt-processor.js +0 -2
- package/xslt-processor.js.map +0 -1
- /package/{src/constants.d.ts → constants.d.ts} +0 -0
- /package/{src/constants.js → constants.js} +0 -0
- /package/{src/dom → dom}/xmltoken.d.ts +0 -0
- /package/{src → umd}/xpath/expressions/binary-expr.d.ts +0 -0
- /package/{src → umd}/xpath/expressions/expression.d.ts +0 -0
- /package/{src → umd}/xpath/expressions/filter-expr.d.ts +0 -0
- /package/{src → umd}/xpath/expressions/index.d.ts +0 -0
- /package/{src → umd}/xpath/expressions/literal-expr.d.ts +0 -0
- /package/{src → umd}/xpath/expressions/number-expr.d.ts +0 -0
- /package/{src → umd}/xpath/expressions/path-expr.d.ts +0 -0
- /package/{src → umd}/xpath/expressions/predicate-expr.d.ts +0 -0
- /package/{src → umd}/xpath/expressions/token-expr.d.ts +0 -0
- /package/{src → umd}/xpath/expressions/unary-minus-expr.d.ts +0 -0
- /package/{src → umd}/xpath/expressions/union-expr.d.ts +0 -0
- /package/{src → umd}/xpath/expressions/variable-expr.d.ts +0 -0
- /package/{src → umd}/xpath/index.d.ts +0 -0
- /package/{src → umd}/xpath/node-test-any.d.ts +0 -0
- /package/{src → umd}/xpath/node-test-comment.d.ts +0 -0
- /package/{src → umd}/xpath/node-test-nc.d.ts +0 -0
- /package/{src → umd}/xpath/node-test-pi.d.ts +0 -0
- /package/{src → umd}/xpath/node-test-text.d.ts +0 -0
- /package/{src → umd}/xpath/tokens.d.ts +0 -0
- /package/{src → umd}/xpath/values/boolean-value.d.ts +0 -0
- /package/{src → umd}/xpath/values/index.d.ts +0 -0
- /package/{src → umd}/xpath/values/node-set-value.d.ts +0 -0
- /package/{src → umd}/xpath/values/number-value.d.ts +0 -0
- /package/{src → umd}/xpath/values/string-value.d.ts +0 -0
- /package/{src → umd}/xpath/xpath-grammar-rules.d.ts +0 -0
- /package/{src → umd}/xpathdebug.d.ts +0 -0
- /package/{src/xpath → xpath}/expressions/index.js +0 -0
- /package/{src/xpath → xpath}/index.js +0 -0
- /package/{src/xpath → xpath}/values/index.js +0 -0
- /package/{src/xpath → xpath}/xpath-grammar-rules.js +0 -0
|
@@ -37,19 +37,19 @@
|
|
|
37
37
|
// Original author: Steffen Meschkat <mesch@google.com>
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.XPath = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
40
|
+
var util_1 = require("../dom/util");
|
|
41
|
+
var expressions_1 = require("./expressions");
|
|
42
|
+
var node_test_any_1 = require("./node-test-any");
|
|
43
|
+
var node_test_comment_1 = require("./node-test-comment");
|
|
44
|
+
var node_test_element_or_attribute_1 = require("./node-test-element-or-attribute");
|
|
45
|
+
var node_test_name_1 = require("./node-test-name");
|
|
46
|
+
var node_test_nc_1 = require("./node-test-nc");
|
|
47
|
+
var node_test_pi_1 = require("./node-test-pi");
|
|
48
|
+
var node_test_text_1 = require("./node-test-text");
|
|
49
|
+
var tokens_1 = require("./tokens");
|
|
50
|
+
var xpath_grammar_rules_1 = require("./xpath-grammar-rules");
|
|
51
|
+
var XPath = /** @class */ (function () {
|
|
52
|
+
function XPath() {
|
|
53
53
|
// The productions of the grammar. Columns of the table:
|
|
54
54
|
//
|
|
55
55
|
// - target nonterminal,
|
|
@@ -146,67 +146,67 @@ class XPath {
|
|
|
146
146
|
// tree, an expression object with an evaluate() method that evaluates the
|
|
147
147
|
// expression in an actual context. These factory functions are used
|
|
148
148
|
// in the specification of the grammar rules, below.
|
|
149
|
-
makeTokenExpr(m) {
|
|
149
|
+
XPath.prototype.makeTokenExpr = function (m) {
|
|
150
150
|
return new expressions_1.TokenExpr(m);
|
|
151
|
-
}
|
|
152
|
-
passExpr(e) {
|
|
151
|
+
};
|
|
152
|
+
XPath.prototype.passExpr = function (e) {
|
|
153
153
|
return e;
|
|
154
|
-
}
|
|
155
|
-
makeLocationExpr1(slash, rel) {
|
|
154
|
+
};
|
|
155
|
+
XPath.prototype.makeLocationExpr1 = function (slash, rel) {
|
|
156
156
|
rel.absolute = true;
|
|
157
157
|
return rel;
|
|
158
|
-
}
|
|
159
|
-
makeLocationExpr2(dslash, rel) {
|
|
158
|
+
};
|
|
159
|
+
XPath.prototype.makeLocationExpr2 = function (dslash, rel) {
|
|
160
160
|
rel.absolute = true;
|
|
161
161
|
rel.prependStep(this.makeAbbrevStep(dslash.value));
|
|
162
162
|
return rel;
|
|
163
|
-
}
|
|
164
|
-
makeLocationExpr3() {
|
|
165
|
-
|
|
163
|
+
};
|
|
164
|
+
XPath.prototype.makeLocationExpr3 = function () {
|
|
165
|
+
var ret = new expressions_1.LocationExpr(this);
|
|
166
166
|
ret.appendStep(this.makeAbbrevStep('.'));
|
|
167
167
|
ret.absolute = true;
|
|
168
168
|
return ret;
|
|
169
|
-
}
|
|
170
|
-
makeLocationExpr4(dslash) {
|
|
171
|
-
|
|
169
|
+
};
|
|
170
|
+
XPath.prototype.makeLocationExpr4 = function (dslash) {
|
|
171
|
+
var ret = new expressions_1.LocationExpr(this);
|
|
172
172
|
ret.absolute = true;
|
|
173
173
|
ret.appendStep(this.makeAbbrevStep(dslash.value));
|
|
174
174
|
return ret;
|
|
175
|
-
}
|
|
176
|
-
makeLocationExpr5(step) {
|
|
177
|
-
|
|
175
|
+
};
|
|
176
|
+
XPath.prototype.makeLocationExpr5 = function (step) {
|
|
177
|
+
var ret = new expressions_1.LocationExpr(this);
|
|
178
178
|
ret.appendStep(step);
|
|
179
179
|
return ret;
|
|
180
|
-
}
|
|
181
|
-
makeLocationExpr6(rel, slash, step) {
|
|
180
|
+
};
|
|
181
|
+
XPath.prototype.makeLocationExpr6 = function (rel, slash, step) {
|
|
182
182
|
rel.appendStep(step);
|
|
183
183
|
return rel;
|
|
184
|
-
}
|
|
185
|
-
makeLocationExpr7(rel, dslash, step) {
|
|
184
|
+
};
|
|
185
|
+
XPath.prototype.makeLocationExpr7 = function (rel, dslash, step) {
|
|
186
186
|
rel.appendStep(this.makeAbbrevStep(dslash.value));
|
|
187
187
|
rel.appendStep(step);
|
|
188
188
|
return rel;
|
|
189
|
-
}
|
|
190
|
-
makeStepExpr1(dot) {
|
|
189
|
+
};
|
|
190
|
+
XPath.prototype.makeStepExpr1 = function (dot) {
|
|
191
191
|
return this.makeAbbrevStep(dot.value);
|
|
192
|
-
}
|
|
193
|
-
makeStepExpr2(ddot) {
|
|
192
|
+
};
|
|
193
|
+
XPath.prototype.makeStepExpr2 = function (ddot) {
|
|
194
194
|
return this.makeAbbrevStep(ddot.value);
|
|
195
|
-
}
|
|
196
|
-
makeStepExpr3(axisname, axis, nodetest) {
|
|
195
|
+
};
|
|
196
|
+
XPath.prototype.makeStepExpr3 = function (axisname, axis, nodetest) {
|
|
197
197
|
return new expressions_1.StepExpr(axisname.value, nodetest, this);
|
|
198
|
-
}
|
|
199
|
-
makeStepExpr4(at, nodetest) {
|
|
198
|
+
};
|
|
199
|
+
XPath.prototype.makeStepExpr4 = function (at, nodetest) {
|
|
200
200
|
return new expressions_1.StepExpr('attribute', nodetest, this);
|
|
201
|
-
}
|
|
202
|
-
makeStepExpr5(nodetest) {
|
|
201
|
+
};
|
|
202
|
+
XPath.prototype.makeStepExpr5 = function (nodetest) {
|
|
203
203
|
return new expressions_1.StepExpr('child', nodetest, this);
|
|
204
|
-
}
|
|
205
|
-
makeStepExpr6(step, predicate) {
|
|
204
|
+
};
|
|
205
|
+
XPath.prototype.makeStepExpr6 = function (step, predicate) {
|
|
206
206
|
step.appendPredicate(predicate);
|
|
207
207
|
return step;
|
|
208
|
-
}
|
|
209
|
-
makeAbbrevStep(abbrev) {
|
|
208
|
+
};
|
|
209
|
+
XPath.prototype.makeAbbrevStep = function (abbrev) {
|
|
210
210
|
switch (abbrev) {
|
|
211
211
|
case '//':
|
|
212
212
|
return new expressions_1.StepExpr('descendant-or-self', new node_test_any_1.NodeTestAny(), this);
|
|
@@ -215,18 +215,18 @@ class XPath {
|
|
|
215
215
|
case '..':
|
|
216
216
|
return new expressions_1.StepExpr('parent', new node_test_any_1.NodeTestAny(), this);
|
|
217
217
|
}
|
|
218
|
-
}
|
|
219
|
-
makeNodeTestExpr1() {
|
|
218
|
+
};
|
|
219
|
+
XPath.prototype.makeNodeTestExpr1 = function () {
|
|
220
220
|
return new node_test_element_or_attribute_1.NodeTestElementOrAttribute();
|
|
221
|
-
}
|
|
222
|
-
makeNodeTestExpr2(ncname) {
|
|
221
|
+
};
|
|
222
|
+
XPath.prototype.makeNodeTestExpr2 = function (ncname) {
|
|
223
223
|
return new node_test_nc_1.NodeTestNC(ncname.value);
|
|
224
|
-
}
|
|
225
|
-
makeNodeTestExpr3(qname) {
|
|
224
|
+
};
|
|
225
|
+
XPath.prototype.makeNodeTestExpr3 = function (qname) {
|
|
226
226
|
return new node_test_name_1.NodeTestName(qname.value);
|
|
227
|
-
}
|
|
228
|
-
makeNodeTestExpr4(typeo) {
|
|
229
|
-
|
|
227
|
+
};
|
|
228
|
+
XPath.prototype.makeNodeTestExpr4 = function (typeo) {
|
|
229
|
+
var type = typeo.value.replace(/\s*\($/, '');
|
|
230
230
|
switch (type) {
|
|
231
231
|
case 'node':
|
|
232
232
|
return new node_test_any_1.NodeTestAny();
|
|
@@ -237,139 +237,135 @@ class XPath {
|
|
|
237
237
|
case 'processing-instruction':
|
|
238
238
|
return new node_test_pi_1.NodeTestPI('');
|
|
239
239
|
}
|
|
240
|
-
}
|
|
241
|
-
makeNodeTestExpr5(typeo, target) {
|
|
242
|
-
|
|
240
|
+
};
|
|
241
|
+
XPath.prototype.makeNodeTestExpr5 = function (typeo, target) {
|
|
242
|
+
var type = typeo.replace(/\s*\($/, '');
|
|
243
243
|
if (type != 'processing-instruction') {
|
|
244
244
|
throw type;
|
|
245
245
|
}
|
|
246
246
|
return new node_test_pi_1.NodeTestPI(target.value);
|
|
247
|
-
}
|
|
248
|
-
makePredicateExpr(pareno, expr) {
|
|
247
|
+
};
|
|
248
|
+
XPath.prototype.makePredicateExpr = function (pareno, expr) {
|
|
249
249
|
return new expressions_1.PredicateExpr(expr);
|
|
250
|
-
}
|
|
251
|
-
makePrimaryExpr(pareno, expr) {
|
|
250
|
+
};
|
|
251
|
+
XPath.prototype.makePrimaryExpr = function (pareno, expr) {
|
|
252
252
|
return expr;
|
|
253
|
-
}
|
|
254
|
-
makeFunctionCallExpr1(name) {
|
|
253
|
+
};
|
|
254
|
+
XPath.prototype.makeFunctionCallExpr1 = function (name) {
|
|
255
255
|
return new expressions_1.FunctionCallExpr(name);
|
|
256
|
-
}
|
|
257
|
-
makeFunctionCallExpr2(name, pareno, arg1, args) {
|
|
258
|
-
|
|
256
|
+
};
|
|
257
|
+
XPath.prototype.makeFunctionCallExpr2 = function (name, pareno, arg1, args) {
|
|
258
|
+
var ret = new expressions_1.FunctionCallExpr(name);
|
|
259
259
|
ret.appendArg(arg1);
|
|
260
|
-
for (
|
|
260
|
+
for (var i = 0; i < args.length; ++i) {
|
|
261
261
|
ret.appendArg(args[i]);
|
|
262
262
|
}
|
|
263
263
|
return ret;
|
|
264
|
-
}
|
|
265
|
-
makeArgumentExpr(comma, expr) {
|
|
264
|
+
};
|
|
265
|
+
XPath.prototype.makeArgumentExpr = function (comma, expr) {
|
|
266
266
|
return expr;
|
|
267
|
-
}
|
|
268
|
-
makeUnionExpr(expr1, pipe, expr2) {
|
|
267
|
+
};
|
|
268
|
+
XPath.prototype.makeUnionExpr = function (expr1, pipe, expr2) {
|
|
269
269
|
return new expressions_1.UnionExpr(expr1, expr2);
|
|
270
|
-
}
|
|
271
|
-
makePathExpr1(filter, slash, rel) {
|
|
270
|
+
};
|
|
271
|
+
XPath.prototype.makePathExpr1 = function (filter, slash, rel) {
|
|
272
272
|
return new expressions_1.PathExpr(filter, rel);
|
|
273
|
-
}
|
|
274
|
-
makePathExpr2(filter, dslash, rel) {
|
|
273
|
+
};
|
|
274
|
+
XPath.prototype.makePathExpr2 = function (filter, dslash, rel) {
|
|
275
275
|
rel.prependStep(this.makeAbbrevStep(dslash.value));
|
|
276
276
|
return new expressions_1.PathExpr(filter, rel);
|
|
277
|
-
}
|
|
278
|
-
makeFilterExpr(expr, predicates) {
|
|
277
|
+
};
|
|
278
|
+
XPath.prototype.makeFilterExpr = function (expr, predicates) {
|
|
279
279
|
if (predicates.length > 0) {
|
|
280
280
|
return new expressions_1.FilterExpr(expr, predicates);
|
|
281
281
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
}
|
|
286
|
-
makeUnaryMinusExpr(minus, expr) {
|
|
282
|
+
return expr;
|
|
283
|
+
};
|
|
284
|
+
XPath.prototype.makeUnaryMinusExpr = function (minus, expr) {
|
|
287
285
|
return new expressions_1.UnaryMinusExpr(expr);
|
|
288
|
-
}
|
|
289
|
-
makeBinaryExpr(expr1, op, expr2) {
|
|
286
|
+
};
|
|
287
|
+
XPath.prototype.makeBinaryExpr = function (expr1, op, expr2) {
|
|
290
288
|
return new expressions_1.BinaryExpr(expr1, op, expr2);
|
|
291
|
-
}
|
|
292
|
-
makeLiteralExpr(token) {
|
|
289
|
+
};
|
|
290
|
+
XPath.prototype.makeLiteralExpr = function (token) {
|
|
293
291
|
// remove quotes from the parsed value:
|
|
294
|
-
|
|
292
|
+
var value = token.value.substring(1, token.value.length - 1);
|
|
295
293
|
return new expressions_1.LiteralExpr(value);
|
|
296
|
-
}
|
|
297
|
-
makeNumberExpr(token) {
|
|
294
|
+
};
|
|
295
|
+
XPath.prototype.makeNumberExpr = function (token) {
|
|
298
296
|
return new expressions_1.NumberExpr(token.value);
|
|
299
|
-
}
|
|
300
|
-
makeVariableReference(dollar, name) {
|
|
297
|
+
};
|
|
298
|
+
XPath.prototype.makeVariableReference = function (dollar, name) {
|
|
301
299
|
return new expressions_1.VariableExpr(name.value);
|
|
302
|
-
}
|
|
300
|
+
};
|
|
303
301
|
// Used before parsing for optimization of common simple cases. See
|
|
304
302
|
// the begin of xpathParse() for which they are.
|
|
305
|
-
makeSimpleExpr(expr) {
|
|
303
|
+
XPath.prototype.makeSimpleExpr = function (expr) {
|
|
306
304
|
if (expr.charAt(0) == '$') {
|
|
307
305
|
return new expressions_1.VariableExpr(expr.substr(1));
|
|
308
306
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
return
|
|
307
|
+
if (expr.charAt(0) == '@') {
|
|
308
|
+
var a_1 = new node_test_name_1.NodeTestName(expr.substr(1));
|
|
309
|
+
var b_1 = new expressions_1.StepExpr('attribute', a_1, this);
|
|
310
|
+
var c_1 = new expressions_1.LocationExpr(this);
|
|
311
|
+
c_1.appendStep(b_1);
|
|
312
|
+
return c_1;
|
|
315
313
|
}
|
|
316
|
-
|
|
314
|
+
if (expr.match(/^[0-9]+$/)) {
|
|
317
315
|
return new expressions_1.NumberExpr(expr);
|
|
318
316
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
const a = new node_test_name_1.NodeTestName(steps[i]);
|
|
332
|
-
const b = new expressions_1.StepExpr('child', a, this);
|
|
317
|
+
var a = new node_test_name_1.NodeTestName(expr);
|
|
318
|
+
var b = new expressions_1.StepExpr('child', a, this);
|
|
319
|
+
var c = new expressions_1.LocationExpr(this);
|
|
320
|
+
c.appendStep(b);
|
|
321
|
+
return c;
|
|
322
|
+
};
|
|
323
|
+
XPath.prototype.makeSimpleExpr2 = function (expr) {
|
|
324
|
+
var steps = expr.split('/');
|
|
325
|
+
var c = new expressions_1.LocationExpr(this);
|
|
326
|
+
for (var i = 0; i < steps.length; ++i) {
|
|
327
|
+
var a = new node_test_name_1.NodeTestName(steps[i]);
|
|
328
|
+
var b = new expressions_1.StepExpr('child', a, this);
|
|
333
329
|
c.appendStep(b);
|
|
334
330
|
}
|
|
335
331
|
return c;
|
|
336
|
-
}
|
|
337
|
-
stackToString(stack) {
|
|
338
|
-
|
|
339
|
-
for (
|
|
332
|
+
};
|
|
333
|
+
XPath.prototype.stackToString = function (stack) {
|
|
334
|
+
var ret = '';
|
|
335
|
+
for (var i = 0; i < stack.length; ++i) {
|
|
340
336
|
if (ret) {
|
|
341
337
|
ret += '\n';
|
|
342
338
|
}
|
|
343
339
|
ret += stack[i].tag.label;
|
|
344
340
|
}
|
|
345
341
|
return ret;
|
|
346
|
-
}
|
|
347
|
-
xPathCacheLookup(expr) {
|
|
342
|
+
};
|
|
343
|
+
XPath.prototype.xPathCacheLookup = function (expr) {
|
|
348
344
|
return this.xPathParseCache[expr];
|
|
349
|
-
}
|
|
350
|
-
xPathCollectDescendants(nodelist, node, opt_tagName) {
|
|
345
|
+
};
|
|
346
|
+
XPath.prototype.xPathCollectDescendants = function (nodelist, node, opt_tagName) {
|
|
351
347
|
if (opt_tagName && node.getElementsByTagName) {
|
|
352
348
|
(0, util_1.copyArray)(nodelist, node.getElementsByTagName(opt_tagName));
|
|
353
349
|
return;
|
|
354
350
|
}
|
|
355
|
-
for (
|
|
351
|
+
for (var n = node.firstChild; n; n = n.nextSibling) {
|
|
356
352
|
nodelist.push(n);
|
|
357
353
|
this.xPathCollectDescendants(nodelist, n);
|
|
358
354
|
}
|
|
359
|
-
}
|
|
360
|
-
xPathCollectDescendantsReverse(nodelist, node) {
|
|
361
|
-
for (
|
|
355
|
+
};
|
|
356
|
+
XPath.prototype.xPathCollectDescendantsReverse = function (nodelist, node) {
|
|
357
|
+
for (var n = node.lastChild; n; n = n.previousSibling) {
|
|
362
358
|
nodelist.push(n);
|
|
363
359
|
this.xPathCollectDescendantsReverse(nodelist, n);
|
|
364
360
|
}
|
|
365
|
-
}
|
|
361
|
+
};
|
|
366
362
|
// Parses and then evaluates the given XPath expression in the given
|
|
367
363
|
// input context. Notice that parsed xpath expressions are cached.
|
|
368
|
-
xPathEval(select, context) {
|
|
369
|
-
|
|
370
|
-
|
|
364
|
+
XPath.prototype.xPathEval = function (select, context) {
|
|
365
|
+
var expr = this.xPathParse(select);
|
|
366
|
+
var ret = expr.evaluate(context);
|
|
371
367
|
return ret;
|
|
372
|
-
}
|
|
368
|
+
};
|
|
373
369
|
/**
|
|
374
370
|
* DGF - extract a tag name suitable for getElementsByTagName
|
|
375
371
|
*
|
|
@@ -379,7 +375,7 @@ class XPath {
|
|
|
379
375
|
* non-element nodes. This can boost
|
|
380
376
|
* performance. This is false by default.
|
|
381
377
|
*/
|
|
382
|
-
xPathExtractTagNameFromNodeTest(nodetest, ignoreNonElementNodesForNTA) {
|
|
378
|
+
XPath.prototype.xPathExtractTagNameFromNodeTest = function (nodetest, ignoreNonElementNodesForNTA) {
|
|
383
379
|
if (nodetest instanceof node_test_name_1.NodeTestName) {
|
|
384
380
|
return nodetest.name;
|
|
385
381
|
}
|
|
@@ -387,24 +383,24 @@ class XPath {
|
|
|
387
383
|
nodetest instanceof node_test_element_or_attribute_1.NodeTestElementOrAttribute) {
|
|
388
384
|
return '*';
|
|
389
385
|
}
|
|
390
|
-
}
|
|
391
|
-
xPathMatchStack(stack, pattern) {
|
|
386
|
+
};
|
|
387
|
+
XPath.prototype.xPathMatchStack = function (stack, pattern) {
|
|
392
388
|
// NOTE(mesch): The stack matches for variable cardinality are
|
|
393
389
|
// greedy but don't do backtracking. This would be an issue only
|
|
394
390
|
// with rules of the form A* A, i.e. with an element with variable
|
|
395
391
|
// cardinality followed by the same element. Since that doesn't
|
|
396
392
|
// occur in the grammar at hand, all matches on the stack are
|
|
397
393
|
// unambiguous.
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
394
|
+
var S = stack.length;
|
|
395
|
+
var P = pattern.length;
|
|
396
|
+
var p;
|
|
397
|
+
var s;
|
|
398
|
+
var match = [];
|
|
403
399
|
match.matchlength = 0;
|
|
404
|
-
|
|
400
|
+
var ds = 0;
|
|
405
401
|
for (p = P - 1, s = S - 1; p >= 0 && s >= 0; --p, s -= ds) {
|
|
406
402
|
ds = 0;
|
|
407
|
-
|
|
403
|
+
var qmatch = [];
|
|
408
404
|
if (pattern[p] == tokens_1.Q_MM) {
|
|
409
405
|
p -= 1;
|
|
410
406
|
match.push(qmatch);
|
|
@@ -446,7 +442,7 @@ class XPath {
|
|
|
446
442
|
return [];
|
|
447
443
|
}
|
|
448
444
|
(0, util_1.reverseInplace)(qmatch);
|
|
449
|
-
qmatch.expr = (0, util_1.mapExpr)(qmatch, (m)
|
|
445
|
+
qmatch.expr = (0, util_1.mapExpr)(qmatch, function (m) { return m.expr; });
|
|
450
446
|
}
|
|
451
447
|
(0, util_1.reverseInplace)(match);
|
|
452
448
|
if (p == -1) {
|
|
@@ -455,20 +451,23 @@ class XPath {
|
|
|
455
451
|
else {
|
|
456
452
|
return [];
|
|
457
453
|
}
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
454
|
+
};
|
|
455
|
+
/**
|
|
456
|
+
* The entry point for the parser.
|
|
457
|
+
* @param expr a string that contains an XPath expression.
|
|
458
|
+
* @param xPathLog TODO
|
|
459
|
+
* @returns an expression object that can be evaluated with an
|
|
460
|
+
* expression context.
|
|
461
|
+
*/
|
|
462
|
+
XPath.prototype.xPathParse = function (expr, xPathLog) {
|
|
463
|
+
if (xPathLog === void 0) { xPathLog = function (message) {
|
|
464
|
+
// console.log(message);
|
|
465
|
+
}; }
|
|
466
|
+
xPathLog("parse ".concat(expr));
|
|
467
|
+
this.xPathParseInit(xPathLog);
|
|
468
|
+
var cached = this.xPathCacheLookup(expr);
|
|
470
469
|
if (cached) {
|
|
471
|
-
|
|
470
|
+
xPathLog(' ... cached');
|
|
472
471
|
return cached;
|
|
473
472
|
}
|
|
474
473
|
// Optimize for a few common cases: simple attribute node tests
|
|
@@ -477,38 +476,38 @@ class XPath {
|
|
|
477
476
|
// step is a plain element node test
|
|
478
477
|
// (page/overlay/locations/location).
|
|
479
478
|
if (expr.match(/^(\$|@)?\w+$/i)) {
|
|
480
|
-
|
|
479
|
+
var ret = this.makeSimpleExpr(expr);
|
|
481
480
|
this.xPathParseCache[expr] = ret;
|
|
482
|
-
|
|
481
|
+
xPathLog(' ... simple');
|
|
483
482
|
return ret;
|
|
484
483
|
}
|
|
485
484
|
if (expr.match(/^\w+(\/\w+)*$/i)) {
|
|
486
|
-
|
|
485
|
+
var ret = this.makeSimpleExpr2(expr);
|
|
487
486
|
this.xPathParseCache[expr] = ret;
|
|
488
|
-
|
|
487
|
+
xPathLog(' ... simple 2');
|
|
489
488
|
return ret;
|
|
490
489
|
}
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
490
|
+
var cachekey = expr; // expr is modified during parse
|
|
491
|
+
var stack = [];
|
|
492
|
+
var ahead = null;
|
|
493
|
+
var previous = null;
|
|
494
|
+
var done = false;
|
|
495
|
+
var parse_count = 0;
|
|
496
|
+
var lexer_count = 0;
|
|
497
|
+
var reduce_count = 0;
|
|
499
498
|
while (!done) {
|
|
500
499
|
parse_count++;
|
|
501
500
|
expr = expr.replace(/^\s*/, '');
|
|
502
501
|
previous = ahead;
|
|
503
502
|
ahead = null;
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
for (
|
|
507
|
-
|
|
503
|
+
var rule = null;
|
|
504
|
+
var match = '';
|
|
505
|
+
for (var i = 0; i < tokens_1.xpathTokenRules.length; ++i) {
|
|
506
|
+
var result_1 = tokens_1.xpathTokenRules[i].re.exec(expr);
|
|
508
507
|
lexer_count++;
|
|
509
|
-
if (
|
|
508
|
+
if (result_1 && result_1.length > 0 && result_1[0].length > match.length) {
|
|
510
509
|
rule = tokens_1.xpathTokenRules[i];
|
|
511
|
-
match =
|
|
510
|
+
match = result_1[0];
|
|
512
511
|
break;
|
|
513
512
|
}
|
|
514
513
|
}
|
|
@@ -536,38 +535,38 @@ class XPath {
|
|
|
536
535
|
}
|
|
537
536
|
if (rule) {
|
|
538
537
|
expr = expr.substr(match.length);
|
|
539
|
-
|
|
538
|
+
xPathLog("token: ".concat(match, " -- ").concat(rule.label));
|
|
540
539
|
ahead = {
|
|
541
540
|
tag: rule,
|
|
542
|
-
match,
|
|
541
|
+
match: match,
|
|
543
542
|
prec: rule.prec ? rule.prec : 0,
|
|
544
543
|
expr: this.makeTokenExpr(match)
|
|
545
544
|
};
|
|
546
545
|
}
|
|
547
546
|
else {
|
|
548
|
-
|
|
547
|
+
xPathLog('DONE');
|
|
549
548
|
done = true;
|
|
550
549
|
}
|
|
551
|
-
while (this.xPathReduce(stack, ahead,
|
|
550
|
+
while (this.xPathReduce(stack, ahead, xPathLog)) {
|
|
552
551
|
reduce_count++;
|
|
553
|
-
|
|
552
|
+
xPathLog("stack: ".concat(this.stackToString(stack)));
|
|
554
553
|
}
|
|
555
554
|
}
|
|
556
|
-
|
|
555
|
+
xPathLog("stack: ".concat(this.stackToString(stack)));
|
|
557
556
|
// DGF any valid XPath should "reduce" to a single Expr token
|
|
558
557
|
if (stack.length != 1) {
|
|
559
|
-
throw
|
|
558
|
+
throw "XPath parse error ".concat(cachekey, ":\n").concat(this.stackToString(stack));
|
|
560
559
|
}
|
|
561
|
-
|
|
560
|
+
var result = stack[0].expr;
|
|
562
561
|
this.xPathParseCache[cachekey] = result;
|
|
563
|
-
|
|
562
|
+
xPathLog("XPath parse: ".concat(parse_count, " / ").concat(lexer_count, " / ").concat(reduce_count));
|
|
564
563
|
return result;
|
|
565
|
-
}
|
|
566
|
-
xPathParseInit(
|
|
564
|
+
};
|
|
565
|
+
XPath.prototype.xPathParseInit = function (xPathLog) {
|
|
567
566
|
if (this.xPathRules.length) {
|
|
568
567
|
return;
|
|
569
568
|
}
|
|
570
|
-
|
|
569
|
+
var xpathNonTerminals = [
|
|
571
570
|
xpath_grammar_rules_1.XPathLocationPath,
|
|
572
571
|
xpath_grammar_rules_1.XPathRelativeLocationPath,
|
|
573
572
|
xpath_grammar_rules_1.XPathAbsoluteLocationPath,
|
|
@@ -589,9 +588,9 @@ class XPath {
|
|
|
589
588
|
// Some simple optimizations for the xpath expression parser: sort
|
|
590
589
|
// grammar rules descending by length, so that the longest match is
|
|
591
590
|
// first found.
|
|
592
|
-
this.xPathGrammarRules.sort((a, b)
|
|
593
|
-
|
|
594
|
-
|
|
591
|
+
this.xPathGrammarRules.sort(function (a, b) {
|
|
592
|
+
var la = a[1].length;
|
|
593
|
+
var lb = b[1].length;
|
|
595
594
|
if (la < lb) {
|
|
596
595
|
return 1;
|
|
597
596
|
}
|
|
@@ -602,14 +601,14 @@ class XPath {
|
|
|
602
601
|
return 0;
|
|
603
602
|
}
|
|
604
603
|
});
|
|
605
|
-
|
|
606
|
-
for (
|
|
604
|
+
var k = 1;
|
|
605
|
+
for (var i = 0; i < xpathNonTerminals.length; ++i) {
|
|
607
606
|
xpathNonTerminals[i].key = k++;
|
|
608
607
|
}
|
|
609
|
-
for (
|
|
608
|
+
for (var i = 0; i < tokens_1.xpathTokenRules.length; ++i) {
|
|
610
609
|
tokens_1.xpathTokenRules[i].key = k++;
|
|
611
610
|
}
|
|
612
|
-
|
|
611
|
+
xPathLog("XPath parse INIT: ".concat(k, " rules"));
|
|
613
612
|
// Another slight optimization: sort the rules into bins according
|
|
614
613
|
// to the last element (observing quantifiers), so we can restrict
|
|
615
614
|
// the match against the stack to the subest of rules that match the
|
|
@@ -624,10 +623,10 @@ class XPath {
|
|
|
624
623
|
}
|
|
625
624
|
array[position].push(element);
|
|
626
625
|
}
|
|
627
|
-
for (
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
for (
|
|
626
|
+
for (var i = 0; i < this.xPathGrammarRules.length; ++i) {
|
|
627
|
+
var rule = this.xPathGrammarRules[i];
|
|
628
|
+
var pattern = rule[1];
|
|
629
|
+
for (var j = pattern.length - 1; j >= 0; --j) {
|
|
631
630
|
if (pattern[j] == tokens_1.Q_1M) {
|
|
632
631
|
push_(this.xPathRules, pattern[j - 1].key, rule);
|
|
633
632
|
break;
|
|
@@ -642,15 +641,15 @@ class XPath {
|
|
|
642
641
|
}
|
|
643
642
|
}
|
|
644
643
|
}
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
(0, util_1.mapExec)(this.xPathRules, (i)
|
|
644
|
+
xPathLog("XPath parse INIT: ".concat(this.xPathRules.length, " rule bins"));
|
|
645
|
+
var sum = 0;
|
|
646
|
+
(0, util_1.mapExec)(this.xPathRules, function (i) {
|
|
648
647
|
if (i) {
|
|
649
648
|
sum += i.length;
|
|
650
649
|
}
|
|
651
650
|
});
|
|
652
|
-
|
|
653
|
-
}
|
|
651
|
+
xPathLog("XPath parse INIT: ".concat(sum / this.xPathRules.length, " average bin size"));
|
|
652
|
+
};
|
|
654
653
|
/*DGF xpathReduce is where the magic happens in this parser.
|
|
655
654
|
Skim down to the bottom of this file to find the table of
|
|
656
655
|
grammatical rules and precedence numbers, "The productions of the grammar".
|
|
@@ -676,22 +675,23 @@ class XPath {
|
|
|
676
675
|
Some tokens have left associativity, in which case we shift when they
|
|
677
676
|
have LOWER precedence than the candidate.
|
|
678
677
|
*/
|
|
679
|
-
xPathReduce(stack, ahead, xpathLog
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
678
|
+
XPath.prototype.xPathReduce = function (stack, ahead, xpathLog) {
|
|
679
|
+
if (xpathLog === void 0) { xpathLog = function (message) {
|
|
680
|
+
// console.log(message);
|
|
681
|
+
}; }
|
|
682
|
+
var cand = null;
|
|
683
683
|
if (stack.length > 0) {
|
|
684
|
-
|
|
685
|
-
|
|
684
|
+
var top_1 = stack[stack.length - 1];
|
|
685
|
+
var ruleset = this.xPathRules[top_1.tag.key];
|
|
686
686
|
if (ruleset) {
|
|
687
|
-
for (
|
|
688
|
-
|
|
689
|
-
|
|
687
|
+
for (var i = 0; i < ruleset.length; ++i) {
|
|
688
|
+
var rule = ruleset[i];
|
|
689
|
+
var match = this.xPathMatchStack(stack, rule[1]);
|
|
690
690
|
if (match.length) {
|
|
691
691
|
cand = {
|
|
692
692
|
tag: rule[0],
|
|
693
|
-
rule,
|
|
694
|
-
match
|
|
693
|
+
rule: rule,
|
|
694
|
+
match: match
|
|
695
695
|
};
|
|
696
696
|
cand.prec = this.xPathGrammarPrecedence(cand);
|
|
697
697
|
break;
|
|
@@ -699,44 +699,45 @@ class XPath {
|
|
|
699
699
|
}
|
|
700
700
|
}
|
|
701
701
|
}
|
|
702
|
-
|
|
702
|
+
var ret;
|
|
703
703
|
if (cand && (!ahead || cand.prec > ahead.prec || (ahead.tag.left && cand.prec >= ahead.prec))) {
|
|
704
|
-
for (
|
|
704
|
+
for (var i = 0; i < cand.match.matchlength; ++i) {
|
|
705
705
|
stack.pop();
|
|
706
706
|
}
|
|
707
|
-
xpathLog(
|
|
708
|
-
|
|
709
|
-
xpathLog(
|
|
707
|
+
xpathLog("reduce ".concat(cand.tag.label, " ").concat(cand.prec, " ahead ").concat(ahead ? ahead.tag.label + ' ' + ahead.prec + (ahead.tag.left ? ' left' : '') : ' none '));
|
|
708
|
+
var matchexpr = (0, util_1.mapExpr)(cand.match, function (m) { return m.expr; });
|
|
709
|
+
xpathLog("going to apply ".concat(cand.rule[3]));
|
|
710
710
|
cand.expr = cand.rule[3].apply(this, matchexpr);
|
|
711
711
|
stack.push(cand);
|
|
712
712
|
ret = true;
|
|
713
713
|
}
|
|
714
714
|
else {
|
|
715
715
|
if (ahead) {
|
|
716
|
-
xpathLog(
|
|
716
|
+
xpathLog("shift ".concat(ahead.tag.label, " ").concat(ahead.prec).concat(ahead.tag.left ? ' left' : '', " over ").concat(cand ? cand.tag.label + ' ' + cand.prec : ' none'));
|
|
717
717
|
stack.push(ahead);
|
|
718
718
|
}
|
|
719
719
|
ret = false;
|
|
720
720
|
}
|
|
721
721
|
return ret;
|
|
722
|
-
}
|
|
722
|
+
};
|
|
723
723
|
// Utility function to sort a list of nodes. Used by xsltSort() and
|
|
724
724
|
// nxslSelect().
|
|
725
|
-
xPathSort(
|
|
725
|
+
XPath.prototype.xPathSort = function (context, sort) {
|
|
726
726
|
if (sort.length == 0) {
|
|
727
727
|
return;
|
|
728
728
|
}
|
|
729
|
-
|
|
730
|
-
for (
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
node,
|
|
729
|
+
var sortlist = [];
|
|
730
|
+
for (var i = 0; i < context.contextSize(); ++i) {
|
|
731
|
+
var node = context.nodelist[i];
|
|
732
|
+
var sortitem = {
|
|
733
|
+
node: node,
|
|
734
734
|
key: []
|
|
735
735
|
};
|
|
736
|
-
|
|
737
|
-
for (
|
|
738
|
-
|
|
739
|
-
|
|
736
|
+
var clonedContext = context.clone([node], 0);
|
|
737
|
+
for (var _i = 0, sort_1 = sort; _i < sort_1.length; _i++) {
|
|
738
|
+
var s = sort_1[_i];
|
|
739
|
+
var value = s.expr.evaluate(clonedContext);
|
|
740
|
+
var evalue = void 0;
|
|
740
741
|
if (s.type == 'text') {
|
|
741
742
|
evalue = value.stringValue();
|
|
742
743
|
}
|
|
@@ -758,13 +759,13 @@ class XPath {
|
|
|
758
759
|
sortlist.push(sortitem);
|
|
759
760
|
}
|
|
760
761
|
sortlist.sort(this.xPathSortByKey);
|
|
761
|
-
|
|
762
|
-
for (
|
|
762
|
+
var nodes = [];
|
|
763
|
+
for (var i = 0; i < sortlist.length; ++i) {
|
|
763
764
|
nodes.push(sortlist[i].node);
|
|
764
765
|
}
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
}
|
|
766
|
+
context.nodelist = nodes;
|
|
767
|
+
context.setNode(0);
|
|
768
|
+
};
|
|
768
769
|
// Sorts by all order criteria defined. According to the JavaScript
|
|
769
770
|
// spec ([ECMA] Section 11.8.5), the compare operators compare strings
|
|
770
771
|
// as strings and numbers as numbers.
|
|
@@ -772,25 +773,25 @@ class XPath {
|
|
|
772
773
|
// NOTE: In browsers which do not follow the spec, this breaks only in
|
|
773
774
|
// the case that numbers should be sorted as strings, which is very
|
|
774
775
|
// uncommon.
|
|
775
|
-
xPathSortByKey(v1, v2) {
|
|
776
|
+
XPath.prototype.xPathSortByKey = function (v1, v2) {
|
|
776
777
|
// NOTE: Sort key vectors of different length never occur in
|
|
777
778
|
// xsltSort.
|
|
778
|
-
for (
|
|
779
|
-
|
|
779
|
+
for (var i = 0; i < v1.key.length; ++i) {
|
|
780
|
+
var o = v1.key[i].order == 'descending' ? -1 : 1;
|
|
780
781
|
if (v1.key[i].value > v2.key[i].value) {
|
|
781
782
|
return +1 * o;
|
|
782
783
|
}
|
|
783
|
-
|
|
784
|
+
if (v1.key[i].value < v2.key[i].value) {
|
|
784
785
|
return -1 * o;
|
|
785
786
|
}
|
|
786
787
|
}
|
|
787
788
|
return 0;
|
|
788
|
-
}
|
|
789
|
-
xPathStep(nodes, steps, step, input, ctx) {
|
|
790
|
-
|
|
791
|
-
|
|
789
|
+
};
|
|
790
|
+
XPath.prototype.xPathStep = function (nodes, steps, step, input, ctx) {
|
|
791
|
+
var s = steps[step];
|
|
792
|
+
var ctx2 = ctx.clone([input], 0);
|
|
792
793
|
if (ctx.returnOnFirstMatch && !s.hasPositionalPredicate) {
|
|
793
|
-
|
|
794
|
+
var nodelist = s.evaluate(ctx2).nodeSetValue();
|
|
794
795
|
// the predicates were not processed in the last evaluate(), so that we can
|
|
795
796
|
// process them here with the returnOnFirstMatch optimization. We do a
|
|
796
797
|
// depth-first grab at any nodes that pass the predicate tests. There is no
|
|
@@ -798,21 +799,20 @@ class XPath {
|
|
|
798
799
|
// indexes or uses of the last() or position() functions, because they
|
|
799
800
|
// typically require the entire nodelist for context. Process without
|
|
800
801
|
// optimization if we encounter such selectors.
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
nodelistLoop: for (
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
if (!s.predicate[j].evaluate(ctx.clone(n, i, nodelist)).booleanValue()) {
|
|
802
|
+
var nLength = nodelist.length;
|
|
803
|
+
var pLength = s.predicate.length;
|
|
804
|
+
nodelistLoop: for (var i = 0; i < nLength; ++i) {
|
|
805
|
+
for (var j = 0; j < pLength; ++j) {
|
|
806
|
+
if (!s.predicate[j].evaluate(ctx.clone(nodelist, i)).booleanValue()) {
|
|
807
807
|
continue nodelistLoop;
|
|
808
808
|
}
|
|
809
809
|
}
|
|
810
810
|
// n survived the predicate tests!
|
|
811
811
|
if (step == steps.length - 1) {
|
|
812
|
-
nodes.push(
|
|
812
|
+
nodes.push(nodelist[i]);
|
|
813
813
|
}
|
|
814
814
|
else {
|
|
815
|
-
this.xPathStep(nodes, steps, step + 1,
|
|
815
|
+
this.xPathStep(nodes, steps, step + 1, nodelist[i], ctx);
|
|
816
816
|
}
|
|
817
817
|
if (nodes.length > 0) {
|
|
818
818
|
break;
|
|
@@ -824,8 +824,8 @@ class XPath {
|
|
|
824
824
|
// behavior in StepExpr.prototype.evaluate is driven off its value. Note
|
|
825
825
|
// that the original context may still have true for this value.
|
|
826
826
|
ctx2.returnOnFirstMatch = false;
|
|
827
|
-
|
|
828
|
-
for (
|
|
827
|
+
var nodelist = s.evaluate(ctx2).nodeSetValue();
|
|
828
|
+
for (var i = 0; i < nodelist.length; ++i) {
|
|
829
829
|
if (step == steps.length - 1) {
|
|
830
830
|
nodes.push(nodelist[i]);
|
|
831
831
|
}
|
|
@@ -834,17 +834,17 @@ class XPath {
|
|
|
834
834
|
}
|
|
835
835
|
}
|
|
836
836
|
}
|
|
837
|
-
}
|
|
838
|
-
xPathGrammarPrecedence(frame) {
|
|
839
|
-
|
|
837
|
+
};
|
|
838
|
+
XPath.prototype.xPathGrammarPrecedence = function (frame) {
|
|
839
|
+
var ret = 0;
|
|
840
840
|
if (frame.rule) {
|
|
841
841
|
/* normal reduce */
|
|
842
842
|
if (frame.rule.length >= 3 && frame.rule[2] >= 0) {
|
|
843
843
|
ret = frame.rule[2];
|
|
844
844
|
}
|
|
845
845
|
else {
|
|
846
|
-
for (
|
|
847
|
-
|
|
846
|
+
for (var i = 0; i < frame.rule[1].length; ++i) {
|
|
847
|
+
var p = this.xPathTokenPrecedence(frame.rule[1][i]);
|
|
848
848
|
ret = Math.max(ret, p);
|
|
849
849
|
}
|
|
850
850
|
}
|
|
@@ -855,16 +855,17 @@ class XPath {
|
|
|
855
855
|
}
|
|
856
856
|
else if (frame.length) {
|
|
857
857
|
/* Q_ match */
|
|
858
|
-
for (
|
|
859
|
-
|
|
858
|
+
for (var j = 0; j < frame.length; ++j) {
|
|
859
|
+
var p = this.xPathGrammarPrecedence(frame[j]);
|
|
860
860
|
ret = Math.max(ret, p);
|
|
861
861
|
}
|
|
862
862
|
}
|
|
863
863
|
return ret;
|
|
864
|
-
}
|
|
865
|
-
xPathTokenPrecedence(tag) {
|
|
864
|
+
};
|
|
865
|
+
XPath.prototype.xPathTokenPrecedence = function (tag) {
|
|
866
866
|
return tag.prec || 2;
|
|
867
|
-
}
|
|
868
|
-
|
|
867
|
+
};
|
|
868
|
+
return XPath;
|
|
869
|
+
}());
|
|
869
870
|
exports.XPath = XPath;
|
|
870
871
|
//# sourceMappingURL=xpath.js.map
|