|
62 | 62 | this.pselector = new PSelector(task[1]); |
63 | 63 | }; |
64 | 64 | PSelectorIfTask.prototype.target = true; |
| 65 | + Object.defineProperty(PSelectorIfTask.prototype, 'invalid', { |
| 66 | + get: function() { |
| 67 | + return this.pselector.invalid; |
| 68 | + } |
| 69 | + }); |
65 | 70 | PSelectorIfTask.prototype.exec = function(input) { |
66 | 71 | var output = []; |
67 | 72 | for ( var node of input ) { |
|
113 | 118 | [ ':xpath', PSelectorXpathTask ] |
114 | 119 | ]); |
115 | 120 | } |
116 | | - this.invalid = false; |
117 | 121 | this.raw = o.raw; |
118 | 122 | this.selector = o.selector; |
119 | 123 | this.tasks = []; |
|
125 | 129 | this.invalid = true; |
126 | 130 | break; |
127 | 131 | } |
128 | | - this.tasks.push(new ctor(task)); |
| 132 | + var pselector = new ctor(task); |
| 133 | + if ( pselector instanceof PSelectorIfTask && pselector.invalid ) { |
| 134 | + this.invalid = true; |
| 135 | + break; |
| 136 | + } |
| 137 | + this.tasks.push(pselector); |
129 | 138 | } |
130 | 139 | }; |
131 | 140 | PSelector.prototype.operatorToTaskMap = undefined; |
| 141 | + PSelector.prototype.invalid = false; |
132 | 142 | PSelector.prototype.prime = function(input) { |
133 | 143 | var root = input || docRegister; |
134 | 144 | if ( this.selector !== '' ) { |
|
145 | 155 | } |
146 | 156 | return nodes; |
147 | 157 | }; |
| 158 | + PSelector.prototype.test = function(input) { |
| 159 | + if ( this.invalid ) { return false; } |
| 160 | + var nodes = this.prime(input), AA = [ null ], aa; |
| 161 | + for ( var node of nodes ) { |
| 162 | + AA[0] = node; aa = AA; |
| 163 | + for ( var task of this.tasks ) { |
| 164 | + aa = task.exec(aa); |
| 165 | + if ( aa.length === 0 ) { break; } |
| 166 | + } |
| 167 | + if ( aa.length !== 0 ) { return true; } |
| 168 | + } |
| 169 | + return false; |
| 170 | + }; |
148 | 171 |
|
149 | 172 | var logOne = function(details, selector) { |
150 | 173 | loggerRegister.writeOne( |
|
0 commit comments