Make tag last optional param everywhere (#1739)
* Make tag last optional param * Update all test assertions with correct tag format * Format ts * Some progress on tests and code mods * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu) * More sketch fixes * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu) * Only 1 test left * Clean up console.log * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu) * Fix last ts test * Clean up fmt * Fix clippy too * Update docs and fix small oversight on angled lines * Fix more rust tests * Make typescript happy * Fmt --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Jess Frazelle <jessfraz@users.noreply.github.com>
This commit is contained in:
@ -23,11 +23,7 @@ import {
|
||||
getNodePathFromSourceRange,
|
||||
isNodeSafeToReplace,
|
||||
} from './queryAst'
|
||||
import {
|
||||
addTagForSketchOnFace,
|
||||
getFirstArg,
|
||||
createFirstArg,
|
||||
} from './std/sketch'
|
||||
import { addTagForSketchOnFace } from './std/sketch'
|
||||
import { isLiteralArrayOrStatic } from './std/sketchcombos'
|
||||
import { DefaultPlaneStr } from 'clientSideScene/sceneEntities'
|
||||
import { roundOff } from 'lib/utils'
|
||||
@ -606,22 +602,25 @@ export function giveSketchFnCallTag(
|
||||
path,
|
||||
'CallExpression'
|
||||
)
|
||||
const firstArg = getFirstArg(primaryCallExp)
|
||||
const isTagExisting = !!firstArg.tag
|
||||
const tagValue = (firstArg.tag ||
|
||||
createLiteral(tag || findUniqueName(ast, 'seg', 2))) as Literal
|
||||
const tagStr = String(tagValue.value)
|
||||
const newFirstArg = createFirstArg(
|
||||
primaryCallExp.callee.name as ToolTip,
|
||||
firstArg.val,
|
||||
tagValue
|
||||
)
|
||||
primaryCallExp.arguments[0] = newFirstArg
|
||||
return {
|
||||
modifiedAst: ast,
|
||||
tag: tagStr,
|
||||
isTagExisting,
|
||||
pathToNode: path,
|
||||
// Tag is always 3rd expression now, using arg index feels brittle
|
||||
// but we can come up with a better way to identify tag later.
|
||||
const thirdArg = primaryCallExp.arguments?.[2]
|
||||
const tagLiteral =
|
||||
thirdArg || (createLiteral(tag || findUniqueName(ast, 'seg', 2)) as Literal)
|
||||
const isTagExisting = !!thirdArg
|
||||
if (!isTagExisting) {
|
||||
primaryCallExp.arguments[2] = tagLiteral
|
||||
}
|
||||
if ('value' in tagLiteral) {
|
||||
// Now TypeScript knows tagLiteral has a value property
|
||||
return {
|
||||
modifiedAst: ast,
|
||||
tag: String(tagLiteral.value),
|
||||
isTagExisting,
|
||||
pathToNode: path,
|
||||
}
|
||||
} else {
|
||||
throw new Error('Unable to assign tag without value')
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user