|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: Announcing Scala.js 1.2.0 |
| 4 | +category: news |
| 5 | +tags: [releases] |
| 6 | +permalink: /news/2020/09/09/announcing-scalajs-1.2.0/ |
| 7 | +--- |
| 8 | + |
| 9 | + |
| 10 | +We are pleased to announce the release of Scala.js 1.2.0! |
| 11 | + |
| 12 | +The highlight of this release is the addition of the JavaScript types `js.Map[K, V]` and `js.Set[T]` in the standard library. |
| 13 | +Thanks to [@exoego](https://github.com/exoego) for this contribution! |
| 14 | + |
| 15 | +In addition, this release contains a number of bug fixes and small improvements. |
| 16 | +The version of the Scala standard library has been upgraded to Scala 2.12.12 and 2.13.3. |
| 17 | + |
| 18 | +Read on for more details. |
| 19 | + |
| 20 | +<!--more--> |
| 21 | + |
| 22 | +## Getting started |
| 23 | + |
| 24 | +If you are new to Scala.js, head over to [the tutorial]({{ BASE_PATH }}/tutorial/). |
| 25 | + |
| 26 | +If you need help with anything related to Scala.js, you may find our community [on Gitter](https://gitter.im/scala-js/scala-js) and [on Stack Overflow](https://stackoverflow.com/questions/tagged/scala.js). |
| 27 | + |
| 28 | +Bug reports can be filed [on GitHub](https://github.com/scala-js/scala-js/issues). |
| 29 | + |
| 30 | +## Release notes |
| 31 | + |
| 32 | +If upgrading from Scala.js 0.6.x, make sure to read [the release notes of Scala.js 1.0.0]({{ BASE_PATH }}/news/2020/02/25/announcing-scalajs-1.0.0/) first, as they contain a host of important information, including breaking changes. |
| 33 | + |
| 34 | +This is a **minor** release: |
| 35 | + |
| 36 | +* It is backward binary compatible with all earlier versions in the 1.x series: libraries compiled with 1.0.x and 1.1.x can be used with 1.2.0 without change. |
| 37 | +* It is *not* forward binary compatible with 1.1.x: libraries compiled with 1.2.0 cannot be used with 1.1.x or earlier. |
| 38 | +* It is *not* entirely backward source compatible: it is not guaranteed that a codebase will compile *as is* when upgrading from 1.1.x (in particular in the presence of `-Xfatal-warnings`). |
| 39 | + |
| 40 | +As a reminder, libraries compiled with 0.6.x cannot be used with Scala.js 1.x; they must be republished with 1.x first. |
| 41 | + |
| 42 | +## Known source breaking changes |
| 43 | + |
| 44 | +### `js.JSON.stringify` |
| 45 | + |
| 46 | +The type of the `space` argument has been narrowed from `js.Any` in Scala.js <= 1.1.1 to `Int | String` in Scala.js 1.2.0. |
| 47 | +This may cause code that uses this method not to compile anymore. |
| 48 | +For example: |
| 49 | + |
| 50 | +{% highlight scala %} |
| 51 | +def configString(config: js.Dictionary[String], mySpace: js.Any): String = |
| 52 | + js.JSON.stringify(config, space = mySpace) |
| 53 | +{% endhighlight %} |
| 54 | + |
| 55 | +will stop compiling because `js.Any` is not a subtype of `Int | String`. |
| 56 | +Ideally, this issue would be addressed by changing the type of `mySpace` itself and the callers of `configString`. |
| 57 | +If that is not possible, for example due to binary compatibility constraints, it is always possible to use a cast: |
| 58 | + |
| 59 | +{% highlight scala %} |
| 60 | +def configString(config: js.Dictionary[String], mySpace: js.Any): String = |
| 61 | + js.JSON.stringify(config, space = mySpace.asInstanceOf[Int | String]) |
| 62 | +{% endhighlight %} |
| 63 | + |
| 64 | +## Enhancements |
| 65 | + |
| 66 | +### `js.Map[K, V]` and `js.Set[T]` |
| 67 | + |
| 68 | +The standard library now contains definitions for the JavaScript built-in classes `Map` and `Set`, as `js.Map[K, V]` and `js.Set[T]`, respectively. |
| 69 | +Like `js.Array`, they support the full Scala collection API. |
| 70 | + |
| 71 | +### ECMAScript module support in `testHtml` |
| 72 | + |
| 73 | +The task `testHtml` creates a .html page that runs the unit tests of a codebase in a browser. |
| 74 | +Until Scala.js 1.1.1, it only supported Scripts (i.e., with the default `ModuleKind.NoModule`). |
| 75 | +Starting with v1.2.0, it also supports ECMAScript modules (`ModuleKind.ESModule`). |
| 76 | + |
| 77 | +It still does not support CommonJS modules, since those are not supported by browsers at all. |
| 78 | + |
| 79 | +### Export abstract JS classes |
| 80 | + |
| 81 | +It is now possible to export `abstract` JS classes (that extend `js.Any`), for example: |
| 82 | + |
| 83 | +{% highlight scala %} |
| 84 | +@JSExportTopLevel("AbstractBase") |
| 85 | +abstract class AbstractBase extends js.Object |
| 86 | +{% endhighlight %} |
| 87 | + |
| 88 | +These can be extended by classes written in JavaScript. |
| 89 | + |
| 90 | +## Miscellaneous |
| 91 | + |
| 92 | +### New JDK APIs |
| 93 | + |
| 94 | +* `java.util.Date.toInstant()` and `java.util.Date.from(Instant)`, although they will only transitively link if support for `java.time` APIs is enabled (e.g., using [scala-java-time](https://github.com/cquiroz/scala-java-time)) |
| 95 | +* `java.lang.Character.codePointCount` |
| 96 | + |
| 97 | +### Upgrade to GCC v20200719 |
| 98 | + |
| 99 | +The Google Closure Compiler used internally by Scala.js for `fullOptJS` has been upgraded to v20200719. |
| 100 | + |
| 101 | +## Bug fixes |
| 102 | + |
| 103 | +Among others, the following bugs have been fixed in 1.2.0: |
| 104 | + |
| 105 | +* [#4131](https://github.com/scala-js/scala-js/issues/4131) `getTime` on `java.util.Date` returns `0` when initialized with a value outside the ECMAScript Time Range |
| 106 | +* [#4114](https://github.com/scala-js/scala-js/issues/4114) Compiler crash for JS class containing nested JS objects |
| 107 | +* [#4171](https://github.com/scala-js/scala-js/issues/4171) "`NoSuchElementException`: key not found: `LabelName<matchAlts1>`" with dotty 0.27.0-RC1 |
| 108 | +* [#4174](https://github.com/scala-js/scala-js/issues/4174) fullOptJS shouldn't add a sourceMap references when sourceMap's are disabled |
| 109 | +* [#4151](https://github.com/scala-js/scala-js/issues/4151) Very Long String in source results in cryptic error message |
| 110 | +* [#4148](https://github.com/scala-js/scala-js/issues/4148) and [#4168](https://github.com/scala-js/scala-js/issues/4168) Unable to find extant inner trait IR during fastopt |
| 111 | + |
| 112 | +You can find the full list [on GitHub](https://github.com/scala-js/scala-js/issues?q=is%3Aissue+milestone%3Av1.2.0+is%3Aclosed). |
0 commit comments