quick bugfix (#78)
This commit is contained in:
@ -347,6 +347,11 @@ export function splitPathAtLastIndex(pathToNode: PathToNode): {
|
|||||||
path: pathToNode.slice(0, -1),
|
path: pathToNode.slice(0, -1),
|
||||||
index: last,
|
index: last,
|
||||||
}
|
}
|
||||||
|
} else if (pathToNode.length === 0) {
|
||||||
|
return {
|
||||||
|
path: [],
|
||||||
|
index: -1,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return splitPathAtLastIndex(pathToNode.slice(0, -1))
|
return splitPathAtLastIndex(pathToNode.slice(0, -1))
|
||||||
}
|
}
|
||||||
|
@ -157,7 +157,7 @@ export function findAllPreviousVariables(
|
|||||||
const { node: bodyItems } = getNodeFromPath<Program['body']>(ast, bodyPath)
|
const { node: bodyItems } = getNodeFromPath<Program['body']>(ast, bodyPath)
|
||||||
|
|
||||||
const variables: PrevVariable<any>[] = []
|
const variables: PrevVariable<any>[] = []
|
||||||
bodyItems.forEach((item) => {
|
bodyItems?.forEach?.((item) => {
|
||||||
if (item.type !== 'VariableDeclaration' || item.end > sourceRange[0]) return
|
if (item.type !== 'VariableDeclaration' || item.end > sourceRange[0]) return
|
||||||
const varName = item.declarations[0].id.name
|
const varName = item.declarations[0].id.name
|
||||||
const varValue = programMemory?.root[varName]
|
const varValue = programMemory?.root[varName]
|
||||||
|
@ -1272,7 +1272,8 @@ export function addNewSketchLn({
|
|||||||
pathToNode,
|
pathToNode,
|
||||||
}: Omit<CreateLineFnCallArgs, 'from'>): { modifiedAst: Program } {
|
}: Omit<CreateLineFnCallArgs, 'from'>): { modifiedAst: Program } {
|
||||||
const node = JSON.parse(JSON.stringify(_node))
|
const node = JSON.parse(JSON.stringify(_node))
|
||||||
const { add, updateArgs } = sketchLineHelperMap[fnName]
|
const { add, updateArgs } = sketchLineHelperMap?.[fnName] || {}
|
||||||
|
if (!add || !updateArgs) throw new Error('not a sketch line helper')
|
||||||
const { node: varDec } = getNodeFromPath<VariableDeclarator>(
|
const { node: varDec } = getNodeFromPath<VariableDeclarator>(
|
||||||
node,
|
node,
|
||||||
pathToNode,
|
pathToNode,
|
||||||
|
Reference in New Issue
Block a user