-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port JS fixes from Gleam 1.7.0 to Nix (#40)
* glistix/nix: add some missing tests for js for parity * glistix: impl and test for nix and gleam files with conflicting names * port js fix for nested string prefixes Should not generate 'prefix = "w".wobble.whatever._0.else' but rather 'prefix = "w"'
- Loading branch information
Showing
10 changed files
with
352 additions
and
3 deletions.
There are no files selected for viewing
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
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
12 changes: 12 additions & 0 deletions
12
...ests/snapshots/glistix_core__nix__tests__assignments__escaped_variables_in_constants.snap
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,12 @@ | ||
--- | ||
source: compiler-core/src/nix/tests/assignments.rs | ||
expression: "\npub const with = 5\npub const in = with\n" | ||
--- | ||
----- SOURCE CODE | ||
|
||
pub const with = 5 | ||
pub const in = with | ||
|
||
|
||
----- COMPILED NIX | ||
let with' = 5; in' = with'; in { inherit with' in'; } |
15 changes: 15 additions & 0 deletions
15
...re/src/nix/tests/snapshots/glistix_core__nix__tests__assignments__keyword_assignment.snap
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,15 @@ | ||
--- | ||
source: compiler-core/src/nix/tests/assignments.rs | ||
expression: "\npub fn main() {\n let with = 10\n let in = 50\n in\n}\n" | ||
--- | ||
----- SOURCE CODE | ||
|
||
pub fn main() { | ||
let with = 10 | ||
let in = 50 | ||
in | ||
} | ||
|
||
|
||
----- COMPILED NIX | ||
let main = { }: let with' = 10; in' = 50; in in'; in { inherit main; } |
43 changes: 43 additions & 0 deletions
43
...sts/snapshots/glistix_core__nix__tests__assignments__let_assert_nested_string_prefix.snap
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,43 @@ | ||
--- | ||
source: compiler-core/src/nix/tests/assignments.rs | ||
expression: "\ntype Wibble {\n Wibble(wibble: String)\n}\n\npub fn main() {\n let assert Wibble(wibble: \"w\" as prefix <> rest) = Wibble(\"wibble\")\n prefix <> rest\n}\n" | ||
--- | ||
----- SOURCE CODE | ||
|
||
type Wibble { | ||
Wibble(wibble: String) | ||
} | ||
|
||
pub fn main() { | ||
let assert Wibble(wibble: "w" as prefix <> rest) = Wibble("wibble") | ||
prefix <> rest | ||
} | ||
|
||
|
||
----- COMPILED NIX | ||
let | ||
inherit (builtins.import ./../gleam.nix) strHasPrefix makeError; | ||
|
||
Wibble = wibble: { __gleamTag = "Wibble"; inherit wibble; }; | ||
|
||
main = | ||
{ }: | ||
let | ||
_pat' = (Wibble "wibble"); | ||
_assert' = | ||
if _pat'.__gleamTag != "Wibble" || !(strHasPrefix "w" _pat'.wibble) then | ||
builtins.throw | ||
(makeError | ||
"let_assert" | ||
"my/mod" | ||
7 | ||
"main" | ||
"Pattern match failed, no pattern matched the value." | ||
{ value = _pat'; }) | ||
else null; | ||
rest = builtins.seq _assert' (builtins.substring 1 (-1) _pat'.wibble); | ||
prefix = builtins.seq _assert' "w"; | ||
in | ||
builtins.seq _assert' (prefix + rest); | ||
in | ||
{ inherit main; } |
63 changes: 63 additions & 0 deletions
63
...sts/snapshots/glistix_core__nix__tests__case__deeply_nested_string_prefix_assignment.snap
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,63 @@ | ||
--- | ||
source: compiler-core/src/nix/tests/case.rs | ||
expression: "\ntype Wibble {\n Wibble(Wobble)\n}\ntype Wobble {\n Wobble(wabble: Wabble)\n}\ntype Wabble {\n Wabble(tuple: #(Int, String))\n}\n\npub fn main() {\n let tmp = Wibble(Wobble(Wabble(#(42, \"wibble\"))))\n case tmp {\n Wibble(Wobble(Wabble(#(_int, \"w\" as wibble <> rest)))) -> wibble <> rest\n _ -> panic\n }\n}\n" | ||
--- | ||
----- SOURCE CODE | ||
|
||
type Wibble { | ||
Wibble(Wobble) | ||
} | ||
type Wobble { | ||
Wobble(wabble: Wabble) | ||
} | ||
type Wabble { | ||
Wabble(tuple: #(Int, String)) | ||
} | ||
|
||
pub fn main() { | ||
let tmp = Wibble(Wobble(Wabble(#(42, "wibble")))) | ||
case tmp { | ||
Wibble(Wobble(Wabble(#(_int, "w" as wibble <> rest)))) -> wibble <> rest | ||
_ -> panic | ||
} | ||
} | ||
|
||
|
||
----- COMPILED NIX | ||
let | ||
inherit (builtins.import ./../gleam.nix) strHasPrefix makeError; | ||
|
||
Wibble = x0: { __gleamTag = "Wibble"; _0 = x0; }; | ||
|
||
Wobble = wabble: { __gleamTag = "Wobble"; inherit wabble; }; | ||
|
||
Wabble = tuple: { __gleamTag = "Wabble"; inherit tuple; }; | ||
|
||
main = | ||
{ }: | ||
let | ||
tmp = Wibble (Wobble (Wabble [ 42 "wibble" ])); | ||
in | ||
if | ||
tmp.__gleamTag == "Wibble" && | ||
tmp._0.__gleamTag == "Wobble" && | ||
tmp._0.wabble.__gleamTag == "Wabble" && | ||
strHasPrefix "w" (builtins.elemAt tmp._0.wabble.tuple 1) | ||
then | ||
let | ||
rest = | ||
(builtins.substring 1 (-1) (builtins.elemAt tmp._0.wabble.tuple 1)); | ||
wibble = "w"; | ||
in | ||
wibble + rest | ||
else | ||
builtins.throw | ||
(makeError | ||
"panic" | ||
"my/mod" | ||
16 | ||
"main" | ||
"`panic` expression evaluated." | ||
{ }); | ||
in | ||
{ inherit main; } |
Oops, something went wrong.