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
|
.idea
|
||||||
.vscode
|
.vscode
|
||||||
|
.helix
|
||||||
src/wasm-lib/.idea
|
src/wasm-lib/.idea
|
||||||
src/wasm-lib/.vscode
|
src/wasm-lib/.vscode
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,8 @@ import { Selection } from 'lib/selections'
|
|||||||
import {
|
import {
|
||||||
Program,
|
Program,
|
||||||
CallExpression,
|
CallExpression,
|
||||||
|
LabeledArg,
|
||||||
|
CallExpressionKw,
|
||||||
PipeExpression,
|
PipeExpression,
|
||||||
VariableDeclaration,
|
VariableDeclaration,
|
||||||
VariableDeclarator,
|
VariableDeclarator,
|
||||||
@ -132,10 +134,11 @@ export function addSketchTo(
|
|||||||
createLiteral('default'),
|
createLiteral('default'),
|
||||||
createPipeSubstitution(),
|
createPipeSubstitution(),
|
||||||
])
|
])
|
||||||
const initialLineTo = createCallExpressionStdLib('line', [
|
const initialLineTo = createCallExpressionStdLibKw(
|
||||||
createLiteral('default'),
|
'line',
|
||||||
createPipeSubstitution(),
|
createPipeSubstitution(),
|
||||||
])
|
[createLabeledArg('end', createLiteral('default'))]
|
||||||
|
)
|
||||||
|
|
||||||
const pipeBody = [startSketchOn, startProfileAt, initialLineTo]
|
const pipeBody = [startSketchOn, startProfileAt, initialLineTo]
|
||||||
|
|
||||||
@ -286,11 +289,11 @@ export function extrudeSketch(
|
|||||||
if (err(_node3)) return _node3
|
if (err(_node3)) return _node3
|
||||||
const { node: variableDeclarator, shallowPath: pathToDecleration } = _node3
|
const { node: variableDeclarator, shallowPath: pathToDecleration } = _node3
|
||||||
|
|
||||||
const extrudeCall = createCallExpressionStdLib('extrude', [
|
const sketchToExtrude = shouldPipe
|
||||||
distance,
|
? createPipeSubstitution()
|
||||||
shouldPipe
|
: createIdentifier(variableDeclarator.id.name)
|
||||||
? createPipeSubstitution()
|
const extrudeCall = createCallExpressionStdLibKw('extrude', sketchToExtrude, [
|
||||||
: createIdentifier(variableDeclarator.id.name),
|
createLabeledArg('length', distance),
|
||||||
])
|
])
|
||||||
|
|
||||||
if (shouldPipe) {
|
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(
|
export function createCallExpression(
|
||||||
name: string,
|
name: string,
|
||||||
args: CallExpression['arguments']
|
args: CallExpression['arguments']
|
||||||
@ -1374,3 +1400,7 @@ export async function deleteFromSelection(
|
|||||||
const nonCodeMetaEmpty = () => {
|
const nonCodeMetaEmpty = () => {
|
||||||
return { nonCodeNodes: {}, startNodes: [], start: 0, end: 0 }
|
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 { ReturnStatement } from '../wasm-lib/kcl/bindings/ReturnStatement'
|
||||||
export type { ExpressionStatement } from '../wasm-lib/kcl/bindings/ExpressionStatement'
|
export type { ExpressionStatement } from '../wasm-lib/kcl/bindings/ExpressionStatement'
|
||||||
export type { CallExpression } from '../wasm-lib/kcl/bindings/CallExpression'
|
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 { VariableDeclarator } from '../wasm-lib/kcl/bindings/VariableDeclarator'
|
||||||
export type { BinaryPart } from '../wasm-lib/kcl/bindings/BinaryPart'
|
export type { BinaryPart } from '../wasm-lib/kcl/bindings/BinaryPart'
|
||||||
export type { Literal } from '../wasm-lib/kcl/bindings/Literal'
|
export type { Literal } from '../wasm-lib/kcl/bindings/Literal'
|
||||||
|
|||||||
@ -2,7 +2,9 @@ import {
|
|||||||
createArrayExpression,
|
createArrayExpression,
|
||||||
createBinaryExpression,
|
createBinaryExpression,
|
||||||
createCallExpressionStdLib,
|
createCallExpressionStdLib,
|
||||||
|
createCallExpressionStdLibKw,
|
||||||
createIdentifier,
|
createIdentifier,
|
||||||
|
createLabeledArg,
|
||||||
createLiteral,
|
createLiteral,
|
||||||
createPipeSubstitution,
|
createPipeSubstitution,
|
||||||
createTagDeclarator,
|
createTagDeclarator,
|
||||||
@ -62,12 +64,14 @@ export const getRectangleCallExpressions = (
|
|||||||
createPipeSubstitution(),
|
createPipeSubstitution(),
|
||||||
createTagDeclarator(tags[2]),
|
createTagDeclarator(tags[2]),
|
||||||
]),
|
]),
|
||||||
createCallExpressionStdLib('lineTo', [
|
createCallExpressionStdLibKw('line', createPipeSubstitution(), [
|
||||||
createArrayExpression([
|
createLabeledArg(
|
||||||
createCallExpressionStdLib('profileStartX', [createPipeSubstitution()]),
|
'endAbsolute',
|
||||||
createCallExpressionStdLib('profileStartY', [createPipeSubstitution()]),
|
createArrayExpression([
|
||||||
]),
|
createCallExpressionStdLib('profileStartX', [createPipeSubstitution()]),
|
||||||
createPipeSubstitution(),
|
createCallExpressionStdLib('profileStartY', [createPipeSubstitution()]),
|
||||||
|
])
|
||||||
|
),
|
||||||
]), // close the rectangle
|
]), // close the rectangle
|
||||||
createCallExpressionStdLib('close', [createPipeSubstitution()]),
|
createCallExpressionStdLib('close', [createPipeSubstitution()]),
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user