Start changing JS codemods

This commit is contained in:
Adam Chalmers
2025-03-19 11:28:26 -05:00
parent e13ee69c40
commit 1125a6a1e6
5 changed files with 1321 additions and 1595 deletions

File diff suppressed because it is too large Load Diff

View File

@ -5,3 +5,8 @@ export const ARG_END_ABSOLUTE = 'endAbsolute'
export const ARG_CIRCLE_CENTER = 'center'
export const ARG_CIRCLE_RADIUS = 'radius'
export const DETERMINING_ARGS = [ARG_LENGTH, ARG_END, ARG_END_ABSOLUTE]
export const ARG_LENGTH_X = 'lengthX'
export const ARG_LENGTH_Y = 'lengthY'
export const ARG_ANGLE = 'angle'
export const ARG_END_ABSOLUTE_X = 'endAbsoluteX'
export const ARG_END_ABSOLUTE_Y = 'endAbsoluteY'

View File

@ -182,6 +182,7 @@ const commonConstraintInfoHelper = (
pathToNode: PathToNode,
filterValue?: string
) => {
console.warn('ADAM: Must be updated to handle angled line kw args')
if (callExp.type !== 'CallExpression' && callExp.type !== 'CallExpressionKw')
return []
const firstArg = (() => {
@ -235,39 +236,39 @@ const commonConstraintInfoHelper = (
const pathToFirstArg: PathToNode = isArr
? [...pathToArrayExpression, [0, 'index']]
: [
...pathToArrayExpression,
[
firstArg.properties.findIndex(
(a) => a.key.name === abbreviatedInputs[0].objInput
),
'index',
],
['value', 'Property'],
]
...pathToArrayExpression,
[
firstArg.properties.findIndex(
(a) => a.key.name === abbreviatedInputs[0].objInput
),
'index',
],
['value', 'Property'],
]
const pathToSecondArg: PathToNode = isArr
? [...pathToArrayExpression, [1, 'index']]
: [
...pathToArrayExpression,
[
firstArg.properties.findIndex(
(a) => a.key.name === abbreviatedInputs[1].objInput
),
'index',
],
['value', 'Property'],
]
...pathToArrayExpression,
[
firstArg.properties.findIndex(
(a) => a.key.name === abbreviatedInputs[1].objInput
),
'index',
],
['value', 'Property'],
]
const input1 = isArr
? firstArg.elements[0]
: firstArg.properties.find(
(a) => a.key.name === abbreviatedInputs[0].objInput
)?.value
(a) => a.key.name === abbreviatedInputs[0].objInput
)?.value
const input2 = isArr
? firstArg.elements[1]
: firstArg.properties.find(
(a) => a.key.name === abbreviatedInputs[1].objInput
)?.value
(a) => a.key.name === abbreviatedInputs[1].objInput
)?.value
const constraints: ConstrainInfo[] = []
if (input1)
@ -2169,7 +2170,7 @@ export const circleThreePoint: SketchLineHelperKw = {
return finalConstraints
},
}
export const angledLine: SketchLineHelper = {
export const angledLine: SketchLineHelperKw = {
add: ({ node, pathToNode, segmentInput, replaceExistingCallback }) => {
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
const { from, to } = segmentInput
@ -2181,12 +2182,13 @@ export const angledLine: SketchLineHelper = {
const newAngleVal = createLiteral(roundOff(getAngle(from, to), 0))
const newLengthVal = createLiteral(roundOff(getLength(from, to), 2))
const newLine = createCallExpression('angledLine', [
createArrayExpression([newAngleVal, newLengthVal]),
createPipeSubstitution(),
const newLine = createCallExpressionStdLibKw('angledLine', null, [
createLabeledArg('angle', newAngleVal),
createLabeledArg('length', newLengthVal),
])
if (replaceExistingCallback) {
console.warn('ADAM: Probably needs to be adjusted for kw args')
const { index: callIndex } = splitPathAtPipeExpression(pathToNode)
const result = replaceExistingCallback([
{
@ -2224,7 +2226,7 @@ export const angledLine: SketchLineHelper = {
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
const { to, from } = input
const _node = { ...node }
const nodeMeta = getNodeFromPath<CallExpression>(_node, pathToNode)
const nodeMeta = getNodeFromPath<CallExpressionKw>(_node, pathToNode)
if (err(nodeMeta)) return nodeMeta
const { node: callExpression } = nodeMeta
const angle = roundOff(getAngle(from, to), 0)
@ -2234,18 +2236,17 @@ export const angledLine: SketchLineHelper = {
const lengthLit = createLiteral(lineLength)
const firstArg = callExpression.arguments?.[0]
if (!mutateArrExp(firstArg, createArrayExpression([angleLit, lengthLit]))) {
mutateObjExpProp(firstArg, angleLit, 'angle')
mutateObjExpProp(firstArg, lengthLit, 'length')
}
removeDeterminingArgs(callExpression)
mutateKwArg(ARG_ANGLE, callExpression, angleLit)
mutateKwArg(ARG_LENGTH, callExpression, lengthLit)
return {
modifiedAst: _node,
pathToNode,
}
},
getTag: getTag(),
addTag: addTag(),
getTag: getTagKwArg(),
addTag: addTagKw(),
getConstraintInfo: (callExp, ...args) =>
commonConstraintInfoHelper(
callExp,
@ -2259,7 +2260,7 @@ export const angledLine: SketchLineHelper = {
),
}
export const angledLineOfXLength: SketchLineHelper = {
export const angledLineOfXLength: SketchLineHelperKw = {
add: ({
node,
variables,
@ -2313,9 +2314,9 @@ export const angledLineOfXLength: SketchLineHelper = {
if (err(result)) return result
newLine = result.callExp
} else {
newLine = createCallExpression('angledLineOfXLength', [
createArrayExpression([angle, xLength]),
createPipeSubstitution(),
newLine = createCallExpressionStdLibKw('angledLineOfXLength', null, [
createLabeledArg(ARG_ANGLE, angle),
createLabeledArg(ARG_LENGTH_X, xLength),
])
}
const { index: callIndex } = splitPathAtPipeExpression(pathToNode)
@ -2333,32 +2334,38 @@ export const angledLineOfXLength: SketchLineHelper = {
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
const { to, from } = input
const _node = { ...node }
const nodeMeta = getNodeFromPath<CallExpression>(_node, pathToNode)
const nodeMeta = getNodeFromPath<CallExpressionKw>(_node, pathToNode)
if (err(nodeMeta)) return nodeMeta
const { node: callExpression } = nodeMeta
const angle = roundOff(getAngle(from, to), 0)
const xLength = roundOff(Math.abs(to[0] - from[0]), 2)
const firstArg = callExpression.arguments?.[0]
const adjustedXLength = isAngleLiteral(firstArg)
const oldAngle = findKwArg(ARG_ANGLE, callExpression)
if (oldAngle === undefined) {
return new Error(
`expected an angle arg, but it was not found. Args were ${allLabels(
callExpression
)}`
)
}
const adjustedXLength = isAngleLiteral(oldAngle)
? Math.abs(xLength)
: xLength // todo make work for variable angle > 180
const angleLit = createLiteral(angle)
const lengthLit = createLiteral(adjustedXLength)
if (!mutateArrExp(firstArg, createArrayExpression([angleLit, lengthLit]))) {
mutateObjExpProp(firstArg, angleLit, 'angle')
mutateObjExpProp(firstArg, lengthLit, 'length')
}
removeDeterminingArgs(callExpression)
mutateKwArg(ARG_ANGLE, callExpression, angleLit)
mutateKwArg(ARG_LENGTH_X, callExpression, lengthLit)
return {
modifiedAst: _node,
pathToNode,
}
},
getTag: getTag(),
addTag: addTag(),
getTag: getTagKwArg(),
addTag: addTagKw(),
getConstraintInfo: (callExp, ...args) =>
commonConstraintInfoHelper(
callExp,
@ -2372,7 +2379,7 @@ export const angledLineOfXLength: SketchLineHelper = {
),
}
export const angledLineOfYLength: SketchLineHelper = {
export const angledLineOfYLength: SketchLineHelperKw = {
add: ({
node,
variables,
@ -2424,9 +2431,9 @@ export const angledLineOfYLength: SketchLineHelper = {
if (err(result)) return result
newLine = result.callExp
} else {
newLine = createCallExpression('angledLineOfYLength', [
createArrayExpression([angle, yLength]),
createPipeSubstitution(),
newLine = createCallExpressionStdLibKw('angledLine', null, [
createLabeledArg(ARG_ANGLE, angle),
createLabeledArg(ARG_LENGTH_Y, yLength),
])
}
const { index: callIndex } = splitPathAtPipeExpression(pathToNode)
@ -2444,32 +2451,38 @@ export const angledLineOfYLength: SketchLineHelper = {
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
const { to, from } = input
const _node = { ...node }
const nodeMeta = getNodeFromPath<CallExpression>(_node, pathToNode)
const nodeMeta = getNodeFromPath<CallExpressionKw>(_node, pathToNode)
if (err(nodeMeta)) return nodeMeta
const { node: callExpression } = nodeMeta
const angle = roundOff(getAngle(from, to), 0)
const yLength = roundOff(to[1] - from[1], 2)
const firstArg = callExpression.arguments?.[0]
const adjustedYLength = isAngleLiteral(firstArg)
const oldAngle = findKwArg(ARG_ANGLE, callExpression)
if (oldAngle === undefined) {
return new Error(
`expected an angle arg, but it was not found. Args were ${allLabels(
callExpression
)}`
)
}
const adjustedYLength = isAngleLiteral(oldAngle)
? Math.abs(yLength)
: yLength // todo make work for variable angle > 180
const angleLit = createLiteral(angle)
const lengthLit = createLiteral(adjustedYLength)
if (!mutateArrExp(firstArg, createArrayExpression([angleLit, lengthLit]))) {
mutateObjExpProp(firstArg, angleLit, 'angle')
mutateObjExpProp(firstArg, lengthLit, 'length')
}
removeDeterminingArgs(callExpression)
mutateKwArg(ARG_ANGLE, callExpression, angleLit)
mutateKwArg(ARG_LENGTH_Y, callExpression, lengthLit)
return {
modifiedAst: _node,
pathToNode,
}
},
getTag: getTag(),
addTag: addTag(),
getTag: getTagKwArg(),
addTag: addTagKw(),
getConstraintInfo: (callExp, ...args) =>
commonConstraintInfoHelper(
callExp,
@ -2483,7 +2496,7 @@ export const angledLineOfYLength: SketchLineHelper = {
),
}
export const angledLineToX: SketchLineHelper = {
export const angledLineToX: SketchLineHelperKw = {
add: ({ node, pathToNode, segmentInput, replaceExistingCallback }) => {
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
const { from, to } = segmentInput
@ -2526,9 +2539,9 @@ export const angledLineToX: SketchLineHelper = {
}
}
const callExp = createCallExpression('angledLineToX', [
createArrayExpression([angle, xArg]),
createPipeSubstitution(),
const callExp = createCallExpressionStdLibKw('angledLineToX', null, [
createLabeledArg(ARG_ANGLE, angle),
createLabeledArg(ARG_END_ABSOLUTE_X, xArg),
])
pipe.body = [...pipe.body, callExp]
return {
@ -2540,30 +2553,28 @@ export const angledLineToX: SketchLineHelper = {
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
const { to, from } = input
const _node = { ...node }
const nodeMeta = getNodeFromPath<CallExpression>(_node, pathToNode)
const nodeMeta = getNodeFromPath<CallExpressionKw>(_node, pathToNode)
if (err(nodeMeta)) return nodeMeta
const { node: callExpression } = nodeMeta
const angle = roundOff(getAngle(from, to), 0)
const xLength = roundOff(to[0], 2)
const firstArg = callExpression.arguments?.[0]
const adjustedXLength = xLength
const angleLit = createLiteral(angle)
const lengthLit = createLiteral(adjustedXLength)
if (!mutateArrExp(firstArg, createArrayExpression([angleLit, lengthLit]))) {
mutateObjExpProp(firstArg, angleLit, 'angle')
mutateObjExpProp(firstArg, lengthLit, 'to')
}
removeDeterminingArgs(callExpression)
mutateKwArg(ARG_ANGLE, callExpression, angleLit)
mutateKwArg(ARG_END_ABSOLUTE_X, callExpression, lengthLit)
return {
modifiedAst: _node,
pathToNode,
}
},
getTag: getTag(),
addTag: addTag(),
getTag: getTagKwArg(),
addTag: addTagKw(),
getConstraintInfo: (callExp, ...args) =>
commonConstraintInfoHelper(
callExp,
@ -2577,7 +2588,7 @@ export const angledLineToX: SketchLineHelper = {
),
}
export const angledLineToY: SketchLineHelper = {
export const angledLineToY: SketchLineHelperKw = {
add: ({ node, pathToNode, segmentInput, replaceExistingCallback }) => {
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
const { from, to } = segmentInput
@ -2622,9 +2633,9 @@ export const angledLineToY: SketchLineHelper = {
}
}
const newLine = createCallExpression('angledLineToY', [
createArrayExpression([angle, yArg]),
createPipeSubstitution(),
const newLine = createCallExpressionStdLibKw('angledLine', null, [
createLabeledArg(ARG_ANGLE, angle),
createLabeledArg(ARG_END_ABSOLUTE_Y, yArg),
])
pipe.body = [...pipe.body, newLine]
return {
@ -2636,30 +2647,28 @@ export const angledLineToY: SketchLineHelper = {
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
const { to, from } = input
const _node = { ...node }
const nodeMeta = getNodeFromPath<CallExpression>(_node, pathToNode)
const nodeMeta = getNodeFromPath<CallExpressionKw>(_node, pathToNode)
if (err(nodeMeta)) return nodeMeta
const { node: callExpression } = nodeMeta
const angle = roundOff(getAngle(from, to), 0)
const xLength = roundOff(to[1], 2)
const firstArg = callExpression.arguments?.[0]
const adjustedXLength = xLength
const angleLit = createLiteral(angle)
const lengthLit = createLiteral(adjustedXLength)
if (!mutateArrExp(firstArg, createArrayExpression([angleLit, lengthLit]))) {
mutateObjExpProp(firstArg, angleLit, 'angle')
mutateObjExpProp(firstArg, lengthLit, 'to')
}
removeDeterminingArgs(callExpression)
mutateKwArg(ARG_ANGLE, callExpression, angleLit)
mutateKwArg(ARG_END_ABSOLUTE_Y, callExpression, lengthLit)
return {
modifiedAst: _node,
pathToNode,
}
},
getTag: getTag(),
addTag: addTag(),
getTag: getTagKwArg(),
addTag: addTagKw(),
getConstraintInfo: (callExp, ...args) =>
commonConstraintInfoHelper(
callExp,
@ -2750,7 +2759,7 @@ export const angledLineThatIntersects: SketchLineHelper = {
const intersectTag =
firstArg.type === 'ObjectExpression'
? firstArg.properties.find((p) => p.key.name === 'intersectTag')
?.value || createLiteral('')
?.value || createLiteral('')
: createLiteral('')
const intersectTagName =
intersectTag.type === 'Name' ? intersectTag.name.name : ''
@ -2918,11 +2927,6 @@ export const updateStartProfileAtArgs: SketchLineHelper['updateArgs'] = ({
}
export const sketchLineHelperMap: { [key: string]: SketchLineHelper } = {
angledLine,
angledLineOfXLength,
angledLineOfYLength,
angledLineToX,
angledLineToY,
angledLineThatIntersects,
tangentialArcTo,
arc,
@ -2938,6 +2942,11 @@ export const sketchLineHelperMapKw: { [key: string]: SketchLineHelperKw } = {
yLine,
xLineTo,
yLineTo,
angledLine,
angledLineOfXLength,
angledLineOfYLength,
angledLineToX,
angledLineToY,
} as const
export function changeSketchArguments(
@ -2945,13 +2954,13 @@ export function changeSketchArguments(
variables: VariableMap,
sourceRangeOrPath:
| {
type: 'sourceRange'
sourceRange: SourceRange
}
type: 'sourceRange'
sourceRange: SourceRange
}
| {
type: 'path'
pathToNode: PathToNode
},
type: 'path'
pathToNode: PathToNode
},
input: SegmentInputs
): { modifiedAst: Node<Program>; pathToNode: PathToNode } | Error {
// TODO/less-than-ideal, this obvious relies on node getting mutated, as changing the following with `_node = structuredClone(node)` breaks the draft line animation.
@ -2983,10 +2992,10 @@ export function changeSketchArguments(
})
}
if (fnName in sketchLineHelperMapKw) {
const isAbsolute =
callExpression.type === 'CallExpressionKw' &&
findKwArg(ARG_END_ABSOLUTE, callExpression) !== undefined
const correctFnName = fnNameToTooltip(isAbsolute, fnName)
const correctFnName =
callExpression.type === 'CallExpressionKw'
? fnNameToTooltip(allLabels(callExpression), fnName)
: fnName
if (err(correctFnName)) {
return correctFnName
}
@ -3015,9 +3024,11 @@ export function changeSketchArguments(
* To put it another way, function names don't map cleanly to tooltips, but function names + arguments do.
*/
export function fnNameToTooltip(
isAbsolute: boolean,
argLabels: string[],
fnName: string
): ToolTip | Error {
const isAbsolute =
argLabels.findIndex((label) => label === ARG_END_ABSOLUTE) >= 0
switch (fnName) {
case 'line':
return isAbsolute ? 'lineTo' : 'line'
@ -3028,6 +3039,23 @@ export function fnNameToTooltip(
case 'circleThreePoint':
case 'circle':
return fnName
case 'angledLine': {
const argmap: Record<string, ToolTip> = {
ARG_LENGTH_X: 'angledLineOfXLength',
ARG_LENGTH_Y: 'angledLineOfYLength',
ARG_END_ABSOLUTE_X: 'angledLineToX',
ARG_END_ABSOLUTE_Y: 'angledLineToY',
ARG_LENGTH: 'angledLine',
}
for (const [arg, tooltip] of Object.entries(argmap)) {
if (argLabels.findIndex((label) => label === arg) >= 0) {
return tooltip
}
}
const err = `Unknown angledline arguments, could not map to tooltip. Args were ${argLabels}`
console.error(err)
return new Error(err)
}
default:
const err = `Unknown sketch line function ${fnName}`
console.error(err)
@ -3055,6 +3083,12 @@ export function tooltipToFnName(tooltip: ToolTip): string | Error {
return 'xLine'
case 'yLineTo':
return 'yLine'
case 'angledLine':
case 'angledLineToX':
case 'angledLineToY':
case 'angledLineOfXLength':
case 'angledLineOfYLength':
return 'angledLine'
default:
return new Error(`Unknown tooltip function ${tooltip}`)
}
@ -3092,7 +3126,7 @@ export function getConstraintInfoKw(
return []
}
if (!(fnName in sketchLineHelperMapKw)) return []
const correctFnName = fnNameToTooltip(isAbsolute, fnName)
const correctFnName = fnNameToTooltip(allLabels(callExpression), fnName)
if (err(correctFnName)) {
console.error(correctFnName)
return []
@ -3147,9 +3181,9 @@ export function addNewSketchLn({
spliceBetween = false,
}: CreateLineFnCallArgs):
| {
modifiedAst: Node<Program>
pathToNode: PathToNode
}
modifiedAst: Node<Program>
pathToNode: PathToNode
}
| Error {
const node = structuredClone(_node)
const { add, updateArgs } =
@ -3244,10 +3278,10 @@ export function replaceSketchLine({
referencedSegment?: Path
}):
| {
modifiedAst: Node<Program>
valueUsedInTransform?: number
pathToNode: PathToNode
}
modifiedAst: Node<Program>
valueUsedInTransform?: number
pathToNode: PathToNode
}
| Error {
if (![...toolTips, 'intersect', 'circle'].includes(fnName)) {
return new Error(`The following function name is not tooltip: ${fnName}`)
@ -3299,9 +3333,9 @@ function addTagToChamfer(
edgeCutMeta: EdgeCutInfo
):
| {
modifiedAst: Node<Program>
tag: string
}
modifiedAst: Node<Program>
tag: string
}
| Error {
const _node = structuredClone(tagInfo.node)
let pipeIndex = 0
@ -3416,9 +3450,9 @@ export function addTagForSketchOnFace(
edgeCutMeta: EdgeCutInfo | null
):
| {
modifiedAst: Node<Program>
tag: string
}
modifiedAst: Node<Program>
tag: string
}
| Error {
if (expressionName === 'close') {
return addTagKw()(tagInfo)
@ -3453,15 +3487,35 @@ export function getTagFromCallExpression(
return new Error(`"${callExp.callee.name.name}" is not a sketch line helper`)
}
<<<<<<< HEAD
function isAngleLiteral(lineArugement: Expr): boolean {
return lineArugement?.type === 'ArrayExpression'
? isLiteralArrayOrStatic(lineArugement.elements[0])
: lineArugement?.type === 'ObjectExpression'
? isLiteralArrayOrStatic(
lineArugement.properties.find(({ key }) => key.name === 'angle')
?.value
)
lineArugement.properties.find(({ key }) => key.name === 'angle')
?.value
)
: false
||||||| parent of 27a8a2a50 (Start changing JS codemods)
function isAngleLiteral(lineArugement: Expr): boolean {
return lineArugement?.type === 'ArrayExpression'
? isLiteralArrayOrStatic(lineArugement.elements[0])
: lineArugement?.type === 'ObjectExpression'
? isLiteralArrayOrStatic(
lineArugement.properties.find(({ key }) => key.name === 'angle')?.value
)
: false
=======
function isAngleLiteral(lineArgument: Expr): boolean {
return lineArgument?.type === 'ArrayExpression'
? isLiteralArrayOrStatic(lineArgument.elements[0])
: lineArgument?.type === 'ObjectExpression'
? isLiteralArrayOrStatic(
lineArgument.properties.find(({ key }) => key.name === 'angle')?.value
)
: lineArgument?.type === 'Literal'
>>>>>>> 27a8a2a50 (Start changing JS codemods)
}
type addTagFn = (
@ -3522,14 +3576,14 @@ function addTagKw(): addTagFn {
callExpr.node.type === 'CallExpressionKw'
? callExpr.node
: {
type: 'CallExpressionKw',
callee: callExpr.node.callee,
unlabeled: callExpr.node.arguments.length
? callExpr.node.arguments[0]
: null,
nonCodeMeta: nonCodeMetaEmpty(),
arguments: [],
}
type: 'CallExpressionKw',
callee: callExpr.node.callee,
unlabeled: callExpr.node.arguments.length
? callExpr.node.arguments[0]
: null,
nonCodeMeta: nonCodeMetaEmpty(),
arguments: [],
}
const tagArg = findKwArg(ARG_TAG, primaryCallExp)
const tagDeclarator =
tagArg || createTagDeclarator(findUniqueName(_node, 'seg', 2))
@ -3586,9 +3640,9 @@ export function getXComponent(
function getFirstArgValuesForXYFns(callExpression: CallExpression):
| {
val: [Expr, Expr]
tag?: Expr
}
val: [Expr, Expr]
tag?: Expr
}
| Error {
// used for lineTo, line
const firstArg = callExpression.arguments[0]
@ -3597,9 +3651,9 @@ function getFirstArgValuesForXYFns(callExpression: CallExpression):
function getValuesForXYFns(arg: Expr):
| {
val: [Expr, Expr]
tag?: Expr
}
val: [Expr, Expr]
tag?: Expr
}
| Error {
if (arg.type === 'ArrayExpression') {
return { val: [arg.elements[0], arg.elements[1]] }
@ -3617,9 +3671,9 @@ function getValuesForXYFns(arg: Expr):
function getFirstArgValuesForAngleFns(callExpression: CallExpression):
| {
val: [Expr, Expr]
tag?: Expr
}
val: [Expr, Expr]
tag?: Expr
}
| Error {
// used for angledLine, angledLineOfXLength, angledLineToX, angledLineOfYLength, angledLineToY
const firstArg = callExpression.arguments[0]
@ -3676,9 +3730,9 @@ export const getCircle = (
callExp: CallExpressionKw
):
| {
val: [Expr, Expr, Expr]
tag?: Expr
}
val: [Expr, Expr, Expr]
tag?: Expr
}
| Error => {
const firstArg = callExp.arguments[0]
if (firstArg.type === 'LabeledArg') {
@ -3704,9 +3758,9 @@ const getAngledLineThatIntersects = (
callExp: CallExpression
):
| {
val: [Expr, Expr, Expr]
tag?: Expr
}
val: [Expr, Expr, Expr]
tag?: Expr
}
| Error => {
const firstArg = callExp.arguments[0]
if (firstArg.type === 'ObjectExpression') {
@ -3765,9 +3819,9 @@ Also known as the 'determining' arg.
*/
export function getArgForEnd(lineCall: CallExpressionKw):
| {
val: Expr | [Expr, Expr] | [Expr, Expr, Expr]
tag?: Expr
}
val: Expr | [Expr, Expr] | [Expr, Expr, Expr]
tag?: Expr
}
| Error {
const name = lineCall?.callee?.name.name
@ -3782,7 +3836,7 @@ export function getArgForEnd(lineCall: CallExpressionKw):
return getValuesForXYFns(arg)
}
case 'yLine':
case 'xLine':
case 'xLine': {
const arg = findKwArgAny(DETERMINING_ARGS, lineCall)
const tag = findKwArg(ARG_TAG, lineCall)
if (arg === undefined) {
@ -3790,6 +3844,30 @@ export function getArgForEnd(lineCall: CallExpressionKw):
} else {
return { val: arg, tag }
}
}
case 'angledLine': {
const angle = findKwArg(ARG_ANGLE, lineCall)
if (angle === undefined) {
return new Error(`call to ${name} needs an ${ARG_ANGLE} arg`)
}
const length = findKwArgAny(
[
ARG_LENGTH,
ARG_LENGTH_X,
ARG_LENGTH_Y,
ARG_END_ABSOLUTE_X,
ARG_END_ABSOLUTE_Y,
],
lineCall
)
if (length === undefined) {
return new Error(
`call to ${name} needs an arg like ${ARG_LENGTH}, or ${ARG_END_ABSOLUTE_X} or something`
)
}
const tag = findKwArg(ARG_TAG, lineCall)
return { val: [angle, length], tag }
}
default:
return new Error(`unknown function ${name}`)
}
@ -3797,9 +3875,9 @@ export function getArgForEnd(lineCall: CallExpressionKw):
export function getFirstArg(callExp: CallExpression):
| {
val: Expr | [Expr, Expr] | [Expr, Expr, Expr]
tag?: Expr
}
val: Expr | [Expr, Expr] | [Expr, Expr, Expr]
tag?: Expr
}
| Error {
const name = callExp?.callee?.name.name
if (

View File

@ -5,7 +5,12 @@ import {
ARG_END_ABSOLUTE,
ARG_LENGTH,
ARG_TAG,
ARG_ANGLE,
DETERMINING_ARGS,
ARG_END_ABSOLUTE_X,
ARG_END_ABSOLUTE_Y,
ARG_LENGTH_X,
ARG_LENGTH_Y,
} from '@src/lang/constants'
import {
createArrayExpression,
@ -162,6 +167,43 @@ function createCallWrapper(
valueUsedInTransform,
}
}
if (
tooltip === 'angledLine' ||
tooltip === 'angledLineToX' ||
tooltip === 'angledLineToY' ||
tooltip === 'angledLineOfXLength' ||
tooltip === 'angledLineOfYLength'
) {
const args = [createLabeledArg(ARG_ANGLE, val[0])]
const v = val[1]
args.push(
(() => {
switch (tooltip) {
case 'angledLine':
return createLabeledArg(ARG_LENGTH, v)
case 'angledLineToX':
return createLabeledArg(ARG_END_ABSOLUTE_X, v)
case 'angledLineToY':
return createLabeledArg(ARG_END_ABSOLUTE_Y, v)
case 'angledLineOfXLength':
return createLabeledArg(ARG_LENGTH_X, v)
case 'angledLineOfYLength':
return createLabeledArg(ARG_LENGTH_Y, v)
}
})()
)
if (tag) {
args.push(createLabeledArg(ARG_TAG, tag))
}
return {
callExp: createCallExpressionStdLibKw(
'angledLine',
null, // Assumes this is being called in a pipeline, so the first arg is optional and if not given, will become pipeline substitution.
args
),
valueUsedInTransform,
}
}
} else {
// In this branch, `val` is an expression.
const arg = (() => {
@ -321,17 +363,17 @@ type TransformMap = {
const xyLineSetLength =
(xOrY: 'xLine' | 'yLine', referenceSeg = false): CreateStdLibSketchCallExpr =>
({ referenceSegName, tag, forceValueUsedInTransform, rawArgs: args }) => {
const segRef = createSegLen(referenceSegName)
const lineVal = forceValueUsedInTransform
? forceValueUsedInTransform
: referenceSeg
? segRef
: args[0].expr
const literalArg = asNum(args[0].expr.value)
if (err(literalArg)) return literalArg
return createCallWrapper(xOrY, lineVal, tag, literalArg)
}
({ referenceSegName, tag, forceValueUsedInTransform, rawArgs: args }) => {
const segRef = createSegLen(referenceSegName)
const lineVal = forceValueUsedInTransform
? forceValueUsedInTransform
: referenceSeg
? segRef
: args[0].expr
const literalArg = asNum(args[0].expr.value)
if (err(literalArg)) return literalArg
return createCallWrapper(xOrY, lineVal, tag, literalArg)
}
type AngLenNone = 'ang' | 'len' | 'none'
const basicAngledLineCreateNode =
@ -340,49 +382,49 @@ const basicAngledLineCreateNode =
valToForce: AngLenNone = 'none',
varValToUse: AngLenNone = 'none'
): CreateStdLibSketchCallExpr =>
({
referenceSegName,
tag,
forceValueUsedInTransform,
inputs,
rawArgs: args,
referencedSegment: path,
}) => {
const refAng = path ? getAngle(path?.from, path?.to) : 0
const argValue = asNum(args[0].expr.value)
if (err(argValue)) return argValue
const nonForcedAng =
varValToUse === 'ang'
? inputs[0].expr
: referenceSeg === 'ang'
? getClosesAngleDirection(
({
referenceSegName,
tag,
forceValueUsedInTransform,
inputs,
rawArgs: args,
referencedSegment: path,
}) => {
const refAng = path ? getAngle(path?.from, path?.to) : 0
const argValue = asNum(args[0].expr.value)
if (err(argValue)) return argValue
const nonForcedAng =
varValToUse === 'ang'
? inputs[0].expr
: referenceSeg === 'ang'
? getClosesAngleDirection(
argValue,
refAng,
createSegAngle(referenceSegName)
)
: args[0].expr
const nonForcedLen =
varValToUse === 'len'
? inputs[1].expr
: referenceSeg === 'len'
? createSegLen(referenceSegName)
: args[1].expr
const shouldForceAng = valToForce === 'ang' && forceValueUsedInTransform
const shouldForceLen = valToForce === 'len' && forceValueUsedInTransform
const literalArg = asNum(
valToForce === 'ang' ? args[0].expr.value : args[1].expr.value
)
if (err(literalArg)) return literalArg
return createCallWrapper(
'angledLine',
[
shouldForceAng ? forceValueUsedInTransform : nonForcedAng,
shouldForceLen ? forceValueUsedInTransform : nonForcedLen,
],
tag,
literalArg
)
}
: args[0].expr
const nonForcedLen =
varValToUse === 'len'
? inputs[1].expr
: referenceSeg === 'len'
? createSegLen(referenceSegName)
: args[1].expr
const shouldForceAng = valToForce === 'ang' && forceValueUsedInTransform
const shouldForceLen = valToForce === 'len' && forceValueUsedInTransform
const literalArg = asNum(
valToForce === 'ang' ? args[0].expr.value : args[1].expr.value
)
if (err(literalArg)) return literalArg
return createCallWrapper(
'angledLine',
[
shouldForceAng ? forceValueUsedInTransform : nonForcedAng,
shouldForceLen ? forceValueUsedInTransform : nonForcedLen,
],
tag,
literalArg
)
}
const angledLineAngleCreateNode: CreateStdLibSketchCallExpr = ({
referenceSegName,
inputs,
@ -453,57 +495,57 @@ function getClosesAngleDirection(
const setHorzVertDistanceCreateNode =
(xOrY: 'x' | 'y', index = xOrY === 'x' ? 0 : 1): CreateStdLibSketchCallExpr =>
({
referenceSegName,
tag,
forceValueUsedInTransform,
rawArgs: args,
referencedSegment,
}) => {
const refNum = referencedSegment?.to?.[index]
const literalArg = asNum(args?.[index].expr.value)
if (isUndef(refNum) || err(literalArg)) return REF_NUM_ERR
const valueUsedInTransform = roundOff(literalArg - refNum, 2)
let finalValue: Node<Expr> = createBinaryExpressionWithUnary([
createSegEnd(referenceSegName, !index),
forceValueUsedInTransform || createLiteral(valueUsedInTransform),
])
if (isValueZero(forceValueUsedInTransform)) {
finalValue = createSegEnd(referenceSegName, !index)
}
return createCallWrapper(
'lineTo',
!index ? [finalValue, args[1].expr] : [args[0].expr, finalValue],
({
referenceSegName,
tag,
valueUsedInTransform
)
}
forceValueUsedInTransform,
rawArgs: args,
referencedSegment,
}) => {
const refNum = referencedSegment?.to?.[index]
const literalArg = asNum(args?.[index].expr.value)
if (isUndef(refNum) || err(literalArg)) return REF_NUM_ERR
const valueUsedInTransform = roundOff(literalArg - refNum, 2)
let finalValue: Node<Expr> = createBinaryExpressionWithUnary([
createSegEnd(referenceSegName, !index),
forceValueUsedInTransform || createLiteral(valueUsedInTransform),
])
if (isValueZero(forceValueUsedInTransform)) {
finalValue = createSegEnd(referenceSegName, !index)
}
return createCallWrapper(
'lineTo',
!index ? [finalValue, args[1].expr] : [args[0].expr, finalValue],
tag,
valueUsedInTransform
)
}
const setHorzVertDistanceForAngleLineCreateNode =
(xOrY: 'x' | 'y', index = xOrY === 'x' ? 0 : 1): CreateStdLibSketchCallExpr =>
({
referenceSegName,
tag,
forceValueUsedInTransform,
inputs,
rawArgs: args,
referencedSegment,
}) => {
const refNum = referencedSegment?.to?.[index]
const literalArg = asNum(args?.[1].expr.value)
if (isUndef(refNum) || err(literalArg)) return REF_NUM_ERR
const valueUsedInTransform = roundOff(literalArg - refNum, 2)
const binExp = createBinaryExpressionWithUnary([
createSegEnd(referenceSegName, !index),
forceValueUsedInTransform || createLiteral(valueUsedInTransform),
])
return createCallWrapper(
xOrY === 'x' ? 'angledLineToX' : 'angledLineToY',
[inputs[0].expr, binExp],
({
referenceSegName,
tag,
valueUsedInTransform
)
}
forceValueUsedInTransform,
inputs,
rawArgs: args,
referencedSegment,
}) => {
const refNum = referencedSegment?.to?.[index]
const literalArg = asNum(args?.[1].expr.value)
if (isUndef(refNum) || err(literalArg)) return REF_NUM_ERR
const valueUsedInTransform = roundOff(literalArg - refNum, 2)
const binExp = createBinaryExpressionWithUnary([
createSegEnd(referenceSegName, !index),
forceValueUsedInTransform || createLiteral(valueUsedInTransform),
])
return createCallWrapper(
xOrY === 'x' ? 'angledLineToX' : 'angledLineToY',
[inputs[0].expr, binExp],
tag,
valueUsedInTransform
)
}
const setAbsDistanceCreateNode =
(
@ -511,94 +553,94 @@ const setAbsDistanceCreateNode =
isXOrYLine = false,
index = xOrY === 'x' ? 0 : 1
): CreateStdLibSketchCallExpr =>
({ tag, forceValueUsedInTransform, rawArgs: args }) => {
const literalArg = asNum(args?.[index].expr.value)
if (err(literalArg)) return literalArg
const valueUsedInTransform = roundOff(literalArg, 2)
const val = forceValueUsedInTransform || createLiteral(valueUsedInTransform)
if (isXOrYLine) {
({ tag, forceValueUsedInTransform, rawArgs: args }) => {
const literalArg = asNum(args?.[index].expr.value)
if (err(literalArg)) return literalArg
const valueUsedInTransform = roundOff(literalArg, 2)
const val = forceValueUsedInTransform || createLiteral(valueUsedInTransform)
if (isXOrYLine) {
return createCallWrapper(
xOrY === 'x' ? 'xLineTo' : 'yLineTo',
val,
tag,
valueUsedInTransform
)
}
return createCallWrapper(
xOrY === 'x' ? 'xLineTo' : 'yLineTo',
val,
'lineTo',
!index ? [val, args[1].expr] : [args[0].expr, val],
tag,
valueUsedInTransform
)
}
return createCallWrapper(
'lineTo',
!index ? [val, args[1].expr] : [args[0].expr, val],
tag,
valueUsedInTransform
)
}
const setAbsDistanceForAngleLineCreateNode =
(xOrY: 'x' | 'y'): CreateStdLibSketchCallExpr =>
({ tag, forceValueUsedInTransform, inputs, rawArgs: args }) => {
const literalArg = asNum(args?.[1].expr.value)
if (err(literalArg)) return literalArg
const valueUsedInTransform = roundOff(literalArg, 2)
const val = forceValueUsedInTransform || createLiteral(valueUsedInTransform)
return createCallWrapper(
xOrY === 'x' ? 'angledLineToX' : 'angledLineToY',
[inputs[0].expr, val],
tag,
valueUsedInTransform
)
}
({ tag, forceValueUsedInTransform, inputs, rawArgs: args }) => {
const literalArg = asNum(args?.[1].expr.value)
if (err(literalArg)) return literalArg
const valueUsedInTransform = roundOff(literalArg, 2)
const val = forceValueUsedInTransform || createLiteral(valueUsedInTransform)
return createCallWrapper(
xOrY === 'x' ? 'angledLineToX' : 'angledLineToY',
[inputs[0].expr, val],
tag,
valueUsedInTransform
)
}
const setHorVertDistanceForXYLines =
(xOrY: 'x' | 'y'): CreateStdLibSketchCallExpr =>
({
referenceSegName,
tag,
forceValueUsedInTransform,
rawArgs: args,
referencedSegment,
}) => {
const index = xOrY === 'x' ? 0 : 1
const refNum = referencedSegment?.to?.[index]
const literalArg = asNum(args?.[index].expr.value)
if (isUndef(refNum) || err(literalArg)) return REF_NUM_ERR
const valueUsedInTransform = roundOff(literalArg - refNum, 2)
const makeBinExp = createBinaryExpressionWithUnary([
createSegEnd(referenceSegName, xOrY === 'x'),
forceValueUsedInTransform || createLiteral(valueUsedInTransform),
])
return createCallWrapper(
xOrY === 'x' ? 'xLineTo' : 'yLineTo',
makeBinExp,
({
referenceSegName,
tag,
valueUsedInTransform
)
}
forceValueUsedInTransform,
rawArgs: args,
referencedSegment,
}) => {
const index = xOrY === 'x' ? 0 : 1
const refNum = referencedSegment?.to?.[index]
const literalArg = asNum(args?.[index].expr.value)
if (isUndef(refNum) || err(literalArg)) return REF_NUM_ERR
const valueUsedInTransform = roundOff(literalArg - refNum, 2)
const makeBinExp = createBinaryExpressionWithUnary([
createSegEnd(referenceSegName, xOrY === 'x'),
forceValueUsedInTransform || createLiteral(valueUsedInTransform),
])
return createCallWrapper(
xOrY === 'x' ? 'xLineTo' : 'yLineTo',
makeBinExp,
tag,
valueUsedInTransform
)
}
const setHorzVertDistanceConstraintLineCreateNode =
(isX: boolean): CreateStdLibSketchCallExpr =>
({ referenceSegName, tag, inputs, rawArgs: args, referencedSegment }) => {
let varVal = isX ? inputs[1].expr : inputs[0].expr
varVal = isExprBinaryPart(varVal) ? varVal : createLiteral(0)
const varValBinExp = createBinaryExpressionWithUnary([
createLastSeg(!isX),
varVal,
])
const makeBinExp = (index: 0 | 1) => {
const arg = asNum(args?.[index].expr.value)
const refNum = referencedSegment?.to?.[index]
if (err(arg) || isUndef(refNum)) return REF_NUM_ERR
return createBinaryExpressionWithUnary([
createSegEnd(referenceSegName, isX),
createLiteral(roundOff(arg - refNum, 2)),
({ referenceSegName, tag, inputs, rawArgs: args, referencedSegment }) => {
let varVal = isX ? inputs[1].expr : inputs[0].expr
varVal = isExprBinaryPart(varVal) ? varVal : createLiteral(0)
const varValBinExp = createBinaryExpressionWithUnary([
createLastSeg(!isX),
varVal,
])
const makeBinExp = (index: 0 | 1) => {
const arg = asNum(args?.[index].expr.value)
const refNum = referencedSegment?.to?.[index]
if (err(arg) || isUndef(refNum)) return REF_NUM_ERR
return createBinaryExpressionWithUnary([
createSegEnd(referenceSegName, isX),
createLiteral(roundOff(arg - refNum, 2)),
])
}
const binExpr = isX ? makeBinExp(0) : makeBinExp(1)
if (err(binExpr)) return new Error('Invalid value for distance')
return createCallWrapper(
'lineTo',
isX ? [binExpr, varValBinExp] : [varValBinExp, binExpr],
tag
)
}
const binExpr = isX ? makeBinExp(0) : makeBinExp(1)
if (err(binExpr)) return new Error('Invalid value for distance')
return createCallWrapper(
'lineTo',
isX ? [binExpr, varValBinExp] : [varValBinExp, binExpr],
tag
)
}
const setAngledIntersectLineForLines: CreateStdLibSketchCallExpr = ({
referenceSegName,
@ -651,48 +693,48 @@ const setAngledIntersectForAngledLines: CreateStdLibSketchCallExpr = ({
const setAngleBetweenCreateNode =
(tranformToType: 'none' | 'xAbs' | 'yAbs'): CreateStdLibSketchCallExpr =>
({
referenceSegName,
tag,
forceValueUsedInTransform,
inputs,
rawArgs: args,
referencedSegment,
}) => {
const refAngle = referencedSegment
? getAngle(referencedSegment?.from, referencedSegment?.to)
: 0
const val = asNum(args[0].expr.value)
if (err(val)) return val
let valueUsedInTransform = roundOff(normaliseAngle(val - refAngle))
let firstHalfValue = createSegAngle(referenceSegName)
if (Math.abs(valueUsedInTransform) > 90) {
firstHalfValue = createBinaryExpression([
firstHalfValue,
'+',
createName(['turns'], 'HALF_TURN'),
])
valueUsedInTransform = normaliseAngle(valueUsedInTransform - 180)
}
const binExp = createBinaryExpressionWithUnary([
firstHalfValue,
forceValueUsedInTransform || createLiteral(valueUsedInTransform),
])
return createCallWrapper(
tranformToType === 'none'
? 'angledLine'
: tranformToType === 'xAbs'
? 'angledLineToX'
: 'angledLineToY',
tranformToType === 'none'
? [binExp, args[1].expr]
: tranformToType === 'xAbs'
? [binExp, inputs[0].expr]
: [binExp, inputs[1].expr],
({
referenceSegName,
tag,
valueUsedInTransform
)
}
forceValueUsedInTransform,
inputs,
rawArgs: args,
referencedSegment,
}) => {
const refAngle = referencedSegment
? getAngle(referencedSegment?.from, referencedSegment?.to)
: 0
const val = asNum(args[0].expr.value)
if (err(val)) return val
let valueUsedInTransform = roundOff(normaliseAngle(val - refAngle))
let firstHalfValue = createSegAngle(referenceSegName)
if (Math.abs(valueUsedInTransform) > 90) {
firstHalfValue = createBinaryExpression([
firstHalfValue,
'+',
createName(['turns'], 'HALF_TURN'),
])
valueUsedInTransform = normaliseAngle(valueUsedInTransform - 180)
}
const binExp = createBinaryExpressionWithUnary([
firstHalfValue,
forceValueUsedInTransform || createLiteral(valueUsedInTransform),
])
return createCallWrapper(
tranformToType === 'none'
? 'angledLine'
: tranformToType === 'xAbs'
? 'angledLineToX'
: 'angledLineToY',
tranformToType === 'none'
? [binExp, args[1].expr]
: tranformToType === 'xAbs'
? [binExp, inputs[0].expr]
: [binExp, inputs[1].expr],
tag,
valueUsedInTransform
)
}
/**
IMO, the transformMap is a nested structure that maps like this:
@ -1506,7 +1548,7 @@ export function removeSingleConstraint({
rawValue.type === 'arrayInObject' &&
rawValue.key === currentArg.key &&
rawValue.index ===
(currentArg.type === 'arrayInObject' ? currentArg.index : -1)
(currentArg.type === 'arrayInObject' ? currentArg.index : -1)
)
const rawLiteralObjProp = rawArgs.find(
(rawValue) =>
@ -1612,10 +1654,10 @@ function getTransformMapPath(
constraintType: ConstraintType
):
| {
toolTip: ToolTip
lineInputType: LineInputsType | 'free'
constraintType: ConstraintType
}
toolTip: ToolTip
lineInputType: LineInputsType | 'free'
constraintType: ConstraintType
}
| false {
const name = sketchFnExp.callee.name.name as ToolTip
if (!toolTips.includes(name)) {
@ -1669,10 +1711,10 @@ function getTransformMapPathKw(
constraintType: ConstraintType
):
| {
toolTip: ToolTip
lineInputType: LineInputsType | 'free'
constraintType: ConstraintType
}
toolTip: ToolTip
lineInputType: LineInputsType | 'free'
constraintType: ConstraintType
}
| false {
const name = sketchFnExp.callee.name.name as ToolTip
if (name === 'circleThreePoint') {
@ -1685,8 +1727,7 @@ function getTransformMapPathKw(
}
return false
}
const isAbsolute = findKwArg(ARG_END_ABSOLUTE, sketchFnExp) !== undefined
const tooltip = fnNameToTooltip(isAbsolute, name)
const tooltip = fnNameToTooltip(allLabels(sketchFnExp), name)
if (err(tooltip)) {
return false
}
@ -1717,6 +1758,7 @@ function getTransformMapPathKw(
}
// check what constraints the function has
const isAbsolute = findKwArg(ARG_END_ABSOLUTE, sketchFnExp) !== undefined
const lineInputType = getConstraintType(argForEnd.val, name, isAbsolute)
if (lineInputType) {
const info = transformMap?.[tooltip]?.[lineInputType]?.[constraintType]
@ -1873,14 +1915,14 @@ export function transformSecondarySketchLinesTagFirst({
forceValueUsedInTransform?: BinaryPart
}):
| {
modifiedAst: Node<Program>
valueUsedInTransform?: number
pathToNodeMap: PathToNodeMap
tagInfo: {
tag: string
isTagExisting: boolean
}
modifiedAst: Node<Program>
valueUsedInTransform?: number
pathToNodeMap: PathToNodeMap
tagInfo: {
tag: string
isTagExisting: boolean
}
}
| Error {
// let node = structuredClone(ast)
@ -1952,10 +1994,10 @@ export function transformAstSketchLines({
forceValueUsedInTransform?: BinaryPart
}):
| {
modifiedAst: Node<Program>
valueUsedInTransform?: number
pathToNodeMap: PathToNodeMap
}
modifiedAst: Node<Program>
valueUsedInTransform?: number
pathToNodeMap: PathToNodeMap
}
| Error {
// deep clone since we are mutating in a loop, of which any could fail
let node = structuredClone(ast)
@ -2100,25 +2142,25 @@ export function transformAstSketchLines({
segmentInput:
seg.type === 'Circle'
? {
type: 'arc-segment',
center: seg.center,
radius: seg.radius,
from,
to: from, // For a full circle, to is the same as from
ccw: true, // Default to counter-clockwise for circles
}
type: 'arc-segment',
center: seg.center,
radius: seg.radius,
from,
to: from, // For a full circle, to is the same as from
ccw: true, // Default to counter-clockwise for circles
}
: seg.type === 'CircleThreePoint' || seg.type === 'ArcThreePoint'
? {
type: 'circle-three-point-segment',
p1: seg.p1,
p2: seg.p2,
p3: seg.p3,
}
type: 'circle-three-point-segment',
p1: seg.p1,
p2: seg.p2,
p3: seg.p3,
}
: {
type: 'straight-segment',
to,
from,
},
type: 'straight-segment',
to,
from,
},
replaceExistingCallback: (rawArgs) =>
callBack({

View File

@ -2,7 +2,7 @@ import type { Binary as BSONBinary } from 'bson'
import { v4 } from 'uuid'
import type { AnyMachineSnapshot } from 'xstate'
import type { SourceRange } from '@src/lang/wasm'
import type { CallExpressionKw, SourceRange } from '@src/lang/wasm'
import { isDesktop } from '@src/lib/isDesktop'
import type { AsyncFn } from '@src/lib/types'
@ -469,3 +469,7 @@ export function binaryToUuid(
hexValues.slice(10, 16).join(''),
].join('-')
}
export function allLabels(callExpression: CallExpressionKw): string[] {
return callExpression.arguments.map((a) => a.label.name)
}