Skip to content

Commit a00f566

Browse files
Refactor Shell codemod to allow variable-less pipes (#7691)
* WIP: Allow all sweeps to work on variable-less profiles Fixes #7657 * Fix test * Fix circ dep * Add unit tests for getVariableExprsFromSelection * Codespell * Add unit tests for createVariableExpressionsArray * Add unit test createPathToNodeForLastVariable * WIP new util function * Add other test case * We going * Lint & complete addExtrude tests * Add addSweep test * Add basic addLoft and addRevolve tests, will have to see how to distribute coverage * Add getSketchSelectionsFromOperation test * retrieveSelectionsFromOpArg generic fn and tests * Extend getVariableExprsFromSelection to include child look up * Add test to catch potentially wrong double pipe substitutions * Fix circular dep and test * Fix bad imports * WIP: Refactor Shell codemod to allow variable-less pipes * Fix test, still need to fix circ dep * Fix circular dep * Remove playwright tests and beefing up vitest integration tests * Back to a px click for loft selection :sad:, other fixes * Leverage @jtran's magic 🙏 * Fix existing test * Another test case * Clean up * Clean up * Edit cases * WIP pw * Fix test * Add todo * Remove pw sketch on face pw tests * Clean up * WIP more unit tests * Making things a bit more reliable * Add test case for issue #7640 * Add new case when for no var no pipe * Improve test and fix spelling * Update snapshots * Update snapshots * Update snapshots * Update snapshots * Update snapshots * Update snapshots * Fix url-checker * Remove explicit solids selection, also fixing #7669 at the same time * Codespell --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent b52ade2 commit a00f566

File tree

9 files changed

+744
-719
lines changed

9 files changed

+744
-719
lines changed

e2e/playwright/point-click.spec.ts

Lines changed: 38 additions & 378 deletions
Large diffs are not rendered by default.

src/lang/modifyAst.ts

Lines changed: 23 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import type {
4747
ArrayExpression,
4848
CallExpressionKw,
4949
Expr,
50+
ExpressionStatement,
5051
Literal,
5152
PathToNode,
5253
PipeExpression,
@@ -337,64 +338,6 @@ export function mutateObjExpProp(
337338
return false
338339
}
339340

340-
export function addShell({
341-
node,
342-
sweepName,
343-
faces,
344-
thickness,
345-
insertIndex,
346-
variableName,
347-
}: {
348-
node: Node<Program>
349-
sweepName: string
350-
faces: Expr[]
351-
thickness: Expr
352-
insertIndex?: number
353-
variableName?: string
354-
}): { modifiedAst: Node<Program>; pathToNode: PathToNode } {
355-
const modifiedAst = structuredClone(node)
356-
const name =
357-
variableName ?? findUniqueName(node, KCL_DEFAULT_CONSTANT_PREFIXES.SHELL)
358-
const shell = createCallExpressionStdLibKw(
359-
'shell',
360-
createLocalName(sweepName),
361-
[
362-
createLabeledArg('faces', createArrayExpression(faces)),
363-
createLabeledArg('thickness', thickness),
364-
]
365-
)
366-
367-
const variable = createVariableDeclaration(name, shell)
368-
const insertAt =
369-
insertIndex !== undefined
370-
? insertIndex
371-
: modifiedAst.body.length
372-
? modifiedAst.body.length
373-
: 0
374-
375-
if (modifiedAst.body.length) {
376-
modifiedAst.body.splice(insertAt, 0, variable)
377-
} else {
378-
modifiedAst.body.push(variable)
379-
}
380-
381-
const argIndex = 0
382-
const pathToNode: PathToNode = [
383-
['body', ''],
384-
[insertAt, 'index'],
385-
['declaration', 'VariableDeclaration'],
386-
['init', 'VariableDeclarator'],
387-
['arguments', 'CallExpressionKw'],
388-
[argIndex, ARG_INDEX_FIELD],
389-
['arg', LABELED_ARG_FIELD],
390-
]
391-
392-
return {
393-
modifiedAst,
394-
pathToNode,
395-
}
396-
}
397-
398341
export function sketchOnExtrudedFace(
399342
node: Node<Program>,
400343
sketchPathToNode: PathToNode,
@@ -1275,7 +1218,28 @@ export function setCallInAst(
12751218
if (err(pipe)) {
12761219
return pipe
12771220
}
1278-
pipe.node.body.push(call)
1221+
1222+
if (pipe.node.type === 'PipeExpression') {
1223+
pipe.node.body.push(call)
1224+
} else if (pipe.node.type === 'CallExpressionKw') {
1225+
const expression = getNodeFromPath<ExpressionStatement>(
1226+
ast,
1227+
pathIfPipe,
1228+
'ExpressionStatement'
1229+
)
1230+
if (err(expression) || expression.node.type !== 'ExpressionStatement') {
1231+
return new Error('Could not retrieve ExpressionStatement')
1232+
}
1233+
1234+
expression.node.expression = createPipeExpression([
1235+
expression.node.expression,
1236+
call,
1237+
])
1238+
} else {
1239+
return new Error(
1240+
'Expected pipeIfPipe to be a PipeExpression or CallExpressionKw'
1241+
)
1242+
}
12791243
pathToNode = pathIfPipe
12801244
} else {
12811245
const name = findUniqueName(ast, call.callee.name.name)

0 commit comments

Comments
 (0)