KCL: No 'let' or 'const' required when declaring vars (#4063)

Previously variable declaration required a keyword, e.g.

```kcl
let x = 4
const x = 4
var x = 4
```

These were all valid, and did the exact same thing. As of this PR, they're all still valid, but the KCL formatter will change them all to just:

```kcl
x = 4
```

which is the new preferred way to declare a constant. 

But the formatter will remove the var/let/const keywords.

Closes https://github.com/KittyCAD/modeling-app/issues/3985
This commit is contained in:
Adam Chalmers
2024-10-02 14:19:40 -05:00
committed by GitHub
parent a24789c236
commit 0c478680cb
160 changed files with 1357 additions and 1360 deletions

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]
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 startSketchAt(p0)
|> lineTo(p1, %)
@ -16,4 +16,4 @@ fn cube = (length, center) => {
|> extrude(length, %)
}
const myCube = cube(40, [0,0])
myCube = cube(40, [0,0])

View File

@ -1,4 +1,4 @@
const part001 = startSketchOn('XY')
part001 = startSketchOn('XY')
|> startProfileAt([11.19, 28.35], %)
|> line([28.67, -13.25], %, $here)
|> line([-4.12, -22.81], %)
@ -6,7 +6,7 @@ const part001 = startSketchOn('XY')
|> close(%)
|> extrude(5, %)
const part002 = startSketchOn(part001, here)
part002 = startSketchOn(part001, here)
|> startProfileAt([0, 0], %)
|> line([0, 10], %)
|> line([10, 0], %)

View File

@ -2027,7 +2027,7 @@ const extrusion = extrude(10, sketch001)
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_angled_line_of_x_length_270() {
let code = r#"const sketch001 = startSketchOn('XZ')
let code = r#"sketch001 = startSketchOn('XZ')
|> startProfileAt([0, 0], %)
|> angledLineOfXLength({ angle: 90, length: 10 }, %, $edge1)
|> angledLineOfXLength({ angle: -15, length: 20 }, %, $edge2)

View File

@ -87,7 +87,7 @@ async fn setup(code: &str, name: &str) -> Result<(ExecutorContext, Program, uuid
async fn kcl_test_modify_sketch_part001() {
let name = "part001";
let code = format!(
r#"const {} = startSketchOn("XY")
r#"{} = startSketchOn("XY")
|> startProfileAt([8.41, 5.78], %)
|> line([7.37, -11.0], %)
|> line([-8.69, -3.75], %)
@ -112,7 +112,7 @@ async fn kcl_test_modify_sketch_part001() {
async fn kcl_test_modify_sketch_part002() {
let name = "part002";
let code = format!(
r#"const {} = startSketchOn("XY")
r#"{} = startSketchOn("XY")
|> startProfileAt([8.41, 5.78], %)
|> line([7.42, -8.62], %)
|> line([-6.38, -3.51], %)
@ -138,7 +138,7 @@ async fn kcl_test_modify_sketch_part002() {
async fn kcl_test_modify_close_sketch() {
let name = "part002";
let code = format!(
r#"const {} = startSketchOn("XY")
r#"{} = startSketchOn("XY")
|> startProfileAt([7.91, 3.89], %)
|> line([7.42, -8.62], %)
|> line([-6.38, -3.51], %)
@ -184,7 +184,7 @@ async fn kcl_test_modify_line_to_close_sketch() {
assert_eq!(
new_code,
format!(
r#"const {} = startSketchOn("XY")
r#"{} = startSketchOn("XY")
|> startProfileAt([7.91, 3.89], %)
|> line([7.42, -8.62], %)
|> line([-6.38, -3.51], %)
@ -246,7 +246,7 @@ async fn kcl_test_modify_line_should_close_sketch() {
assert_eq!(
new_code,
format!(
r#"const {} = startSketchOn("XY")
r#"{} = startSketchOn("XY")
|> startProfileAt([13.69, 3.8], %)
|> line([4.23, -11.79], %)
|> line([-10.7, -1.16], %)