|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: Announcing Scala.js 1.1.0 |
| 4 | +category: news |
| 5 | +tags: [releases] |
| 6 | +permalink: /news/2020/05/18/announcing-scalajs-1.1.0/ |
| 7 | +--- |
| 8 | + |
| 9 | + |
| 10 | +We are pleased to announce the release of Scala.js 1.1.0! |
| 11 | + |
| 12 | +The highlight of this release is the new support for `@js.native` `val`s and `def`s, which we detail below. |
| 13 | +The version of the Scala standard library has been upgraded to Scala 2.12.11 and 2.13.2. |
| 14 | +In addition, it contains a number of bug fixes, including all the ones fixed in v0.6.33. |
| 15 | + |
| 16 | +Important note: if you use [scalajs-bundler](https://scalacenter.github.io/scalajs-bundler/), you will need to upgrade it to v0.18.0 or later. |
| 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 it contains 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 can be used with 1.1.0 without change. |
| 37 | +* It is *not* forward binary compatible with 1.0.x: libraries compiled with 1.1.0 cannot be used with 1.0.x. |
| 38 | +* It is *not* entirely backward source compatible: it is not guaranteed that a codebase will compile *as is* when upgrading from 1.0.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 | +## New warnings |
| 43 | + |
| 44 | +These changes already exist in Scala.js 0.6.33, but are new compared to 1.0.1. |
| 45 | + |
| 46 | +In Scala.js 1.1.0, the Scala.js compiler will start reporting warnings when trying to override `equals` and `hashCode` in a JS type (extending `js.Any`). |
| 47 | +For example: |
| 48 | + |
| 49 | +{% highlight scala %} |
| 50 | +class A extends js.Object { |
| 51 | + override def hashCode(): Int = 1 |
| 52 | + override def equals(obj: Any): Boolean = false |
| 53 | +} |
| 54 | +{% endhighlight %} |
| 55 | + |
| 56 | +will report the following warnings: |
| 57 | + |
| 58 | +{% highlight none %} |
| 59 | +Test.scala:6: warning: Overriding hashCode in a JS class does not change its hash code. |
| 60 | + To silence this warning, change the name of the method and optionally add @JSName("hashCode"). |
| 61 | + override def hashCode(): Int = 1 |
| 62 | + ^ |
| 63 | +Test.scala:7: warning: Overriding equals in a JS class does not change how it is compared. |
| 64 | + To silence this warning, change the name of the method and optionally add @JSName("equals"). |
| 65 | + override def equals(obj: Any): Boolean = false |
| 66 | + ^ |
| 67 | +{% endhighlight %} |
| 68 | + |
| 69 | +Overriding `equals` and `hashCode` never *worked*, in the sense that it would not affect `==` and `##`. |
| 70 | +The new warnings make it clear. |
| 71 | + |
| 72 | +## New features |
| 73 | + |
| 74 | +### `@js.native` `val`s and `def`s |
| 75 | + |
| 76 | +Scala.js 1.1.0 adds support for `@js.native` `val`s and `def`s (but not `lazy val`s, `var`s or setter `def`s) in Scala `object`s. |
| 77 | +For example: |
| 78 | + |
| 79 | +{% highlight scala %} |
| 80 | +object QueryString { |
| 81 | + @js.native |
| 82 | + @JSImport("querystring", "stringify") |
| 83 | + def stringify(obj: js.Dictionary[String], sep: String = "&", |
| 84 | + eq: String = "="): String = js.native |
| 85 | +} |
| 86 | + |
| 87 | +object OS { |
| 88 | + @js.native |
| 89 | + @JSImport("os", "EOL") |
| 90 | + val EOL: String = js.native |
| 91 | +} |
| 92 | +{% endhighlight %} |
| 93 | + |
| 94 | +The rhs of such members must be `= js.native`, and they must have an `@JSGlobal` or `@JSImport` annotation to specify where to load it from. |
| 95 | + |
| 96 | +As illustrated by the above example, they are particularly suited to `import` top-level functions and variables from JavaScript modules, without requiring to import the whole module namespace (with `JSImport.Namespace`). |
| 97 | + |
| 98 | +They can also be used to accurately load resources from pseudo-modules, like Webpack allows for CSS, JSON and image files, among others: |
| 99 | + |
| 100 | +{% highlight scala %} |
| 101 | +object LogoPage { |
| 102 | + @js.native |
| 103 | + @JSImport("resources/img/logo-banner.png", JSImport.Default) |
| 104 | + val logoBanner: String = js.native |
| 105 | + |
| 106 | + ... |
| 107 | + img(src := logoBanner, alt := "My logo") |
| 108 | + ... |
| 109 | +} |
| 110 | +{% endhighlight %} |
| 111 | + |
| 112 | +## Miscellaneous |
| 113 | + |
| 114 | +### Upgrade to GCC v20200315 |
| 115 | + |
| 116 | +The Google Closure Compiler used internally by Scala.js for `fullOptJS` has been upgraded to v20200315. |
| 117 | + |
| 118 | +## Bug fixes |
| 119 | + |
| 120 | +Among others, the following bugs have been fixed in 1.1.0: |
| 121 | + |
| 122 | +* [#4021](https://github.com/scala-js/scala-js/issues/4021) The Refiner eliminates needed static fields in non-instantiated classes |
| 123 | +* [#4001](https://github.com/scala-js/scala-js/issues/4001) Scala.js 1.0.0 unnecessary generates imports for parent classes |
| 124 | + |
| 125 | +as well as the following bugs, carried from v0.6.33: |
| 126 | + |
| 127 | +* [#4034](https://github.com/scala-js/scala-js/issues/4034) Incorrect result for `-x` when `x` is `+0.0` |
| 128 | +* [#3998](https://github.com/scala-js/scala-js/issues/3998) Self-types in non-native JS traits cause confusing error message |
| 129 | +* [#3818](https://github.com/scala-js/scala-js/issues/3818) Linking error for `Future.never` from Scala 2.13 |
| 130 | +* [#3939](https://github.com/scala-js/scala-js/issues/3939) Compile error on a method with `@JSName("finalize")` in a non-native JS class |
| 131 | + |
| 132 | +You can find the full list [on GitHub](https://github.com/scala-js/scala-js/issues?q=is%3Aissue+milestone%3Av1.1.0+is%3Aclosed). |
0 commit comments