Tree nodes are not properly generated if TreeBuffer is not ordered

I’ve been working on a custom language where I take a token list from an existing language server and transform it into a buffer, which I feed to Tree.build(). So far all of my nodes have been properly ordered, but a recent addition made a change where I end up with the nodes out of order. Here’s an example for what I mean:

// original buffer - ordered
[
  [nodeId, 0, 4, size],
  [nodeId, 5, 10, size],
  [parentId, 0, 10, size],
]

// new buffer - unordered
[
  [nodeId, 0, 4, size],
  [nodeId, 8, 12, size],
  [nodeId, 5, 6, size],
  [parentId, 0, 12, size],
]

I’ve noticed that the last node from [5,6] is not properly tokenized–it seems like it’s ignored or something like that. However, when I change the order (sort it):

[
  [nodeId, 0, 4, size],
  [nodeId, 5, 6, size],
  [nodeId, 8, 12, size],
  [parentId, 0, 12, size],
]

It works just fine. Is this a bug or does the buffer expect the incoming nodes to be properly sorted?

They are definitely expected to be sorted (in postfix order, as the docs state).

Ah, I have read the docs a bunch but seem to have always read around that line. Thank you!