Skip to content

Commit d48998c

Browse files
committed
Announcing Scala.js 1.1.0.
1 parent eaba09f commit d48998c

File tree

6 files changed

+185
-9
lines changed

6 files changed

+185
-9
lines changed

_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ colors: #in hex code if not noted else
5757

5858
### VERSIONS ###
5959
versions:
60-
scalaJS: 1.0.1
60+
scalaJS: 1.1.0
6161
scalaJSBinary: 1
6262
scalaJS06x: 0.6.33
6363
scalaJS06xBinary: 0.6

_posts/news/2020-03-10-announcing-scalajs-1.0.1.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ The Google Closure Compiler used internally by Scala.js for `fullOptJS` has been
3939

4040
## Bug fixes
4141

42-
Among others, the following bugs have been fixed in 0.6.32:
42+
Among others, the following bugs have been fixed in 1.0.1:
4343

4444
* [#3950](https://github.com/scala-js/scala-js/issues/3950) Static forwarders are not generated for static nested objects
4545
* [#3984](https://github.com/scala-js/scala-js/issues/3984) `(-0.0).getClass()` returns `classOf[Integer]` instead of `classOf[Float]`
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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).

doc/all-api.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@ title: All previous versions of the Scala.js API
55

66
## All previous versions of the API
77

8+
### Scala.js 1.1.0
9+
* [1.1.0 scalajs-library]({{ site.production_url }}/api/scalajs-library/1.1.0/scala/scalajs/js/index.html)
10+
* [1.1.0 scalajs-test-interface]({{ site.production_url }}/api/scalajs-test-interface/1.1.0/)
11+
* [1.1.0 scalajs-ir]({{ site.production_url }}/api/scalajs-ir/1.1.0/org/scalajs/ir/index.html)
12+
* [1.1.0 scalajs-logging]({{ site.production_url }}/api/scalajs-logging/1.1.0/org/scalajs/logging/index.html)
13+
* [1.1.0 scalajs-linker-interface]({{ site.production_url }}/api/scalajs-linker-interface/1.1.0/org/scalajs/linker/interface/index.html) ([Scala.js version]({{ site.production_url }}/api/scalajs-linker-interface-js/1.1.0/org/scalajs/linker/interface/index.html))
14+
* [1.1.0 scalajs-linker]({{ site.production_url }}/api/scalajs-linker/1.1.0/org/scalajs/linker/index.html) ([Scala.js version]({{ site.production_url }}/api/scalajs-linker-js/1.1.0/org/scalajs/linker/index.html))
15+
* [1.1.0 scalajs-js-envs]({{ site.production_url }}/api/scalajs-js-envs/1.1.0/org/scalajs/jsenv/index.html)
16+
* [1.1.0 scalajs-env-nodejs]({{ site.production_url }}/api/scalajs-env-nodejs/1.1.0/org/scalajs/jsenv/nodejs/index.html)
17+
* [1.1.0 scalajs-js-envs-test-kit]({{ site.production_url }}/api/scalajs-js-envs-test-kit/1.1.0/org/scalajs/jsenv/test/index.html)
18+
* [1.1.0 scalajs-test-adapter]({{ site.production_url }}/api/scalajs-sbt-test-adapter/1.1.0/org/scalajs/testing/adapter/index.html)
19+
* [1.1.0 sbt-scalajs]({{ site.production_url }}/api/sbt-scalajs/1.1.0/#org.scalajs.sbtplugin.package)
20+
821
### Scala.js 0.6.33
922
* [0.6.33 scalajs-library]({{ site.production_url }}/api/scalajs-library/0.6.33/#scala.scalajs.js.package)
1023
* [0.6.33 scalajs-test-interface]({{ site.production_url }}/api/scalajs-test-interface/0.6.33/)

doc/internals/version-history.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ title: Version history
55

66
## Version history of Scala.js
77

8+
- [1.1.0](/news/2020/05/18/announcing-scalajs-1.1.0/)
89
- [0.6.33](/news/2020/05/13/announcing-scalajs-0.6.33/)
910
- [1.0.1](/news/2020/03/10/announcing-scalajs-1.0.1/)
1011
- [1.0.0](/news/2020/02/25/announcing-scalajs-1.0.0/)

doc/interoperability/facade-types.md

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,28 @@ Inner classes and objects will be looked up as fields of the enclosing JS object
253253

254254
## Variables and functions in the global scope
255255

256-
Besides object-like top-level definitions, JavaScript also defines variables
257-
and functions in the global scope. Scala does not have top-level variables and
258-
functions. Instead, in Scala.js, top-level objects annotated with
259-
`@JSGlobalScope` are considered to represent the global scope.
256+
Besides object-like top-level definitions, JavaScript also defines variables and functions in the global scope.
257+
Scala does not have top-level variables and functions, but we can define `val`s and `def`s in top-level `object`s instead.
258+
For example, we can define the `document` variable and the `alert` function as follows.
259+
260+
**Requires Scala.js 1.1.0 or later**
261+
262+
{% highlight scala %}
263+
import js.annotation._
264+
265+
object DOMGlobals {
266+
@js.native
267+
@JSGlobal("document")
268+
val document: HTMLDocument = js.native
269+
270+
@js.native
271+
@JSGlobal("alert")
272+
def alert(message: String): Unit = js.native
273+
}
274+
{% endhighlight %}
275+
276+
An alternative, more practical if there are a lot of variables and functions to declare, and also available in earlier versions, is to use a top-level object annotated with `@JSGlobalScope`.
277+
Such objects are considered to represent the global scope.
260278

261279
{% highlight scala %}
262280
import js.annotation._
@@ -282,7 +300,7 @@ Prior to 0.6.13, `extends js.GlobalScope` was used instead of `@JSGlobalScope`.
282300
The previous sections on native classes and objects all refer to *global variables*, i.e., variables declared in the JavaScript global scope.
283301
In modern JavaScript ecosystems, we often want to load things from other *modules*.
284302
This is what `@JSImport` is designed for.
285-
You can annotate an `@js.native` class or object with `@JSImport` instead of `@JSGlobal` to signify that it is defined in a module.
303+
You can annotate an `@js.native` class, object, val or def with `@JSImport` instead of `@JSGlobal` to signify that it is defined in a module.
286304
For example, in the following snippet:
287305

288306
{% highlight scala %}
@@ -319,7 +337,7 @@ It can be one of the following:
319337
* The constant `JSImport.Namespace`, to select the module itself (with its exports as fields).
320338
This corresponds to `import * as Foobaz from "bar.js"`.
321339

322-
The latter is particularly useful if you want to import members of the modules that are neither classes nor objects (for example, functions):
340+
Before Scala.js 1.1.0, the latter was particularly useful to import members of the modules that are neither classes nor objects (for example, functions):
323341

324342
{% highlight scala %}
325343
@js.native
@@ -351,9 +369,21 @@ var y = moduleDefault(bar).exportedFunction(5);
351369

352370
This is subject to change in future versions of Scala.js, to better reflect the evolution of specifications in ECMAScript itself, and its implementations.
353371

372+
Starting with Scala.js 1.1.0, the above example would probably be written as follows instead:
373+
374+
{% highlight scala %}
375+
object Bar {
376+
@js.native
377+
@JSImport("bar.js", "exportedFunction")
378+
def exportedFunction(x: Int): Int = js.native
379+
}
380+
381+
val y = Bar.exportedFunction(5)
382+
{% endhighlight %}
383+
354384
**Important:** `@JSImport` is completely incompatible with [`jsDependencies`](./dependencies.html).
355385
You should use a separate mechanism to manage your JavaScript dependencies.
356-
Scala.js does not provide any facility to do so, at the moment.
386+
The sbt plugin [scalajs-bundler](https://scalacenter.github.io/scalajs-bundler/) provides one such mechanism.
357387

358388
### Translating ES imports to Scala.js `@JSImport`
359389

0 commit comments

Comments
 (0)