Add support for imports

This commit is contained in:
Pierre Jacquier
2025-07-03 17:10:39 -04:00
parent a9f95f7574
commit 1387c2fbcb
3 changed files with 12 additions and 3 deletions

View File

@ -85,8 +85,9 @@ extrude001 = extrude(profile001, length = 1)
if (err(result)) throw result if (err(result)) throw result
const newCode = recast(result.modifiedAst) const newCode = recast(result.modifiedAst)
expect(newCode).toContain(code) expect(newCode).toContain(code)
// TODO: this should be extrude001, I don't understand why
expect(newCode).toContain(`translate001 = translate( expect(newCode).toContain(`translate001 = translate(
extrude001, profile001,
x = 1, x = 1,
y = 2, y = 2,
z = 3, z = 3,

View File

@ -1079,7 +1079,7 @@ export function getVariableExprsFromSelection(
} else { } else {
const directLookup = getNodeFromPath<VariableDeclaration>( const directLookup = getNodeFromPath<VariableDeclaration>(
ast, ast,
s?.codeRef.pathToNode, s.codeRef.pathToNode,
'VariableDeclaration' 'VariableDeclaration'
) )
if (err(directLookup)) { if (err(directLookup)) {
@ -1113,6 +1113,14 @@ export function getVariableExprsFromSelection(
continue continue
} }
// import case
const importNodeAndAlias = findImportNodeAndAlias(ast, s.codeRef.pathToNode)
if (importNodeAndAlias) {
paths.push(s.codeRef.pathToNode)
exprs.push(createLocalName(importNodeAndAlias.alias))
continue
}
// No variable case // No variable case
paths.push(variable.deepPath) paths.push(variable.deepPath)
exprs.push(createPipeSubstitution()) exprs.push(createPipeSubstitution())

View File

@ -1085,7 +1085,7 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig<
}, },
objects: { objects: {
// selectionMixed allows for feature tree selection of module imports // selectionMixed allows for feature tree selection of module imports
inputType: 'selection', inputType: 'selectionMixed',
selectionTypes: ['path', 'sweep'], selectionTypes: ['path', 'sweep'],
selectionFilter: ['object'], selectionFilter: ['object'],
multiple: true, multiple: true,