Coverage

95%
497
476
21

dom-util.js

93%
128
120
8
LineHitsSource
1// Generated by CoffeeScript 1.6.3
21(function() {
31 var DOMUtil, exports;
4
51 DOMUtil = (function() {
61 function DOMUtil(params) {
766 var _ref;
866 if (params == null) {
966 params = {};
10 }
1166 this.decode = (_ref = params != null ? params['decode'] : void 0) != null ? _ref : function(str) {
1210 return str;
13 };
14 }
15
161 DOMUtil.prototype.parse_html = function(html, options, callback) {
1718 var err, handler, parser, _ref;
1818 if (typeof options === 'function' && typeof callback !== 'function') {
194 _ref = [callback, options], options = _ref[0], callback = _ref[1];
20 }
2118 if (this.htmlparser == null) {
2218 try {
2318 this.htmlparser = require('htmlparser');
24 } catch (_error) {
250 err = _error;
260 callback(err, null);
27 }
28 }
2918 if (this.htmlparser != null) {
3018 handler = new this.htmlparser.DefaultHandler(function(err, domset) {
3118 if (err != null) {
320 return callback(err, null);
3318 } else if (Array.isArray(domset) && domset.length <= 1) {
3417 return callback(null, domset[0]);
35 } else {
361 return callback(null, domset);
37 }
38 });
3918 parser = new this.htmlparser.Parser(handler, options);
4018 return parser.parseComplete(html);
41 }
42 };
43
441 DOMUtil.prototype.as_node = function(nodeset) {
456 if (Array.isArray(nodeset)) {
464 return nodeset[0];
47 } else {
482 return nodeset;
49 }
50 };
51
521 DOMUtil.prototype.as_nodeset = function(node) {
53138 if (Array.isArray(node)) {
54123 return node;
5515 } else if (node != null) {
5614 return [node];
57 } else {
581 return [];
59 }
60 };
61
621 DOMUtil.prototype._kt = function() {
6327 return true;
64 };
65
661 DOMUtil.prototype.to_text = function(elt, filter) {
674 var buffer,
68 _this = this;
694 if (filter == null) {
703 filter = this._kt;
71 }
724 buffer = '';
734 this.walk_dom(elt, {
74 visit: function(node, node_metadata, all_metadata) {
7533 if (filter(node, node_metadata, all_metadata)) {
7632 if ((node != null ? node.type : void 0) === 'text' && ((node != null ? node.raw : void 0) != null)) {
7710 buffer += _this.decode(node.raw);
78 }
7932 return {
80 'continue': true,
81 'visit_children': true
82 };
83 } else {
841 return {
85 'continue': true,
86 'visit_children': false
87 };
88 }
89 }
90 });
914 return buffer;
92 };
93
941 DOMUtil.prototype.inner_text = function(elt, filter) {
951 return this.to_text(elt, filter);
96 };
97
981 DOMUtil.prototype.to_html = function(elt) {
994 var buffer;
1004 buffer = '';
1014 this.walk_dom(elt, {
102 visit: function(node) {
10336 var name, value, _ref;
10436 switch (node.type) {
105 case 'text':
10614 buffer += node.raw;
10714 break;
108 case 'tag':
10922 buffer += "<" + node.name;
11022 if (node.attribs != null) {
1118 _ref = node.attribs;
1128 for (name in _ref) {
1138 value = _ref[name];
1148 buffer += " " + name + "=\"" + value + "\"";
115 }
116 }
11722 buffer += ">";
118 }
11936 return true;
120 },
121 after_visit: function(node) {
12236 switch (node.type) {
123 case 'tag':
12422 buffer += "</" + node.name + ">";
125 }
12636 return true;
127 }
128 });
1294 return buffer;
130 };
131
1321 DOMUtil.prototype.inner_html = function(elt) {
1332 var buffer, node, _i, _len;
1342 buffer = null;
1352 if (Array.isArray(elt)) {
1360 buffer = '';
1370 for (_i = 0, _len = elt.length; _i < _len; _i++) {
1380 node = elt[_i];
1390 if (node.children != null) {
1400 buffer += this.to_html(node.children);
141 }
142 }
1432 } else if ((elt != null ? elt.children : void 0) != null) {
1442 buffer = this.to_html(elt.children);
145 }
1462 return buffer;
147 };
148
1491 DOMUtil.prototype.walk_dom = function(dom, callbacks) {
150133 var dom_metadata, node, node_metadata, nodes, should_continue, sib_index, _i, _len, _results;
151133 if (typeof callbacks === 'function') {
1525 callbacks = {
153 visit: callbacks
154 };
155 }
156133 nodes = this.as_nodeset(dom);
157133 dom_metadata = [];
158133 _results = [];
159133 for (sib_index = _i = 0, _len = nodes.length; _i < _len; sib_index = ++_i) {
160136 node = nodes[sib_index];
161136 node_metadata = {
162 parent: null,
163 path: [],
164 siblings: nodes,
165 sib_index: sib_index
166 };
167136 node._stew_node_id = dom_metadata.length;
168136 dom_metadata.push(node_metadata);
169136 should_continue = this._unguarded_walk_dom(node, node_metadata, dom_metadata, callbacks);
170136 if (!should_continue) {
1715 break;
172 } else {
173131 _results.push(void 0);
174 }
175 }
176133 return _results;
177 };
178
1791 DOMUtil.prototype._unguarded_walk_dom = function(node, node_metadata, dom_metadata, callbacks) {
1803988 var child, index, new_node_metadata, new_path, response, should_continue, _i, _len, _ref;
1813988 response = {
182 'continue': true,
183 'visit_children': true
184 };
1853988 if (callbacks.visit != null) {
1863988 response = callbacks.visit(node, node_metadata, dom_metadata);
187 }
1883988 if (response === true || (response != null ? response['continue'] : void 0) === true || ((response != null ? response['continue'] : void 0) == null)) {
1893983 if ((node.children != null) && (response === true || (response != null ? response['visit_children'] : void 0) === true || ((response != null ? response['visit_children'] : void 0) == null))) {
1901725 new_path = [].concat(node_metadata.path);
1911725 new_path.push(node);
1921725 _ref = node.children;
1931725 for (index = _i = 0, _len = _ref.length; _i < _len; index = ++_i) {
1943852 child = _ref[index];
1953852 new_node_metadata = {
196 parent: node,
197 path: new_path,
198 siblings: node.children,
199 sib_index: index
200 };
2013852 child._stew_node_id = dom_metadata.length;
2023852 dom_metadata.push(new_node_metadata);
2033852 should_continue = this._unguarded_walk_dom(child, new_node_metadata, dom_metadata, callbacks);
2043852 if (!should_continue) {
20517 return false;
206 }
207 }
208 }
2093966 if (callbacks['after_visit'] != null) {
21036 response = callbacks.after_visit(node, node_metadata, dom_metadata);
21136 return response === true || (response != null ? response['continue'] : void 0) === true || ((response != null ? response['continue'] : void 0) == null);
212 } else {
2133930 return true;
214 }
215 } else {
2165 return false;
217 }
218 };
219
2201 return DOMUtil;
221
222 })();
223
2241 exports = exports != null ? exports : this;
225
2261 exports.DOMUtil = DOMUtil;
227
228}).call(this);

predicate-factory.js

97%
167
162
5
LineHitsSource
1// Generated by CoffeeScript 1.6.3
21(function() {
31 var PredicateFactory, exports,
4404 __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
5
61 PredicateFactory = (function() {
71 function PredicateFactory() {
849 this.by_attr_value_pipe_equals = __bind(this.by_attr_value_pipe_equals, this);
949 this.by_attr_value_predicate = __bind(this.by_attr_value_predicate, this);
1049 this.by_attr_exists_predicate = __bind(this.by_attr_exists_predicate, this);
1149 this.by_id_predicate = __bind(this.by_id_predicate, this);
1249 this.by_class_predicate = __bind(this.by_class_predicate, this);
13 }
14
151 PredicateFactory.prototype.and_predicate = function(predicates) {
16166 return function(node, node_metadata, dom_metadata) {
174106 var predicate, _i, _len;
184106 for (_i = 0, _len = predicates.length; _i < _len; _i++) {
194421 predicate = predicates[_i];
204421 if (!predicate(node, node_metadata, dom_metadata)) {
213760 return false;
22 }
23 }
24346 return true;
25 };
26 };
27
281 PredicateFactory.prototype.or_predicate = function(predicates) {
292 return function(node, node_metadata, dom_metadata) {
3066 var predicate, _i, _len;
3166 for (_i = 0, _len = predicates.length; _i < _len; _i++) {
32128 predicate = predicates[_i];
33128 if (predicate(node, node_metadata, dom_metadata)) {
348 return true;
35 }
36 }
3758 return false;
38 };
39 };
40
411 PredicateFactory.prototype.by_attribute_predicate = function(attrname, attrvalue, valuedelim) {
42159 var np, vp;
43159 if (attrvalue == null) {
448 attrvalue = null;
45 }
46159 if (valuedelim == null) {
4788 valuedelim = null;
48 }
49159 if (typeof attrname === 'string') {
50154 np = function(str) {
511023 return str === attrname;
52 };
53 } else {
545 np = function(str) {
556 return attrname.test(str);
56 };
57 }
58159 if (attrvalue === null) {
598 vp = null;
60151 } else if (typeof attrvalue === 'string') {
6174 attrvalue = attrvalue.replace(/\\\"/g, '"');
6274 vp = function(str) {
63240 return str === attrvalue;
64 };
6577 } else if ((attrvalue != null ? attrvalue.test : void 0) != null) {
6677 vp = function(str) {
67202 return attrvalue.test(str);
68 };
69 }
70159 return function(node) {
711004 var name, token, value, _i, _len, _ref, _ref1;
721004 _ref = node != null ? node.attribs : void 0;
731004 for (name in _ref) {
741029 value = _ref[name];
751029 if (np(name)) {
76350 if (vp === null) {
775 return true;
78 } else {
79345 if (valuedelim != null) {
80147 if (value != null) {
81146 _ref1 = value.split(valuedelim);
82146 for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
83244 token = _ref1[_i];
84244 if (vp(token)) {
8579 return true;
86 }
87 }
88 }
89 } else {
90198 if (vp(value)) {
91108 return true;
92 }
93 }
94 }
95 }
96 }
97812 return false;
98 };
99 };
100
1011 PredicateFactory.prototype.by_class_predicate = function(klass) {
10264 return this.by_attribute_predicate('class', klass, /\s+/);
103 };
104
1051 PredicateFactory.prototype.by_id_predicate = function(id) {
1068 return this.by_attribute_predicate('id', id);
107 };
108
1091 PredicateFactory.prototype.by_attr_exists_predicate = function(attrname) {
1108 return this.by_attribute_predicate(attrname, null);
111 };
112
1131 PredicateFactory.prototype.by_attr_value_predicate = function(attrname, attrvalue, valuedelim) {
11473 return this.by_attribute_predicate(attrname, attrvalue, valuedelim);
115 };
116
1171 PredicateFactory.prototype._escape_for_regexp = function(str) {
11810 return str.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
119 };
120
1211 PredicateFactory.prototype.by_attr_value_pipe_equals = function(attrname, attrvalue) {
1226 var modifier, regexp_source;
1236 if (typeof attrvalue === 'string') {
1242 regexp_source = this._escape_for_regexp(attrvalue);
1252 attrvalue = new RegExp("^" + regexp_source + "($|-)");
126 } else {
1274 regexp_source = attrvalue.source;
1284 modifier = '';
1294 if (attrvalue.ignoreCase) {
1301 modifier += 'i';
131 }
1324 if (attrvalue.global) {
1330 modifier += 'g';
134 }
1354 if (attrvalue.multiline) {
1360 modifier += 'm';
137 }
1384 if (!/^\^/.test(attrvalue.source)) {
1393 regexp_source = "^" + regexp_source;
140 }
1414 if (!/\(\$\|-\)$/.test(regexp_source)) {
1424 regexp_source = "" + regexp_source + "($|-)";
143 }
1444 attrvalue = new RegExp(regexp_source, modifier);
145 }
1466 return this.by_attribute_predicate(attrname, attrvalue);
147 };
148
1491 PredicateFactory.prototype.by_tag_predicate = function(name) {
150130 if (typeof name === 'string') {
151118 return function(node) {
1523073 return name === node.name;
153 };
154 } else {
15512 return function(node) {
156313 return name.test(node.name);
157 };
158 }
159 };
160
1611 PredicateFactory.prototype.first_child_predicate = function() {
1623 return this._first_child_impl;
163 };
164
1651 PredicateFactory.prototype._first_child_impl = function(node, node_metadata, dom_metadata) {
1669 var elt, _i, _len, _ref;
1679 if (node.type === 'tag' && (node_metadata.siblings != null)) {
1689 _ref = node_metadata.siblings;
1699 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
17017 elt = _ref[_i];
17117 if (elt.type === 'tag') {
1729 return node._stew_node_id === elt._stew_node_id;
173 }
174 }
175 }
1760 return false;
177 };
178
1791 PredicateFactory.prototype.any_tag_predicate = function() {
1804 return this._any_tag_impl;
181 };
182
1831 PredicateFactory.prototype._any_tag_impl = function(node) {
18479 return (node != null ? node.type : void 0) === 'tag';
185 };
186
1871 PredicateFactory.prototype.descendant_predicate = function(predicates) {
188123 if (predicates.length === 1) {
189100 return predicates[0];
190 } else {
19123 return function(node, node_metadata, dom_metadata) {
192700 var cloned_path, cloned_predicates;
193700 if (predicates[predicates.length - 1](node, node_metadata, dom_metadata)) {
19478 cloned_path = [].concat(node_metadata.path);
19578 cloned_predicates = [].concat(predicates);
19678 cloned_predicates.pop();
19778 while (cloned_path.length > 0) {
198132 node = cloned_path.pop();
199132 node_metadata = dom_metadata[node._stew_node_id];
200132 if (cloned_predicates[cloned_predicates.length - 1](node, node_metadata, dom_metadata)) {
20156 cloned_predicates.pop();
20256 if (cloned_predicates.length === 0) {
20353 return true;
2040 break;
205 }
206 }
207 }
208 }
209647 return false;
210 };
211 }
212 };
213
2141 PredicateFactory.prototype.direct_descendant_predicate = function(parent_selector, child_selector) {
2153 return function(node, node_metadata, dom_metadata) {
21699 var parent, parent_metadata;
21799 if (child_selector(node, node_metadata, dom_metadata)) {
21818 parent = node_metadata.parent;
21918 parent_metadata = dom_metadata[parent._stew_node_id];
22018 return parent_selector(parent, parent_metadata, dom_metadata);
221 }
22281 return false;
223 };
224 };
225
2261 PredicateFactory.prototype.adjacent_sibling_predicate = function(first, second) {
2275 return function(node, node_metadata, dom_metadata) {
228165 var prev_tag, prev_tag_index;
229165 if (second(node, node_metadata, dom_metadata)) {
23020 prev_tag_index = node_metadata.sib_index - 1;
23120 while (prev_tag_index > 0) {
23222 if (node_metadata.siblings[prev_tag_index].type === 'tag') {
23311 prev_tag = node_metadata.siblings[prev_tag_index];
23411 return first(prev_tag, dom_metadata[prev_tag._stew_node_id], dom_metadata);
235 } else {
23611 prev_tag_index -= 1;
237 }
238 }
239 }
240154 return false;
241 };
242 };
243
2441 PredicateFactory.prototype.preceding_sibling_predicate = function(first, second) {
2454 return function(node, node_metadata, dom_metadata) {
24676 var index, prev, _i, _len, _ref;
24776 if (second(node, node_metadata, dom_metadata)) {
2484 _ref = node_metadata.siblings;
2494 for (index = _i = 0, _len = _ref.length; _i < _len; index = ++_i) {
2508 prev = _ref[index];
2518 if (index === node_metadata.sib_index) {
2520 return false;
2538 } else if (prev.type === 'tag') {
2544 if (first(prev, dom_metadata[prev._stew_node_id], dom_metadata)) {
2554 return true;
256 }
257 }
258 }
259 }
26072 return false;
261 };
262 };
263
2641 return PredicateFactory;
265
266 })();
267
2681 exports = exports != null ? exports : this;
269
2701 exports.PredicateFactory = PredicateFactory;
271
272}).call(this);

stew.js

96%
202
194
8
LineHitsSource
1// Generated by CoffeeScript 1.6.3
21(function() {
31 var DOMUtil, HOMEDIR, LIB_DIR, PredicateFactory, Stew, exports, fs, path;
4
51 fs = require('fs');
6
71 path = require('path');
8
91 HOMEDIR = path.join(__dirname, '..');
10
111 LIB_DIR = fs.existsSync(path.join(HOMEDIR, 'lib-cov')) ? path.join(HOMEDIR, 'lib-cov') : path.join(HOMEDIR, 'lib');
12
131 DOMUtil = require(path.join(LIB_DIR, 'dom-util')).DOMUtil;
14
151 PredicateFactory = require(path.join(LIB_DIR, 'predicate-factory')).PredicateFactory;
16
171 Stew = (function() {
181 var _ATTRIBUTES, _ATTR_NAME, _CLASSES, _DEQUOTED_ATTR_VALUE, _ID, _NAME, _NEVERQUOTED_ATTR_VALUE, _OPERATOR, _PSEUDO_CLASS, _SPLIT_ON_WS_REGEXP;
19
201 function Stew(dom_util) {
2148 this.factory = new PredicateFactory();
2248 this.dom_util = dom_util != null ? dom_util : new DOMUtil();
23 }
24
251 Stew.prototype.select = function(dom, selector, callback) {
26116 var nodeset,
27 _this = this;
28116 if (typeof selector === 'string') {
29116 selector = this._parse_selectors(selector);
30 }
31116 if (typeof dom === 'string') {
322 if (callback != null) {
331 return this.dom_util.parse_html(dom, function(err, dom) {
341 if (err != null) {
350 return callback(err);
36 } else {
371 return callback(null, _this._unguarded_select(dom, selector));
38 }
39 });
40 } else {
411 throw new Error('When select is invoked on a string object, the `callback(err,nodeset)` parameter is required.');
42 }
43 } else {
44114 nodeset = this._unguarded_select(dom, selector);
45114 if (typeof callback === "function") {
461 callback(null, nodeset);
47 }
48114 return nodeset;
49 }
50 };
51
521 Stew.prototype._unguarded_select = function(dom, predicate) {
53115 var result, visit;
54115 result = [];
55115 visit = function(node, parent, path, siblings, sib_index) {
563795 if (predicate(node, parent, path, siblings, sib_index)) {
57218 result.push(node);
58 }
593795 return {
60 'continue': true,
61 'visit_children': true
62 };
63 };
64115 this.dom_util.walk_dom(dom, {
65 visit: visit
66 });
67115 return result;
68 };
69
701 Stew.prototype.select_first = function(dom, selector, callback) {
716 var node,
72 _this = this;
736 if (typeof selector === 'string') {
746 selector = this._parse_selectors(selector);
75 }
766 if (typeof dom === 'string') {
772 if (callback != null) {
781 return this.dom_util.parse_html(dom, function(err, dom) {
791 if (err != null) {
800 return callback(err);
81 } else {
821 return callback(null, _this._unguarded_select_first(dom, selector));
83 }
84 });
85 } else {
861 throw new Error('When select_first is invoked on a string object, the `callback(err,node)` parameter is required.');
87 }
88 } else {
894 node = this._unguarded_select_first(dom, selector);
904 if (typeof callback === "function") {
911 callback(null, node);
92 }
934 return node;
94 }
95 };
96
971 Stew.prototype._unguarded_select_first = function(dom, predicate) {
985 var result, visit;
995 result = null;
1005 visit = function(node, parent, path, siblings, sib_index) {
10184 if (predicate(node, parent, path, siblings, sib_index)) {
1025 result = node;
1035 return {
104 'continue': false,
105 'visit_children': false
106 };
107 } else {
10879 return {
109 'continue': true,
110 'visit_children': true
111 };
112 }
113 };
1145 this.dom_util.walk_dom(dom, {
115 visit: visit
116 });
1175 return result;
118 };
119
1201 _SPLIT_ON_WS_REGEXP = /([^\"\/\s,\+>]|(\"[^\"]+\")|(\/[^\/]+\/)|(\[[^\]]*\]))+|[,\+~>]/g;
121
1221 Stew.prototype._split_on_ws_respecting_quotes = function(selector) {
123123 var result, token;
124123 result = [];
125123 while (true) {
126303 token = _SPLIT_ON_WS_REGEXP.exec(selector);
127303 if ((token != null ? token[0] : void 0) != null) {
128180 result.push(token[0]);
129 } else {
130123 break;
131 }
132 }
133123 return result;
134 };
135
1361 Stew.prototype._parse_selectors = function(selectors) {
137123 var adjacent_operator, child_operator, or_operator, preceding_sibling_operator, predicate, result, selector, _i, _len;
138123 result = [];
139123 if (typeof selectors === 'string') {
140123 selectors = this._split_on_ws_respecting_quotes(selectors);
141 }
142123 child_operator = false;
143123 adjacent_operator = false;
144123 preceding_sibling_operator = false;
145123 or_operator = false;
146123 for (_i = 0, _len = selectors.length; _i < _len; _i++) {
147180 selector = selectors[_i];
148180 if (selector === '>') {
1493 child_operator = true;
150177 } else if (selector === '+') {
1515 adjacent_operator = true;
152172 } else if (selector === '~') {
1534 preceding_sibling_operator = true;
154168 } else if (selector === ',') {
1552 or_operator = true;
156 } else {
157166 predicate = this._parse_selector(selector);
158166 if (child_operator) {
1593 result.push(this.factory.direct_descendant_predicate(result.pop(), predicate));
1603 child_operator = false;
161163 } else if (adjacent_operator) {
1625 result.push(this.factory.adjacent_sibling_predicate(result.pop(), predicate));
1635 adjacent_operator = false;
164158 } else if (preceding_sibling_operator) {
1654 result.push(this.factory.preceding_sibling_predicate(result.pop(), predicate));
1664 preceding_sibling_operator = false;
167154 } else if (or_operator) {
1682 result.push(this.factory.or_predicate([result.pop(), predicate]));
1692 or_operator = false;
170 } else {
171152 result.push(predicate);
172 }
173 }
174 }
175123 if (result.length > 0) {
176123 result = this.factory.descendant_predicate(result);
177 }
178123 return result;
179 };
180
1811 Stew.prototype._CSS_SELECTOR_REGEXP = /((\/[^\/]*\/[gmi]*)|(\*|[\w-]+))?(\#((\/[^\/]*\/[gmi]*)|([\w-]+)))?((\.((\/[^\/]*\/[gmi]*)|([\w-]+)))*)((\[((\/[^\/]*\/[gmi]*)|([\w-]+))(((=)|(~=)|(\|=)|(\*=)|(\^=)|(\$=))(("(([^\\"]|(\\"))*)")|((\/[^\/]*\/[gmi]*)|([\w- ]+))))?\])*)(:([\w-]+))?/;
182
1831 _NAME = 1;
184
1851 _ID = 4;
186
1871 _CLASSES = 8;
188
1891 _ATTRIBUTES = 13;
190
1911 _PSEUDO_CLASS = 35;
192
1931 Stew.prototype._ATTRIBUTE_CLAUSE_REGEXP = /(\[((\/[^\/]*\/[gmi]*)|([\w-]+))(((=)|(~=)|(\|=)|(\*=)|(\^=)|(\$=))(("(([^\\"]|(\\"))*)")|((\/[^\/]*\/[gmi]*)|([\w- ]+))))?\])/g;
194
1951 _ATTR_NAME = 2;
196
1971 _OPERATOR = 6;
198
1991 _DEQUOTED_ATTR_VALUE = 15;
200
2011 _NEVERQUOTED_ATTR_VALUE = 18;
202
2031 Stew.prototype._parse_selector = function(selector) {
204166 var attr_match, aval, c, clauses, cs, delim, match, modifier, regexp_source, _i, _len, _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6;
205166 match = this._CSS_SELECTOR_REGEXP.exec(selector);
206166 clauses = [];
207166 if (match[_NAME] != null) {
208134 if (match[_NAME] === '*') {
2094 clauses.push(this.factory.any_tag_predicate());
210 } else {
211130 clauses.push(this.factory.by_tag_predicate(this._to_string_or_regex(match[_NAME])));
212 }
213 }
214166 if (match[_ID] != null) {
2158 clauses.push(this.factory.by_id_predicate(this._to_string_or_regex(match[_ID].substring(1))));
216 }
217166 if (((_ref = match[_CLASSES]) != null ? _ref.length : void 0) > 0) {
21823 cs = match[_CLASSES].split('.');
21923 cs.shift();
22023 for (_i = 0, _len = cs.length; _i < _len; _i++) {
22128 c = cs[_i];
22228 clauses.push(this.factory.by_class_predicate(this._to_string_or_regex(c)));
223 }
224 }
225166 if (((_ref1 = match[_ATTRIBUTES]) != null ? _ref1.length : void 0) > 0) {
22664 attr_match = this._ATTRIBUTE_CLAUSE_REGEXP.exec(match[_ATTRIBUTES]);
22764 while (attr_match != null) {
22866 if ((attr_match[_ATTR_NAME] != null) && (attr_match[_OPERATOR] == null)) {
2294 clauses.push(this.factory.by_attr_exists_predicate(this._to_string_or_regex(attr_match[_ATTR_NAME])));
230 }
23166 if ((attr_match[_ATTR_NAME] != null) && (attr_match[_OPERATOR] != null) && ((attr_match[_DEQUOTED_ATTR_VALUE] != null) || (attr_match[_NEVERQUOTED_ATTR_VALUE] != null))) {
23262 delim = null;
23362 if (attr_match[_OPERATOR] === '~=') {
2347 delim = /\s+/;
235 }
23662 if (attr_match[_OPERATOR] === '|=') {
2376 clauses.push(this.factory.by_attr_value_pipe_equals(this._to_string_or_regex(attr_match[_ATTR_NAME]), this._to_string_or_regex((_ref2 = attr_match[_DEQUOTED_ATTR_VALUE]) != null ? _ref2 : attr_match[_NEVERQUOTED_ATTR_VALUE])));
23856 } else if (attr_match[_OPERATOR] === '^=') {
2397 aval = this._to_string_or_regex((_ref3 = attr_match[_DEQUOTED_ATTR_VALUE]) != null ? _ref3 : attr_match[_NEVERQUOTED_ATTR_VALUE]);
2407 if (typeof aval === 'string') {
2412 regexp_source = this.factory._escape_for_regexp(aval);
2422 aval = new RegExp("^" + regexp_source);
243 } else {
2445 regexp_source = aval.source;
2455 modifier = '';
2465 if (aval.ignoreCase) {
2470 modifier += 'i';
248 }
2495 if (aval.global) {
2500 modifier += 'g';
251 }
2525 if (aval.multiline) {
2530 modifier += 'm';
254 }
2555 if (!/^\^/.test(regexp_source)) {
2564 aval = new RegExp("^" + regexp_source);
257 }
258 }
2597 clauses.push(this.factory.by_attr_value_predicate(this._to_string_or_regex(attr_match[_ATTR_NAME]), aval));
26049 } else if (attr_match[_OPERATOR] === '$=') {
26112 aval = this._to_string_or_regex((_ref4 = attr_match[_DEQUOTED_ATTR_VALUE]) != null ? _ref4 : attr_match[_NEVERQUOTED_ATTR_VALUE]);
26212 if (typeof aval === 'string') {
2634 regexp_source = this.factory._escape_for_regexp(aval);
2644 aval = new RegExp("" + regexp_source + "$");
265 } else {
2668 regexp_source = aval.source;
2678 modifier = '';
2688 if (aval.ignoreCase) {
2690 modifier += 'i';
270 }
2718 if (aval.global) {
2720 modifier += 'g';
273 }
2748 if (aval.multiline) {
2750 modifier += 'm';
276 }
2778 if (!/\$$/.test(regexp_source)) {
2786 aval = new RegExp("" + regexp_source + "$");
279 }
280 }
28112 clauses.push(this.factory.by_attr_value_predicate(this._to_string_or_regex(attr_match[_ATTR_NAME]), aval));
28237 } else if (attr_match[_OPERATOR] === '*=') {
2834 aval = this._to_string_or_regex((_ref5 = attr_match[_DEQUOTED_ATTR_VALUE]) != null ? _ref5 : attr_match[_NEVERQUOTED_ATTR_VALUE]);
2844 if (typeof aval === 'string') {
2852 regexp_source = this.factory._escape_for_regexp(aval);
2862 aval = new RegExp(regexp_source);
287 }
2884 clauses.push(this.factory.by_attr_value_predicate(this._to_string_or_regex(attr_match[_ATTR_NAME]), aval));
289 } else {
29033 clauses.push(this.factory.by_attr_value_predicate(this._to_string_or_regex(attr_match[_ATTR_NAME]), this._to_string_or_regex((_ref6 = attr_match[_DEQUOTED_ATTR_VALUE]) != null ? _ref6 : attr_match[_NEVERQUOTED_ATTR_VALUE]), delim));
291 }
292 }
29366 attr_match = this._ATTRIBUTE_CLAUSE_REGEXP.exec(match[_ATTRIBUTES]);
294 }
295 }
296166 if (match[_PSEUDO_CLASS] != null) {
2973 if (match[_PSEUDO_CLASS] === 'first-child') {
2983 clauses.push(this.factory.first_child_predicate());
299 }
300 }
301166 if (clauses.length > 0) {
302166 clauses = this.factory.and_predicate(clauses);
303 }
304166 return clauses;
305 };
306
3071 Stew.prototype._to_string_or_regex = function(str) {
308294 var match;
309294 match = str.match(/^\/(.*)\/([gmi]*)$/);
310294 if ((match != null ? match[1] : void 0) != null) {
31156 return new RegExp(match[1], match[2]);
312 } else {
313238 return str;
314 }
315 };
316
3171 return Stew;
318
319 })();
320
3211 exports = exports != null ? exports : this;
322
3231 exports.Stew = Stew;
324
3251 exports.DOMUtil = DOMUtil;
326
327}).call(this);