Repository navigation
Commit 703b425
committed
fix(safe eval): support optional chaining
jsep parses `?.`, `?.[]` and `?.()` and marks the node `optional`, but
the safe evaluator ignored the flag. So under the default eval: "safe" a
filter such as $.books[?(@.meta?.tag === "x")] threw "Cannot read
properties of undefined (reading 'tag')" as soon as one item had no
`meta`, while eval: "native" returned the match.
A member or call link now returns a short-circuit marker when it is
optional and its object or callee is null or undefined; the outer links
pass it up and the whole chain evaluates to undefined, like in JS. The
object is now evaluated before the property and the callee before the
arguments (JS order), so a skipped `?.[expr]` or `?.(args)` does not run
`expr` or `args`.1 parent 970bdb2 commit 703b425
2 files changed
Lines changed: 114 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
153 | 168 | | |
154 | 169 | | |
155 | 170 | | |
| |||
182 | 197 | | |
183 | 198 | | |
184 | 199 | | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
| 200 | + | |
| 201 | + | |
189 | 202 | | |
190 | 203 | | |
191 | 204 | | |
| |||
196 | 209 | | |
197 | 210 | | |
198 | 211 | | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | 212 | | |
205 | 213 | | |
206 | 214 | | |
| |||
288 | 296 | | |
289 | 297 | | |
290 | 298 | | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
291 | 333 | | |
292 | 334 | | |
293 | 335 | | |
294 | 336 | | |
295 | 337 | | |
296 | 338 | | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
297 | 343 | | |
298 | 344 | | |
299 | 345 | | |
| |||
302 | 348 | | |
303 | 349 | | |
304 | 350 | | |
305 | | - | |
306 | 351 | | |
307 | 352 | | |
308 | 353 | | |
| |||
343 | 388 | | |
344 | 389 | | |
345 | 390 | | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
346 | 395 | | |
347 | | - | |
348 | 396 | | |
349 | 397 | | |
350 | 398 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
196 | 196 | | |
197 | 197 | | |
198 | 198 | | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
199 | 254 | | |
200 | 255 | | |
201 | 256 | | |
| |||
0 commit comments