The order enforced by `sort-alternatives` depends on characters outside the sorted alternatives
RunDevelopment opened this issue · comments
Description
Right now, alternatives are sorted 1) by the prefix returned by getLongestPrefix
and 2) by raw source code. The bug is that getLongestPrefix
will also possibly return one character after the alternatives, which means that the sort order of the alternatives depends not only on the alternatives but also on the characters after them. This has some surprising consequences. E.g. right now, sort-alternatives
will sort as follows:
var foo = /^(?:a|ab)a/u;
var foo = /^(?:ab|a)c/u;
I would classify this as a bug.
Fixing this issue will be quite easy. The RAA version of getLongestPrefix
in #415 has options that control its behavior. This includes an option to ensure that the prefix is only of the alternative and does not contain characters from after it.