CM KCL: = and => are optional in fn declarations (#4941)
CM KCL: `=` and `=>` are optional in fn declarations Co-authored-by: Matt Mundell <matt@mundell.me>
This commit is contained in:
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
statement[@isGroup=Statement] {
|
statement[@isGroup=Statement] {
|
||||||
ImportStatement { kw<"import"> ImportItems ImportFrom String } |
|
ImportStatement { kw<"import"> ImportItems ImportFrom String } |
|
||||||
FunctionDeclaration { kw<"export">? kw<"fn"> VariableDefinition Equals ParamList Arrow Body } |
|
FunctionDeclaration { kw<"export">? kw<"fn"> VariableDefinition Equals? ParamList Arrow? Body } |
|
||||||
VariableDeclaration { kw<"export">? (kw<"var"> | kw<"let"> | kw<"const">)? VariableDefinition Equals expression } |
|
VariableDeclaration { kw<"export">? (kw<"var"> | kw<"let"> | kw<"const">)? VariableDefinition Equals expression } |
|
||||||
ReturnStatement { kw<"return"> expression } |
|
ReturnStatement { kw<"return"> expression } |
|
||||||
ExpressionStatement { expression }
|
ExpressionStatement { expression }
|
||||||
|
60
packages/codemirror-lang-kcl/test/fn.txt
Normal file
60
packages/codemirror-lang-kcl/test/fn.txt
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
# 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
|
||||||
|
}
|
||||||
|
|
||||||
|
==>
|
||||||
|
|
||||||
|
Program(FunctionDeclaration(fn,
|
||||||
|
VariableDefinition,
|
||||||
|
ParamList,
|
||||||
|
Body(ReturnStatement(return,
|
||||||
|
Number))))
|
||||||
|
|
Reference in New Issue
Block a user