microsoft / microsoft/vscode-textmate

`ruleStack.clone()` doesn't actually clone

Open
#228 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
678
Forks
135
Avg merge
1d 14h
Merged PRs (30d)
2

Description

The clone() function on StateStack doesn't actually clone the object, but instead just returns the original object (reference)
meaning, tokenizeLine() will still modify the ruleStack that I was given

https://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 the utils.ts file
https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/utils.ts#L7-L9

Found this out when the _enterPos and _anchorPos kept getting modified externally

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Inspect src/main.ts around tokenizeLine(), then read StateStack.clone() in src/grammar/grammar.ts and the clone helper in src/utils.ts. Verify that tokenization no longer mutates the supplied ruleStack, including its _enterPos and _anchorPos values, and add or run coverage for that behavior if the existing tests expose it.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.