Fix circ dep
This commit is contained in:
@ -1209,3 +1209,41 @@ export function insertVariableAndOffsetPathToNode(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create an array expression for variables,
|
||||||
|
// or keep it null if all are PipeSubstitutions
|
||||||
|
export function createVariableExpressionsArray(sketches: Expr[]) {
|
||||||
|
let sketchesExpr: Expr | null = null
|
||||||
|
if (sketches.every((s) => s.type === 'PipeSubstitution')) {
|
||||||
|
// Keeping null so we don't even put it the % sign
|
||||||
|
} else if (sketches.length === 1) {
|
||||||
|
sketchesExpr = sketches[0]
|
||||||
|
} else {
|
||||||
|
sketchesExpr = createArrayExpression(sketches)
|
||||||
|
}
|
||||||
|
return sketchesExpr
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a path to node to the last variable declaroator of an ast
|
||||||
|
// Optionally, can point to the first kwarg of the CallExpressionKw
|
||||||
|
export function createPathToNodeForLastVariable(
|
||||||
|
ast: Node<Program>,
|
||||||
|
toFirstKwarg = true
|
||||||
|
): PathToNode {
|
||||||
|
const argIndex = 0 // first kwarg for all sweeps here
|
||||||
|
const pathToCall: PathToNode = [
|
||||||
|
['body', ''],
|
||||||
|
[ast.body.length - 1, 'index'],
|
||||||
|
['declaration', 'VariableDeclaration'],
|
||||||
|
['init', 'VariableDeclarator'],
|
||||||
|
]
|
||||||
|
if (toFirstKwarg) {
|
||||||
|
pathToCall.push(
|
||||||
|
['arguments', 'CallExpressionKw'],
|
||||||
|
[argIndex, ARG_INDEX_FIELD],
|
||||||
|
['arg', LABELED_ARG_FIELD]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return pathToCall
|
||||||
|
}
|
||||||
|
@ -8,7 +8,11 @@ import {
|
|||||||
createVariableDeclaration,
|
createVariableDeclaration,
|
||||||
findUniqueName,
|
findUniqueName,
|
||||||
} from '@src/lang/create'
|
} from '@src/lang/create'
|
||||||
import { insertVariableAndOffsetPathToNode } from '@src/lang/modifyAst'
|
import {
|
||||||
|
createPathToNodeForLastVariable,
|
||||||
|
createVariableExpressionsArray,
|
||||||
|
insertVariableAndOffsetPathToNode,
|
||||||
|
} from '@src/lang/modifyAst'
|
||||||
import {
|
import {
|
||||||
getEdgeTagCall,
|
getEdgeTagCall,
|
||||||
mutateAstWithTagForSketchSegment,
|
mutateAstWithTagForSketchSegment,
|
||||||
@ -16,8 +20,6 @@ import {
|
|||||||
import {
|
import {
|
||||||
getNodeFromPath,
|
getNodeFromPath,
|
||||||
getVariableExprsFromSelection,
|
getVariableExprsFromSelection,
|
||||||
createVariableExpressionsArray,
|
|
||||||
createPathToNodeForLastVariable,
|
|
||||||
valueOrVariable,
|
valueOrVariable,
|
||||||
} from '@src/lang/queryAst'
|
} from '@src/lang/queryAst'
|
||||||
import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils'
|
import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils'
|
||||||
|
@ -2,11 +2,7 @@ import type { FunctionExpression } from '@rust/kcl-lib/bindings/FunctionExpressi
|
|||||||
import type { ImportStatement } from '@rust/kcl-lib/bindings/ImportStatement'
|
import type { ImportStatement } from '@rust/kcl-lib/bindings/ImportStatement'
|
||||||
import type { Node } from '@rust/kcl-lib/bindings/Node'
|
import type { Node } from '@rust/kcl-lib/bindings/Node'
|
||||||
import type { TypeDeclaration } from '@rust/kcl-lib/bindings/TypeDeclaration'
|
import type { TypeDeclaration } from '@rust/kcl-lib/bindings/TypeDeclaration'
|
||||||
import {
|
import { createLocalName, createPipeSubstitution } from '@src/lang/create'
|
||||||
createLocalName,
|
|
||||||
createPipeSubstitution,
|
|
||||||
createArrayExpression,
|
|
||||||
} from '@src/lang/create'
|
|
||||||
import type { ToolTip } from '@src/lang/langHelpers'
|
import type { ToolTip } from '@src/lang/langHelpers'
|
||||||
import { splitPathAtLastIndex } from '@src/lang/modifyAst'
|
import { splitPathAtLastIndex } from '@src/lang/modifyAst'
|
||||||
import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils'
|
import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils'
|
||||||
@ -1100,44 +1096,6 @@ export function getVariableExprsFromSelection(
|
|||||||
return { exprs, paths }
|
return { exprs, paths }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create an array expression for variables,
|
|
||||||
// or keep it null if all are PipeSubstitutions
|
|
||||||
export function createVariableExpressionsArray(sketches: Expr[]) {
|
|
||||||
let sketchesExpr: Expr | null = null
|
|
||||||
if (sketches.every((s) => s.type === 'PipeSubstitution')) {
|
|
||||||
// Keeping null so we don't even put it the % sign
|
|
||||||
} else if (sketches.length === 1) {
|
|
||||||
sketchesExpr = sketches[0]
|
|
||||||
} else {
|
|
||||||
sketchesExpr = createArrayExpression(sketches)
|
|
||||||
}
|
|
||||||
return sketchesExpr
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a path to node to the last variable declaroator of an ast
|
|
||||||
// Optionally, can point to the first kwarg of the CallExpressionKw
|
|
||||||
export function createPathToNodeForLastVariable(
|
|
||||||
ast: Node<Program>,
|
|
||||||
toFirstKwarg = true
|
|
||||||
): PathToNode {
|
|
||||||
const argIndex = 0 // first kwarg for all sweeps here
|
|
||||||
const pathToCall: PathToNode = [
|
|
||||||
['body', ''],
|
|
||||||
[ast.body.length - 1, 'index'],
|
|
||||||
['declaration', 'VariableDeclaration'],
|
|
||||||
['init', 'VariableDeclarator'],
|
|
||||||
]
|
|
||||||
if (toFirstKwarg) {
|
|
||||||
pathToCall.push(
|
|
||||||
['arguments', 'CallExpressionKw'],
|
|
||||||
[argIndex, ARG_INDEX_FIELD],
|
|
||||||
['arg', LABELED_ARG_FIELD]
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return pathToCall
|
|
||||||
}
|
|
||||||
|
|
||||||
// Go from the sketches argument in a KCL sweep call declaration
|
// Go from the sketches argument in a KCL sweep call declaration
|
||||||
// to a list of graph selections, useful for edit flows.
|
// to a list of graph selections, useful for edit flows.
|
||||||
// Somewhat of an inverse of getSketchExprsFromSelection.
|
// Somewhat of an inverse of getSketchExprsFromSelection.
|
||||||
|
Reference in New Issue
Block a user