KCL optional parameters (#1087)

Part of https://github.com/KittyCAD/modeling-app/issues/1006#issuecomment-1816978586

This adds support for optional parameters to the AST. They are declared with a ? suffix, e.g. `(x, tag?) => {...}`.

This PR does not actually _use_ these optional parameters anywhere. In particular, it does not change the KCL stdlib or any existing function definitions. That will happen in a follow-up PR.
This commit is contained in:
Adam Chalmers
2023-11-20 11:19:08 -06:00
committed by GitHub
parent 957001ee88
commit 6afacd7427
11 changed files with 302 additions and 47 deletions

View File

@ -169,16 +169,24 @@ describe('testing function declaration', () => {
end: 39,
params: [
{
type: 'Identifier',
start: 12,
end: 13,
name: 'a',
type: 'Parameter',
identifier: {
type: 'Identifier',
start: 12,
end: 13,
name: 'a',
},
optional: false,
},
{
type: 'Identifier',
start: 15,
end: 16,
name: 'b',
type: 'Parameter',
identifier: {
type: 'Identifier',
start: 15,
end: 16,
name: 'b',
},
optional: false,
},
],
body: {
@ -244,16 +252,24 @@ const myVar = funcN(1, 2)`
end: 37,
params: [
{
type: 'Identifier',
start: 12,
end: 13,
name: 'a',
type: 'Parameter',
identifier: {
type: 'Identifier',
start: 12,
end: 13,
name: 'a',
},
optional: false,
},
{
type: 'Identifier',
start: 15,
end: 16,
name: 'b',
type: 'Parameter',
identifier: {
type: 'Identifier',
start: 15,
end: 16,
name: 'b',
},
optional: false,
},
],
body: {