Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions core/source/Array.mint
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Array {
Array.any([1, 3], (number : Number) { number % 2 == 0 }) == false
*/
fun any (array : Array(item), function : Function(item, Bool)) : Bool {
find(array, function) != Maybe.Nothing
Array.find(array, function) != Maybe.Nothing
}

/*
Expand All @@ -23,7 +23,7 @@ module Array {
Array.all(["hello", "mint"], (str : String) { String.size(str) > 3 }) == true
*/
fun all (array : Array(item), function : Function(item, Bool)) : Bool {
reduce(array, true) { |memo : Bool, val : item| memo && function(val) }
reduce(array, true, (memo : Bool, val : item) { memo && function(val) })
}

/*
Expand Down Expand Up @@ -52,12 +52,13 @@ module Array {
Array.compact([Maybe.Just("A"), Maybe.Nothing]) == ["A"]
*/
fun compact (array : Array(Maybe(item))) : Array(item) {
reduce(array, []) { |memo : Array(item), item : Maybe(item)|
case item {
Just(value) => Array.push(memo, value)
Nothing => memo
}
}
Array.reduce(array, [],
(memo : Array(item), item : Maybe(item)) : Array(item) {
case item {
Just(value) => Array.push(memo, value)
Nothing => memo
}
})
}

/*
Expand Down Expand Up @@ -95,7 +96,7 @@ module Array {
Array.delete(["a", "b", "c", "a"], "a") == ["b", "c"]
*/
fun delete (array : Array(item), what : item) : Array(item) {
reject(array) { |item : item| item == what }
reject(array, (item : item) { item == what })
}

/*
Expand Down Expand Up @@ -581,7 +582,7 @@ module Array {
*/
fun reverseIf (array : Array(item), condition : Bool) : Array(item) {
if condition {
reverse(array)
Array.reverse(array)
} else {
array
}
Expand Down Expand Up @@ -713,7 +714,8 @@ module Array {
Array.sum([]) == 0
*/
fun sum (array : Array(Number)) : Number {
Array.reduce(array, 0) { |memo : Number, item : Number| item + memo }
Array.reduce(array, 0,
(memo : Number, item : Number) : Number { item + memo })
}

/*
Expand Down
36 changes: 19 additions & 17 deletions core/source/CSV.mint
Original file line number Diff line number Diff line change
Expand Up @@ -256,23 +256,25 @@ module CSV {
lineEnding : CSV.LineEnding = CSV.LineEnding.Unix
) : String {
rows
|> Array.map() { |row : Array(String)|
Array.map(row) { |field : String|
// Double quotes need to be escaped with an extra doublequote.
let value =
String.replace(field, "\"", "\"\"")

// If the string contains a separator, \n, \r\n or " it needs to
// be escaped by wrapping in double quotes.
if String.contains(value, separator) || String.contains(value, "\n") || String.contains(
value, "\"") {
"\"#{value}\""
} else {
value
}
}
}
|> Array.map() { |row : Array(String)| String.join(row, separator) }
|> Array.map(
(row : Array(String)) {
Array.map(row,
(field : String) {
// Double quotes need to be escaped with an extra doublequote.
let value =
String.replace(field, "\"", "\"\"")

// If the string contains a separator, \n, \r\n or " it needs to
// be escaped by wrapping in double quotes.
if String.contains(value, separator) || String.contains(value, "\n") || String.contains(
value, "\"") {
"\"#{value}\""
} else {
value
}
})
})
|> Array.map((row : Array(String)) { String.join(row, separator) })
|> String.join(
case lineEnding {
Windows => "\r\n"
Expand Down
22 changes: 0 additions & 22 deletions spec/compilers/call_with_block_function

This file was deleted.

36 changes: 36 additions & 0 deletions spec/compilers/property_with_tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
component View {
property orientation : Horizontal | Vertical = Horizontal

fun render : Html {
<div/>
}
}

component Main {
fun render : Html {
<>
<View orientation={Vertical}/>
<View/>
</>
}
}
--------------------------------------------------------------------------------
import {
createElement as A,
fragment as B
} from "./runtime.js";

export const
C = ({
a = `Horizontal`
}) => {
return A(`div`, {})
},
D = () => {
return A(B, {}, [
A(C, {
a: `Vertical`
}),
A(C, {})
])
};
58 changes: 58 additions & 0 deletions spec/compilers/tag
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
component Main {
fun a (d : X | Y | Z(String)) {
case d {
X => "X"
Y => "Y"
Z(value) => value
}
}

fun render {
<div>
a(X)
a(Y)
a(Z("Hello"))
</div>
}
}
--------------------------------------------------------------------------------
import {
patternVariable as D,
createElement as E,
newVariant as F,
pattern as C,
variant as A,
match as B
} from "./runtime.js";

export const
G = A(1, `Z`),
H = () => {
const a = (b) => {
return B(b, [
[
`X`,
() => {
return `X`
}
],
[
`Y`,
() => {
return `Y`
}
],
[
C(G, [D]),
(c) => {
return c
}
]
])
};
return E(`div`, {}, [
a(`X`),
a(`Y`),
a(F(G)(`Hello`))
])
};
8 changes: 4 additions & 4 deletions spec/errors/variable_missing
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Test {
fun b : Function(String) {
XTest.a
a
}
}

Expand All @@ -14,16 +14,16 @@ component Main {

I can't find the entity with the name:

XTest
a

Here is where it is referenced:

┌ errors/variable_missing:3:5
├─────────────────────────────
1│ module Test {
2│ fun b : Function(String) {
3│ XTest.a
│ ⌃⌃⌃⌃⌃
3│ a
│ ⌃
4│ }
5│ }
6│
Expand Down
2 changes: 1 addition & 1 deletion spec/examples/access
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ component Main {
Test.b()
}
}
---------------------------------------------------------------variable_missing
--------------------------------------------------------------access_not_record
module Test {
fun b : Function(String) {
XTest.a
Expand Down
12 changes: 0 additions & 12 deletions spec/examples/call
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,3 @@ component Main {
<div>"Hello World!"</div>
}
}
--------------------------------------------------------------------------------
component Main {
fun renderTest (block : Function(String, Html)) {
block("TEST")
}

fun render : Html {
renderTest() { |x : String|
<div>x</div>
}
}
}
1 change: 1 addition & 0 deletions spec/examples/case
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ module Test {
component Main {
fun render : String {
let x = X.Y

case (x) {
Test.X => "x"
Y => "y"
Expand Down
71 changes: 71 additions & 0 deletions spec/examples/property
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,74 @@ component Main {
<Test/>
}
}
-------------------------------------------------------------------------------
component View {
property orientation : Horizontal | Vertical = Horizontal

fun render : Html {
<div/>
}
}

component Main {
fun render : Html {
<View/>
}
}
-------------------------------------------------------------------------------
component View {
property orientation : Horizontal | Vertical = Horizontal

fun render : String {
case orientation {
Horizontal => "horizontal"
Vertical => "vertical"
}
}
}

component Main {
fun render : Html {
<View/>
}
}
-------------------------------------------------------------------------------
component View {
property orientation : Horizontal | Vertical | Custom(String) = Horizontal

fun render : String {
case orientation {
Horizontal => "horizontal"
Vertical => "vertical"
Custom(value) => value
}
}
}

component Main {
fun render : Html {
<View/>
}
}
-------------------------------------------------------------------------------
type Orientation {
Horizontal
Vertical
}

component View {
property orientation : Orientation = Orientation.Horizontal

fun render : String {
case orientation {
Horizontal => "horizontal"
Vertical => "vertical"
}
}
}

component Main {
fun render : Html {
<View/>
}
}
6 changes: 3 additions & 3 deletions spec/examples/variable
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ component Main {
<div::test("Name")/>
}
}
---------------------------------------------------------------variable_missing
--------------------------------------------------------operation_type_mismatch
suite "Suite" {
const TWO = 2

test "Test" {
1 + 1 == THREE
}
}
---------------------------------------------------------------variable_missing
--------------------------------------------------------operation_type_mismatch
suite "Suite 2" {
test "Test" {
1 + 1 == TWO
Expand All @@ -49,7 +49,7 @@ component Main {
}
}
}
---------------------------------------------------------------variable_missing
--------------------------------------------------------------access_not_record
component Main {
fun render : String {
case (C.D(0)) {
Expand Down
Loading
Loading