Fix bug with undo startSketchOn removing existing sketch (#6834)

* Fix bug with `undo startSketchOn` removing existing sketch

Fixes #6822, I believe. in this case the `variableName` was not being
marked as in-use, so I just logged out the AST and made sure this case
was covered. @Irev-Dev this is probably worth a check from you.

* Add a regression test

It's an E2E test because I'm being lazy, but it should probably be an
XState unit test at some point.

* check what's checked

---------

Co-authored-by: Kurt Hutten <k.hutten@protonmail.ch>
This commit is contained in:
Frank Noirot
2025-05-12 02:55:39 -04:00
committed by GitHub
parent 1a325d0b29
commit 22857d77e9
2 changed files with 50 additions and 7 deletions

View File

@ -751,13 +751,22 @@ export const ModelingMachineProvider = ({
if (err(varDec)) return reject(new Error('No varDec'))
const variableName = varDec.node.declaration.id.name
let isIdentifierUsed = false
traverse(newAst, {
enter: (node) => {
if (node.type === 'Name' && node.name.name === variableName) {
isIdentifierUsed = true
}
},
})
const isInitAPipe =
varDec.node.declaration.init.type === 'PipeExpression'
if (isInitAPipe) {
isIdentifierUsed = true
} else {
traverse(newAst, {
enter: (node) => {
if (
node.type === 'Name' &&
node.name.name === variableName
) {
isIdentifierUsed = true
}
},
})
}
if (isIdentifierUsed) return
// remove body item at varDecIndex