Commit 6f4e6c1
Selectors that ran out of tokens before a bracket closed threw
`TypeError: Cannot read properties of undefined` instead of the parser's
own `Expected a closing ...` error. The error path already existed in each
case; it just could not be reached, because building the message
dereferenced the token that was missing.
parser().astSync('a]') // Expected an opening square bracket. (ok)
parser().astSync('a[href') // TypeError: ...reading '0'
Closing delimiters with no opener were already handled properly, so this
brings the two directions into line.
- attribute(): the while loop exits on either a closing bracket or end of
input, and the check after it assumed the former. Errors now point at the
opening bracket.
- namespace(): a trailing `|` with nothing after it now reaches the
existing unexpectedPipe(), which reports against currToken.
- parentheses(): the unbalanced branch falls back to the opening token.
No behaviour change for input that already parsed, and no existing error
message changes.
Tests assert the message rather than the type. exceptions.mjs already
covered this input shape via `throws("unclosed attribute selector", ...)`,
which passed throughout: `throws` falls back to `{instanceOf: Error}` when
no message is given, and TypeError satisfies that.
Co-authored-by: Max T. <git@moox.io>
1 parent 4d8437f commit 6f4e6c1
2 files changed
Lines changed: 39 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
10 | 32 | | |
11 | 33 | | |
12 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
164 | 169 | | |
165 | 170 | | |
166 | 171 | | |
| |||
707 | 712 | | |
708 | 713 | | |
709 | 714 | | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
710 | 720 | | |
711 | 721 | | |
712 | 722 | | |
| |||
740 | 750 | | |
741 | 751 | | |
742 | 752 | | |
| 753 | + | |
743 | 754 | | |
744 | 755 | | |
745 | 756 | | |
| |||
815 | 826 | | |
816 | 827 | | |
817 | 828 | | |
818 | | - | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
819 | 835 | | |
820 | 836 | | |
821 | 837 | | |
| |||
0 commit comments