Remove deprecated syntax (#6561)

* Remove deprecated syntax

Signed-off-by: Nick Cameron <nrc@ncameron.org>

* fix one test

* fix sketch on revolved face test

* fix test: empty-scene default-planes act as expected

* fix up more tests

* another fix

* remove another const

---------

Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Kurt Hutten Irev-Dev <k.hutten@protonmail.ch>
This commit is contained in:
Nick Cameron
2025-04-30 13:12:40 +12:00
committed by GitHub
parent 29b8a442c2
commit 0ea0d1703e
127 changed files with 2092 additions and 2359 deletions

View File

@ -108,7 +108,7 @@ springSketch = startSketchOn(XY)
// Create a helix on a cylinder.
part001 = startSketchOn(XY)
|> circle( center= [5, 5], radius= 10 )
|> circle( center = [5, 5], radius= 10 )
|> extrude(length = 10)
helix(

View File

@ -189,7 +189,7 @@ part001 = revolve(
sketch001,
axis = {
direction = [0.0, 1.0],
origin: [0.0, 0.0]
origin = [0.0, 0.0]
}
)
```

View File

@ -1,6 +1,9 @@
import type { Page } from '@playwright/test'
import type { HomePageFixture } from '@e2e/playwright/fixtures/homePageFixture'
import type { CmdBarFixture } from '@e2e/playwright/fixtures/cmdBarFixture'
import type { SceneFixture } from '@e2e/playwright/fixtures/sceneFixture'
import type { EditorFixture } from '@e2e/playwright/fixtures/editorFixture'
import {
PERSIST_MODELING_CONTEXT,
TEST_COLORS,
@ -13,14 +16,21 @@ test.setTimeout(120000)
async function doBasicSketch(
page: Page,
homePage: HomePageFixture,
openPanes: string[]
openPanes: string[],
fixtures: {
homePage: HomePageFixture
cmdBar: CmdBarFixture
scene: SceneFixture
editor: EditorFixture
}
) {
const { cmdBar, scene, homePage, editor } = fixtures
const u = await getUtils(page)
await page.setBodyDimensions({ width: 1200, height: 500 })
const PUR = 400 / 37.5 //pixeltoUnitRatio
await homePage.goToModelingScene()
await scene.settled(cmdBar)
await u.waitForPageLoad()
await page.waitForTimeout(1000)
await u.openDebugPanel()
@ -51,7 +61,13 @@ async function doBasicSketch(
}
await u.closeDebugPanel()
await page.waitForTimeout(1000) // TODO detect animation ending, or disable animation
// wait for line button to have aria-pressed as proxy for sketch mode
await expect
.poll(async () => page.getByTestId('line').getAttribute('aria-pressed'), {
timeout: 10_000,
})
.toBe('true')
await page.waitForTimeout(200)
const startXPx = 600
await page.mouse.click(startXPx + PUR * 10, 500 - PUR * 10)
@ -144,22 +160,35 @@ async function doBasicSketch(
// Open the code pane.
await u.openKclCodePanel()
await expect(
u.codeLocator
).toHaveText(`@settings(defaultLengthUnit = in)sketch001 = startSketchOn(XZ)profile001 = startProfile(sketch001, at = ${
commonPoints.startAt
})
await editor.expectEditor.toContain(
`@settings(defaultLengthUnit = in)sketch001 = startSketchOn(XZ)profile001 = startProfile(sketch001, at = ${
commonPoints.startAt
})
|> xLine(length = ${commonPoints.num1}, tag = $seg01)
|> yLine(length = ${commonPoints.num1 + 0.01})
|> xLine(length = -segLen(seg01))`)
|> xLine(length = -segLen(seg01))`,
{ shouldNormalise: true }
)
}
test.describe('Basic sketch', () => {
test('code pane open at start', async ({ page, homePage }) => {
await doBasicSketch(page, homePage, ['code'])
test('code pane open at start', async ({
page,
homePage,
cmdBar,
scene,
editor,
}) => {
await doBasicSketch(page, ['code'], { cmdBar, scene, homePage, editor })
})
test('code pane closed at start', async ({ page, homePage }) => {
test('code pane closed at start', async ({
page,
homePage,
cmdBar,
scene,
editor,
}) => {
// Load the app with the code panes
await page.addInitScript(async (persistModelingContext) => {
localStorage.setItem(
@ -167,6 +196,6 @@ test.describe('Basic sketch', () => {
JSON.stringify({ openPanes: [] })
)
}, PERSIST_MODELING_CONTEXT)
await doBasicSketch(page, homePage, [])
await doBasicSketch(page, [], { cmdBar, scene, homePage, editor })
})
})

View File

@ -151,7 +151,7 @@ sketch001 = startSketchOn(XY)
await page.keyboard.press('End')
await page.keyboard.press('Enter')
await page.keyboard.press('Enter')
await page.keyboard.type('const x = 1')
await page.keyboard.type('x = 1')
await page.keyboard.press('Enter')
await u.openDebugPanel()
@ -828,7 +828,7 @@ a1 = startSketchOn(offsetPlane(XY, offset = 10))
height = 0.500
dia = 4
fn squareHole = (l, w) => {
fn squareHole(l, w) {
squareHoleSketch = startSketchOn(XY)
|> startProfile(at = [-width / 2, -length / 2])
|> line(endAbsolute = [width / 2, -length / 2])
@ -870,7 +870,7 @@ a1 = startSketchOn(offsetPlane(XY, offset = 10))
await page.keyboard.press('ArrowDown')
await page.keyboard.press('Enter')
await page.keyboard.type(`extrusion = startSketchOn(XY)
|> circle(center: [0, 0], radius: dia/2)
|> circle(center = [0, 0], radius = dia/2)
|> subtract2d(tool = squareHole(length, width, height))
|> extrude(length = height)`)

View File

@ -228,9 +228,11 @@ export class SceneFixture {
}
connectionEstablished = async () => {
const timeout = 30000
await expect(this.networkToggleConnected).toBeVisible({ timeout })
await expect(this.engineConnectionsSpinner).not.toBeVisible()
const timeout = 30_000
await Promise.all([
expect(this.networkToggleConnected).toBeVisible({ timeout }),
expect(this.engineConnectionsSpinner).not.toBeVisible({ timeout }),
])
}
settled = async (cmdBar: CmdBarFixture) => {

View File

@ -1449,7 +1449,7 @@ test(
'@settings(defaultLengthUnit = in)'
)
await page.locator('.cm-content').fill(`sketch001 = startSketchOn('XZ')
await page.locator('.cm-content').fill(`sketch001 = startSketchOn(XZ)
|> startProfile(at = [-87.4, 282.92])
|> line(end = [324.07, 27.199], tag = $seg01)
|> line(end = [118.328, -291.754])

View File

@ -327,14 +327,15 @@ extrude002 = extrude(profile002, length = 150)
)
const websocketPromise = page.waitForEvent('websocket')
await page.setBodyDimensions({ width: 500, height: 500 })
await toolbar.closePane('code')
await page.setBodyDimensions({ width: 1000, height: 500 })
await homePage.goToModelingScene()
const websocket = await websocketPromise
await scene.connectionEstablished()
await scene.settled(cmdBar)
await toolbar.closePane('code')
await page.setBodyDimensions({ width: 500, height: 500 })
// expect pixel color to be background color
const offModelBefore = { x: 446, y: 250 }

View File

@ -1085,6 +1085,9 @@ profile001 = startProfile(sketch001, at = [${roundOff(scale * 69.6)}, ${roundOff
test('empty-scene default-planes act as expected', async ({
page,
homePage,
scene,
cmdBar,
editor,
}) => {
/**
* Tests the following things
@ -1099,6 +1102,7 @@ profile001 = startProfile(sketch001, at = [${roundOff(scale * 69.6)}, ${roundOff
const u = await getUtils(page)
await homePage.goToModelingScene()
await scene.settled(cmdBar)
await u.openDebugPanel()
await u.expectCmdLog('[data-message-type="execution-done"]')
@ -1154,25 +1158,36 @@ profile001 = startProfile(sketch001, at = [${roundOff(scale * 69.6)}, ${roundOff
.toBeLessThan(8)
await page.mouse.click(XYPlanePoint.x, XYPlanePoint.y)
await page.waitForTimeout(600)
// wait for line button to have aria-pressed as proxy for sketch mode
await expect
.poll(async () => page.getByTestId('line').getAttribute('aria-pressed'), {
timeout: 10_000,
})
.toBe('true')
await page.waitForTimeout(200)
await page.mouse.click(XYPlanePoint.x, XYPlanePoint.y)
await page.waitForTimeout(200)
await page.mouse.click(XYPlanePoint.x + 50, XYPlanePoint.y + 50)
await expect(u.codeLocator).toHaveText(`sketch001 = startSketchOn(XZ)
|> startProfile(at = [11.8, 9.09])
|> line(end = [3.39, -3.39])
`)
await editor.expectEditor.toContain(
`sketch001 = startSketchOn(XZ)
profile001 = startProfile(sketch001, at = [299.72, 230.82])
|> line(end = [86.12, -86.13])
`,
{ shouldNormalise: true }
)
await page.addInitScript(async () => {
localStorage.setItem(
'persistCode',
`sketch001 = startSketchOn(XZ)
|> startProfile(at = [11.8, 9.09])
|> line(end = [3.39, -3.39])
profile001 = startProfile(sketch001, at = [299.72, 230.82])
|> line(end = [86.12, -86.13])
`
)
})
await scene.settled(cmdBar)
await u.openDebugPanel()
await u.expectCmdLog('[data-message-type="execution-done"]')
@ -1195,7 +1210,7 @@ profile001 = startProfile(sketch001, at = [${roundOff(scale * 69.6)}, ${roundOff
lugDiameter = 0.5
lugLength = 2
fn lug = (origin, length, diameter, plane) => {
fn lug(origin, length, diameter, plane) {
lugSketch = startSketchOn(plane)
|> startProfile(at = [origin[0] + lugDiameter / 2, origin[1]])
|> angledLine(angle = 60, lengthY = lugHeadLength)

View File

@ -1126,7 +1126,7 @@ test.describe('Electron constraint tests', () => {
await fsp.writeFile(
path.join(bracketDir, 'main.kcl'),
`@settings(defaultLengthUnit = in)
const part001 = startSketchOn(XY)
part001 = startSketchOn(XY)
|> startProfile(at = [4.83, 12.56])
|> line(end = [15.1, 2.48])
|> line(end = [3.15, -9.85], tag = $seg01)

View File

@ -257,13 +257,13 @@ test.describe(`Testing gizmo, fixture-based`, () => {
localStorage.setItem(
'persistCode',
`@settings(defaultLengthUnit = in)
const sketch002 = startSketchOn(XZ)
sketch002 = startSketchOn(XZ)
|> startProfile(at = [-108.83, -57.48])
|> angledLine(angle = 0, length = 105.13, tag = $rectangleSegmentA001)
|> angledLine(angle = segAng(rectangleSegmentA001) - 90, length = 77.9)
|> angledLine(angle = segAng(rectangleSegmentA001), length = -segLen(rectangleSegmentA001))
|> close()
const sketch001 = startSketchOn(XZ)
sketch001 = startSketchOn(XZ)
|> circle(center = [818.33, 168.1], radius = 182.8)
|> extrude(length = 50)
`

View File

@ -1130,7 +1130,7 @@ part001 = startSketchOn(XZ)
|> line(end = [-20.38, -10.12])
|> line(end = [-15.79, 17.08])
fn yohey = (pos) => {
fn yohey(pos) {
sketch004 = startSketchOn(XZ)
${extrudeAndEditBlockedInFunction}
|> line(end = [27.55, -1.65])

View File

@ -18,8 +18,8 @@
statement[@isGroup=Statement] {
ImportStatement { kw<"import"> ImportItems ImportFrom String } |
FunctionDeclaration { kw<"export">? kw<"fn"> VariableDefinition Equals? ParamList Arrow? Body } |
VariableDeclaration { kw<"export">? (kw<"var"> | kw<"let"> | kw<"const">)? VariableDefinition Equals expression } |
FunctionDeclaration { kw<"export">? kw<"fn"> VariableDefinition ParamList Body } |
VariableDeclaration { kw<"export">? VariableDefinition Equals expression } |
TypeDeclaration { kw<"export">? kw<"type"> identifier ("=" type)? } |
ReturnStatement { kw<"return"> expression } |
ExpressionStatement { expression } |
@ -66,7 +66,7 @@ ObjectProperty { PropertyName (":" | Equals) expression }
AnnotationProperty {
PropertyName
( AddOp | MultOp | ExpOp | LogicOp | BangOp | CompOp | Equals | Arrow | PipeOperator | PipeSubstitution )
( AddOp | MultOp | ExpOp | LogicOp | BangOp | CompOp | Equals | PipeOperator | PipeSubstitution )
expression
}
@ -107,7 +107,6 @@ commaSep1NoTrailingComma<term> { term ("," term)* }
BangOp { "!" }
CompOp { "==" | "!=" | "<=" | ">=" | "<" | ">" }
Equals { "=" }
Arrow { "=>" }
PipeOperator { "|>" }
PipeSubstitution { "%" }

View File

@ -35,13 +35,13 @@ Program(ExpressionStatement(String),
# VariableDeclaration
let a = 'abc'
export const x = 0.2
a = 'abc'
export x = 0.2
==>
Program(VariableDeclaration(let, VariableDefinition, Equals, String),
VariableDeclaration(export, const, VariableDefinition, Equals, Number))
Program(VariableDeclaration(VariableDefinition, Equals, String),
VariableDeclaration(export, VariableDefinition, Equals, Number))
# IfExpression

View File

@ -1,51 +1,5 @@
# full
fn two = () => {
return 2
}
==>
Program(FunctionDeclaration(fn,
VariableDefinition,
Equals,
ParamList,
Arrow,
Body(ReturnStatement(return,
Number))))
# = is optional
fn one () => {
return 1
}
==>
Program(FunctionDeclaration(fn,
VariableDefinition,
ParamList,
Arrow,
Body(ReturnStatement(return,
Number))))
# => is optional
fn one = () {
return 1
}
==>
Program(FunctionDeclaration(fn,
VariableDefinition,
Equals,
ParamList,
Body(ReturnStatement(return,
Number))))
# terse
fn two() {
return 2
}
@ -57,4 +11,3 @@ Program(FunctionDeclaration(fn,
ParamList,
Body(ReturnStatement(return,
Number))))

View File

@ -1,14 +1,14 @@
// This file is used by the import docs.
export fn width = () => {
export fn width() {
return 10
}
export fn height = () => {
export fn height() {
return 10
}
export fn buildSketch = (plane, offset) => {
export fn buildSketch(plane, offset) {
w = width()
h = height()
return startSketchOn(plane)

View File

@ -119,7 +119,7 @@ async fn kcl_test_cache_change_grid_visualizes_grid_off_to_on() {
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_cache_change_grid_visualizes_grid_on_to_off() {
let code = r#"part001 = startSketchOn('XY')
let code = r#"part001 = startSketchOn(XY)
|> startProfile(at = [5.5229, 5.25217])
|> line(end = [10.50433, -1.19122])
|> line(end = [8.01362, -5.48731])
@ -160,7 +160,7 @@ async fn kcl_test_cache_change_grid_visualizes_grid_on_to_off() {
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_cache_change_highlight_edges_changes_visual() {
let code = r#"part001 = startSketchOn('XY')
let code = r#"part001 = startSketchOn(XY)
|> startProfile(at = [5.5229, 5.25217])
|> line(end = [10.50433, -1.19122])
|> line(end = [8.01362, -5.48731])

View File

@ -1,4 +1,4 @@
const part001 = startSketchOn(XY)
part001 = startSketchOn(XY)
|> startProfile(at = [4.83, 12.56])
|> line(end = [15.1, 2.48])
|> line(end = [3.15, -9.85], tag = $seg01)

View File

@ -1,4 +1,4 @@
const part001 = startSketchOn(XY)
part001 = startSketchOn(XY)
|> startProfile(at = [0,0])
|> line(end = [0, 10], tag = $thing)
|> line(end = [10, 0])

View File

@ -1,4 +1,4 @@
const part001 = startSketchOn(XY)
part001 = startSketchOn(XY)
|> startProfile(at = [0,0])
|> line(end = [0, 10], tag = $thing)
|> line(end = [10, 0])

View File

@ -1,4 +1,4 @@
const part001 = startSketchOn(XY)
part001 = startSketchOn(XY)
|> startProfile(at = [0,0])
|> line(end = [0, 10], tag = $thing)
|> line(end = [10, 0], tag = $thing1)

View File

@ -1,4 +1,4 @@
const part001 = startSketchOn(XY)
part001 = startSketchOn(XY)
|> startProfile(at = [0,0])
|> line(end = [0, 10], tag = $thing)
|> line(end = [10, 0], tag = $thing1)

View File

@ -1,4 +1,4 @@
const part001 = startSketchOn(XY)
part001 = startSketchOn(XY)
|> startProfile(at = [0,0])
|> line(end = [0, 10], tag = $thing)
|> line(end = [10, 0])

View File

@ -1,4 +1,4 @@
const part001 = startSketchOn(XY)
part001 = startSketchOn(XY)
|> startProfile(at = [0, 0])
|> line(end = [1, 3.82], tag = $seg01)
|> angled(

View File

@ -1,4 +1,4 @@
const part001 = startSketchOn(XY)
part001 = startSketchOn(XY)
|> startProfile(at = [0, 0])
|> line(end = [1, 3.82], tag = $seg01)
|> angledLine(

View File

@ -2,25 +2,25 @@
// This is a shelf bracket made out of 6061-T6 aluminum sheet metal. The required thickness is calculated based on a point load of 300 lbs applied to the end of the shelf. There are two brackets holding up the shelf, so the moment experienced is divided by 2. The shelf is 1 foot long from the wall.
// Define our bracket feet lengths
const shelfMountL = 8 // The length of the bracket holding up the shelf is 6 inches
const wallMountL = 6 // the length of the bracket
shelfMountL = 8 // The length of the bracket holding up the shelf is 6 inches
wallMountL = 6 // the length of the bracket
// Define constants required to calculate the thickness needed to support 300 lbs
const sigmaAllow = 35000 // psi
const width = 6 // inch
const p = 300 // Force on shelf - lbs
const L = 12 // inches
const M = L * p / 2 // Moment experienced at fixed end of bracket
const FOS = 2 // Factor of safety of 2 to be conservative
sigmaAllow = 35000 // psi
width = 6 // inch
p = 300 // Force on shelf - lbs
L = 12 // inches
M = L * p / 2 // Moment experienced at fixed end of bracket
FOS = 2 // Factor of safety of 2 to be conservative
// Calculate the thickness off the bending stress and factor of safety
const thickness = sqrt(6 * M * FOS / (width * sigmaAllow))
thickness = sqrt(6 * M * FOS / (width * sigmaAllow))
// 0.25 inch fillet radius
const filletR = 0.25
// 0.25 inch filradius
filletR = 0.25
// Sketch the bracket and extrude with fillets
const bracket = startSketchOn(XY)
bracket = startSketchOn(XY)
|> startProfile(at = [0, 0])
|> line(end = [0, wallMountL], tag = 'outerEdge')
|> line(end = [-shelfMountL, 0])

View File

@ -1,9 +1,9 @@
const center = [0,0]
const radius = 40
const height = 3
center = [0,0]
radius = 40
height = 3
const body = startSketchOn(XY)
|> startProfile(at = [center[0]+radius, center[1]])
|> arc(angleEnd = 360, angleStart = 0, radius = radius)
|> close()
|> extrude(length = height)
body = startSketchOn(XY)
|> startProfile(at = [center[0]+radius, center[1]])
|> arc(angleEnd = 360, angleStart = 0, radius = radius)
|> close()
|> extrude(length = height)

View File

@ -1,16 +1,16 @@
// This tests computed properties.
const arr = [0, 0, 0, 10]
const i = 3
const ten = arr[i]
arr = [0, 0, 0, 10]
i = 3
ten = arr[i]
assert(ten, isEqualTo = 10, error = "oops")
const p = "foo"
const obj = {
p = "foo"
obj = {
foo: 1,
bar: 0,
}
const one = obj[p]
one = obj[p]
assert(one, isEqualTo = 1, error = "oops")

View File

@ -1,3 +1,3 @@
const cylinder = startSketchOn(XY)
cylinder = startSketchOn(XY)
|> circle(center= [0, 0], radius= 22)
|> extrude(length = 14)

View File

@ -1,4 +1,4 @@
const part001 = startSketchOn(XY)
part001 = startSketchOn(XY)
|> startProfile(at = [-10, -10])
|> line(end = [20, 0])
|> line(end = [0, 20])

View File

@ -1,27 +1,27 @@
// create a sketch with name sketch000
const sketch000 = startSketchOn(XY)
sketch000 = startSketchOn(XY)
|> startProfile(at = [0.0, 0.0])
|> line(end = [1.0, 1.0], tag = $line000)
|> line(end = [0.0, -1.0], tag = $line001)
|> line(end = [-1.0, 0.0], tag = $line002)
// create an extrusion with name extrude000
const extrude000 = extrude(sketch000, length = 1.0)
extrude000 = extrude(sketch000, length = 1.0)
// define a plane with name plane005
const plane005 = {
origin: [0.0, 0.0, 1.0],
xAxis: [0.707107, 0.707107, 0.0],
yAxis: [-0.0, 0.0, 1.0],
zAxis: [0.707107, -0.707107, 0.0]
plane005 = {
origin = [0.0, 0.0, 1.0],
xAxis = [0.707107, 0.707107, 0.0],
yAxis = [-0.0, 0.0, 1.0],
zAxis = [0.707107, -0.707107, 0.0]
}
// create a sketch with name sketch001
const sketch001 = startSketchOn(plane005)
sketch001 = startSketchOn(plane005)
|> startProfile(at = [0.100000, 0.250000])
|> line(end = [0.075545, 0.494260], tag = $line003)
|> line(end = [0.741390, -0.113317], tag = $line004)
|> line(end = [-0.816935, -0.380943], tag = $line005)
// create an extrusion with name extrude001
const extrude001 = extrude(sketch001, length = 1.0)
extrude001 = extrude(sketch001, length = 1.0)

View File

@ -3,19 +3,19 @@
// define constants in mm
const radius = 6.0
const width = 144.0
const length = 80.0
const depth = 45.0
const thk = 4
const holeDiam = 5
const tabLength = 25
const tabWidth = 12
const tabThk = 4
radius = 6.0
width = 144.0
length = 80.0
depth = 45.0
thk = 4
holeDiam = 5
tabLength = 25
tabWidth = 12
tabThk = 4
// define a rectangular shape func
fn rectShape = (pos, w, l) => {
const rr = startSketchOn(XY)
fn rectShape(pos, w, l) {
rr = startSketchOn(XY)
|> startProfile(at = [pos[0] - (w / 2), pos[1] - (l / 2)])
|> line(endAbsolute = [pos[0] + w / 2, pos[1] - (l / 2)], tag = $edge01)
|> line(endAbsolute = [pos[0] + w / 2, pos[1] + l / 2], tag = $edge02)
@ -25,16 +25,15 @@ fn rectShape = (pos, w, l) => {
}
// define the bracket plane
const bracketPlane = {
origin: { x: 0, y: length / 2 + thk, z: 0 },
xAxis: { x: 1, y: 0, z: 0 },
yAxis: { x: 0, y: 0, z: 1 },
zAxis: { x: 0, y: -1, z: 0 }
bracketPlane = {
origin = { x = 0, y = length / 2 + thk, z = 0 },
xAxis = { x = 1, y = 0, z = 0 },
yAxis = { x = 0, y = 0, z = 1 }
}
// build the bracket sketch around the body
fn bracketSketch = (w, d, t) => {
const s = startSketchOn(bracketPlane)
fn bracketSketch(w, d, t) {
s = startSketchOn(bracketPlane)
|> startProfile(at = [-w / 2 - t, d + t])
|> line(endAbsolute = [-w / 2 - t, -t], tag = $edge1)
|> line(endAbsolute = [w / 2 + t, -t], tag = $edge2)
@ -49,8 +48,8 @@ fn bracketSketch = (w, d, t) => {
}
// build the body of the bracket
const bs = bracketSketch(width, depth, thk)
const bracketBody = bs
bs = bracketSketch(width, depth, thk)
bracketBody = bs
|> fillet(
radius = radius,
tags = [
@ -63,7 +62,7 @@ const bracketBody = bs
// sketch on the face
const retBack = startSketchOn(bs, face = bs.sketch.tags.edge4)
retBack = startSketchOn(bs, face = bs.sketch.tags.edge4)
|> startProfile(at = [length / 2 + thk, 0])
|> line(end = [0, thk])
|> line(end = [-thk, 0])

View File

@ -56,7 +56,7 @@ case = startSketchOn(XY)
)
fn m25Screw = (x, y, height) => {
fn m25Screw(x, y, height) {
screw = startSketchOn(XY)
|> startProfile(at = [0, 0])
|> circle(center= [x, y], radius=2.5)

View File

@ -3,19 +3,19 @@
// define constants in mm
const radius = 6.0
const width = 144.0
const length = 80.0
const depth = 45.0
const thk = 4
const holeDiam = 5
const tabLength = 25
const tabWidth = 12
const tabThk = 4
radius = 6.0
width = 144.0
length = 80.0
depth = 45.0
thk = 4
holeDiam = 5
tabLength = 25
tabWidth = 12
tabThk = 4
// define a rectangular shape func
fn rectShape = (pos, w, l) => {
const rr = startSketchOn('xy')
fn rectShape(pos, w, l) {
rr = startSketchOn('xy')
|> startProfile(at = [pos[0] - (w / 2), pos[1] - (l / 2)])
|> line(endAbsolute = [pos[0] + w / 2, pos[1] - (l / 2)], tag = $edge01)
|> line(endAbsolute = [pos[0] + w / 2, pos[1] + l / 2], tag = $edge02)
@ -25,16 +25,16 @@ fn rectShape = (pos, w, l) => {
}
// define the bracket plane
const bracketPlane = {
origin: { x: 0, y: length / 2 + thk, z: 0 },
xAxis: { x: 1, y: 0, z: 0 },
yAxis: { x: 0, y: 0, z: 1 },
zAxis: { x: 0, y: -1, z: 0 }
bracketPlane = {
origin = { x = 0, y = length / 2 + thk, z = 0 },
xAxis = { x = 1, y = 0, z = 0 },
yAxis = { x = 0, y = 0, z = 1 },
zAxis = { x = 0, y = -1, z = 0 }
}
// build the bracket sketch around the body
fn bracketSketch = (w, d, t) => {
const s = startSketchOn(bracketPlane)
fn bracketSketch(w, d, t) {
s = startSketchOn(bracketPlane)
|> startProfile(at = [-w / 2 - t, d + t])
|> line(endAbsolute = [-w / 2 - t, -t], tag = $edge1)
|> line(endAbsolute = [w / 2 + t, -t], tag = $edge2)
@ -48,8 +48,8 @@ fn bracketSketch = (w, d, t) => {
}
// build the body of the bracket
const bs = bracketSketch(width, depth, thk)
const bracketBody = bs
bs = bracketSketch(width, depth, thk)
bracketBody = bs
|> extrude(length = length + 2 * thk)
|> fillet(
radius = radius,
@ -62,15 +62,15 @@ const bracketBody = bs
)
// define the tab plane
const tabPlane = {
origin: { x: 0, y: 0, z: depth + thk },
xAxis: { x: 1, y: 0, z: 0 },
yAxis: { x: 0, y: 1, z: 0 },
zAxis: { x: 0, y: 0, z: 1 }
tabPlane = {
origin = { x = 0, y = 0, z = depth + thk },
xAxis = { x = 1, y = 0, z = 0 },
yAxis = { x = 0, y = 1, z = 0 },
zAxis = { x = 0, y = 0, z = 1 }
}
// build the tabs of the mounting bracket (right side)
const tabsR = startSketchOn(tabPlane)
tabsR = startSketchOn(tabPlane)
|> startProfile(at = [width / 2 + thk, length / 2 + thk])
|> line(end = [tabWidth, -tabLength / 3], tag = $edge11)
|> line(end = [0, -tabLength / 3 * 2], tag = $edge12)
@ -98,7 +98,7 @@ const tabsR = startSketchOn(tabPlane)
)
// build the tabs of the mounting bracket (left side)
const tabsL = startSketchOn(tabPlane)
tabsL = startSketchOn(tabPlane)
|> startProfile(at = [-width / 2 - thk, length / 2 + thk])
|> line(end = [-tabWidth, -tabLength / 3], tag = $edge21)
|> line(end = [0, -tabLength / 3 * 2], tag = $edge22)
@ -126,15 +126,15 @@ const tabsL = startSketchOn(tabPlane)
)
// define a plane for retention bumps
const retPlane = {
origin: { x: -width / 2 + 20, y: 0, z: 0 },
xAxis: { x: 0, y: 1, z: 0 },
yAxis: { x: 0, y: 0, z: 1 },
zAxis: { x: 1, y: 0, z: 0 }
retPlane = {
origin = { x = -width / 2 + 20, y = 0, z = 0 },
xAxis = { x = 0, y = 1, z = 0 },
yAxis = { x = 0, y = 0, z = 1 },
zAxis = { x = 1, y = 0, z = 0 }
}
// build the retention bump in the front
const retFront = startSketchOn(retPlane)
retFront = startSketchOn(retPlane)
|> startProfile(at = [-length / 2 - thk, 0])
|> line(end = [0, thk])
|> line(end = [thk, -thk])
@ -142,7 +142,7 @@ const retFront = startSketchOn(retPlane)
|> extrude(length = width - 40)
// build the retention bump in the back
const retBack = startSketchOn(retPlane)
retBack = startSketchOn(retPlane)
|> startProfile(at = [length / 2 + thk, 0])
|> line(end = [0, thk])
|> line(end = [-thk, 0])

View File

@ -1,5 +1,5 @@
fn box = (h, l, w) => {
const myBox = startSketchOn(XY)
fn box(h, l, w) {
myBox = startSketchOn(XY)
|> startProfile(at = [0,0])
|> line(end = [0, l])
|> line(end = [w, 0])
@ -10,4 +10,4 @@ fn box = (h, l, w) => {
return myBox
}
const fnBox = box(3, 6, 10)
fnBox = box(3, 6, 10)

View File

@ -1,5 +1,5 @@
fn box = (p, h, l, w) => {
const myBox = startSketchOn(XY)
fn box(p, h, l, w) {
myBox = startSketchOn(XY)
|> startProfile(at = p)
|> line(end = [0, l])
|> line(end = [w, 0])
@ -10,4 +10,4 @@ fn box = (p, h, l, w) => {
return myBox
}
const thing = box([0,0], 3, 6, 10)
thing = box([0,0], 3, 6, 10)

View File

@ -3,19 +3,19 @@
// define constants in mm
const radius = 6.0
const width = 144.0
const length = 80.0
const depth = 45.0
const thk = 4
const holeDiam = 5
const tabLength = 25
const tabWidth = 12
const tabThk = 4
radius = 6.0
width = 144.0
length = 80.0
depth = 45.0
thk = 4
holeDiam = 5
tabLength = 25
tabWidth = 12
tabThk = 4
// define a rectangular shape func
fn rectShape = (pos, w, l) => {
const rr = startSketchOn('xy')
fn rectShape(pos, w, l) {
rr = startSketchOn('xy')
|> startProfile(at = [pos[0] - (w / 2), pos[1] - (l / 2)])
|> line(endAbsolute = [pos[0] + w / 2, pos[1] - (l / 2)], tag = $edge01)
|> line(endAbsolute = [pos[0] + w / 2, pos[1] + l / 2], tag = $edge02)
@ -25,16 +25,16 @@ fn rectShape = (pos, w, l) => {
}
// define the bracket plane
const bracketPlane = {
origin: { x: 0, y: length / 2 + thk, z: 0 },
xAxis: { x: 1, y: 0, z: 0 },
yAxis: { x: 0, y: 0, z: 1 },
zAxis: { x: 0, y: -1, z: 0 }
bracketPlane = {
origin = { x = 0, y = length / 2 + thk, z = 0 },
xAxis = { x = 1, y = 0, z = 0 },
yAxis = { x = 0, y = 0, z = 1 },
zAxis = { x = 0, y = -1, z = 0 }
}
// build the bracket sketch around the body
fn bracketSketch = (w, d, t) => {
const s = startSketchOn(bracketPlane)
fn bracketSketch(w, d, t) {
s = startSketchOn(bracketPlane)
|> startProfile(at = [-w / 2 - t, d + t])
|> line(endAbsolute = [-w / 2 - t, -t], tag = $edge1)
|> line(endAbsolute = [w / 2 + t, -t], tag = $edge2)
@ -48,8 +48,8 @@ fn bracketSketch = (w, d, t) => {
}
// build the body of the bracket
const bs = bracketSketch(width, depth, thk)
const bracketBody = bs
bs = bracketSketch(width, depth, thk)
bracketBody = bs
|> extrude(length = length + 2 * thk)
|> fillet(
radius = radius,
@ -62,15 +62,15 @@ const bracketBody = bs
)
// define the tab plane
const tabPlane = {
origin: { x: 0, y: 0, z: depth + thk },
xAxis: { x: 1, y: 0, z: 0 },
yAxis: { x: 0, y: 1, z: 0 },
zAxis: { x: 0, y: 0, z: 1 }
tabPlane = {
origin = { x = 0, y = 0, z = depth + thk },
xAxis = { x = 1, y = 0, z = 0 },
yAxis = { x = 0, y = 1, z = 0 },
zAxis = { x = 0, y = 0, z = 1 }
}
// build the tabs of the mounting bracket (right side)
const tabsR = startSketchOn(tabPlane)
tabsR = startSketchOn(tabPlane)
|> startProfile(at = [width / 2 + thk, length / 2 + thk])
|> line(end = [tabWidth, -tabLength / 3], tag = $edge11)
|> line(end = [0, -tabLength / 3 * 2], tag = $edge12)
@ -98,7 +98,7 @@ const tabsR = startSketchOn(tabPlane)
)
// build the tabs of the mounting bracket (left side)
const tabsL = startSketchOn(tabPlane)
tabsL = startSketchOn(tabPlane)
|> startProfile(at = [-width / 2 - thk, length / 2 + thk])
|> line(end = [-tabWidth, -tabLength / 3], tag = $edge21)
|> line(end = [0, -tabLength / 3 * 2], tag = $edge22)
@ -126,15 +126,15 @@ const tabsL = startSketchOn(tabPlane)
)
// define a plane for retention bumps
const retPlane = {
origin: { x: -width / 2 + 20, y: 0, z: 0 },
xAxis: { x: 0, y: 1, z: 0 },
yAxis: { x: 0, y: 0, z: 1 },
zAxis: { x: 1, y: 0, z: 0 }
retPlane = {
origin = { x = -width / 2 + 20, y = 0, z = 0 },
xAxis = { x = 0, y = 1, z = 0 },
yAxis = { x = 0, y = 0, z = 1 },
zAxis = { x = 1, y = 0, z = 0 }
}
// build the retention bump in the front
const retFront = startSketchOn(retPlane)
retFront = startSketchOn(retPlane)
|> startProfile(at = [-length / 2 - thk, 0])
|> line(end = [0, thk])
|> line(end = [thk, -thk])
@ -142,7 +142,7 @@ const retFront = startSketchOn(retPlane)
|> extrude(length = width - 40)
// build the retention bump in the back
const retBack = startSketchOn(retPlane)
retBack = startSketchOn(retPlane)
|> startProfile(at = [length / 2 + thk, 0])
|> line(end = [0, thk])
|> line(end = [-thk, 0])

View File

@ -1,4 +1,4 @@
const part001 = startSketchOn(XY)
part001 = startSketchOn(XY)
|> circle(center= [5, 5], radius= 10)
|> extrude(length = 10)
|> helix(revolutions = 16, angleStart = 0, cylinder = %)

View File

@ -1,4 +1,4 @@
const part001 = startSketchOn(XY)
part001 = startSketchOn(XY)
|> circle(center = [5, 5], radius = 10)
|> extrude(length = -10)
|> helix(revolutions = 16, angleStart = 0, cylinder = %)

View File

@ -1,4 +1,4 @@
const part001 = startSketchOn(XY)
part001 = startSketchOn(XY)
|> circle(center= [5, 5], radius= 10)
|> extrude(length = 10)
|> helix(revolutions = 16, angleStart = 0, length = 3, cylinder = %)

View File

@ -1,13 +1,13 @@
let d_wrist_circumference = [22.8, 10.7, 16.4, 18.5]
let width = d_wrist_circumference[0] + d_wrist_circumference[1] + d_wrist_circumference[2] + d_wrist_circumference[3]
let length = 120.0
let hand_thickness = 24.0
let corner_radius = 5.0
d_wrist_circumference = [22.8, 10.7, 16.4, 18.5]
width = d_wrist_circumference[0] + d_wrist_circumference[1] + d_wrist_circumference[2] + d_wrist_circumference[3]
length = 120.0
hand_thickness = 24.0
corner_radius = 5.0
// At first I thought this was going to be symmetric,
// but I measured intentionally to not be symmetric,
// because your wrist isn't a perfect cylindrical surface
let brace_base = startSketchOn(XY)
brace_base = startSketchOn(XY)
|> startProfile(at = [corner_radius, 0])
|> line(end = [width - corner_radius, 0.0])
|> tangentialArc(end = [corner_radius, corner_radius])
@ -35,7 +35,7 @@ let brace_base = startSketchOn(XY)
|> tangentialArc(end = [corner_radius, -corner_radius])
|> close()
let inner = startSketchOn(XY)
inner = startSketchOn(XY)
|> startProfile(at = [0, 0])
|> xLine(length = 1.0)
|> tangentialArc(end = [corner_radius, corner_radius])
@ -47,7 +47,7 @@ let inner = startSketchOn(XY)
|> tangentialArc(end = [corner_radius, -corner_radius])
|> close()
let final = brace_base
final = brace_base
|> subtract2d(tool = inner)
|> extrude(length = 3.0)

View File

@ -1,4 +1,4 @@
const svg = startSketchOn(XY)
svg = startSketchOn(XY)
|> startProfile(at = [0, 0])
|> line(endAbsolute = [2.52, -26.04]) // MoveAbsolute

View File

@ -1,25 +1,25 @@
// Lego Brick
const lbumps = 10 // number of bumps long
const wbumps = 6 // number of bumps wide
lbumps = 10 // number of bumps long
wbumps = 6 // number of bumps wide
const pitch = 8.0
const clearance = 0.1
const bumpDiam = 4.8
const bumpHeight = 1.8
const height = 3.2
pitch = 8.0
clearance = 0.1
bumpDiam = 4.8
bumpHeight = 1.8
height = 3.2
const t = (pitch - (2 * clearance) - bumpDiam) / 2.0
const postDiam = pitch - t // works out to 6.5
const total_length = lbumps * pitch - (2.0 * clearance)
const total_width = wbumps * pitch - (2.0 * clearance)
t = (pitch - (2 * clearance) - bumpDiam) / 2.0
postDiam = pitch - t // works out to 6.5
total_length = lbumps * pitch - (2.0 * clearance)
total_width = wbumps * pitch - (2.0 * clearance)
const lSegments = total_length / (lbumps + 1)
const wSegments = total_width / (wbumps + 1)
lSegments = total_length / (lbumps + 1)
wSegments = total_width / (wbumps + 1)
// make the base
const s = startSketchOn(XY)
s = startSketchOn(XY)
|> startProfile(at = [-total_width / 2, -total_length / 2])
|> line(end = [total_width, 0])
|> line(end = [0, total_length])
@ -27,7 +27,7 @@ const s = startSketchOn(XY)
|> close()
|> extrude(length = height)
const shellExtrude = startSketchOn(s, face = "start")
shellExtrude = startSketchOn(s, face = "start")
|> startProfile(at = [-(total_width / 2 - t), -(total_length / 2 - t)])
|> line(end = [total_width - (2 * t), 0])
|> line(end = [0, total_length - (2 * t)])
@ -35,7 +35,7 @@ const shellExtrude = startSketchOn(s, face = "start")
|> close()
|> extrude(length = -(height - t))
const peg = startSketchOn(s, face = "end")
peg = startSketchOn(s, face = "end")
|> circle( center= [
-(total_width / 2 - wSegments),
-(total_length / 2 - lSegments)

View File

@ -3,83 +3,83 @@
// Comparators
fn cond = (bools) => {
return (a, b) => {
fn cond(bools) {
return fn(a, b) {
x = min([max([-1, a-b]), 1]) + 1
return bools[x]
}
}
fn Not = (b) => { return if b { false } else { true } }
fn And = (a, b) => { return if a { if b { true } else { false } } else { false }}
fn Or = (a, b) => { return if a { true } else { if b { true } else { false }}}
fn Not(b) { return if b { false } else { true } }
fn And(a, b) { return if a { if b { true } else { false } } else { false }}
fn Or(a, b) { return if a { true } else { if b { true } else { false }}}
Eq = cond([false, true, false])
Lt = cond([true, false, false])
Gt = cond([false, false, true])
fn Lte = (a, b) => { return Not(Gt(a, b)) }
fn Gte = (a, b) => { return Not(Lt(a, b)) }
fn Lte(a, b) { return Not(Gt(a, b)) }
fn Gte(a, b) { return Not(Lt(a, b)) }
// L-system
// Note: it was most concise to encode productions directly in axioms.
// Change them as you need.
fn setSketch = (state, q) => {
fn setSketch(state, q) {
return {
depthMax: state.depthMax,
depth: state.depth + 1,
currentLength: state.currentLength,
factor: state.factor,
currentAngle: state.currentAngle,
angle: state.angle,
depthMax = state.depthMax,
depth = state.depth + 1,
currentLength = state.currentLength,
factor = state.factor,
currentAngle = state.currentAngle,
angle = state.angle,
q
}
}
fn setDepth = (state, q) => {
fn setDepth(state, q) {
return {
depthMax: state.depthMax,
depth: q,
currentLength: state.currentLength,
factor: state.factor,
currentAngle: state.currentAngle,
angle: state.angle,
q: state.q
depthMax = state.depthMax,
depth = q,
currentLength = state.currentLength,
factor = state.factor,
currentAngle = state.currentAngle,
angle = state.angle,
q = state.q
}
}
fn setAngle = (state, q) => {
fn setAngle(state, q) {
return {
depthMax: state.depthMax,
depth: state.depth,
currentLength: state.currentLength,
factor: state.factor,
currentAngle: q,
angle: state.angle,
q: state.q
depthMax = state.depthMax,
depth = state.depth,
currentLength = state.currentLength,
factor = state.factor,
currentAngle = q,
angle = state.angle,
q = state.q
}
}
fn setLength = (state, q) => {
fn setLength(state, q) {
return {
depthMax: state.depthMax,
depth: state.depth,
currentLength: q,
factor: state.factor,
currentAngle: state.currentAngle,
angle: state.angle,
q: state.q
depthMax = state.depthMax,
depth = state.depth,
currentLength = q,
factor = state.factor,
currentAngle = state.currentAngle,
angle = state.angle,
q = state.q
}
}
fn Gt2 = (state) => { return setLength(state, state.currentLength * state.factor) }
fn Lt2 = (state) => { return setLength(state, state.currentLength / state.factor) }
fn Add = (state) => { return setAngle(state, rem(state.currentAngle - state.angle, divisor = 360)) }
fn Sub = (state) => { return setAngle(state, rem(state.currentAngle + state.angle, divisor = 360)) }
fn Gt2(state) { return setLength(state, state.currentLength * state.factor) }
fn Lt2(state) { return setLength(state, state.currentLength / state.factor) }
fn Add(state) { return setAngle(state, rem(state.currentAngle - state.angle, divisor = 360)) }
fn Sub(state) { return setAngle(state, rem(state.currentAngle + state.angle, divisor = 360)) }
// Only necessary to get around recursion limitations...
fn F = (state, F) => {
fn F(state, F) {
return if Lt(state.depth, state.depthMax) {
stateNext = state |> setDepth(%, state.depth + 1)
@ -97,25 +97,25 @@ fn F = (state, F) => {
}
}
fn LSystem = (args, axioms) => {
fn LSystem(args, axioms) {
myThing = startSketchOn(XY)
|> startProfile(at = [0, 0])
return axioms({
depthMax: args.iterations,
depth: 0,
currentLength: 1.0,
factor: args.factor,
currentAngle: 0,
angle: args.angle,
depthMax = args.iterations,
depth = 0,
currentLength = 1.0,
factor = args.factor,
currentAngle = 0,
angle = args.angle,
q = myThing,
})
}
LSystem({
iterations: 1,
factor: 1.36,
angle: 60,
}, (q) => {
iterations = 1,
factor = 1.36,
angle = 60,
}, fn(q) {
result = q |> F(%, F) |> Add(%) |> Add(%) |> F(%, F) |> Add(%) |> Add(%) |> F(%, F)
return result.q
})

View File

@ -1,4 +1,4 @@
const svg = startSketchOn(XY)
svg = startSketchOn(XY)
|> lineTo([0],%)
|> lineTo([0 + 1],%)
|> lineTo([0 + 1 + 2],%)

View File

@ -1,4 +1,4 @@
fn square = (pos, scale) => {
fn square(pos, scale) {
sg = startSketchOn(XY)
|> startProfile(at = pos)
|> line(end = [0, scale])

View File

@ -1,4 +1,4 @@
const part001 = startSketchOn(XY)
part001 = startSketchOn(XY)
|> startProfile(at = [0.0, 0.0])
|> line(end = [-0.3670208139314082, 0.21201331909674526])
|> line(end = [-0.4707511307971115, 0.4905279615419764])

View File

@ -1,9 +1,9 @@
const width = 5
const height = 10
const length = 12
width = 5
height = 10
length = 12
fn box = (sk1, sk2, scale) => {
const boxSketch = startSketchOn(XY)
fn box(sk1, sk2, scale) {
boxSketch = startSketchOn(XY)
|> startProfile(at = [sk1, sk2])
|> line(end = [0, scale])
|> line(end = [scale, 0])
@ -15,5 +15,5 @@ fn box = (sk1, sk2, scale) => {
box(0, 0, 5)
box(10, 23, 8)
let thing = box(-12, -15, 10)
thing = box(-12, -15, 10)
box(-20, -5, 10)

View File

@ -1,2 +1,2 @@
let arr = []
let x = arr[0]
arr = []
x = arr[0]

View File

@ -1,4 +1,4 @@
export fn foo = () => { return 0 }
export fn foo() { return 0 }
// This interacts with the engine.
part001 = startSketchOn(XY)

View File

@ -1,3 +1,3 @@
export fn identity = (x) => {
export fn identity(x) {
return x
}

View File

@ -1,5 +1,5 @@
let x = if true {
let y = 1
x = if true {
y = 1
} else {
let z = 1
z = 1
}

View File

@ -1,3 +1,3 @@
import two from "import_cycle2.kcl"
export fn one = () => { return two() - 1 }
export fn one() { return two() - 1 }

View File

@ -1,3 +1,3 @@
import three from "import_cycle3.kcl"
export fn two = () => { return three() - 1 }
export fn two() { return three() - 1 }

View File

@ -1,3 +1,3 @@
import one from "import_cycle1.kcl"
export fn three = () => { return one() + one() + one() }
export fn three() { return one() + one() + one() }

View File

@ -1,4 +1,4 @@
fn foo = () => {
fn foo() {
import identity from "identity.kcl"
return 1
}

View File

@ -1,2 +1,2 @@
let arr = [1, 2, 3]
let x = arr[1.2]
arr = [1, 2, 3]
x = arr[1.2]

View File

@ -1,3 +1,3 @@
let arr = [1, 2, 3]
let i = -1
let x = arr[i]
arr = [1, 2, 3]
i = -1
x = arr[i]

View File

@ -1,2 +1,2 @@
let arr = [1, 2, 3]
let x = arr["s"]
arr = [1, 2, 3]
x = arr["s"]

View File

@ -1,2 +1,2 @@
let num = 999
let x = num[3]
num = 999
x = num[3]

View File

@ -1,2 +1,2 @@
let b = true
let x = b["property"]
b = true
x = b["property"]

View File

@ -1,2 +1,2 @@
let obj = {key: 123}
let num = obj[3]
obj = {key: 123}
num = obj[3]

View File

@ -1,7 +1,7 @@
export fn increment = (x) => {
export fn increment(x) {
return x + 1
}
export fn decrement = (x) => {
export fn decrement(x) {
return x - 1
}

View File

@ -1,2 +1,2 @@
let obj = {}
let k = obj["age"]
obj = {}
k = obj["age"]

View File

@ -1,7 +1,7 @@
// Make sure pipe value doesn't leak into the function call.
fn f = (ignored) => {
fn f(ignored) {
return %
}
const answer = %
answer = %
|> f(%)

View File

@ -1,21 +1,16 @@
// define a plane with UID 94894440791888
const plane94894440791888 = {
origin: [0.005000000000000001, 0.01, -0.005],
xAxis: [
plane94894440791888 = {
origin = [0.005000000000000001, 0.01, -0.005],
xAxis = [
0.9285064634886234,
0.37131623619207604,
0.0
],
yAxis: [-0.0, 0.0, 1.0],
zAxis: [
0.37131623619207604,
-0.9285064634886234,
0.0
]
yAxis = [-0.0, 0.0, 1.0]
}
// create a sketch with UID 94894440902176
const sketch94894440902176 = startSketchOn('-XZ')
sketch94894440902176 = startSketchOn('-XZ')
|> startProfile(at = [-0.005, -0.005])
|> line(end = [0.01, 0.0], tag = $line94894439494384)
|> line(end = [0.0, 0.01], tag = $line94894439429616)
@ -23,10 +18,10 @@ const sketch94894440902176 = startSketchOn('-XZ')
|> line(end = [0.0, -0.01], tag = $line94894439971808)
// create an extrusion with UID 94894439487136
const extrude94894439487136 = extrude(sketch94894440902176, length = 0.01)
extrude94894439487136 = extrude(sketch94894440902176, length = 0.01)
// create a sketch with UID 94894439448464
const sketch94894439448464 = startSketchOn(plane94894440791888)
sketch94894439448464 = startSketchOn(plane94894440791888)
|> startProfile(at = [0.00074557205559017, 0.00306415853984399])
|> line(end = [0.004999999999999999, 0.0], tag = $line94894440230336)
|> line(end = [0.0, -0.005], tag = $line94894439497168)

View File

@ -1,21 +1,16 @@
// define a plane with UID 94894440791888
const plane94894440791888 = {
origin: [0.005000000000000001, 0.01, -0.005],
xAxis: [
plane94894440791888 = {
origin = [0.005000000000000001, 0.01, -0.005],
xAxis = [
0.9285064634886234,
0.37131623619207604,
0.0
],
yAxis: [-0.0, 0.0, 1.0],
zAxis: [
0.37131623619207604,
-0.9285064634886234,
0.0
]
yAxis = [-0.0, 0.0, 1.0]
}
// create a sketch with UID 94894440902176
const sketch94894440902176 = startSketchOn('-XZ')
sketch94894440902176 = startSketchOn('-XZ')
|> startProfile(at = [-0.005, -0.005])
|> line(end = [0.01, 0.0], tag = $line94894439494384)
|> line(end = [0.0, 0.01], tag = $line94894439429616)
@ -23,7 +18,7 @@ const sketch94894440902176 = startSketchOn('-XZ')
|> line(end = [0.0, -0.01], tag = $line94894439971808)
// create a sketch with UID 94894439448464
const sketch94894439448464 = startSketchOn(plane94894440791888)
sketch94894439448464 = startSketchOn(plane94894440791888)
|> startProfile(at = [0.00074557205559017, 0.00306415853984399])
|> line(end = [0.004999999999999999, 0.0], tag = $line94894440230336)
|> line(end = [0.0, -0.005], tag = $line94894439497168)
@ -31,4 +26,4 @@ const sketch94894439448464 = startSketchOn(plane94894440791888)
|> line(end = [0.0, 0.005], tag = $line94894440231952)
// create an extrusion with UID 94894439487136
const extrude94894439487136 = extrude(sketch94894440902176, length = 0.01)
extrude94894439487136 = extrude(sketch94894440902176, length = 0.01)

View File

@ -1,13 +1,13 @@
const sigmaAllow = 35000 // psi
const width = 9 // inch
const p = 150 // Force on shelf - lbs
const distance = 6 // inches
const FOS = 2
sigmaAllow = 35000 // psi
width = 9 // inch
p = 150 // Force on shelf - lbs
distance = 6 // inches
FOS = 2
const leg1 = 5 // inches
const leg2 = 8 // inches
const thickness = sqrt(distance * p * FOS * 6 / sigmaAllow / width) // inches
const bracket = startSketchOn(XY)
leg1 = 5 // inches
leg2 = 8 // inches
thickness = sqrt(distance * p * FOS * 6 / sigmaAllow / width) // inches
bracket = startSketchOn(XY)
|> startProfile(at = [0, 0])
|> line(end = [0, leg1])
|> line(end = [leg2, 0])

View File

@ -1,14 +1,14 @@
const sigmaAllow = 15000 // psi
const width = 11 // inch
const p = 150 // Force on shelf - lbs
const distance = 12 // inches
const FOS = 2
const thickness = sqrt(distance * p * FOS * 6 / ( sigmaAllow * width ))
const filletR = thickness * 2
const shelfMountL = 9
const wallMountL = 8
sigmaAllow = 15000 // psi
width = 11 // inch
p = 150 // Force on shelf - lbs
distance = 12 // inches
FOS = 2
thickness = sqrt(distance * p * FOS * 6 / ( sigmaAllow * width ))
filletR = thickness * 2
shelfMountL = 9
wallMountL = 8
const bracket = startSketchOn(XY)
bracket = startSketchOn(XY)
|> startProfile(at = [0, 0])
|> line(end = [0, wallMountL])
|> tangentialArc(

View File

@ -1,19 +1,19 @@
// Parameters
const r = 50 // base radius
const h = 10 // layer height
const t = 0.005 // taper factor [0-1)
r = 50 // base radius
h = 10 // layer height
t = 0.005 // taper factor [0-1)
// Defines how to modify each layer of the vase.
// Each replica is shifted up the Z axis, and has a smoothly-varying radius
fn transform = (replicaId) => {
let scale = r * abs(1 - (t * replicaId)) * (5 + math::cos((replicaId / 8): number(rad)))
fn transform(replicaId) {
scale = r * abs(1 - (t * replicaId)) * (5 + math::cos((replicaId / 8): number(rad)))
return {
translate: [0, 0, replicaId * 10],
scale: [scale, scale, 0],
translate = [0, 0, replicaId * 10],
scale = [scale, scale, 0],
}
}
// Each layer is just a pretty thin cylinder with a fillet.
fn layer = () => {
return startSketchOn("XY") // or some other plane idk
fn layer() {
return startSketchOn(XY) // or some other plane idk
|> circle(center = [0, 0], radius = 1, tag = $tag1)
|> extrude(length = h)
// |> fillet(
@ -23,4 +23,4 @@ fn layer = () => {
}
// The vase is 100 layers tall.
// The 100 layers are replica of each other, with a slight transformation applied to each.
let vase = layer() |> patternTransform(instances = 100, transform = transform)
vase = layer() |> patternTransform(instances = 100, transform = transform)

View File

@ -1,16 +1,16 @@
let triangleHeight = 200
let plumbusLen = 100
let radius = 80
triangleHeight = 200
plumbusLen = 100
radius = 80
let triangleLen = 500
const p = startSketchOn(XY)
triangleLen = 500
p = startSketchOn(XY)
|> startProfile(at = [0, 0])
|> angledLine(angle = 60, length = triangleLen, tag = $a)
|> angledLine(angle = 180, length = triangleLen, tag = $b)
|> angledLine(angle = 300, length = triangleLen, tag = $c)
|> extrude(length = triangleHeight)
fn circl = (x, face) => {
fn circl(x, face) {
return startSketchOn(p, face = face)
|> startProfile(at = [x + radius, triangleHeight/2])
|> arc(
@ -22,16 +22,16 @@ return startSketchOn(p, face = face)
|> close()
}
const c1 = circl(-200,c)
const plumbus1 =
c1 = circl(-200,c)
plumbus1 =
c1
|> extrude(length = plumbusLen)
|> fillet(
radius = 5,
tags = [c1.tags.arc_tag, getOppositeEdge(c1.tags.arc_tag)]
)
const c2 = circl(200, a)
const plumbus0 =
c2 = circl(200, a)
plumbus0 =
c2
|> extrude(length = plumbusLen)
|> fillet(

View File

@ -1,11 +1,11 @@
fn cube = (length, center) => {
let l = length/2
let x = center[0]
let y = center[1]
let p0 = [-l + x, -l + y]
let p1 = [-l + x, l + y]
let p2 = [ l + x, l + y]
let p3 = [ l + x, -l + y]
fn cube(length, center) {
l = length/2
x = center[0]
y = center[1]
p0 = [-l + x, -l + y]
p1 = [-l + x, l + y]
p2 = [ l + x, l + y]
p3 = [ l + x, -l + y]
return startSketchOn(XY)
|> startProfile(at = p0)
@ -17,7 +17,7 @@ fn cube = (length, center) => {
|> extrude(length = length)
}
fn double = (x) => { return x * 2}
fn width = () => { return 200 }
fn double(x) { return x * 2}
fn width() { return 200 }
const myCube = cube(200 |> double(%), [0,0])
myCube = cube(200 |> double(%), [0,0])

View File

@ -1,4 +1,4 @@
const svg = startSketchOn(XY)
svg = startSketchOn(XY)
|> startProfile(at = [0, 0])
|> line(endAbsolute = [22.687663, -2.7664351]) // MoveRelative

View File

@ -1,12 +1,12 @@
const ANSWER = 41803
ANSWER = 41803
fn m = (s) => {
fn m(s) {
return (ANSWER * s + 12345) % 214748
}
fn p = (xs, ys) => {
let ox = 35 - (m(xs) % 70)
let oy = 35 - (m(ys) % 70)
const r = startSketchOn(XZ)
fn p(xs, ys) {
ox = 35 - (m(xs) % 70)
oy = 35 - (m(ys) % 70)
r = startSketchOn(XZ)
|> startProfile(at = [ox, oy])
|> line(end = [1, 0])
|> line(end = [0, -1])

View File

@ -1,14 +1,14 @@
const ANSWER = 41803
ANSWER = 41803
fn t = (s) => {
fn t(s) {
return (ANSWER * s + 12345) % 214748
}
let xs = 205804
let ys = 71816
let ox = 35 - (t(xs) % 70)
let oy = 35 - (t(ys) % 70)
const r = startSketchOn(XZ)
xs = 205804
ys = 71816
ox = 35 - (t(xs) % 70)
oy = 35 - (t(ys) % 70)
r = startSketchOn(XZ)
|> startProfile(at = [ox, oy])
|> line(end = [1, 0])
|> line(end = [0, -1])

View File

@ -1,15 +1,15 @@
const routerDiameter = 12.7
const mmInInch = 25.4
const templateDiameter = mmInInch * 11 / 16
const templateGap = ((templateDiameter - routerDiameter) / 2) -0.5
const slateWidthHalf = 41.5 / 2
const minClampingDistance = 50 + 30
const templateThickness = 10
const radius = 10
const depth = 30
const length001 = slateWidthHalf - radius
const length002 = depth + minClampingDistance
const sketch001 = startSketchOn(XZ)
routerDiameter = 12.7
mmInInch = 25.4
templateDiameter = mmInInch * 11 / 16
templateGap = ((templateDiameter - routerDiameter) / 2) -0.5
slateWidthHalf = 41.5 / 2
minClampingDistance = 50 + 30
templateThickness = 10
radius = 10
depth = 30
length001 = slateWidthHalf - radius
length002 = depth + minClampingDistance
sketch001 = startSketchOn(XZ)
|> startProfile(at = [0, depth - templateGap])
|> xLine(length = length001, tag = $seg01)
|> arc(
@ -32,20 +32,20 @@ const sketch001 = startSketchOn(XZ)
)
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|> close()
const extrude001 = extrude(sketch001, length = 5)
const sketch002 = startSketchOn(extrude001, face = 'START')
extrude001 = extrude(sketch001, length = 5)
sketch002 = startSketchOn(extrude001, face = 'START')
|> startProfile(at = [-slateWidthHalf, -templateGap * 2 - (templateDiameter / 2)])
|> xLine(length = -7, tag = $rectangleSegmentA001)
|> angledLine(angle = segAng(rectangleSegmentA001, %) + 90, length = minClampingDistance, tag = $rectangleSegmentB001)
|> angledLine(angle = segAng(rectangleSegmentA001, %), length = -segLen(rectangleSegmentA001, %), tag = $rectangleSegmentC001)
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|> close()
const extrude002 = extrude(sketch002, length = 7.5)
const sketch003 = startSketchOn(extrude001, face = 'START')
extrude002 = extrude(sketch002, length = 7.5)
sketch003 = startSketchOn(extrude001, face = 'START')
|> startProfile(at = [slateWidthHalf, -templateGap * 2 - (templateDiameter / 2)])
|> xLine(length = 7, tag = $rectangleSegmentA002)
|> angledLine(angle = segAng(rectangleSegmentA002, %) - 90, length = minClampingDistance)
|> angledLine(angle = segAng(rectangleSegmentA002, %), length = -segLen(rectangleSegmentA002, %))
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|> close()
const extrude003 = extrude(sketch003, length = 7.5)
extrude003 = extrude(sketch003, length = 7.5)

View File

@ -1,4 +1,4 @@
fn rect = (origin) => {
fn rect(origin) {
return startSketchOn(XZ)
|> startProfile(at = origin)
|> angledLine(

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,11 @@
const sketch001 = startSketchOn(XZ)
sketch001 = startSketchOn(XZ)
|> startProfile(at = [75.8, 317.2]) // [$startCapTag, $EndCapTag]
|> angledLine(angle = 0, length = 268.43, tag = $rectangleSegmentA001)
|> angledLine(angle = segAng(rectangleSegmentA001) - 90, length = 217.26, tag = $seg01)
|> angledLine(angle = segAng(rectangleSegmentA001), length = -segLen(rectangleSegmentA001))
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|> close()
const extrude001 = extrude(sketch001, length = 100)
extrude001 = extrude(sketch001, length = 100)
|> fillet( radius = 20, tags = [seg01] )
|> chamfer(
length = 50,
@ -14,18 +14,18 @@ const extrude001 = extrude(sketch001, length = 100)
)
|> chamfer(length = 50, tags = [seg02], tag = $seg04)
const sketch003 = startSketchOn(extrude001, face = seg04)
sketch003 = startSketchOn(extrude001, face = seg04)
|> startProfile(at = [-69.1, 277.34])
|> angledLine(angle = 0, length = 41.48, tag = $rectangleSegmentA003)
|> angledLine(angle = segAng(rectangleSegmentA003) - 90, length = 104.8, tag = $rectangleSegmentB002)
|> angledLine(angle = segAng(rectangleSegmentA003), length = -segLen(rectangleSegmentA003), tag = $rectangleSegmentC002)
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|> close()
const sketch002 = startSketchOn(extrude001, face = seg03)
sketch002 = startSketchOn(extrude001, face = seg03)
|> startProfile(at = [159.25, 278.35])
|> angledLine(angle = 0, length = 40.82, tag = $rectangleSegmentA002)
|> angledLine(angle = segAng(rectangleSegmentA002) - 90, length = 132.27, tag = $rectangleSegmentB001)
|> angledLine(angle = segAng(rectangleSegmentA002), length = -segLen(rectangleSegmentA002), tag = $rectangleSegmentC001)
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|> close()
const extrude002 = extrude(sketch002, length = 50)
extrude002 = extrude(sketch002, length = 50)

View File

@ -1,11 +1,11 @@
const sketch001 = startSketchOn(XZ)
sketch001 = startSketchOn(XZ)
|> startProfile(at = [75.8, 317.2]) // [$startCapTag, $EndCapTag]
|> angledLine(angle = 0, length = 268.43, tag = $rectangleSegmentA001)
|> angledLine(angle = segAng(rectangleSegmentA001) - 90, length = 217.26, tag = $seg01)
|> angledLine(angle = segAng(rectangleSegmentA001), length = -segLen(rectangleSegmentA001))
|> line(endAbsolute = [profileStartX(%), profileStartY(%)], tag = $seg02)
|> close()
const extrude001 = extrude(sketch001, length = 100)
extrude001 = extrude(sketch001, length = 100)
|> fillet(radius = 20, tags = [seg01])
|> chamfer(length = 50, tags = [seg02], tag = $seg04)
|> chamfer(
@ -14,18 +14,18 @@ const extrude001 = extrude(sketch001, length = 100)
tag = $seg03
)
const sketch003 = startSketchOn(extrude001, face = seg04)
sketch003 = startSketchOn(extrude001, face = seg04)
|> startProfile(at = [-69.1, 277.34])
|> angledLine(angle = 0, length = 41.48, tag = $rectangleSegmentA003)
|> angledLine(angle = segAng(rectangleSegmentA003) - 90, length = 104.8, tag = $rectangleSegmentB002)
|> angledLine(angle = segAng(rectangleSegmentA003), length = -segLen(rectangleSegmentA003), tag = $rectangleSegmentC002)
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|> close()
const sketch002 = startSketchOn(extrude001, face = seg03)
sketch002 = startSketchOn(extrude001, face = seg03)
|> startProfile(at = [159.25, 278.35])
|> angledLine(angle = 0, length = 40.82, tag = $rectangleSegmentA002)
|> angledLine(angle = segAng(rectangleSegmentA002) - 90, length = 132.27, tag = $rectangleSegmentB001)
|> angledLine(angle = segAng(rectangleSegmentA002), length = -segLen(rectangleSegmentA002), tag = $rectangleSegmentC001)
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|> close()
const extrude002 = extrude(sketch002, length = 50)
extrude002 = extrude(sketch002, length = 50)

View File

@ -1,5 +1,5 @@
fn cube = (pos, scale) => {
const sg = startSketchOn(XY)
fn cube(pos, scale) {
sg = startSketchOn(XY)
|> startProfile(at = pos)
|> line(end = [0, scale])
|> line(end = [scale, 0])
@ -7,10 +7,10 @@ fn cube = (pos, scale) => {
return sg
}
const part001 = cube([0,0], 20)
part001 = cube([0,0], 20)
|> close()
|> extrude(length = 20)
const part002 = startSketchOn(part001, face = "end")
part002 = startSketchOn(part001, face = "end")
|> circle(center: [0, 0], radius: 5, tag =$myCircle)
|> extrude(length = 5)

View File

@ -1,5 +1,5 @@
fn cube = (pos, scale) => {
const sg = startSketchOn(XY)
fn cube(pos, scale) {
sg = startSketchOn(XY)
|> startProfile(at = pos)
|> line(end = [0, scale])
|> line(end = [scale, 0])
@ -7,11 +7,11 @@ fn cube = (pos, scale) => {
return sg
}
const part001 = cube([0,0], 20)
part001 = cube([0,0], 20)
|> close()
|> extrude(length = 20)
const part002 = startSketchOn(part001, face = "END")
part002 = startSketchOn(part001, face = "END")
|> startProfile(at = [0, 0])
|> line(end = [0, 10])
|> line(end = [10, 0])

View File

@ -1,5 +1,5 @@
fn cube = (pos, scale) => {
const sg = startSketchOn(XY)
fn cube(pos, scale) {
sg = startSketchOn(XY)
|> startProfile(at = pos)
|> line(end = [0, scale])
|> line(end = [scale, 0])
@ -7,11 +7,11 @@ fn cube = (pos, scale) => {
return sg
}
const part001 = cube([0,0], 20)
part001 = cube([0,0], 20)
|> close()
|> extrude(length = 20)
const part002 = startSketchOn(part001, face = "END")
part002 = startSketchOn(part001, face = "END")
|> startProfile(at = [0, 0])
|> line(end = [0, 10])
|> line(end = [10, 0])

View File

@ -1,5 +1,5 @@
fn cube = (pos, scale) => {
const sg = startSketchOn(XY)
fn cube(pos, scale) {
sg = startSketchOn(XY)
|> startProfile(at = pos)
|> line(end = [0, scale])
|> line(end = [scale, 0])
@ -7,11 +7,11 @@ fn cube = (pos, scale) => {
return sg
}
const part001 = cube([0,0], 20)
part001 = cube([0,0], 20)
|> close()
|> extrude(length = 20)
const part002 = startSketchOn(part001, face = "start")
part002 = startSketchOn(part001, face = "start")
|> startProfile(at = [0, 0])
|> line(end = [0, 10])
|> line(end = [10, 0])

View File

@ -1,32 +1,32 @@
// 2x8 Lego Brick
// A standard Lego brick with 2 bumps wide and 8 bumps long.
// Define constants
const lbumps = 10 // number of bumps long
const wbumps = {{N}} // number of bumps wide
const pitch = 8.0
const clearance = 0.1
const bumpDiam = 4.8
const bumpHeight = 1.8
const height = 9.6
const t = (pitch - (2 * clearance) - bumpDiam) / 2.0
const totalLength = lbumps * pitch - (2.0 * clearance)
const totalWidth = wbumps * pitch - (2.0 * clearance)
lbumps = 10 // number of bumps long
wbumps = {{N}} // number of bumps wide
pitch = 8.0
clearance = 0.1
bumpDiam = 4.8
bumpHeight = 1.8
height = 9.6
t = (pitch - (2 * clearance) - bumpDiam) / 2.0
totalLength = lbumps * pitch - (2.0 * clearance)
totalWidth = wbumps * pitch - (2.0 * clearance)
// Create the plane for the pegs. This is a hack so that the pegs can be patterned along the face of the lego base.
const pegFace = {
origin: { x: 0, y: 0, z: height },
xAxis: { x: 1, y: 0, z: 0 },
yAxis: { x: 0, y: 1, z: 0 },
zAxis: { x: 0, y: 0, z: 1 }
pegFace = {
origin = { x = 0, y = 0, z = height },
xAxis = { x = 1, y = 0, z = 0 },
yAxis = { x = 0, y = 1, z = 0 },
zAxis = { x = 0, y = 0, z = 1 }
}
// Create the plane for the tubes underneath the lego. This is a hack so that the tubes can be patterned underneath the lego.
const tubeFace = {
origin: { x: 0, y: 0, z: height - t },
xAxis: { x: 1, y: 0, z: 0 },
yAxis: { x: 0, y: 1, z: 0 },
zAxis: { x: 0, y: 0, z: 1 }
tubeFace = {
origin = { x = 0, y = 0, z = height - t },
xAxis = { x = 1, y = 0, z = 0 },
yAxis = { x = 0, y = 1, z = 0 },
zAxis = { x = 0, y = 0, z = 1 }
}
// Make the base
const s = startSketchOn('XY')
s = startSketchOn('XY')
|> startProfile(at = [-totalWidth / 2, -totalLength / 2])
|> line([totalWidth, 0], %)
|> line([0, totalLength], %)
@ -35,7 +35,7 @@ const s = startSketchOn('XY')
|> extrude(height, %)
// Sketch and extrude a rectangular shape to create the shell underneath the lego. This is a hack until we have a shell function.
const shellExtrude = startSketchOn(s, "start")
shellExtrude = startSketchOn(s, "start")
|> startProfile(at = [
-(totalWidth / 2 - t),
-(totalLength / 2 - t)
@ -46,18 +46,18 @@ const shellExtrude = startSketchOn(s, "start")
|> close(%)
|> extrude(-(height - t), %)
fn tr = (i) => {
let j = i + 1
let x = (j/wbumps) * pitch
let y = (j % wbumps) * pitch
fn tr(i) {
j = i + 1
x = (j/wbumps) * pitch
y = (j % wbumps) * pitch
return {
translate: [x, y, 0],
translate = [x, y, 0],
}
}
// Create the pegs on the top of the base
const totalBumps = (wbumps * lbumps)-1
const peg = startSketchOn(s, 'end')
totalBumps = (wbumps * lbumps)-1
peg = startSketchOn(s, 'end')
|> circle( center = [
-(pitch*(wbumps-1)/2),
-(pitch*(lbumps-1)/2)

View File

@ -1,8 +1,8 @@
let startX = 0
let startY = 0
let angleOffset = 135
let r = 1
let angleStart = 110
startX = 0
startY = 0
angleOffset = 135
r = 1
angleStart = 110
startSketchOn(XY)
|> startProfile(at = [startX, startY])

View File

@ -1,4 +1,4 @@
const boxSketch = startSketchOn(XY)
boxSketch = startSketchOn(XY)
|> startProfile(at = [0, 0])
|> line(end = [0, 10])
|> tangentialArc(radius = 5, angle = 90)

View File

@ -186,7 +186,7 @@ async fn kcl_test_different_planes_same_drawing() {
height = 10
length = 12
fn box = (sk1, sk2, scale, plane) => {
fn box(sk1, sk2, scale, plane) {
boxsketch = startSketchOn(plane)
|> startProfile(at = [sk1, sk2])
|> line(end = [0, scale])
@ -200,7 +200,7 @@ fn box = (sk1, sk2, scale, plane) => {
box(0, 0, 5, 'xy')
box(10, 23, 8, 'xz')
box(30, 43, 18, '-xy')
let thing = box(-12, -15, 10, 'yz')
thing = box(-12, -15, 10, 'yz')
box(-20, -5, 10, 'xy')"#;
let result = execute_and_snapshot(code, None).await.unwrap();
@ -285,7 +285,7 @@ async fn kcl_test_holes() {
#[tokio::test(flavor = "multi_thread")]
async fn optional_params() {
let code = r#"
fn other_circle = (pos, radius, tag?) => {
fn other_circle(pos, radius, tag?) {
sg = startSketchOn(XY)
|> startProfile(at = pos)
|> arc(angleEnd = 360, angleStart = 0, radius = radius)
@ -303,11 +303,11 @@ thing = other_circle([2, 2], 20)
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_rounded_with_holes() {
let code = r#"fn tarc = (to, sktch, tag?) => {
let code = r#"fn tarc(to, sktch, tag?) {
return tangentialArc(sktch, endAbsolute = to, tag = tag)
}
fn roundedRectangle = (pos, w, l, cornerRadius) => {
fn roundedRectangle(pos, w, l, cornerRadius) {
rr = startSketchOn(XY)
|> startProfile(at = [pos[0] - w/2, 0])
|> line(endAbsolute = [pos[0] - w/2, pos[1] - l/2 + cornerRadius])
@ -569,7 +569,7 @@ model = cube"#;
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_cube_mm() {
let code = r#"fn cube = (pos, scale) => {
let code = r#"fn cube(pos, scale) {
sg = startSketchOn(XY)
|> startProfile(at = pos)
|> line(end = [0, scale])
@ -591,7 +591,7 @@ myCube = cube([0,0], 10)
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_cube_cm() {
let code = r#"@settings(defaultLengthUnit = cm)
fn cube = (pos, scale) => {
fn cube(pos, scale) {
sg = startSketchOn(XY)
|> startProfile(at = pos)
|> line(end = [0, scale])
@ -613,7 +613,7 @@ myCube = cube([0,0], 10)
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_cube_m() {
let code = r#"@settings(defaultLengthUnit = m)
fn cube = (pos, scale) => {
fn cube(pos, scale) {
sg = startSketchOn(XY)
|> startProfile(at = pos)
|> line(end = [0, scale])
@ -635,7 +635,7 @@ myCube = cube([0,0], 10)
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_cube_in() {
let code = r#"@settings(defaultLengthUnit = in)
fn cube = (pos, scale) => {
fn cube(pos, scale) {
sg = startSketchOn(XY)
|> startProfile(at = pos)
|> line(end = [0, scale])
@ -657,7 +657,7 @@ myCube = cube([0,0], 10)
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_cube_ft() {
let code = r#"@settings(defaultLengthUnit = ft)
fn cube = (pos, scale) => {
fn cube(pos, scale) {
sg = startSketchOn(XY)
|> startProfile(at = pos)
|> line(end = [0, scale])
@ -679,7 +679,7 @@ myCube = cube([0,0], 10)
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_cube_yd() {
let code = r#"@settings(defaultLengthUnit = yd)
fn cube = (pos, scale) => {
fn cube(pos, scale) {
sg = startSketchOn(XY)
|> startProfile(at = pos)
|> line(end = [0, scale])
@ -700,7 +700,7 @@ myCube = cube([0,0], 10)
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_error_sketch_on_arc_face() {
let code = r#"fn cube = (pos, scale) => {
let code = r#"fn cube(pos, scale) {
sg = startSketchOn(XY)
|> startProfile(at = pos)
|> tangentialArc(end = [0, scale], tag = $here)
@ -736,7 +736,7 @@ part002 = startSketchOn(part001, face = part001.sketch.tags.here)
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_sketch_on_face_of_face() {
let code = r#"fn cube = (pos, scale) => {
let code = r#"fn cube(pos, scale) {
sg = startSketchOn(XY)
|> startProfile(at = pos)
|> line(end = [0, scale])
@ -796,7 +796,7 @@ async fn kcl_test_stdlib_kcl_error_right_code_path() {
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_sketch_on_face_circle() {
let code = r#"fn cube = (pos, scale) => {
let code = r#"fn cube(pos, scale) {
sg = startSketchOn(XY)
|> startProfile(at = pos)
|> line(end = [0, scale])
@ -824,7 +824,7 @@ async fn kcl_test_stdlib_kcl_error_circle() {
// A flat piece of material, often metal or plastic, that serves as a support or base for attaching, securing, or mounting various types of equipment, devices, or components.
// Create a function that defines the body width and length of the mounting plate. Tag the corners so they can be passed through the fillet function.
fn rectShape = (pos, w, l) => {
fn rectShape(pos, w, l) {
rr = startSketchOn(XY)
|> startProfile(at = [pos[0] - (w / 2), pos[1] - (l / 2)])
|> line(endAbsolute = [pos[0] + w / 2, pos[1] - (l / 2)], tag = $edge1)
@ -1011,7 +1011,7 @@ async fn kcl_test_simple_revolve_custom_axis() {
|> line(end = [0, -5.5])
|> line(end = [-2, 0])
|> close()
|> revolve(axis = { direction = [0, -1], origin: [0,0] }, angle = 180)
|> revolve(axis = { direction = [0, -1], origin = [0,0] }, angle = 180)
"#;
@ -1186,7 +1186,7 @@ part002 = startSketchOn(part001, face = END)
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_plumbus_fillets() {
let code = r#"fn make_circle = (ext, face, pos, radius) => {
let code = r#"fn make_circle(ext, face, pos, radius) {
sg = startSketchOn(ext, face = face)
|> startProfile(at = [pos[0] + radius, pos[1]])
|> arc(
@ -1200,7 +1200,7 @@ async fn kcl_test_plumbus_fillets() {
return sg
}
fn pentagon = (len) => {
fn pentagon(len) {
sg = startSketchOn(XY)
|> startProfile(at = [-len / 2, -len / 2])
|> angledLine(angle = 0, length = len, tag = $a)
@ -1261,16 +1261,16 @@ async fn kcl_test_empty_file_is_ok() {
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_member_expression_in_params() {
let code = r#"fn capScrew = (originStart, length, dia, capDia, capHeadLength) => {
let code = r#"fn capScrew(originStart, length, dia, capDia, capHeadLength) {
screwHead = startSketchOn({
origin: {
x: originStart[0],
y: originStart[1],
z: originStart[2],
origin = {
x = originStart[0],
y = originStart[1],
z = originStart[2],
},
xAxis: { x: 0, y: 0, z: -1 },
yAxis: { x: 1, y: 0, z: 0 },
zAxis: { x: 0, y: 1, z: 0 }
xAxis = { x = 0, y = 0, z = -1 },
yAxis = { x = 1, y = 0, z = 0 },
zAxis = { x = 0, y = 1, z = 0 }
})
|> circle(center = [0, 0], radius= capDia / 2)
|> extrude(length = capHeadLength)
@ -1364,7 +1364,7 @@ width = 0.500
height = 0.500
dia = 4
fn squareHole = (l, w) => {
fn squareHole(l, w) {
squareHoleSketch = startSketchOn(XY)
|> startProfile(at = [-width / 2, -length / 2])
|> line(endAbsolute = [width / 2, -length / 2])
@ -1439,7 +1439,7 @@ sketch002 = plane001
|> extrude(length = 10)
let extrudes = [sketch001, sketch002]
extrudes = [sketch001, sketch002]
pattn1 = patternLinear3d(
extrudes,
@ -1571,7 +1571,7 @@ async fn kcl_test_shell_with_tag() {
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_linear_pattern3d_filleted_sketch() {
let code = r#"fn cube = (pos, scale) => {
let code = r#"fn cube(pos, scale) {
sg = startSketchOn(XY)
|> startProfile(at = pos)
|> line(end = [0, scale])
@ -1602,7 +1602,7 @@ pattn1 = patternLinear3d(
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_circular_pattern3d_filleted_sketch() {
let code = r#"fn cube = (pos, scale) => {
let code = r#"fn cube(pos, scale) {
sg = startSketchOn(XY)
|> startProfile(at = pos)
|> line(end = [0, scale])
@ -1629,7 +1629,7 @@ pattn2 = patternCircular3d(part001, axis = [0,0, 1], center = [-20, -20, -20], i
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_circular_pattern3d_chamfered_sketch() {
let code = r#"fn cube = (pos, scale) => {
let code = r#"fn cube(pos, scale) {
sg = startSketchOn(XY)
|> startProfile(at = pos)
|> line(end = [0, scale])
@ -1655,7 +1655,7 @@ pattn2 = patternCircular3d(part001, axis = [0,0, 1], center = [-20, -20, -20], i
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_tag_chamfer_with_more_than_one_edge_should_fail() {
let code = r#"fn cube = (pos, scale) => {
let code = r#"fn cube(pos, scale) {
sg = startSketchOn(XY)
|> startProfile(at = pos)
|> line(end = [0, scale])
@ -1689,7 +1689,7 @@ part001 = cube([0,0], 20)
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_duplicate_tags_should_error() {
let code = r#"fn triangle = (len) => {
let code = r#"fn triangle(len) {
return startSketchOn(XY)
|> startProfile(at = [-len / 2, -len / 2])
|> angledLine(angle = 0, length = len , tag = $a)
@ -1705,7 +1705,7 @@ async fn kcl_test_duplicate_tags_should_error() {
)
}
let p = triangle(200)
p = triangle(200)
"#;
let result = execute_and_snapshot(code, None).await;
@ -1975,7 +1975,7 @@ example = extrude(exampleSketch, length = 10)
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_error_inside_fn_also_has_source_range_of_call_site() {
let code = r#"fn someFunction = (something) => {
let code = r#"fn someFunction(something) {
startSketchOn(something)
}
@ -1986,14 +1986,14 @@ someFunction('INVALID')
assert!(result.is_err());
assert_eq!(
result.err().unwrap().to_string(),
r#"semantic: KclErrorDetails { source_ranges: [SourceRange([51, 60, 0]), SourceRange([65, 88, 0])], message: "This function expected the input argument to be Solid or Plane but it's actually of type string (text)" }"#
r#"semantic: KclErrorDetails { source_ranges: [SourceRange([45, 54, 0]), SourceRange([59, 82, 0])], message: "This function expected the input argument to be Solid or Plane but it's actually of type string (text)" }"#
);
}
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_error_inside_fn_also_has_source_range_of_call_site_recursive() {
let code = r#"fn someFunction = (something) => {
fn someNestedFunction = (something2) => {
let code = r#"fn someFunction(something) {
fn someNestedFunction(something2) {
startSketchOn(something2)
}
@ -2007,13 +2007,13 @@ someFunction('INVALID')
assert!(result.is_err());
assert_eq!(
result.err().unwrap().to_string(),
r#"semantic: KclErrorDetails { source_ranges: [SourceRange([103, 113, 0]), SourceRange([126, 155, 0]), SourceRange([159, 182, 0])], message: "This function expected the input argument to be Solid or Plane but it's actually of type string (text)" }"#
r#"semantic: KclErrorDetails { source_ranges: [SourceRange([91, 101, 0]), SourceRange([114, 143, 0]), SourceRange([147, 170, 0])], message: "This function expected the input argument to be Solid or Plane but it's actually of type string (text)" }"#
);
}
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_error_no_auth_websocket() {
let code = r#"const sketch001 = startSketchOn(XZ)
let code = r#"sketch001 = startSketchOn(XZ)
|> startProfile(at = [61.74, 206.13])
|> xLine(length = 305.11, tag = $seg01)
|> yLine(length = -291.85)

View File

@ -1269,16 +1269,16 @@ mod tests {
#[tokio::test(flavor = "multi_thread")]
async fn test_execute_fn_definitions() {
let ast = r#"fn def = (x) => {
let ast = r#"fn def(x) {
return x
}
fn ghi = (x) => {
fn ghi(x) {
return x
}
fn jkl = (x) => {
fn jkl(x) {
return x
}
fn hmm = (x) => {
fn hmm(x) {
return x
}
@ -1302,8 +1302,8 @@ yo2 = hmm([identifierGuy + 5])"#;
#[tokio::test(flavor = "multi_thread")]
async fn test_execute_with_pipe_substitutions_unary() {
let ast = r#"const myVar = 3
const part001 = startSketchOn(XY)
let ast = r#"myVar = 3
part001 = startSketchOn(XY)
|> startProfile(at = [0, 0])
|> line(end = [3, 4], tag = $seg01)
|> line(end = [
@ -1317,8 +1317,8 @@ const part001 = startSketchOn(XY)
#[tokio::test(flavor = "multi_thread")]
async fn test_execute_with_pipe_substitutions() {
let ast = r#"const myVar = 3
const part001 = startSketchOn(XY)
let ast = r#"myVar = 3
part001 = startSketchOn(XY)
|> startProfile(at = [0, 0])
|> line(end = [3, 4], tag = $seg01)
|> line(end = [
@ -1332,21 +1332,21 @@ const part001 = startSketchOn(XY)
#[tokio::test(flavor = "multi_thread")]
async fn test_execute_with_inline_comment() {
let ast = r#"const baseThick = 1
const armAngle = 60
let ast = r#"baseThick = 1
armAngle = 60
const baseThickHalf = baseThick / 2
const halfArmAngle = armAngle / 2
baseThickHalf = baseThick / 2
halfArmAngle = armAngle / 2
const arrExpShouldNotBeIncluded = [1, 2, 3]
const objExpShouldNotBeIncluded = { a: 1, b: 2, c: 3 }
arrExpShouldNotBeIncluded = [1, 2, 3]
objExpShouldNotBeIncluded = { a = 1, b = 2, c = 3 }
const part001 = startSketchOn(XY)
part001 = startSketchOn(XY)
|> startProfile(at = [0, 0])
|> yLine(endAbsolute = 1)
|> xLine(length = 3.84) // selection-range-7ish-before-this
const variableBelowShouldNotBeIncluded = 3
variableBelowShouldNotBeIncluded = 3
"#;
parse_execute(ast).await.unwrap();
@ -1354,15 +1354,15 @@ const variableBelowShouldNotBeIncluded = 3
#[tokio::test(flavor = "multi_thread")]
async fn test_execute_with_function_literal_in_pipe() {
let ast = r#"const w = 20
const l = 8
const h = 10
let ast = r#"w = 20
l = 8
h = 10
fn thing = () => {
fn thing() {
return -8
}
const firstExtrude = startSketchOn(XY)
firstExtrude = startSketchOn(XY)
|> startProfile(at = [0,0])
|> line(end = [0, l])
|> line(end = [w, 0])
@ -1375,15 +1375,15 @@ const firstExtrude = startSketchOn(XY)
#[tokio::test(flavor = "multi_thread")]
async fn test_execute_with_function_unary_in_pipe() {
let ast = r#"const w = 20
const l = 8
const h = 10
let ast = r#"w = 20
l = 8
h = 10
fn thing = (x) => {
fn thing(x) {
return -x
}
const firstExtrude = startSketchOn(XY)
firstExtrude = startSketchOn(XY)
|> startProfile(at = [0,0])
|> line(end = [0, l])
|> line(end = [w, 0])
@ -1396,15 +1396,15 @@ const firstExtrude = startSketchOn(XY)
#[tokio::test(flavor = "multi_thread")]
async fn test_execute_with_function_array_in_pipe() {
let ast = r#"const w = 20
const l = 8
const h = 10
let ast = r#"w = 20
l = 8
h = 10
fn thing = (x) => {
fn thing(x) {
return [0, -x]
}
const firstExtrude = startSketchOn(XY)
firstExtrude = startSketchOn(XY)
|> startProfile(at = [0,0])
|> line(end = [0, l])
|> line(end = [w, 0])
@ -1417,19 +1417,19 @@ const firstExtrude = startSketchOn(XY)
#[tokio::test(flavor = "multi_thread")]
async fn test_execute_with_function_call_in_pipe() {
let ast = r#"const w = 20
const l = 8
const h = 10
let ast = r#"w = 20
l = 8
h = 10
fn other_thing = (y) => {
fn other_thing(y) {
return -y
}
fn thing = (x) => {
fn thing(x) {
return other_thing(x)
}
const firstExtrude = startSketchOn(XY)
firstExtrude = startSketchOn(XY)
|> startProfile(at = [0,0])
|> line(end = [0, l])
|> line(end = [w, 0])
@ -1442,8 +1442,8 @@ const firstExtrude = startSketchOn(XY)
#[tokio::test(flavor = "multi_thread")]
async fn test_execute_with_function_sketch() {
let ast = r#"fn box = (h, l, w) => {
const myBox = startSketchOn(XY)
let ast = r#"fn box(h, l, w) {
myBox = startSketchOn(XY)
|> startProfile(at = [0,0])
|> line(end = [0, l])
|> line(end = [w, 0])
@ -1454,15 +1454,15 @@ const firstExtrude = startSketchOn(XY)
return myBox
}
const fnBox = box(3, 6, 10)"#;
fnBox = box(3, 6, 10)"#;
parse_execute(ast).await.unwrap();
}
#[tokio::test(flavor = "multi_thread")]
async fn test_get_member_of_object_with_function_period() {
let ast = r#"fn box = (obj) => {
let myBox = startSketchOn(XY)
let ast = r#"fn box(obj) {
myBox = startSketchOn(XY)
|> startProfile(at = obj.start)
|> line(end = [0, obj.l])
|> line(end = [obj.w, 0])
@ -1473,7 +1473,7 @@ const fnBox = box(3, 6, 10)"#;
return myBox
}
const thisBox = box({start: [0,0], l: 6, w: 10, h: 3})
thisBox = box({start = [0,0], l = 6, w = 10, h = 3})
"#;
parse_execute(ast).await.unwrap();
}
@ -1482,7 +1482,7 @@ const thisBox = box({start: [0,0], l: 6, w: 10, h: 3})
#[ignore] // https://github.com/KittyCAD/modeling-app/issues/3338
async fn test_object_member_starting_pipeline() {
let ast = r#"
fn test2 = () => {
fn test2() {
return {
thing: startSketchOn(XY)
|> startProfile(at = [0, 0])
@ -1493,7 +1493,7 @@ fn test2 = () => {
}
}
const x2 = test2()
x2 = test2()
x2.thing
|> extrude(length = 10)
@ -1504,7 +1504,7 @@ x2.thing
#[tokio::test(flavor = "multi_thread")]
#[ignore] // ignore til we get loops
async fn test_execute_with_function_sketch_loop_objects() {
let ast = r#"fn box = (obj) => {
let ast = r#"fn box(obj) {
let myBox = startSketchOn(XY)
|> startProfile(at = obj.start)
|> line(end = [0, obj.l])
@ -1517,7 +1517,7 @@ let myBox = startSketchOn(XY)
}
for var in [{start: [0,0], l: 6, w: 10, h: 3}, {start: [-10,-10], l: 3, w: 5, h: 1.5}] {
const thisBox = box(var)
thisBox = box(var)
}"#;
parse_execute(ast).await.unwrap();
@ -1526,8 +1526,8 @@ for var in [{start: [0,0], l: 6, w: 10, h: 3}, {start: [-10,-10], l: 3, w: 5, h:
#[tokio::test(flavor = "multi_thread")]
#[ignore] // ignore til we get loops
async fn test_execute_with_function_sketch_loop_array() {
let ast = r#"fn box = (h, l, w, start) => {
const myBox = startSketchOn(XY)
let ast = r#"fn box(h, l, w, start) {
myBox = startSketchOn(XY)
|> startProfile(at = [0,0])
|> line(end = [0, l])
|> line(end = [w, 0])
@ -1548,8 +1548,8 @@ for var in [[3, 6, 10, [0,0]], [1.5, 3, 5, [-10,-10]]] {
#[tokio::test(flavor = "multi_thread")]
async fn test_get_member_of_array_with_function() {
let ast = r#"fn box = (arr) => {
let myBox =startSketchOn(XY)
let ast = r#"fn box(arr) {
myBox =startSketchOn(XY)
|> startProfile(at = arr[0])
|> line(end = [0, arr[1]])
|> line(end = [arr[2], 0])
@ -1560,7 +1560,7 @@ for var in [[3, 6, 10, [0,0]], [1.5, 3, 5, [-10,-10]]] {
return myBox
}
const thisBox = box([[0,0], 6, 10, 3])
thisBox = box([[0,0], 6, 10, 3])
"#;
parse_execute(ast).await.unwrap();
@ -1569,27 +1569,18 @@ const thisBox = box([[0,0], 6, 10, 3])
#[tokio::test(flavor = "multi_thread")]
async fn test_function_cannot_access_future_definitions() {
let ast = r#"
fn returnX = () => {
fn returnX() {
// x shouldn't be defined yet.
return x
}
const x = 5
x = 5
const answer = returnX()"#;
answer = returnX()"#;
let result = parse_execute(ast).await;
let err = result.unwrap_err();
assert_eq!(
err,
KclError::UndefinedValue(KclErrorDetails {
message: "`x` is not defined".to_owned(),
source_ranges: vec![
SourceRange::new(64, 65, ModuleId::default()),
SourceRange::new(97, 106, ModuleId::default())
],
}),
);
assert_eq!(err.message(), "`x` is not defined");
}
#[tokio::test(flavor = "multi_thread")]
@ -1619,7 +1610,7 @@ type Other = MyTy | Helix
#[tokio::test(flavor = "multi_thread")]
async fn test_cannot_shebang_in_fn() {
let ast = r#"
fn foo () {
fn foo() {
#!hello
return true
}
@ -1633,7 +1624,7 @@ foo
err,
KclError::Syntax(KclErrorDetails {
message: "Unexpected token: #".to_owned(),
source_ranges: vec![SourceRange::new(15, 16, ModuleId::default())],
source_ranges: vec![SourceRange::new(14, 15, ModuleId::default())],
}),
);
}
@ -1641,36 +1632,30 @@ foo
#[tokio::test(flavor = "multi_thread")]
async fn test_pattern_transform_function_cannot_access_future_definitions() {
let ast = r#"
fn transform = (replicaId) => {
fn transform(replicaId) {
// x shouldn't be defined yet.
let scale = x
scale = x
return {
translate: [0, 0, replicaId * 10],
scale: [scale, 1, 0],
translate = [0, 0, replicaId * 10],
scale = [scale, 1, 0],
}
}
fn layer = () => {
fn layer() {
return startSketchOn(XY)
|> circle( center= [0, 0], radius= 1 , tag =$tag1)
|> circle( center= [0, 0], radius= 1, tag = $tag1)
|> extrude(length = 10)
}
const x = 5
x = 5
// The 10 layers are replicas of each other, with a transform applied to each.
let shape = layer() |> patternTransform(instances = 10, transform = transform)
shape = layer() |> patternTransform(instances = 10, transform = transform)
"#;
let result = parse_execute(ast).await;
let err = result.unwrap_err();
assert_eq!(
err,
KclError::UndefinedValue(KclErrorDetails {
message: "`x` is not defined".to_owned(),
source_ranges: vec![SourceRange::new(80, 81, ModuleId::default())],
}),
);
assert_eq!(err.message(), "`x` is not defined",);
}
// ADAM: Move some of these into simulation tests.
@ -1689,7 +1674,7 @@ let shape = layer() |> patternTransform(instances = 10, transform = transform)
#[tokio::test(flavor = "multi_thread")]
async fn test_math_execute() {
let ast = r#"const myVar = 1 + 2 * (3 - 4) / -5 + 6"#;
let ast = r#"myVar = 1 + 2 * (3 - 4) / -5 + 6"#;
let result = parse_execute(ast).await.unwrap();
assert_eq!(
7.4,
@ -1701,7 +1686,7 @@ let shape = layer() |> patternTransform(instances = 10, transform = transform)
#[tokio::test(flavor = "multi_thread")]
async fn test_math_execute_start_negative() {
let ast = r#"const myVar = -5 + 6"#;
let ast = r#"myVar = -5 + 6"#;
let result = parse_execute(ast).await.unwrap();
assert_eq!(
1.0,
@ -1713,7 +1698,7 @@ let shape = layer() |> patternTransform(instances = 10, transform = transform)
#[tokio::test(flavor = "multi_thread")]
async fn test_math_execute_with_pi() {
let ast = r#"const myVar = PI * 2"#;
let ast = r#"myVar = PI * 2"#;
let result = parse_execute(ast).await.unwrap();
assert_eq!(
std::f64::consts::TAU,
@ -1725,7 +1710,7 @@ let shape = layer() |> patternTransform(instances = 10, transform = transform)
#[tokio::test(flavor = "multi_thread")]
async fn test_math_define_decimal_without_leading_zero() {
let ast = r#"let thing = .4 + 7"#;
let ast = r#"thing = .4 + 7"#;
let result = parse_execute(ast).await.unwrap();
assert_eq!(
7.4,
@ -1737,12 +1722,12 @@ let shape = layer() |> patternTransform(instances = 10, transform = transform)
#[tokio::test(flavor = "multi_thread")]
async fn test_zero_param_fn() {
let ast = r#"const sigmaAllow = 35000 // psi
const leg1 = 5 // inches
const leg2 = 8 // inches
fn thickness = () => { return 0.56 }
let ast = r#"sigmaAllow = 35000 // psi
leg1 = 5 // inches
leg2 = 8 // inches
fn thickness() { return 0.56 }
const bracket = startSketchOn(XY)
bracket = startSketchOn(XY)
|> startProfile(at = [0,0])
|> line(end = [0, leg1])
|> line(end = [leg2, 0])
@ -1765,7 +1750,7 @@ d = !returnTrue()
assertIs(!false, error = "expected to pass")
fn check = (x) => {
fn check(x) {
assertIs(!x, error = "expected argument to be false")
return true
}
@ -1802,74 +1787,56 @@ check(false)
async fn test_unary_operator_not_on_non_bool_fails() {
let code1 = r#"
// Yup, this is null.
let myNull = 0 / 0
let notNull = !myNull
myNull = 0 / 0
notNull = !myNull
"#;
assert_eq!(
parse_execute(code1).await.unwrap_err(),
KclError::Semantic(KclErrorDetails {
message: "Cannot apply unary operator ! to non-boolean value: number".to_owned(),
source_ranges: vec![SourceRange::new(56, 63, ModuleId::default())],
})
parse_execute(code1).await.unwrap_err().message(),
"Cannot apply unary operator ! to non-boolean value: number",
);
let code2 = "let notZero = !0";
let code2 = "notZero = !0";
assert_eq!(
parse_execute(code2).await.unwrap_err(),
KclError::Semantic(KclErrorDetails {
message: "Cannot apply unary operator ! to non-boolean value: number".to_owned(),
source_ranges: vec![SourceRange::new(14, 16, ModuleId::default())],
})
parse_execute(code2).await.unwrap_err().message(),
"Cannot apply unary operator ! to non-boolean value: number",
);
let code3 = r#"
let notEmptyString = !""
notEmptyString = !""
"#;
assert_eq!(
parse_execute(code3).await.unwrap_err(),
KclError::Semantic(KclErrorDetails {
message: "Cannot apply unary operator ! to non-boolean value: string (text)".to_owned(),
source_ranges: vec![SourceRange::new(22, 25, ModuleId::default())],
})
parse_execute(code3).await.unwrap_err().message(),
"Cannot apply unary operator ! to non-boolean value: string (text)",
);
let code4 = r#"
let obj = { a: 1 }
let notMember = !obj.a
obj = { a = 1 }
notMember = !obj.a
"#;
assert_eq!(
parse_execute(code4).await.unwrap_err(),
KclError::Semantic(KclErrorDetails {
message: "Cannot apply unary operator ! to non-boolean value: number".to_owned(),
source_ranges: vec![SourceRange::new(36, 42, ModuleId::default())],
})
parse_execute(code4).await.unwrap_err().message(),
"Cannot apply unary operator ! to non-boolean value: number",
);
let code5 = "
let a = []
let notArray = !a";
a = []
notArray = !a";
assert_eq!(
parse_execute(code5).await.unwrap_err(),
KclError::Semantic(KclErrorDetails {
message: "Cannot apply unary operator ! to non-boolean value: array (list)".to_owned(),
source_ranges: vec![SourceRange::new(27, 29, ModuleId::default())],
})
parse_execute(code5).await.unwrap_err().message(),
"Cannot apply unary operator ! to non-boolean value: array (list)",
);
let code6 = "
let x = {}
let notObject = !x";
x = {}
notObject = !x";
assert_eq!(
parse_execute(code6).await.unwrap_err(),
KclError::Semantic(KclErrorDetails {
message: "Cannot apply unary operator ! to non-boolean value: object".to_owned(),
source_ranges: vec![SourceRange::new(28, 30, ModuleId::default())],
})
parse_execute(code6).await.unwrap_err().message(),
"Cannot apply unary operator ! to non-boolean value: object",
);
let code7 = "
fn x = () => { return 1 }
let notFunction = !x";
fn x() { return 1 }
notFunction = !x";
let fn_err = parse_execute(code7).await.unwrap_err();
// These are currently printed out as JSON objects, so we don't want to
// check the full error.
@ -1882,8 +1849,8 @@ let notFunction = !x";
);
let code8 = "
let myTagDeclarator = $myTag
let notTagDeclarator = !myTagDeclarator";
myTagDeclarator = $myTag
notTagDeclarator = !myTagDeclarator";
let tag_declarator_err = parse_execute(code8).await.unwrap_err();
// These are currently printed out as JSON objects, so we don't want to
// check the full error.
@ -1896,8 +1863,8 @@ let notTagDeclarator = !myTagDeclarator";
);
let code9 = "
let myTagDeclarator = $myTag
let notTagIdentifier = !myTag";
myTagDeclarator = $myTag
notTagIdentifier = !myTag";
let tag_identifier_err = parse_execute(code9).await.unwrap_err();
// These are currently printed out as JSON objects, so we don't want to
// check the full error.
@ -1909,27 +1876,27 @@ let notTagIdentifier = !myTag";
tag_identifier_err
);
let code10 = "let notPipe = !(1 |> 2)";
let code10 = "notPipe = !(1 |> 2)";
assert_eq!(
// TODO: We don't currently parse this, but we should. It should be
// a runtime error instead.
parse_execute(code10).await.unwrap_err(),
KclError::Syntax(KclErrorDetails {
message: "Unexpected token: !".to_owned(),
source_ranges: vec![SourceRange::new(14, 15, ModuleId::default())],
source_ranges: vec![SourceRange::new(10, 11, ModuleId::default())],
})
);
let code11 = "
fn identity = (x) => { return x }
let notPipeSub = 1 |> identity(!%))";
fn identity(x) { return x }
notPipeSub = 1 |> identity(!%))";
assert_eq!(
// TODO: We don't currently parse this, but we should. It should be
// a runtime error instead.
parse_execute(code11).await.unwrap_err(),
KclError::Syntax(KclErrorDetails {
message: "Unexpected token: |>".to_owned(),
source_ranges: vec![SourceRange::new(54, 56, ModuleId::default())],
source_ranges: vec![SourceRange::new(44, 46, ModuleId::default())],
})
);
@ -1940,20 +1907,20 @@ let notPipeSub = 1 |> identity(!%))";
#[tokio::test(flavor = "multi_thread")]
async fn test_math_negative_variable_in_binary_expression() {
let ast = r#"const sigmaAllow = 35000 // psi
const width = 1 // inch
let ast = r#"sigmaAllow = 35000 // psi
width = 1 // inch
const p = 150 // lbs
const distance = 6 // inches
const FOS = 2
p = 150 // lbs
distance = 6 // inches
FOS = 2
const leg1 = 5 // inches
const leg2 = 8 // inches
leg1 = 5 // inches
leg2 = 8 // inches
const thickness_squared = distance * p * FOS * 6 / sigmaAllow
const thickness = 0.56 // inches. App does not support square root function yet
thickness_squared = distance * p * FOS * 6 / sigmaAllow
thickness = 0.56 // inches. App does not support square root function yet
const bracket = startSketchOn(XY)
bracket = startSketchOn(XY)
|> startProfile(at = [0,0])
|> line(end = [0, leg1])
|> line(end = [leg2, 0])
@ -1965,7 +1932,7 @@ const bracket = startSketchOn(XY)
#[tokio::test(flavor = "multi_thread")]
async fn test_execute_function_no_return() {
let ast = r#"fn test = (origin) => {
let ast = r#"fn test(origin) {
origin
}
@ -1978,16 +1945,16 @@ test([0, 0])
#[tokio::test(flavor = "multi_thread")]
async fn test_math_doubly_nested_parens() {
let ast = r#"const sigmaAllow = 35000 // psi
const width = 4 // inch
const p = 150 // Force on shelf - lbs
const distance = 6 // inches
const FOS = 2
const leg1 = 5 // inches
const leg2 = 8 // inches
const thickness_squared = (distance * p * FOS * 6 / (sigmaAllow - width))
const thickness = 0.32 // inches. App does not support square root function yet
const bracket = startSketchOn(XY)
let ast = r#"sigmaAllow = 35000 // psi
width = 4 // inch
p = 150 // Force on shelf - lbs
distance = 6 // inches
FOS = 2
leg1 = 5 // inches
leg2 = 8 // inches
thickness_squared = (distance * p * FOS * 6 / (sigmaAllow - width))
thickness = 0.32 // inches. App does not support square root function yet
bracket = startSketchOn(XY)
|> startProfile(at = [0,0])
|> line(end = [0, leg1])
|> line(end = [leg2, 0])
@ -2002,16 +1969,16 @@ const bracket = startSketchOn(XY)
#[tokio::test(flavor = "multi_thread")]
async fn test_math_nested_parens_one_less() {
let ast = r#"const sigmaAllow = 35000 // psi
const width = 4 // inch
const p = 150 // Force on shelf - lbs
const distance = 6 // inches
const FOS = 2
const leg1 = 5 // inches
const leg2 = 8 // inches
const thickness_squared = distance * p * FOS * 6 / (sigmaAllow - width)
const thickness = 0.32 // inches. App does not support square root function yet
const bracket = startSketchOn(XY)
let ast = r#" sigmaAllow = 35000 // psi
width = 4 // inch
p = 150 // Force on shelf - lbs
distance = 6 // inches
FOS = 2
leg1 = 5 // inches
leg2 = 8 // inches
thickness_squared = distance * p * FOS * 6 / (sigmaAllow - width)
thickness = 0.32 // inches. App does not support square root function yet
bracket = startSketchOn(XY)
|> startProfile(at = [0,0])
|> line(end = [0, leg1])
|> line(end = [leg2, 0])
@ -2026,11 +1993,11 @@ const bracket = startSketchOn(XY)
#[tokio::test(flavor = "multi_thread")]
async fn test_fn_as_operand() {
let ast = r#"fn f = () => { return 1 }
let x = f()
let y = x + 1
let z = f() + 1
let w = f() + f()
let ast = r#"fn f() { return 1 }
x = f()
y = x + 1
z = f() + 1
w = f() + f()
"#;
parse_execute(ast).await.unwrap();
}

View File

@ -84,34 +84,10 @@ mod tests {
#[tokio::test]
async fn z0001_const() {
assert_finding!(
lint_variables,
Z0001,
"const Thickness = 0.5",
"found 'Thickness'",
None
);
assert_finding!(
lint_variables,
Z0001,
"const THICKNESS = 0.5",
"found 'THICKNESS'",
None
);
assert_finding!(
lint_variables,
Z0001,
"const THICC_NES = 0.5",
"found 'THICC_NES'",
None
);
assert_finding!(
lint_variables,
Z0001,
"const thicc_nes = 0.5",
"found 'thicc_nes'",
None
);
assert_finding!(lint_variables, Z0001, "Thickness = 0.5", "found 'Thickness'", None);
assert_finding!(lint_variables, Z0001, "THICKNESS = 0.5", "found 'THICKNESS'", None);
assert_finding!(lint_variables, Z0001, "THICC_NES = 0.5", "found 'THICC_NES'", None);
assert_finding!(lint_variables, Z0001, "thicc_nes = 0.5", "found 'thicc_nes'", None);
}
test_finding!(
@ -120,13 +96,13 @@ mod tests {
Z0001,
"\
// Define constants
const pipeLength = 40
const pipeSmallDia = 10
const pipeLargeDia = 20
const thickness = 0.5
pipeLength = 40
pipeSmallDia = 10
pipeLargeDia = 20
thickness = 0.5
// Create the sketch to be revolved around the y-axis. Use the small diameter, large diameter, length, and thickness to define the sketch.
const Part001 = startSketchOn(XY)
Part001 = startSketchOn(XY)
|> startProfile(at = [pipeLargeDia - (thickness / 2), 38])
|> line(end = [thickness, 0])
|> line(end = [0, -1])
@ -152,13 +128,13 @@ const Part001 = startSketchOn(XY)
Z0001,
"\
// Define constants
const pipeLength = 40
const pipeSmallDia = 10
const pipeLargeDia = 20
const thickness = 0.5
pipeLength = 40
pipeSmallDia = 10
pipeLargeDia = 20
thickness = 0.5
// Create the sketch to be revolved around the y-axis. Use the small diameter, large diameter, length, and thickness to define the sketch.
const part001 = startSketchOn(XY)
part001 = startSketchOn(XY)
|> startProfile(at = [pipeLargeDia - (thickness / 2), 38])
|> line(end = [thickness, 0])
|> line(end = [0, -1])
@ -181,7 +157,7 @@ const part001 = startSketchOn(XY)
lint_object_properties,
Z0001,
"\
let circ = {angle_start = 0, angle_end = 360, radius = 5}
circ = {angle_start = 0, angle_end = 360, radius = 5}
",
"found 'angle_start'",
None

View File

@ -262,15 +262,15 @@ impl Backend {
// if self.dev_mode
if false {
completion_list.push(
r#"fn cube = (pos, scale) => {
const sg = startSketchOn('XY')
r#"fn cube(pos, scale) {
sg = startSketchOn(XY)
|> startProfile(at = pos)
|> line([0, scale], %)
|> line([scale, 0], %)
|> line([0, -scale], %)
return sg
}
const part001 = cube([0,0], 20)
part001 = cube([0,0], 20)
|> close(%)
|> extrude(length=20)"#
.to_string(),

View File

@ -1573,10 +1573,10 @@ async fn test_kcl_lsp_semantic_tokens_with_modifiers() {
|> close()
|> extrude(length = 3.14)
thing = {blah: "foo"}
thing = {blah = "foo"}
bar = thing.blah
fn myFn = (param1) => {
fn myFn(param1) {
return param1
}"#
.to_string(),

View File

@ -3623,7 +3623,7 @@ mod tests {
#[test]
fn test_get_lsp_folding_ranges() {
let code = r#"const part001 = startSketchOn(XY)
let code = r#"part001 = startSketchOn(XY)
|> startProfile(at = [0.0000000000, 5.0000000000])
|> line([0.4900857016, -0.0240763666], %)
@ -3631,13 +3631,13 @@ startSketchOn(XY)
|> startProfile(at = [0.0000000000, 5.0000000000])
|> line([0.4900857016, -0.0240763666], %)
const part002 = "part002"
const things = [part001, 0.0]
let blah = 1
const foo = false
let baz = {a: 1, b: "thing"}
part002 = "part002"
things = [part001, 0.0]
blah = 1
foo = false
baz = {a = 1, b = "thing"}
fn ghi = (x) => {
fn ghi(x) {
return x
}
@ -3647,32 +3647,32 @@ ghi("things")
let folding_ranges = program.get_lsp_folding_ranges();
assert_eq!(folding_ranges.len(), 3);
assert_eq!(folding_ranges[0].start_line, 27);
assert_eq!(folding_ranges[0].end_line, 132);
assert_eq!(folding_ranges[0].end_line, 126);
assert_eq!(
folding_ranges[0].collapsed_text,
Some("part001 = startSketchOn(XY)".to_string())
);
assert_eq!(folding_ranges[1].start_line, 151);
assert_eq!(folding_ranges[1].end_line, 250);
assert_eq!(folding_ranges[1].start_line, 145);
assert_eq!(folding_ranges[1].end_line, 244);
assert_eq!(folding_ranges[1].collapsed_text, Some("startSketchOn(XY)".to_string()));
assert_eq!(folding_ranges[2].start_line, 380);
assert_eq!(folding_ranges[2].end_line, 399);
assert_eq!(folding_ranges[2].start_line, 350);
assert_eq!(folding_ranges[2].end_line, 363);
assert_eq!(folding_ranges[2].collapsed_text, Some("fn ghi(x) {".to_string()));
}
#[test]
fn test_get_lsp_symbols() {
let code = r#"const part001 = startSketchOn('XY')
let code = r#"part001 = startSketchOn(XY)
|> startProfile(at = [0.0000000000, 5.0000000000])
|> line([0.4900857016, -0.0240763666], %)
const part002 = "part002"
const things = [part001, 0.0]
let blah = 1
const foo = false
let baz = {a: 1, b: "thing"}
part002 = "part002"
things = [part001, 0.0]
blah = 1
foo = false
baz = {a = 1, b = "thing"}
fn ghi = (x) => {
fn ghi(x) {
return x
}
"#;
@ -3684,58 +3684,59 @@ fn ghi = (x) => {
#[test]
fn test_ast_in_comment() {
let some_program_string = r#"r = 20 / pow(pi(), exp = 1 / 3)
const h = 30
h = 30
// st
const cylinder = startSketchOn('-XZ')
cylinder = startSketchOn(-XZ)
|> startProfile(at = [50, 0])
|> arc({
angle_end: 360,
angle_start: 0,
radius: r
angle_end = 360,
angle_start = 0,
radius = r
}, %)
|> extrude(h, %)
"#;
let program = crate::parsing::top_level_parse(some_program_string).unwrap();
assert!(program.in_comment(50));
assert!(program.in_comment(43));
}
#[test]
fn test_ast_in_comment_pipe() {
let some_program_string = r#"r = 20 / pow(pi(), exp = 1 / 3)
const h = 30
h = 30
// st
const cylinder = startSketchOn('-XZ')
cylinder = startSketchOn(-XZ)
|> startProfile(at = [50, 0])
// comment
|> arc({
angle_end: 360,
angle_start: 0,
radius: r
angle_end= 360,
angle_start= 0,
radius= r
}, %)
|> extrude(h, %)
"#;
let program = crate::parsing::top_level_parse(some_program_string).unwrap();
assert!(program.in_comment(124));
assert!(program.in_comment(117));
}
#[test]
fn test_ast_in_comment_inline() {
let some_program_string = r#"const part001 = startSketchOn('XY')
let some_program_string = r#"part001 = startSketchOn(XY)
|> startProfile(at = [0,0])
|> xLine(length = 5) // lin
"#;
let program = crate::parsing::top_level_parse(some_program_string).unwrap();
assert!(program.in_comment(92));
assert!(program.in_comment(85));
}
#[tokio::test(flavor = "multi_thread")]
async fn test_parse_type_args_on_functions() {
let some_program_string = r#"fn thing = (arg0: number(mm), arg1: string, tag?: string) => {
let some_program_string = r#"fn thing(arg0: number(mm), arg1: string, tag?: string) {
return arg0
}"#;
let program = crate::parsing::top_level_parse(some_program_string).unwrap();
@ -3766,7 +3767,7 @@ const cylinder = startSketchOn('-XZ')
#[tokio::test(flavor = "multi_thread")]
async fn test_parse_type_args_array_on_functions() {
let some_program_string = r#"fn thing = (arg0: [number], arg1: [string], tag?: string) => {
let some_program_string = r#"fn thing(arg0: [number], arg1: [string], tag?: string) {
return arg0
}"#;
let program = crate::parsing::top_level_parse(some_program_string).unwrap();
@ -3803,7 +3804,7 @@ const cylinder = startSketchOn('-XZ')
#[tokio::test(flavor = "multi_thread")]
async fn test_parse_type_args_object_on_functions() {
let some_program_string = r#"fn thing = (arg0: [number], arg1: {thing: number, things: [string], more?: string}, tag?: string) => {
let some_program_string = r#"fn thing(arg0: [number], arg1: {thing: number, things: [string], more?: string}, tag?: string) {
return arg0
}"#;
let module_id = ModuleId::default();
@ -3836,14 +3837,14 @@ const cylinder = startSketchOn('-XZ')
name: "thing".to_owned(),
digest: None,
},
35,
40,
32,
37,
module_id,
),
type_: Some(Node::new(
Type::Primitive(PrimitiveType::Number(NumericSuffix::None)),
42,
48,
39,
45,
module_id
)),
default_value: None,
@ -3856,8 +3857,8 @@ const cylinder = startSketchOn('-XZ')
name: "things".to_owned(),
digest: None,
},
50,
56,
47,
53,
module_id,
),
type_: Some(Node::new(
@ -3865,8 +3866,8 @@ const cylinder = startSketchOn('-XZ')
ty: Box::new(Type::Primitive(PrimitiveType::String)),
len: ArrayLen::None
},
59,
65,
56,
62,
module_id
)),
default_value: None,
@ -3879,11 +3880,11 @@ const cylinder = startSketchOn('-XZ')
name: "more".to_owned(),
digest: None
},
68,
72,
65,
69,
module_id,
),
type_: Some(Node::new(Type::Primitive(PrimitiveType::String), 75, 81, module_id)),
type_: Some(Node::new(Type::Primitive(PrimitiveType::String), 72, 78, module_id)),
labeled: true,
default_value: Some(DefaultParamVal::none()),
digest: None
@ -3897,91 +3898,6 @@ const cylinder = startSketchOn('-XZ')
);
}
#[tokio::test(flavor = "multi_thread")]
async fn test_parse_return_type_on_functions() {
let some_program_string = r#"fn thing(): {thing: number, things: [string], more?: string} {
return 1
}"#;
let module_id = ModuleId::default();
let program = crate::parsing::parse_str(some_program_string, module_id).unwrap();
// Check the program output for the types of the parameters.
let function = program.body.first().unwrap();
let BodyItem::VariableDeclaration(var_decl) = function else {
panic!("expected a variable declaration")
};
let Expr::FunctionExpression(ref func_expr) = var_decl.declaration.init else {
panic!("expected a function expression")
};
let params = &func_expr.params;
assert_eq!(params.len(), 0);
assert_eq!(
func_expr.return_type.as_ref().unwrap().inner,
Type::Object {
properties: vec![
Parameter {
identifier: Node::new(
Identifier {
name: "thing".to_owned(),
digest: None
},
13,
18,
module_id,
),
type_: Some(Node::new(
Type::Primitive(PrimitiveType::Number(NumericSuffix::None)),
20,
26,
module_id
)),
default_value: None,
labeled: true,
digest: None
},
Parameter {
identifier: Node::new(
Identifier {
name: "things".to_owned(),
digest: None
},
28,
34,
module_id,
),
type_: Some(Node::new(
Type::Array {
ty: Box::new(Type::Primitive(PrimitiveType::String)),
len: ArrayLen::None
},
37,
43,
module_id
)),
default_value: None,
labeled: true,
digest: None
},
Parameter {
identifier: Node::new(
Identifier {
name: "more".to_owned(),
digest: None
},
46,
50,
module_id,
),
type_: Some(Node::new(Type::Primitive(PrimitiveType::String), 53, 59, module_id)),
labeled: true,
default_value: Some(DefaultParamVal::none()),
digest: None
}
]
}
);
}
#[test]
fn required_params() {
for (i, (test_name, expected, function_expr)) in [

View File

@ -936,7 +936,7 @@ fn object_property(i: &mut TokenSlice) -> PResult<Node<ObjectProperty>> {
);
if sep.token_type == TokenType::Colon {
ParseContext::warn(
ParseContext::err(
CompilationError::err(
sep.into(),
"Using `:` to initialize objects is deprecated, prefer using `=`.",
@ -1221,20 +1221,10 @@ fn if_expr(i: &mut TokenSlice) -> PResult<BoxNode<IfExpression>> {
fn function_expr(i: &mut TokenSlice) -> PResult<Expr> {
let fn_tok = opt(fun).parse_next(i)?;
ignore_whitespace(i);
let (result, has_arrow) = function_decl.parse_next(i)?;
let result = function_decl.parse_next(i)?;
if fn_tok.is_none() {
if has_arrow {
ParseContext::warn(
CompilationError::err(
result.as_source_range().start_as_range(),
"Missing `fn` in function declaration",
)
.with_suggestion("Add `fn`", "fn", None, Tag::None),
);
} else {
let err = CompilationError::fatal(result.as_source_range(), "Anonymous function requires `fn` before `(`");
return Err(ErrMode::Cut(err.into()));
}
let err = CompilationError::fatal(result.as_source_range(), "Anonymous function requires `fn` before `(`");
return Err(ErrMode::Cut(err.into()));
}
Ok(Expr::FunctionExpression(Box::new(result)))
}
@ -1244,7 +1234,7 @@ fn function_expr(i: &mut TokenSlice) -> PResult<Expr> {
// const x = arg0 + arg1;
// return x
// }
fn function_decl(i: &mut TokenSlice) -> PResult<(Node<FunctionExpression>, bool)> {
fn function_decl(i: &mut TokenSlice) -> PResult<Node<FunctionExpression>> {
fn return_type(i: &mut TokenSlice) -> PResult<Node<Type>> {
colon(i)?;
ignore_whitespace(i);
@ -1256,8 +1246,6 @@ fn function_decl(i: &mut TokenSlice) -> PResult<(Node<FunctionExpression>, bool)
let params = parameters(i)?;
close_paren(i)?;
ignore_whitespace(i);
let arrow = opt(big_arrow).parse_next(i)?;
ignore_whitespace(i);
// Optional return type.
let return_type = opt(return_type).parse_next(i)?;
ignore_whitespace(i);
@ -1282,18 +1270,7 @@ fn function_decl(i: &mut TokenSlice) -> PResult<(Node<FunctionExpression>, bool)
open.module_id,
);
let has_arrow =
if let Some(arrow) = arrow {
ParseContext::warn(
CompilationError::err(arrow.as_source_range(), "Unnecessary `=>` in function declaration")
.with_suggestion("Remove `=>`", "", None, Tag::Unnecessary),
);
true
} else {
false
};
Ok((result, has_arrow))
Ok(result)
}
/// E.g. `person.name`
@ -2140,7 +2117,7 @@ fn declaration(i: &mut TokenSlice) -> PResult<BoxNode<VariableDeclaration>> {
ignore_whitespace(i);
let val = function_decl
.map(|t| Box::new(t.0))
.map(Box::new)
.map(Expr::FunctionExpression)
.context(expected("a KCL function expression, like () { return 1 }"))
.parse_next(i);
@ -2174,7 +2151,7 @@ fn declaration(i: &mut TokenSlice) -> PResult<BoxNode<VariableDeclaration>> {
if let Some((_, tok)) = decl_token {
let range_to_remove = SourceRange::new(tok.start, id.start, id.module_id);
ParseContext::warn(
ParseContext::err(
CompilationError::err(
tok.as_source_range(),
format!(
@ -2582,12 +2559,6 @@ fn some_brace(symbol: &'static str, i: &mut TokenSlice) -> PResult<Token> {
.parse_next(i)
}
/// Parse a => operator.
fn big_arrow(i: &mut TokenSlice) -> PResult<Token> {
one_of((TokenType::Operator, "=>"))
.context(expected("the => symbol, used for declaring functions"))
.parse_next(i)
}
/// Parse a |> operator.
fn pipe_operator(i: &mut TokenSlice) -> PResult<Token> {
one_of((TokenType::Operator, PIPE_OPERATOR))
@ -3313,7 +3284,7 @@ mod tests {
return 1
}"#;
let tokens = crate::parsing::token::lex(test_program, ModuleId::default()).unwrap();
let expr = function_decl.map(|t| t.0).parse_next(&mut tokens.as_slice()).unwrap();
let expr = function_decl.parse_next(&mut tokens.as_slice()).unwrap();
assert_eq!(expr.params, vec![]);
let comment_start = expr.body.body[0].get_comments();
let comment0 = expr.body.body[1].get_comments();
@ -3330,7 +3301,7 @@ mod tests {
comment */
}"#;
let tokens = crate::parsing::token::lex(test_program, ModuleId::default()).unwrap();
let expr = function_decl.map(|t| t.0).parse_next(&mut tokens.as_slice()).unwrap();
let expr = function_decl.parse_next(&mut tokens.as_slice()).unwrap();
let comment0 = &expr.body.non_code_meta.non_code_nodes.get(&0).unwrap()[0];
assert_eq!(comment0.value(), "block\ncomment");
}
@ -3399,7 +3370,7 @@ mySk1 = startSketchOn(XY)
}";
let module_id = ModuleId::from_usize(1);
let tokens = crate::parsing::token::lex(test_program, module_id).unwrap();
let expr = function_decl.map(|t| t.0).parse_next(&mut tokens.as_slice()).unwrap();
let expr = function_decl.parse_next(&mut tokens.as_slice()).unwrap();
assert_eq!(
expr.body.non_code_meta.start_nodes,
vec![Node::new(
@ -4559,7 +4530,7 @@ export fn cos(num: number(rad)): number(_) {}"#;
#[test]
fn zero_param_function() {
let code = r#"
fn firstPrimeNumber = () => {
fn firstPrimeNumber() {
return 2
}
firstPrimeNumber()
@ -4647,26 +4618,6 @@ thing(false)
crate::parsing::top_level_parse(some_program_string).unwrap();
}
#[test]
fn test_error_define_function_as_var() {
for name in ["var", "let", "const"] {
let some_program_string = format!(
r#"{} thing = (param) => {{
return true
}}
thing(false)
"#,
name
);
assert_err(
&some_program_string,
"Expected a `fn` variable kind, found: `const`",
[0, name.len()],
);
}
}
#[test]
fn test_error_define_var_as_function() {
// TODO: https://github.com/KittyCAD/modeling-app/issues/784
@ -4690,7 +4641,7 @@ thing(false)
#[test]
fn test_member_expression_sketch() {
let some_program_string = r#"fn cube = (pos, scale) => {
let some_program_string = r#"fn cube(pos, scale) {
sg = startSketchOn('XY')
|> startProfileAt(pos, %)
|> line([0, scale], %)
@ -4718,7 +4669,7 @@ let other_thing = 2 * cos(3)"#;
#[test]
fn test_negative_arguments() {
let some_program_string = r#"fn box = (p, h, l, w) => {
let some_program_string = r#"fn box(p, h, l, w) {
myBox = startSketchOn('XY')
|> startProfileAt(p, %)
|> line([0, l], %)
@ -4969,67 +4920,6 @@ bar = 1
);
}
#[test]
fn warn_object_expr() {
let some_program_string = "{ foo: bar }";
let (_, errs) = assert_no_err(some_program_string);
assert_eq!(errs.len(), 1);
assert_eq!(errs[0].apply_suggestion(some_program_string).unwrap(), "{ foo = bar }")
}
#[test]
fn warn_fn_decl() {
let some_program_string = r#"fn foo = () => {
return 0
}"#;
let (_, errs) = assert_no_err(some_program_string);
assert_eq!(errs.len(), 2);
let replaced = errs[0].apply_suggestion(some_program_string).unwrap();
let replaced = errs[1].apply_suggestion(&replaced).unwrap();
// Note the whitespace here is bad, but we're just testing the suggestion spans really. In
// real life we might reformat after applying suggestions.
assert_eq!(
replaced,
r#"fn foo () {
return 0
}"#
);
let some_program_string = r#"myMap = map([0..5], (n) => {
return n * 2
})"#;
let (_, errs) = assert_no_err(some_program_string);
assert_eq!(errs.len(), 2);
let replaced = errs[0].apply_suggestion(some_program_string).unwrap();
let replaced = errs[1].apply_suggestion(&replaced).unwrap();
assert_eq!(
replaced,
r#"myMap = map([0..5], fn(n) {
return n * 2
})"#
);
}
#[test]
fn warn_const() {
let some_program_string = r#"const foo = 0
let bar = 1
var baz = 2
"#;
let (_, errs) = assert_no_err(some_program_string);
assert_eq!(errs.len(), 3);
let replaced = errs[2].apply_suggestion(some_program_string).unwrap();
let replaced = errs[1].apply_suggestion(&replaced).unwrap();
let replaced = errs[0].apply_suggestion(&replaced).unwrap();
assert_eq!(
replaced,
r#"foo = 0
bar = 1
baz = 2
"#
);
}
#[test]
fn test_unary_not_on_keyword_bool() {
let some_program_string = r#"!true"#;
@ -5196,11 +5086,11 @@ mod snapshot_tests {
snapshot_test!(c, "myVar = min(-legLen(5, 4), 5)");
snapshot_test!(d, "myVar = 5 + 6 |> myFunc(45, %)");
snapshot_test!(e, "let x = 1 * (3 - 4)");
snapshot_test!(e, "x = 1 * (3 - 4)");
snapshot_test!(f, r#"x = 1 // this is an inline comment"#);
snapshot_test!(
g,
r#"fn x = () => {
r#"fn x() {
return sg
return sg
}"#
@ -5208,32 +5098,32 @@ mod snapshot_tests {
snapshot_test!(d2, r#"x = -leg2 + thickness"#);
snapshot_test!(
h,
r#"obj = { a: 1, b: 2 }
r#"obj = { a = 1, b = 2 }
height = 1 - obj.a"#
);
snapshot_test!(
i,
r#"obj = { a: 1, b: 2 }
r#"obj = { a = 1, b = 2 }
height = 1 - obj["a"]"#
);
snapshot_test!(
j,
r#"obj = { a: 1, b: 2 }
r#"obj = { a = 1, b = 2 }
height = obj["a"] - 1"#
);
snapshot_test!(
k,
r#"obj = { a: 1, b: 2 }
r#"obj = { a = 1, b = 2 }
height = [1 - obj["a"], 0]"#
);
snapshot_test!(
l,
r#"obj = { a: 1, b: 2 }
r#"obj = { a = 1, b = 2 }
height = [obj["a"] - 1, 0]"#
);
snapshot_test!(
m,
r#"obj = { a: 1, b: 2 }
r#"obj = {a = 1, b = 2 }
height = [obj["a"] -1, 0]"#
);
snapshot_test!(n, "height = 1 - obj.a");
@ -5242,7 +5132,7 @@ mod snapshot_tests {
snapshot_test!(q, r#"height = [ obj["a"], 0 ]"#);
snapshot_test!(
r,
r#"obj = { a: 1, b: 2 }
r#"obj = { a = 1, b = 2 }
height = obj["a"]"#
);
snapshot_test!(s, r#"prop = yo["one"][two]"#);
@ -5263,14 +5153,14 @@ mod snapshot_tests {
snapshot_test!(
ad,
r#"
fn firstPrimeNumber = () => {
fn firstPrimeNumber() {
return 2
}
firstPrimeNumber()"#
);
snapshot_test!(
ae,
r#"fn thing = (param) => {
r#"fn thing(param) {
return true
}
thing(false)"#
@ -5300,10 +5190,10 @@ mod snapshot_tests {
snapshot_test!(ar, r#"5 + "a""#);
snapshot_test!(at, "line([0, l], %)");
snapshot_test!(au, include_str!("../../e2e/executor/inputs/cylinder.kcl"));
snapshot_test!(av, "fn f = (angle?) => { return default(angle, 360) }");
snapshot_test!(av, "fn f(angle?) { return default(angle, 360) }");
snapshot_test!(
aw,
"let numbers = [
"numbers = [
1,
// A,
// B,
@ -5312,7 +5202,7 @@ mod snapshot_tests {
);
snapshot_test!(
ax,
"let numbers = [
"numbers = [
1,
2,
// A,
@ -5329,7 +5219,7 @@ mod snapshot_tests {
);
snapshot_test!(
az,
"let props = {
"props = {
a: 1,
// b: 2,
c: 3
@ -5359,14 +5249,14 @@ my14 = 4 ^ 2 - 3 ^ 2 * 2
5
}"#
);
snapshot_test!(be, "let x = 3 == 3");
snapshot_test!(bf, "let x = 3 != 3");
snapshot_test!(be, "x = 3 == 3");
snapshot_test!(bf, "x = 3 != 3");
snapshot_test!(bg, r#"x = 4"#);
snapshot_test!(bh, "obj = {center : [10, 10], radius: 5}");
snapshot_test!(bh, "obj = {center = [10, 10], radius =5}");
snapshot_test!(
bi,
r#"x = 3
obj = { x, y: 4}"#
obj = { x, y = 4}"#
);
snapshot_test!(bj, "true");
snapshot_test!(bk, "truee");

View File

@ -8,7 +8,7 @@ expression: actual
"commentStart": 5,
"declaration": {
"commentStart": 8,
"end": 57,
"end": 51,
"id": {
"commentStart": 8,
"end": 24,
@ -21,10 +21,10 @@ expression: actual
"body": [
{
"argument": {
"commentStart": 50,
"end": 51,
"commentStart": 44,
"end": 45,
"raw": "2",
"start": 50,
"start": 44,
"type": "Literal",
"type": "Literal",
"value": {
@ -32,65 +32,65 @@ expression: actual
"suffix": "None"
}
},
"commentStart": 43,
"end": 51,
"start": 43,
"commentStart": 37,
"end": 45,
"start": 37,
"type": "ReturnStatement",
"type": "ReturnStatement"
}
],
"commentStart": 33,
"end": 57,
"start": 33
"commentStart": 27,
"end": 51,
"start": 27
},
"commentStart": 27,
"end": 57,
"commentStart": 24,
"end": 51,
"params": [],
"start": 27,
"start": 24,
"type": "FunctionExpression",
"type": "FunctionExpression"
},
"start": 8,
"type": "VariableDeclarator"
},
"end": 57,
"end": 51,
"kind": "fn",
"start": 5,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"commentStart": 62,
"end": 80,
"commentStart": 56,
"end": 74,
"expression": {
"arguments": [],
"callee": {
"abs_path": false,
"commentStart": 62,
"end": 78,
"commentStart": 56,
"end": 72,
"name": {
"commentStart": 62,
"end": 78,
"commentStart": 56,
"end": 72,
"name": "firstPrimeNumber",
"start": 62,
"start": 56,
"type": "Identifier"
},
"path": [],
"start": 62,
"start": 56,
"type": "Name"
},
"commentStart": 62,
"end": 80,
"start": 62,
"commentStart": 56,
"end": 74,
"start": 56,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 62,
"start": 56,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
}
],
"commentStart": 0,
"end": 80,
"end": 74,
"start": 0
}

View File

@ -8,7 +8,7 @@ expression: actual
"commentStart": 0,
"declaration": {
"commentStart": 3,
"end": 49,
"end": 43,
"id": {
"commentStart": 3,
"end": 8,
@ -21,62 +21,62 @@ expression: actual
"body": [
{
"argument": {
"commentStart": 39,
"end": 43,
"commentStart": 33,
"end": 37,
"raw": "true",
"start": 39,
"start": 33,
"type": "Literal",
"type": "Literal",
"value": true
},
"commentStart": 32,
"end": 43,
"start": 32,
"commentStart": 26,
"end": 37,
"start": 26,
"type": "ReturnStatement",
"type": "ReturnStatement"
}
],
"commentStart": 22,
"end": 49,
"start": 22
"commentStart": 16,
"end": 43,
"start": 16
},
"commentStart": 11,
"end": 49,
"commentStart": 8,
"end": 43,
"params": [
{
"type": "Parameter",
"identifier": {
"commentStart": 12,
"end": 17,
"commentStart": 9,
"end": 14,
"name": "param",
"start": 12,
"start": 9,
"type": "Identifier"
}
}
],
"start": 11,
"start": 8,
"type": "FunctionExpression",
"type": "FunctionExpression"
},
"start": 3,
"type": "VariableDeclarator"
},
"end": 49,
"end": 43,
"kind": "fn",
"start": 0,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"commentStart": 54,
"end": 66,
"commentStart": 48,
"end": 60,
"expression": {
"arguments": [
{
"commentStart": 60,
"end": 65,
"commentStart": 54,
"end": 59,
"raw": "false",
"start": 60,
"start": 54,
"type": "Literal",
"type": "Literal",
"value": false
@ -84,31 +84,31 @@ expression: actual
],
"callee": {
"abs_path": false,
"commentStart": 54,
"end": 59,
"commentStart": 48,
"end": 53,
"name": {
"commentStart": 54,
"end": 59,
"commentStart": 48,
"end": 53,
"name": "thing",
"start": 54,
"start": 48,
"type": "Identifier"
},
"path": [],
"start": 54,
"start": 48,
"type": "Name"
},
"commentStart": 54,
"end": 66,
"start": 54,
"commentStart": 48,
"end": 60,
"start": 48,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 54,
"start": 48,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
}
],
"commentStart": 0,
"end": 66,
"end": 60,
"start": 0
}

View File

@ -7,13 +7,13 @@ expression: actual
{
"commentStart": 0,
"declaration": {
"commentStart": 6,
"end": 104,
"commentStart": 0,
"end": 98,
"id": {
"commentStart": 6,
"end": 14,
"commentStart": 0,
"end": 8,
"name": "cylinder",
"start": 6,
"start": 0,
"type": "Identifier"
},
"init": {
@ -22,39 +22,39 @@ expression: actual
"arguments": [
{
"abs_path": false,
"commentStart": 31,
"end": 33,
"commentStart": 25,
"end": 27,
"name": {
"commentStart": 31,
"end": 33,
"commentStart": 25,
"end": 27,
"name": "XY",
"start": 31,
"start": 25,
"type": "Identifier"
},
"path": [],
"start": 31,
"start": 25,
"type": "Name",
"type": "Name"
}
],
"callee": {
"abs_path": false,
"commentStart": 17,
"end": 30,
"commentStart": 11,
"end": 24,
"name": {
"commentStart": 17,
"end": 30,
"commentStart": 11,
"end": 24,
"name": "startSketchOn",
"start": 17,
"start": 11,
"type": "Identifier"
},
"path": [],
"start": 17,
"start": 11,
"type": "Name"
},
"commentStart": 17,
"end": 34,
"start": 17,
"commentStart": 11,
"end": 28,
"start": 11,
"type": "CallExpression",
"type": "CallExpression"
},
@ -63,20 +63,20 @@ expression: actual
{
"type": "LabeledArg",
"label": {
"commentStart": 49,
"end": 55,
"commentStart": 43,
"end": 49,
"name": "center",
"start": 49,
"start": 43,
"type": "Identifier"
},
"arg": {
"commentStart": 57,
"commentStart": 51,
"elements": [
{
"commentStart": 58,
"end": 59,
"commentStart": 52,
"end": 53,
"raw": "0",
"start": 58,
"start": 52,
"type": "Literal",
"type": "Literal",
"value": {
@ -85,10 +85,10 @@ expression: actual
}
},
{
"commentStart": 61,
"end": 62,
"commentStart": 55,
"end": 56,
"raw": "0",
"start": 61,
"start": 55,
"type": "Literal",
"type": "Literal",
"value": {
@ -97,8 +97,8 @@ expression: actual
}
}
],
"end": 63,
"start": 57,
"end": 57,
"start": 51,
"type": "ArrayExpression",
"type": "ArrayExpression"
}
@ -106,17 +106,17 @@ expression: actual
{
"type": "LabeledArg",
"label": {
"commentStart": 65,
"end": 71,
"commentStart": 59,
"end": 65,
"name": "radius",
"start": 65,
"start": 59,
"type": "Identifier"
},
"arg": {
"commentStart": 73,
"end": 75,
"commentStart": 67,
"end": 69,
"raw": "22",
"start": 73,
"start": 67,
"type": "Literal",
"type": "Literal",
"value": {
@ -128,22 +128,22 @@ expression: actual
],
"callee": {
"abs_path": false,
"commentStart": 42,
"end": 48,
"commentStart": 36,
"end": 42,
"name": {
"commentStart": 42,
"end": 48,
"commentStart": 36,
"end": 42,
"name": "circle",
"start": 42,
"start": 36,
"type": "Identifier"
},
"path": [],
"start": 42,
"start": 36,
"type": "Name"
},
"commentStart": 42,
"end": 76,
"start": 42,
"commentStart": 36,
"end": 70,
"start": 36,
"type": "CallExpressionKw",
"type": "CallExpressionKw",
"unlabeled": null
@ -153,17 +153,17 @@ expression: actual
{
"type": "LabeledArg",
"label": {
"commentStart": 92,
"end": 98,
"commentStart": 86,
"end": 92,
"name": "length",
"start": 92,
"start": 86,
"type": "Identifier"
},
"arg": {
"commentStart": 101,
"end": 103,
"commentStart": 95,
"end": 97,
"raw": "14",
"start": 101,
"start": 95,
"type": "Literal",
"type": "Literal",
"value": {
@ -175,37 +175,37 @@ expression: actual
],
"callee": {
"abs_path": false,
"commentStart": 84,
"end": 91,
"commentStart": 78,
"end": 85,
"name": {
"commentStart": 84,
"end": 91,
"commentStart": 78,
"end": 85,
"name": "extrude",
"start": 84,
"start": 78,
"type": "Identifier"
},
"path": [],
"start": 84,
"start": 78,
"type": "Name"
},
"commentStart": 84,
"end": 104,
"start": 84,
"commentStart": 78,
"end": 98,
"start": 78,
"type": "CallExpressionKw",
"type": "CallExpressionKw",
"unlabeled": null
}
],
"commentStart": 17,
"end": 104,
"start": 17,
"commentStart": 11,
"end": 98,
"start": 11,
"type": "PipeExpression",
"type": "PipeExpression"
},
"start": 6,
"start": 0,
"type": "VariableDeclarator"
},
"end": 104,
"end": 98,
"kind": "const",
"start": 0,
"type": "VariableDeclaration",
@ -213,6 +213,6 @@ expression: actual
}
],
"commentStart": 0,
"end": 105,
"end": 99,
"start": 0
}

View File

@ -8,7 +8,7 @@ expression: actual
"commentStart": 0,
"declaration": {
"commentStart": 3,
"end": 49,
"end": 43,
"id": {
"commentStart": 3,
"end": 4,
@ -24,25 +24,25 @@ expression: actual
"arguments": [
{
"abs_path": false,
"commentStart": 36,
"end": 41,
"commentStart": 30,
"end": 35,
"name": {
"commentStart": 36,
"end": 41,
"commentStart": 30,
"end": 35,
"name": "angle",
"start": 36,
"start": 30,
"type": "Identifier"
},
"path": [],
"start": 36,
"start": 30,
"type": "Name",
"type": "Name"
},
{
"commentStart": 43,
"end": 46,
"commentStart": 37,
"end": 40,
"raw": "360",
"start": 43,
"start": 37,
"type": "Literal",
"type": "Literal",
"value": {
@ -53,46 +53,46 @@ expression: actual
],
"callee": {
"abs_path": false,
"commentStart": 28,
"end": 35,
"commentStart": 22,
"end": 29,
"name": {
"commentStart": 28,
"end": 35,
"commentStart": 22,
"end": 29,
"name": "default",
"start": 28,
"start": 22,
"type": "Identifier"
},
"path": [],
"start": 28,
"start": 22,
"type": "Name"
},
"commentStart": 28,
"end": 47,
"start": 28,
"commentStart": 22,
"end": 41,
"start": 22,
"type": "CallExpression",
"type": "CallExpression"
},
"commentStart": 21,
"end": 47,
"start": 21,
"commentStart": 15,
"end": 41,
"start": 15,
"type": "ReturnStatement",
"type": "ReturnStatement"
}
],
"commentStart": 19,
"end": 49,
"start": 19
"commentStart": 13,
"end": 43,
"start": 13
},
"commentStart": 7,
"end": 49,
"commentStart": 4,
"end": 43,
"params": [
{
"type": "Parameter",
"identifier": {
"commentStart": 8,
"end": 13,
"commentStart": 5,
"end": 10,
"name": "angle",
"start": 8,
"start": 5,
"type": "Identifier"
},
"default_value": {
@ -102,14 +102,14 @@ expression: actual
}
}
],
"start": 7,
"start": 4,
"type": "FunctionExpression",
"type": "FunctionExpression"
},
"start": 3,
"type": "VariableDeclarator"
},
"end": 49,
"end": 43,
"kind": "fn",
"start": 0,
"type": "VariableDeclaration",
@ -117,6 +117,6 @@ expression: actual
}
],
"commentStart": 0,
"end": 49,
"end": 43,
"start": 0
}

View File

@ -7,23 +7,23 @@ expression: actual
{
"commentStart": 0,
"declaration": {
"commentStart": 4,
"end": 91,
"commentStart": 0,
"end": 87,
"id": {
"commentStart": 4,
"end": 11,
"commentStart": 0,
"end": 7,
"name": "numbers",
"start": 4,
"start": 0,
"type": "Identifier"
},
"init": {
"commentStart": 14,
"commentStart": 10,
"elements": [
{
"commentStart": 28,
"end": 29,
"commentStart": 24,
"end": 25,
"raw": "1",
"start": 28,
"start": 24,
"type": "Literal",
"type": "Literal",
"value": {
@ -32,10 +32,10 @@ expression: actual
}
},
{
"commentStart": 79,
"end": 80,
"commentStart": 75,
"end": 76,
"raw": "3",
"start": 79,
"start": 75,
"type": "Literal",
"type": "Literal",
"value": {
@ -44,14 +44,14 @@ expression: actual
}
}
],
"end": 91,
"end": 87,
"nonCodeMeta": {
"nonCodeNodes": {
"1": [
{
"commentStart": 43,
"end": 48,
"start": 43,
"commentStart": 39,
"end": 44,
"start": 39,
"type": "NonCodeNode",
"value": {
"type": "blockComment",
@ -62,9 +62,9 @@ expression: actual
],
"2": [
{
"commentStart": 61,
"end": 66,
"start": 61,
"commentStart": 57,
"end": 62,
"start": 57,
"type": "NonCodeNode",
"value": {
"type": "blockComment",
@ -76,14 +76,14 @@ expression: actual
},
"startNodes": []
},
"start": 14,
"start": 10,
"type": "ArrayExpression",
"type": "ArrayExpression"
},
"start": 4,
"start": 0,
"type": "VariableDeclarator"
},
"end": 91,
"end": 87,
"kind": "const",
"start": 0,
"type": "VariableDeclaration",
@ -91,6 +91,6 @@ expression: actual
}
],
"commentStart": 0,
"end": 91,
"end": 87,
"start": 0
}

View File

@ -7,23 +7,23 @@ expression: actual
{
"commentStart": 0,
"declaration": {
"commentStart": 4,
"end": 91,
"commentStart": 0,
"end": 87,
"id": {
"commentStart": 4,
"end": 11,
"commentStart": 0,
"end": 7,
"name": "numbers",
"start": 4,
"start": 0,
"type": "Identifier"
},
"init": {
"commentStart": 14,
"commentStart": 10,
"elements": [
{
"commentStart": 28,
"end": 29,
"commentStart": 24,
"end": 25,
"raw": "1",
"start": 28,
"start": 24,
"type": "Literal",
"type": "Literal",
"value": {
@ -32,10 +32,10 @@ expression: actual
}
},
{
"commentStart": 43,
"end": 44,
"commentStart": 39,
"end": 40,
"raw": "2",
"start": 43,
"start": 39,
"type": "Literal",
"type": "Literal",
"value": {
@ -44,14 +44,14 @@ expression: actual
}
}
],
"end": 91,
"end": 87,
"nonCodeMeta": {
"nonCodeNodes": {
"2": [
{
"commentStart": 58,
"end": 63,
"start": 58,
"commentStart": 54,
"end": 59,
"start": 54,
"type": "NonCodeNode",
"value": {
"type": "blockComment",
@ -62,9 +62,9 @@ expression: actual
],
"3": [
{
"commentStart": 76,
"end": 81,
"start": 76,
"commentStart": 72,
"end": 77,
"start": 72,
"type": "NonCodeNode",
"value": {
"type": "blockComment",
@ -76,14 +76,14 @@ expression: actual
},
"startNodes": []
},
"start": 14,
"start": 10,
"type": "ArrayExpression",
"type": "ArrayExpression"
},
"start": 4,
"start": 0,
"type": "VariableDeclarator"
},
"end": 91,
"end": 87,
"kind": "const",
"start": 0,
"type": "VariableDeclaration",
@ -91,6 +91,6 @@ expression: actual
}
],
"commentStart": 0,
"end": 91,
"end": 87,
"start": 0
}

Some files were not shown because too many files have changed in this diff Show More