Open RedCMD opened 9 months ago
This is intentional and is a technique to save memory.
The _enterPos
and _anchorPos
fields are used for temporary storage and they only make sense during tokenization of a line. No external user of the library should make any assumption about those two fields. Then, clone()
returns this
because all other fields are immutable. This is to save memory.
The
clone()
function onStateStack
doesn't actually clone the object, but instead just returns the original object (reference) meaning,tokenizeLine()
will still modify theruleStack
that I was givenhttps://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/main.ts#L262
Problem is that the clone implementation doesn't actually do any cloning https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/grammar/grammar.ts#L732-L734 instead something like
structuredClone()
should be used or use the clone function provided in theutils.ts
file https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/utils.ts#L7-L9Found this out when the
_enterPos
and_anchorPos
kept getting modified externally