Skip to content

0.5.0

Pre-release
Pre-release
Compare
Choose a tag to compare
@gdotdesign gdotdesign released this 15 Apr 06:44

JavaScript output optimizations

All generated JavaScript code is now optimized in the following way:

  • top level entity names are now mangled (Components, Stores, Modules, etc.)
  • entity level names are now mangled
  • white space is removed from the generated code (build only)
  • the CSS selectors and variables are now mangled

This change means that inlined JavaScripts no longer can access arguments by name.

This will result in a runtime error because the argument message is mangled:

fun log (message : String) : Void {
  `console.log(message)`
}

To fix this we need to interpolate the argument:

fun log (message : String) : Void {
  `console.log(#{message})`
}

Calls on expressions

Previously the calls to functions were implemented in two forms: call on a
variable and call on a module function.

This meant that calling a function which
is in a record or which is a result of a function call were not possible.

This release makes it possible to make a call on the result of an expression.

This is an example which raises in error in 0.4.0 but compiles properly in 0.5.0:

module Test {
  fun a (message : String) : Function(String) {
    () : String => { message }
  }

  fun b : String {
    a("Hello")()
  }

  fun c : String {
    try {
      record = {
        function = (message : String) : String => { message }
      }

      record.message("Hello")
    }
  }
}

Partial Application

Functions now can be partially applied by calling them with less arguments than
needed.

An example of using partial application:

/* Format a number by thousands, output: 1,000,000 */

"1000000"
|> String.split("")
|> Array.groupsOfFromEnd(3)
|> Array.map(String.join(""))
|> String.join(",")

/* 
  The argument String.join("") (to Array.map) is a partially applied function
  where it's type is Function(Array(String), String)
*/

Warning for unknown CSS properties

CSS properties are now checked against a list and will result in an error if
they are not in the list.

Changes

  • Fixed array access ([]) when an expression is used as an index
  • Default values of properties are now only calculated once when the component is initialized
  • Providers can now be accessed the same a stores, or modules for introspection
  • Records now can be created without type definition. Such records have a temporary type definition created for them during type checking
  • [Runtime] Functions are bound to components and modules only once (in the constructor) instead of using .bind every time they are called

Formatter

  • Inline functions can now be forced to format the body on a new line by adding
    a line break after the opening bracket {
  • Properties can now be forced to format the default values on a new line by
    adding a line break after the equal sign =
  • Added missing formatter for array access ([])

Core

  • Added Array.groupsOfFromEnd which is the same as Array.groupsOf but grouping from the end
  • Added Array.indexBy to get an items index by a function
  • Added Http.requests for inspection purposes
  • Added String.rchop
  • Added String.lchop
  • Html.Event is now wrapped in an actual record, so it can now be safely used in sequence or parallel expression