Skip to content

Commit

Permalink
Merge pull request #1591 from DanielXMoore/type-postfix-if-same-line
Browse files Browse the repository at this point in the history
Type's postfix `if` must be on the same line
  • Loading branch information
edemaine authored Nov 11, 2024
2 parents 86f2b30 + 3e9fc54 commit 106e5da
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion source/parser.hera
Original file line number Diff line number Diff line change
Expand Up @@ -8304,7 +8304,7 @@ TypeBullet
return list

TypeWithPostfix
TypeConditional:t ( SameLineOrIndentedFurther TypeIfClause )?:postfix ->
TypeConditional:t ( _? TypeIfClause )?:postfix ->
if (!postfix) return t
return prepend(postfix[0],
expressionizeTypeIf([ ...postfix[1], $1, undefined ]))
Expand Down
20 changes: 20 additions & 0 deletions test/types/function.civet
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,26 @@ describe "[TS] function", ->
}
"""

// #1590
testCase """
not postfix if
---
function fn(i: number): string
if i < 10
"a"
else
"b"
---
function fn(i: number): string {
if (i < 10) {
return "a"
}
else {
return "b"
}
}
"""

describe "application", ->
testCase """
type arguments
Expand Down
5 changes: 2 additions & 3 deletions test/types/type-declaration.civet
Original file line number Diff line number Diff line change
Expand Up @@ -653,14 +653,13 @@ describe "[TS] type declaration", ->
type Example1 = (Dog extends Animal?never: number)
"""

testCase """
throws """
indented postfix if
---
type Example1 = number
if Dog extends Animal
---
type Example1 =
(Dog extends Animal? number:never)
ParseError
"""

testCase """
Expand Down

0 comments on commit 106e5da

Please sign in to comment.