JS: Rectangle and extrude buttons now generate keyword args
This commit is contained in:
committed by
Nick Cameron
parent
2848d6c77c
commit
725ffd952c
1
.gitignore
vendored
1
.gitignore
vendored
@ -25,6 +25,7 @@ yarn-error.log*
|
||||
|
||||
.idea
|
||||
.vscode
|
||||
.helix
|
||||
src/wasm-lib/.idea
|
||||
src/wasm-lib/.vscode
|
||||
|
||||
|
||||
@ -3,6 +3,8 @@ import { Selection } from 'lib/selections'
|
||||
import {
|
||||
Program,
|
||||
CallExpression,
|
||||
LabeledArg,
|
||||
CallExpressionKw,
|
||||
PipeExpression,
|
||||
VariableDeclaration,
|
||||
VariableDeclarator,
|
||||
@ -132,10 +134,11 @@ export function addSketchTo(
|
||||
createLiteral('default'),
|
||||
createPipeSubstitution(),
|
||||
])
|
||||
const initialLineTo = createCallExpressionStdLib('line', [
|
||||
createLiteral('default'),
|
||||
const initialLineTo = createCallExpressionStdLibKw(
|
||||
'line',
|
||||
createPipeSubstitution(),
|
||||
])
|
||||
[createLabeledArg('end', createLiteral('default'))]
|
||||
)
|
||||
|
||||
const pipeBody = [startSketchOn, startProfileAt, initialLineTo]
|
||||
|
||||
@ -286,11 +289,11 @@ export function extrudeSketch(
|
||||
if (err(_node3)) return _node3
|
||||
const { node: variableDeclarator, shallowPath: pathToDecleration } = _node3
|
||||
|
||||
const extrudeCall = createCallExpressionStdLib('extrude', [
|
||||
distance,
|
||||
shouldPipe
|
||||
? createPipeSubstitution()
|
||||
: createIdentifier(variableDeclarator.id.name),
|
||||
const sketchToExtrude = shouldPipe
|
||||
? createPipeSubstitution()
|
||||
: createIdentifier(variableDeclarator.id.name)
|
||||
const extrudeCall = createCallExpressionStdLibKw('extrude', sketchToExtrude, [
|
||||
createLabeledArg('length', distance),
|
||||
])
|
||||
|
||||
if (shouldPipe) {
|
||||
@ -810,6 +813,29 @@ export function createCallExpressionStdLib(
|
||||
}
|
||||
}
|
||||
|
||||
export function createCallExpressionStdLibKw(
|
||||
name: string,
|
||||
unlabeled: CallExpressionKw['unlabeled'],
|
||||
args: CallExpressionKw['arguments']
|
||||
): Node<CallExpressionKw> {
|
||||
return {
|
||||
type: 'CallExpressionKw',
|
||||
start: 0,
|
||||
end: 0,
|
||||
moduleId: 0,
|
||||
callee: {
|
||||
type: 'Identifier',
|
||||
start: 0,
|
||||
end: 0,
|
||||
moduleId: 0,
|
||||
|
||||
name,
|
||||
},
|
||||
unlabeled,
|
||||
arguments: args,
|
||||
}
|
||||
}
|
||||
|
||||
export function createCallExpression(
|
||||
name: string,
|
||||
args: CallExpression['arguments']
|
||||
@ -1374,3 +1400,7 @@ export async function deleteFromSelection(
|
||||
const nonCodeMetaEmpty = () => {
|
||||
return { nonCodeNodes: {}, startNodes: [], start: 0, end: 0 }
|
||||
}
|
||||
|
||||
export const createLabeledArg = (name: string, arg: Expr): LabeledArg => {
|
||||
return { label: createIdentifier(name), arg, type: 'LabeledArg' }
|
||||
}
|
||||
|
||||
@ -84,6 +84,8 @@ export type { BinaryExpression } from '../wasm-lib/kcl/bindings/BinaryExpression
|
||||
export type { ReturnStatement } from '../wasm-lib/kcl/bindings/ReturnStatement'
|
||||
export type { ExpressionStatement } from '../wasm-lib/kcl/bindings/ExpressionStatement'
|
||||
export type { CallExpression } from '../wasm-lib/kcl/bindings/CallExpression'
|
||||
export type { CallExpressionKw } from '../wasm-lib/kcl/bindings/CallExpressionKw'
|
||||
export type { LabeledArg } from '../wasm-lib/kcl/bindings/LabeledArg'
|
||||
export type { VariableDeclarator } from '../wasm-lib/kcl/bindings/VariableDeclarator'
|
||||
export type { BinaryPart } from '../wasm-lib/kcl/bindings/BinaryPart'
|
||||
export type { Literal } from '../wasm-lib/kcl/bindings/Literal'
|
||||
|
||||
@ -2,7 +2,9 @@ import {
|
||||
createArrayExpression,
|
||||
createBinaryExpression,
|
||||
createCallExpressionStdLib,
|
||||
createCallExpressionStdLibKw,
|
||||
createIdentifier,
|
||||
createLabeledArg,
|
||||
createLiteral,
|
||||
createPipeSubstitution,
|
||||
createTagDeclarator,
|
||||
@ -62,12 +64,14 @@ export const getRectangleCallExpressions = (
|
||||
createPipeSubstitution(),
|
||||
createTagDeclarator(tags[2]),
|
||||
]),
|
||||
createCallExpressionStdLib('lineTo', [
|
||||
createArrayExpression([
|
||||
createCallExpressionStdLib('profileStartX', [createPipeSubstitution()]),
|
||||
createCallExpressionStdLib('profileStartY', [createPipeSubstitution()]),
|
||||
]),
|
||||
createPipeSubstitution(),
|
||||
createCallExpressionStdLibKw('line', createPipeSubstitution(), [
|
||||
createLabeledArg(
|
||||
'endAbsolute',
|
||||
createArrayExpression([
|
||||
createCallExpressionStdLib('profileStartX', [createPipeSubstitution()]),
|
||||
createCallExpressionStdLib('profileStartY', [createPipeSubstitution()]),
|
||||
])
|
||||
),
|
||||
]), // close the rectangle
|
||||
createCallExpressionStdLib('close', [createPipeSubstitution()]),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user