Error on trailing backslash by blakeembrey · Pull Request #434 · pillarjs/path-to-regexp (original) (raw)

Closes #433. Most straightforward approach that takes minimal bytes.

An alternative might be to re-introduce the consume function that throws an error itself, and tryConsume token by token, but I removed that a while back to reduce bytes and function call overhead. The main difference would come down to the error message, which using a tryConsume style approach would hit the universal error message and print something like Unexpected end at index 9, expected char from:

Unexpected <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mrow><mi>t</mi><mi>o</mi><mi>k</mi><mi>e</mi><mi>n</mi><mi mathvariant="normal">.</mi><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi></mrow><mi>a</mi><mi>t</mi><mi>i</mi><mi>n</mi><mi>d</mi><mi>e</mi><mi>x</mi></mrow><annotation encoding="application/x-tex">{token.type} at index </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord"><span class="mord mathnormal">t</span><span class="mord mathnormal">o</span><span class="mord mathnormal" style="margin-right:0.03148em;">k</span><span class="mord mathnormal">e</span><span class="mord mathnormal">n</span><span class="mord">.</span><span class="mord mathnormal">t</span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mord mathnormal">p</span><span class="mord mathnormal">e</span></span><span class="mord mathnormal">a</span><span class="mord mathnormal">t</span><span class="mord mathnormal">in</span><span class="mord mathnormal">d</span><span class="mord mathnormal">e</span><span class="mord mathnormal">x</span></span></span></span>{token.index}, expected ${endType}

I don't think adding the overhead back is worth it in this case, it's simpler to treat it as a one off error to handle.