-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate JavaScript for match expressions
- Loading branch information
Jordan Mackie
committed
Apr 19, 2022
1 parent
8847623
commit 35ba923
Showing
5 changed files
with
246 additions
and
13 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
crates/ditto-codegen-js/golden-tests/javascript/match_expressions.ditto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Test exports (..); | ||
|
||
type Maybe(a) = Just(a) | Nothing; | ||
|
||
|
||
with_default = (maybe: Maybe(a), default: a): a -> | ||
match maybe with | ||
| Just(a) -> a | ||
| Nothing -> default; |
17 changes: 17 additions & 0 deletions
17
crates/ditto-codegen-js/golden-tests/javascript/match_expressions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
function Just($0) { | ||
return ["Just", $0]; | ||
} | ||
const Nothing = ["Nothing"]; | ||
function withDefault(maybe, $default) { | ||
return maybe[0] === "Nothing" | ||
? $default | ||
: maybe[0] === "Just" | ||
? (() => { | ||
const a = maybe[1]; | ||
return a; | ||
})() | ||
: (() => { | ||
throw new Error("Pattern match error"); | ||
})(); | ||
} | ||
export { Just, Nothing, withDefault }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters