|
3 | 3 |
|
4 | 4 | import test, { is, throws } from 'tst' |
5 | 5 | import { parse, nary, binary, unary } from '../justin.js' |
6 | | -import { compile, operator } from '../parse.js' |
| 6 | +import { compile, operator, cur, idx, seek } from '../parse.js' |
7 | 7 |
|
8 | 8 | const justin = s => compile(parse(s)) |
9 | 9 |
|
@@ -121,6 +121,27 @@ test('justin: optional chaining', () => { |
121 | 121 | is(justin('a?.b?.(arg)?.[c] ?. d')({ a: { b: d => [, , { d }] }, arg: 1, c: 2 }), 1) |
122 | 122 | }) |
123 | 123 |
|
| 124 | +test('justin: parse.space override reaches feature handlers', () => { |
| 125 | + const prevSpace = parse.space |
| 126 | + |
| 127 | + parse.space = () => { |
| 128 | + for (let cc; (cc = prevSpace()); ) { |
| 129 | + if (cc !== 35) return cc |
| 130 | + let i = idx + 1 |
| 131 | + while (cur[i] && cur.charCodeAt(i) !== 10) i++ |
| 132 | + seek(i) |
| 133 | + } |
| 134 | + return 0 |
| 135 | + } |
| 136 | + |
| 137 | + try { |
| 138 | + is(parse('a?.# custom\n[1]'), ['?.[]', 'a', [, 1]]) |
| 139 | + is(justin('a?.# custom\n[1]')({ a: [, 2] }), 2) |
| 140 | + } finally { |
| 141 | + parse.space = prevSpace |
| 142 | + } |
| 143 | +}) |
| 144 | + |
124 | 145 | test('justin: nullish coalescing', () => { |
125 | 146 | is(parse('a ?? b'), ['??', 'a', 'b']) |
126 | 147 | is(justin('a ?? b')({ a: null, b: 'default' }), 'default') |
|
0 commit comments