Skip to content

Commit ea9aa99

Browse files
authored
Merge pull request #561 from sjrd/scalajs-1.8.0
Scalajs 1.8.0
2 parents fd7b819 + 30c521e commit ea9aa99

File tree

8 files changed

+246
-2
lines changed

8 files changed

+246
-2
lines changed

.htaccess

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ redirect 301 /community/libraries/libs.html /libraries/libs.html
3131
redirect 301 /community/libraries/skeletons.html /libraries/skeletons.html
3232
redirect 301 /community/libraries/testing.html /libraries/testing.html
3333
redirect 301 /community/libraries/ /libraries/
34+
35+
redirect 301 /news/2021-10-07/announcing-scalajs-1.7.1/ {{ BASE_PATH }}/news/2021/10/07/announcing-scalajs-1.7.1/

_config.yml

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

6565
### VERSIONS ###
6666
versions:
67-
scalaJS: 1.7.1
67+
scalaJS: 1.8.0
6868
scalaJSBinary: 1
6969
scalaJS06x: 0.6.33
7070
scalaJS06xBinary: 0.6

_data/library/versions.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@
2828
- 1.5.0
2929
- 1.6.0
3030
- 1.7.0
31+
- 1.8.0

_posts/news/2021-10-07-announcing-scalajs-1.7.1.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ layout: post
33
title: Announcing Scala.js 1.7.1
44
category: news
55
tags: [releases]
6-
permalink: /news/2021-10-07/announcing-scalajs-1.7.1/
6+
permalink: /news/2021/10/07/announcing-scalajs-1.7.1/
77
---
88

99

Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
---
2+
layout: post
3+
title: Announcing Scala.js 1.8.0
4+
category: news
5+
tags: [releases]
6+
permalink: /news/2021/12/10/announcing-scalajs-1.8.0/
7+
---
8+
9+
10+
We are excited to announce the release of Scala.js 1.8.0!
11+
12+
This release supports Node.js 17 out of the box.
13+
If you were previously using one of the workarounds described [in this issue](https://github.com/scala-js/scala-js-js-envs/issues/12), you may remove it when upgrading to Scala.js 1.8.0.
14+
15+
It also introduces compiler warnings when using the default `ExecutionContext.global`.
16+
Read below for details about the reasons, replacements and ways to silence the warnings.
17+
18+
Finally, it introduces a few new language features, including support for the JavaScript metaproperty `new.target`.
19+
20+
Read on for more details.
21+
22+
<!--more-->
23+
24+
## Getting started
25+
26+
If you are new to Scala.js, head over to [the tutorial]({{ BASE_PATH }}/tutorial/).
27+
28+
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).
29+
30+
Bug reports can be filed [on GitHub](https://github.com/scala-js/scala-js/issues).
31+
32+
## Release notes
33+
34+
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.
35+
36+
This is a **minor** release:
37+
38+
* It is backward binary compatible with all earlier versions in the 1.x series: libraries compiled with 1.0.x through 1.7.x can be used with 1.8.0 without change.
39+
* It is *not* forward binary compatible with 1.7.x: libraries compiled with 1.8.0 cannot be used with 1.7.x or earlier.
40+
* It is *not* entirely backward source compatible: it is not guaranteed that a codebase will compile *as is* when upgrading from 1.7.x (in particular in the presence of `-Xfatal-warnings`).
41+
42+
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.
43+
44+
## New compiler warnings with broad applicability
45+
46+
### The default `ExecutionContext.global` is now deprecated
47+
48+
The default `ExecutionContext` provided by Scala.js as `ExecutionContext.global` and `ExecutionContext.Implicits.global` uses JavaScript `Promise`s as its underlying mechanism.
49+
While it is standard in ECMAScript 2015+, it turns out that they are not *fair* with respect to other asynchronous events, like timers and network operations.
50+
Details on this issue are explained in [the readme for `scalajs-macrotask-executor`](https://github.com/scala-js/scala-js-macrotask-executor).
51+
52+
We cannot fix the default `ExecutionContext` because the only existing solutions use features of browsers and Node.js that are outside of the ECMAScript standard.
53+
To address the issue, Scala.js 1.8.0 emits a compiler warning to nudge users towards using `scalajs-macrotask-executor`.
54+
55+
Attempts to use either of the following imports:
56+
57+
{% highlight scala %}
58+
import scala.concurrent.ExecutionContext.global
59+
import scala.concurrent.ExecutionContext.Implicits.global
60+
{% endhighlight %}
61+
62+
will emit the following extensive warning:
63+
64+
{% highlight none %}
65+
Test.scala:5: warning: The global execution context in Scala.js is based on JS Promises (microtasks).
66+
Using it may prevent macrotasks (I/O, timers, UI rendering) from running reliably.
67+
68+
Unfortunately, there is no way with ECMAScript only to implement a performant
69+
macrotask execution context (and hence Scala.js core does not contain one).
70+
71+
We recommend you use: https://github.com/scala-js/scala-js-macrotask-executor
72+
Please refer to the README.md of that project for more details regarding
73+
microtask vs. macrotask execution contexts.
74+
75+
If you do not care about macrotask fairness, you can silence this warning by:
76+
- Adding @nowarn("cat=other") (Scala >= 2.13.x only)
77+
- Setting the -P:scalajs:nowarnGlobalExecutionContext compiler option
78+
- Using scala.scalajs.concurrent.JSExecutionContext.queue
79+
(the implementation of ExecutionContext.global in Scala.js) directly.
80+
81+
If you do not care about performance, you can use
82+
scala.scalajs.concurrent.QueueExecutionContext.timeouts().
83+
It is based on setTimeout which makes it fair but slow (due to clamping).
84+
85+
scala.concurrent.Future { }
86+
^
87+
{% endhighlight %}
88+
89+
As the warning says, the recommended fix is to use the executor provided by [`scalajs-macrotask-executor`](https://github.com/scala-js/scala-js-macrotask-executor), as an external dependency.
90+
91+
If you prefer to keep the existing behavior and silence the warning instead, this can be done in a number of ways:
92+
93+
* Adding `@nowarn("cat=other")` (Scala >= 2.13.x only)
94+
* Setting the `-P:scalajs:nowarnGlobalExecutionContext` compiler option (in sbt, with `scalacOptions += "-P:scalajs:..."`)
95+
* Using `scala.scalajs.concurrent.JSExecutionContext.queue` (the implementation of ExecutionContext.global in Scala.js) directly
96+
97+
## New features
98+
99+
### `@JSImport`'s second argument is now optional
100+
101+
When importing native JS members from a module, we use `@JSImport` as follows:
102+
103+
{% highlight scala %}
104+
@js.native @JSImport("module.js", "SomeClass")
105+
class SomeClass extends js.Object
106+
107+
@js.native @JSImport("fs", "readFileSync")
108+
def readFileSync(file: String, charset: String): String = js.native
109+
{% endhighlight %}
110+
111+
The first argument to `@JSImport` represents the module name, while the second one is the module member name to import.
112+
In many cases, like in the examples above, the member name is reused as the Scala name.
113+
114+
Starting with Scala.js 1.8.0, the second argument becomes optional, and defaults to the name of the Scala entity that is annotated.
115+
The above example can be simplified as follows, without change of behavior:
116+
117+
{% highlight scala %}
118+
@js.native @JSImport("module.js")
119+
class SomeClass extends js.Object
120+
121+
@js.native @JSImport("fs")
122+
def readFileSync(file: String, charset: String): String = js.native
123+
{% endhighlight %}
124+
125+
### `@JSGlobal`'s argument is now optional when used inside an `object`
126+
127+
Similarly to the above change, the argument of `@JSGlobal` is now optional when the annotated entity is in a Scala `object`.
128+
It was already optional when used at the top-level.
129+
For example, the following is now allowed:
130+
131+
{% highlight scala %}
132+
object JSTimers {
133+
@js.native @JSGlobal
134+
def setTimeout(f: js.Function0[Any], delay: Int): Unit
135+
}
136+
{% endhighlight %}
137+
138+
### New primitive for JavaScript's metaproperty `new.target`
139+
140+
The [JavaScript metaproperty `new.target`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new.target) gives access to the constructor that was used in a calling `new Foo()` expression.
141+
It is mainly used in a parent class constructor to know what child class is being instantiated:
142+
143+
{% highlight javascript %}
144+
class Parent {
145+
constructor() {
146+
console.log("Instantiating a " + new.target.name);
147+
}
148+
}
149+
150+
class Child extends Parent {
151+
constructor() {
152+
super();
153+
}
154+
}
155+
156+
new Parent() // prints "Instantiating a Parent"
157+
new Child() // prints "Instantiating a Child"
158+
{% endhighlight %}
159+
160+
Scala.js 1.8.0 introduces a new primitive, `js.new.target`, which can be used in the constructor of non-native JS classes, and is equivalent to JavaScript's `new.target`.
161+
With it, the above example can be translated to Scala.js as:
162+
163+
{% highlight scala %}
164+
import scala.scalajs.js
165+
166+
class Parent extends js.Object {
167+
println("Instantiating a " + js.`new`.target.name)
168+
}
169+
170+
class Child extends Parent
171+
172+
new Parent()
173+
new Child()
174+
{% endhighlight %}
175+
176+
Attempting to use `js.new.target` anywhere but in the constructor of a non-native JS class will result in a compile error.
177+
178+
While JavaScript also allows to use `new.target` in a `function` body, there is no equivalent in Scala.js so far.
179+
We expect the use cases for that to be very rare, and we have not found a compelling design for that feature in Scala.js yet.
180+
This is still tracked as [issue #4588](https://github.com/scala-js/scala-js/issues/4588).
181+
182+
### Hashbang lines are accepted in .js file headers
183+
184+
Scala.js 1.7.0 introduced a new linker configuration, `jsHeader`, to specify a comment to insert at the top of .js files:
185+
Scala.js 1.8.0 extends that mechanism to allow hashbang lines at the very beginning of the header.
186+
For example, the following header is now valid:
187+
188+
{% highlight scala %}
189+
scalaJSLinkerConfig ~= {
190+
_.withJSHeader(
191+
"""
192+
|#!/usr/bin/env node
193+
|
194+
|/* This is the header, which source maps
195+
| * take into account.
196+
| */
197+
""".stripMargin.trim() + "\n"
198+
)
199+
}
200+
{% endhighlight %}
201+
202+
## Miscellaneous
203+
204+
### New JDK APIs
205+
206+
The following methods of `java.lang.String` were added (thanks to [@tom91136](https://github.com/tom91136)):
207+
208+
* `isBlank()`
209+
* `strip()`
210+
* `stripLeading()`
211+
* `stripTrailing()`
212+
* `indent(n: Int)`
213+
* `stripIndent()`
214+
* `translateEscapes()`
215+
216+
### Upgrade to GCC v20211201
217+
218+
We upgraded to the Google Closure Compiler v20211201.
219+
220+
## Bug fixes
221+
222+
Among others, the following bugs have been fixed in 1.8.0:
223+
224+
* [#4581](https://github.com/scala-js/scala-js/issues/4581) Scala.js v1.7.0 breaks pattern match in constructor of non-native JS class
225+
* [#4583](https://github.com/scala-js/scala-js/issues/4583) Error while emitting, head of empty list
226+
* [#4560](https://github.com/scala-js/scala-js/issues/4560) Console output (e.g., `println`) not redirected to sbt client
227+
* [#4601](https://github.com/scala-js/scala-js/issues/4601) IR checking error with `scala-java-time`
228+
* [#4604](https://github.com/scala-js/scala-js/issues/4604) `0/0` should throw an exception
229+
230+
You can find the full list [on GitHub](https://github.com/scala-js/scala-js/issues?q=is%3Aissue+milestone%3Av1.8.0+is%3Aclosed).

assets/badges/scalajs-1.8.0.svg

Lines changed: 1 addition & 0 deletions
Loading

doc/all-api.md

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

66
## All previous versions of the API
77

8+
### Scala.js 1.8.0
9+
* [1.8.0 scalajs-library]({{ site.production_url }}/api/scalajs-library/1.8.0/scala/scalajs/js/index.html)
10+
* [1.8.0 scalajs-test-interface]({{ site.production_url }}/api/scalajs-test-interface/1.8.0/)
11+
* [1.8.0 scalajs-ir]({{ site.production_url }}/api/scalajs-ir/1.8.0/org/scalajs/ir/index.html)
12+
* [1.8.0 scalajs-linker-interface]({{ site.production_url }}/api/scalajs-linker-interface/1.8.0/org/scalajs/linker/interface/index.html) ([Scala.js version]({{ site.production_url }}/api/scalajs-linker-interface-js/1.8.0/org/scalajs/linker/interface/index.html))
13+
* [1.8.0 scalajs-linker]({{ site.production_url }}/api/scalajs-linker/1.8.0/org/scalajs/linker/index.html) ([Scala.js version]({{ site.production_url }}/api/scalajs-linker-js/1.8.0/org/scalajs/linker/index.html))
14+
* [1.8.0 scalajs-test-adapter]({{ site.production_url }}/api/scalajs-sbt-test-adapter/1.8.0/org/scalajs/testing/adapter/index.html)
15+
* [1.8.0 sbt-scalajs]({{ site.production_url }}/api/sbt-scalajs/1.8.0/#org.scalajs.sbtplugin.package)
16+
817
### Scala.js 1.7.1
918
* [1.7.1 scalajs-library]({{ site.production_url }}/api/scalajs-library/1.7.1/scala/scalajs/js/index.html)
1019
* [1.7.1 scalajs-test-interface]({{ site.production_url }}/api/scalajs-test-interface/1.7.1/)

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.8.0](/news/2021/12/10/announcing-scalajs-1.8.0/)
89
- [1.7.1](/news/2021/10/07/announcing-scalajs-1.7.1/)
910
- [1.7.0](/news/2021/08/04/announcing-scalajs-1.7.0/)
1011
- [1.6.0](/news/2021/06/09/announcing-scalajs-1.6.0/)

0 commit comments

Comments
 (0)