Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw, it might find a callExpression. So the `giveSketchFnCallTag` thought it was modifying a kwargs call, but it was actually modifying a positional call. This meant it tried to push a labeled argument in, rather than a normal arg, and a lot of other problems. Fixed by doing runtime typechecking.
This commit is contained in:
@ -1022,19 +1022,19 @@ export function giveSketchFnCallTag(
|
||||
| Error {
|
||||
const path = getNodePathFromSourceRange(ast, range)
|
||||
const maybeTag = (() => {
|
||||
const kwCallNode = getNodeFromPath<CallExpressionKw>(
|
||||
const callNode = getNodeFromPath<CallExpression | CallExpressionKw>(
|
||||
ast,
|
||||
path,
|
||||
'CallExpressionKw'
|
||||
['CallExpression', 'CallExpressionKw']
|
||||
)
|
||||
if (!err(kwCallNode)) {
|
||||
const { node: primaryCallExp } = kwCallNode
|
||||
if (!err(callNode) && callNode.node.type === 'CallExpressionKw') {
|
||||
const { node: primaryCallExp } = callNode
|
||||
const existingTag = findKwArg(ARG_TAG, primaryCallExp)
|
||||
const tagDeclarator =
|
||||
existingTag || createTagDeclarator(tag || findUniqueName(ast, 'seg', 2))
|
||||
const isTagExisting = !!existingTag
|
||||
if (!isTagExisting) {
|
||||
kwCallNode.node.arguments.push(createLabeledArg(ARG_TAG, tagDeclarator))
|
||||
callNode.node.arguments.push(createLabeledArg(ARG_TAG, tagDeclarator))
|
||||
}
|
||||
return { tagDeclarator, isTagExisting }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user