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:
@ -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
|
||||
|
Reference in New Issue
Block a user