Update codemod for yLine
This commit is contained in:
@ -1105,7 +1105,9 @@ part002 = startSketchOn('XZ')
|
|||||||
|
|
||||||
await pollEditorLinesSelectedLength(page, 1)
|
await pollEditorLinesSelectedLength(page, 1)
|
||||||
activeLinesContent = await page.locator('.cm-activeLine').all()
|
activeLinesContent = await page.locator('.cm-activeLine').all()
|
||||||
await expect(activeLinesContent[0]).toHaveText(`|> xLine(length = length001)`)
|
await expect(activeLinesContent[0]).toHaveText(
|
||||||
|
`|> xLine(length = length001)`
|
||||||
|
)
|
||||||
|
|
||||||
// checking the count of the overlays is a good proxy check that the client sketch scene is in a good state
|
// checking the count of the overlays is a good proxy check that the client sketch scene is in a good state
|
||||||
await expect(page.getByTestId('segment-overlay')).toHaveCount(2)
|
await expect(page.getByTestId('segment-overlay')).toHaveCount(2)
|
||||||
|
@ -158,7 +158,9 @@ test.describe('Testing selections', { tag: ['@skipWin'] }, () => {
|
|||||||
|
|
||||||
// check the same selection again by putting cursor in code first then selecting axis
|
// check the same selection again by putting cursor in code first then selecting axis
|
||||||
await test.step(`Same selection but code selection then axis`, async () => {
|
await test.step(`Same selection but code selection then axis`, async () => {
|
||||||
await page.getByText(` |> xLine(length = ${commonPoints.num2 * -1})`).click()
|
await page
|
||||||
|
.getByText(` |> xLine(length = ${commonPoints.num2 * -1})`)
|
||||||
|
.click()
|
||||||
await page.keyboard.down('Shift')
|
await page.keyboard.down('Shift')
|
||||||
await constrainButton.click()
|
await constrainButton.click()
|
||||||
await expect(absXButton).toBeDisabled()
|
await expect(absXButton).toBeDisabled()
|
||||||
@ -182,7 +184,9 @@ test.describe('Testing selections', { tag: ['@skipWin'] }, () => {
|
|||||||
process.platform === 'linux' ? 'Control' : 'Meta'
|
process.platform === 'linux' ? 'Control' : 'Meta'
|
||||||
)
|
)
|
||||||
await page.waitForTimeout(100)
|
await page.waitForTimeout(100)
|
||||||
await page.getByText(` |> xLine(length = ${commonPoints.num2 * -1})`).click()
|
await page
|
||||||
|
.getByText(` |> xLine(length = ${commonPoints.num2 * -1})`)
|
||||||
|
.click()
|
||||||
|
|
||||||
await expect(page.locator('.cm-cursor')).toHaveCount(2)
|
await expect(page.locator('.cm-cursor')).toHaveCount(2)
|
||||||
await page.waitForTimeout(500)
|
await page.waitForTimeout(500)
|
||||||
|
@ -125,12 +125,7 @@ export function createFirstArg(
|
|||||||
intersectTag: val[2],
|
intersectTag: val[2],
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
if (
|
if (['startSketchAt'].includes(sketchFn)) return val
|
||||||
['startSketchAt', 'xLine', 'xLineTo', 'yLine', 'yLineTo'].includes(
|
|
||||||
sketchFn
|
|
||||||
)
|
|
||||||
)
|
|
||||||
return val
|
|
||||||
}
|
}
|
||||||
return new Error('Missing sketch line type')
|
return new Error('Missing sketch line type')
|
||||||
}
|
}
|
||||||
@ -303,46 +298,6 @@ const commonConstraintInfoHelper = (
|
|||||||
return constraints
|
return constraints
|
||||||
}
|
}
|
||||||
|
|
||||||
const horzVertConstraintInfoHelper = (
|
|
||||||
callExp: CallExpression,
|
|
||||||
inputConstrainTypes: [ConstrainInfo['type'], ConstrainInfo['type']],
|
|
||||||
stdLibFnName: ConstrainInfo['stdLibFnName'],
|
|
||||||
abbreviatedInput: AbbreviatedInput,
|
|
||||||
code: string,
|
|
||||||
pathToNode: PathToNode,
|
|
||||||
filterValue?: string
|
|
||||||
) => {
|
|
||||||
if (callExp.type !== 'CallExpression') return []
|
|
||||||
const firstArg = callExp.arguments?.[0]
|
|
||||||
const callee = callExp.callee
|
|
||||||
const pathToFirstArg: PathToNode = [
|
|
||||||
...pathToNode,
|
|
||||||
['arguments', 'CallExpression'],
|
|
||||||
[0, 'index'],
|
|
||||||
]
|
|
||||||
const pathToCallee: PathToNode = [...pathToNode, ['callee', 'CallExpression']]
|
|
||||||
return [
|
|
||||||
constrainInfo(
|
|
||||||
inputConstrainTypes[0],
|
|
||||||
true,
|
|
||||||
callee.name,
|
|
||||||
stdLibFnName,
|
|
||||||
undefined,
|
|
||||||
topLevelRange(callee.start, callee.end),
|
|
||||||
pathToCallee
|
|
||||||
),
|
|
||||||
constrainInfo(
|
|
||||||
inputConstrainTypes[1],
|
|
||||||
isNotLiteralArrayOrStatic(callExp.arguments?.[0]),
|
|
||||||
code.slice(firstArg.start, firstArg.end),
|
|
||||||
stdLibFnName,
|
|
||||||
abbreviatedInput,
|
|
||||||
topLevelRange(firstArg.start, firstArg.end),
|
|
||||||
pathToFirstArg
|
|
||||||
),
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
const horzVertConstraintInfoHelperKw = (
|
const horzVertConstraintInfoHelperKw = (
|
||||||
callExp: CallExpressionKw,
|
callExp: CallExpressionKw,
|
||||||
inputConstrainTypes: [ConstrainInfo['type'], ConstrainInfo['type']],
|
inputConstrainTypes: [ConstrainInfo['type'], ConstrainInfo['type']],
|
||||||
@ -353,7 +308,6 @@ const horzVertConstraintInfoHelperKw = (
|
|||||||
filterValue?: string
|
filterValue?: string
|
||||||
) => {
|
) => {
|
||||||
if (callExp.type !== 'CallExpressionKw') return []
|
if (callExp.type !== 'CallExpressionKw') return []
|
||||||
const firstArg = callExp.arguments?.[0]
|
|
||||||
const callee = callExp.callee
|
const callee = callExp.callee
|
||||||
const relevantArg = findKwArgAnyIndex(
|
const relevantArg = findKwArgAnyIndex(
|
||||||
[ARG_END_ABSOLUTE, ARG_END, ARG_LENGTH],
|
[ARG_END_ABSOLUTE, ARG_END, ARG_LENGTH],
|
||||||
@ -367,7 +321,10 @@ const horzVertConstraintInfoHelperKw = (
|
|||||||
[argIndex, ARG_INDEX_FIELD],
|
[argIndex, ARG_INDEX_FIELD],
|
||||||
['arg', LABELED_ARG_FIELD],
|
['arg', LABELED_ARG_FIELD],
|
||||||
]
|
]
|
||||||
const pathToCallee: PathToNode = [...pathToNode, ['callee', 'CallExpression']]
|
const pathToCallee: PathToNode = [
|
||||||
|
...pathToNode,
|
||||||
|
['callee', 'CallExpressionKw'],
|
||||||
|
]
|
||||||
return [
|
return [
|
||||||
constrainInfo(
|
constrainInfo(
|
||||||
inputConstrainTypes[0],
|
inputConstrainTypes[0],
|
||||||
@ -766,7 +723,7 @@ export const xLineTo: SketchLineHelperKw = {
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
export const yLineTo: SketchLineHelper = {
|
export const yLineTo: SketchLineHelperKw = {
|
||||||
add: ({ node, pathToNode, segmentInput, replaceExistingCallback }) => {
|
add: ({ node, pathToNode, segmentInput, replaceExistingCallback }) => {
|
||||||
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
|
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
|
||||||
const { to } = segmentInput
|
const { to } = segmentInput
|
||||||
@ -796,9 +753,8 @@ export const yLineTo: SketchLineHelper = {
|
|||||||
valueUsedInTransform,
|
valueUsedInTransform,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const callExp = createCallExpression('yLineTo', [
|
const callExp = createCallExpressionStdLibKw('yLine', newVal, [
|
||||||
newVal,
|
createLabeledArg(ARG_END_ABSOLUTE, newVal),
|
||||||
createPipeSubstitution(),
|
|
||||||
])
|
])
|
||||||
pipe.body = [...pipe.body, callExp]
|
pipe.body = [...pipe.body, callExp]
|
||||||
return {
|
return {
|
||||||
@ -810,24 +766,20 @@ export const yLineTo: SketchLineHelper = {
|
|||||||
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
|
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
|
||||||
const { to } = input
|
const { to } = input
|
||||||
const _node = { ...node }
|
const _node = { ...node }
|
||||||
const nodeMeta = getNodeFromPath<CallExpression>(_node, pathToNode)
|
const nodeMeta = getNodeFromPath<CallExpressionKw>(_node, pathToNode)
|
||||||
if (err(nodeMeta)) return nodeMeta
|
if (err(nodeMeta)) return nodeMeta
|
||||||
const { node: callExpression } = nodeMeta
|
const { node: callExpression } = nodeMeta
|
||||||
const newY = createLiteral(roundOff(to[1], 2))
|
const newY = createLiteral(roundOff(to[1], 2))
|
||||||
if (isLiteralArrayOrStatic(callExpression.arguments?.[0])) {
|
mutateKwArg(ARG_END_ABSOLUTE, callExpression, newY)
|
||||||
callExpression.arguments[0] = newY
|
|
||||||
} else {
|
|
||||||
mutateObjExpProp(callExpression.arguments?.[0], newY, 'to')
|
|
||||||
}
|
|
||||||
return {
|
return {
|
||||||
modifiedAst: _node,
|
modifiedAst: _node,
|
||||||
pathToNode,
|
pathToNode,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getTag: getTag(),
|
getTag: getTagKwArg(),
|
||||||
addTag: addTag(),
|
addTag: addTagKw(),
|
||||||
getConstraintInfo: (callExp, ...args) =>
|
getConstraintInfo: (callExp, ...args) =>
|
||||||
horzVertConstraintInfoHelper(
|
horzVertConstraintInfoHelperKw(
|
||||||
callExp,
|
callExp,
|
||||||
['vertical', 'yAbsolute'],
|
['vertical', 'yAbsolute'],
|
||||||
'yLineTo',
|
'yLineTo',
|
||||||
@ -907,7 +859,7 @@ export const xLine: SketchLineHelperKw = {
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
export const yLine: SketchLineHelper = {
|
export const yLine: SketchLineHelperKw = {
|
||||||
add: ({ node, pathToNode, segmentInput, replaceExistingCallback }) => {
|
add: ({ node, pathToNode, segmentInput, replaceExistingCallback }) => {
|
||||||
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
|
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
|
||||||
const { from, to } = segmentInput
|
const { from, to } = segmentInput
|
||||||
@ -940,9 +892,8 @@ export const yLine: SketchLineHelper = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const newLine = createCallExpression('yLine', [
|
const newLine = createCallExpressionStdLibKw('yLine', null, [
|
||||||
newVal,
|
createLabeledArg(ARG_LENGTH, newVal),
|
||||||
createPipeSubstitution(),
|
|
||||||
])
|
])
|
||||||
if (dec.init.type === 'PipeExpression') {
|
if (dec.init.type === 'PipeExpression') {
|
||||||
dec.init.body = [...dec.init.body, newLine]
|
dec.init.body = [...dec.init.body, newLine]
|
||||||
@ -955,24 +906,20 @@ export const yLine: SketchLineHelper = {
|
|||||||
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
|
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
|
||||||
const { to, from } = input
|
const { to, from } = input
|
||||||
const _node = { ...node }
|
const _node = { ...node }
|
||||||
const nodeMeta = getNodeFromPath<CallExpression>(_node, pathToNode)
|
const nodeMeta = getNodeFromPath<CallExpressionKw>(_node, pathToNode)
|
||||||
if (err(nodeMeta)) return nodeMeta
|
if (err(nodeMeta)) return nodeMeta
|
||||||
const { node: callExpression } = nodeMeta
|
const { node: callExpression } = nodeMeta
|
||||||
const newY = createLiteral(roundOff(to[1] - from[1], 2))
|
const newY = createLiteral(roundOff(to[1] - from[1], 2))
|
||||||
if (isLiteralArrayOrStatic(callExpression.arguments?.[0])) {
|
mutateKwArg(ARG_LENGTH, callExpression, newY)
|
||||||
callExpression.arguments[0] = newY
|
|
||||||
} else {
|
|
||||||
mutateObjExpProp(callExpression.arguments?.[0], newY, 'length')
|
|
||||||
}
|
|
||||||
return {
|
return {
|
||||||
modifiedAst: _node,
|
modifiedAst: _node,
|
||||||
pathToNode,
|
pathToNode,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getTag: getTag(),
|
getTag: getTagKwArg(),
|
||||||
addTag: addTag(),
|
addTag: addTagKw(),
|
||||||
getConstraintInfo: (callExp, ...args) =>
|
getConstraintInfo: (callExp, ...args) =>
|
||||||
horzVertConstraintInfoHelper(
|
horzVertConstraintInfoHelperKw(
|
||||||
callExp,
|
callExp,
|
||||||
['vertical', 'yRelative'],
|
['vertical', 'yRelative'],
|
||||||
'yLine',
|
'yLine',
|
||||||
@ -2324,8 +2271,6 @@ export const updateStartProfileAtArgs: SketchLineHelper['updateArgs'] = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const sketchLineHelperMap: { [key: string]: SketchLineHelper } = {
|
export const sketchLineHelperMap: { [key: string]: SketchLineHelper } = {
|
||||||
yLine,
|
|
||||||
yLineTo,
|
|
||||||
angledLine,
|
angledLine,
|
||||||
angledLineOfXLength,
|
angledLineOfXLength,
|
||||||
angledLineOfYLength,
|
angledLineOfYLength,
|
||||||
@ -2342,6 +2287,8 @@ export const sketchLineHelperMapKw: { [key: string]: SketchLineHelperKw } = {
|
|||||||
circleThreePoint,
|
circleThreePoint,
|
||||||
xLine,
|
xLine,
|
||||||
xLineTo,
|
xLineTo,
|
||||||
|
yLine,
|
||||||
|
yLineTo,
|
||||||
} as const
|
} as const
|
||||||
|
|
||||||
export function changeSketchArguments(
|
export function changeSketchArguments(
|
||||||
@ -2505,13 +2452,14 @@ export function addNewSketchLn({
|
|||||||
pathToNode,
|
pathToNode,
|
||||||
'PipeExpression'
|
'PipeExpression'
|
||||||
)
|
)
|
||||||
return add({
|
const result = add({
|
||||||
node,
|
node,
|
||||||
variables,
|
variables,
|
||||||
pathToNode,
|
pathToNode,
|
||||||
segmentInput,
|
segmentInput,
|
||||||
spliceBetween,
|
spliceBetween,
|
||||||
})
|
})
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
export function addCallExpressionsToPipe({
|
export function addCallExpressionsToPipe({
|
||||||
@ -2990,10 +2938,7 @@ function getFirstArgValuesForXYLineFns(callExpression: CallExpression): {
|
|||||||
return { val: firstArg }
|
return { val: firstArg }
|
||||||
}
|
}
|
||||||
const tag = firstArg.properties.find((p) => p.key.name === 'tag')?.value
|
const tag = firstArg.properties.find((p) => p.key.name === 'tag')?.value
|
||||||
const secondArgName = ['xLineTo', 'yLineTo', 'startSketchAt'].includes(
|
const secondArgName = ['startSketchAt'].includes(callExpression?.callee?.name)
|
||||||
// const secondArgName = ['xLineTo', 'yLineTo', 'angledLineToX', 'angledLineToY'].includes(
|
|
||||||
callExpression?.callee?.name
|
|
||||||
)
|
|
||||||
? 'to'
|
? 'to'
|
||||||
: 'length'
|
: 'length'
|
||||||
const length = firstArg.properties.find(
|
const length = firstArg.properties.find(
|
||||||
|
@ -139,7 +139,7 @@ function createCallWrapper(
|
|||||||
}
|
}
|
||||||
if (tooltip === 'lineTo') {
|
if (tooltip === 'lineTo') {
|
||||||
const labeledArgs = [
|
const labeledArgs = [
|
||||||
createLabeledArg('endAbsolute', createArrayExpression(val)),
|
createLabeledArg(ARG_END_ABSOLUTE, createArrayExpression(val)),
|
||||||
]
|
]
|
||||||
if (tag) {
|
if (tag) {
|
||||||
labeledArgs.push(createLabeledArg(ARG_TAG, tag))
|
labeledArgs.push(createLabeledArg(ARG_TAG, tag))
|
||||||
@ -153,6 +153,41 @@ function createCallWrapper(
|
|||||||
valueUsedInTransform,
|
valueUsedInTransform,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// This else branch type narrows 'val' to a scalar.
|
||||||
|
if (
|
||||||
|
'xLine' === tooltip ||
|
||||||
|
'yLine' === tooltip ||
|
||||||
|
'xLineTo' === tooltip ||
|
||||||
|
'yLineTo' === tooltip
|
||||||
|
) {
|
||||||
|
const [isAbsolute, callee] = (() => {
|
||||||
|
switch (tooltip) {
|
||||||
|
case 'xLine':
|
||||||
|
return [false, 'xLine']
|
||||||
|
case 'yLine':
|
||||||
|
return [false, 'yLine']
|
||||||
|
case 'xLineTo':
|
||||||
|
return [true, 'xLine']
|
||||||
|
case 'yLineTo':
|
||||||
|
return [true, 'yLine']
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
const labeledArgs = [
|
||||||
|
createLabeledArg(isAbsolute ? ARG_END_ABSOLUTE : ARG_LENGTH, val),
|
||||||
|
]
|
||||||
|
if (tag) {
|
||||||
|
labeledArgs.push(createLabeledArg(ARG_TAG, tag))
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
callExp: createCallExpressionStdLibKw(
|
||||||
|
callee,
|
||||||
|
null, // Assumes this is being called in a pipeline, so the first arg is optional and if not given, will become pipeline substitution.
|
||||||
|
labeledArgs
|
||||||
|
),
|
||||||
|
valueUsedInTransform,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const args =
|
const args =
|
||||||
@ -1642,6 +1677,8 @@ function getTransformMapPathKw(
|
|||||||
return 'lineTo'
|
return 'lineTo'
|
||||||
case 'xLine':
|
case 'xLine':
|
||||||
return 'xLineTo'
|
return 'xLineTo'
|
||||||
|
case 'yLine':
|
||||||
|
return 'yLineTo'
|
||||||
default:
|
default:
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user