Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scala.js: Default to ECMAScript 2015 #1665

Closed
davesmith00000 opened this issue Jan 11, 2022 · 6 comments
Closed

Scala.js: Default to ECMAScript 2015 #1665

davesmith00000 opened this issue Jan 11, 2022 · 6 comments
Milestone

Comments

@davesmith00000
Copy link
Contributor

davesmith00000 commented Jan 11, 2022

The official default for Scala.js is ECMAScript 2015, but Mill currently defaults to ES 5.1, here:

def useECMAScript2015: T[Boolean] = false

https://github.com/com-lihaoyi/mill/blob/main/scalajslib/src/ScalaJSModule.scala#L200

Mill should default to ES 2015 instead. The workaround is to add this line to your build.sc file:

override def useECMAScript2015 = T(true)
@lefou
Copy link
Member

lefou commented Jan 11, 2022

Can you provide a link to that claim?

I only found this:

ES modules and Node.js

Node.js needs explicit signaling that a module is an ECMAScript module (the default is CommonJS).

from https://www.scala-js.org/doc/project/module.html, 2022-01-11

@lolgab
Copy link
Member

lolgab commented Jan 11, 2022

@lefou ESModule is an orthogonal setting to the ESVersion.
Scala.js recently (1.6.0) deprecated the useECMAScript2015 for a esVersion setting that can have multiple values (ES5, ES2015, ES2020).
Mill should probably do the same.

@lefou
Copy link
Member

lefou commented Jan 11, 2022

Yeah. Makes sense. We might infer the default from the selected ScalaJS version then? If that is not possible, we might better provide no default at all.

@davesmith00000
Copy link
Contributor Author

davesmith00000 commented Jan 11, 2022

Fair challenge, all I can only offer is that Scala.js's author suggested I raise this issue (to be fair he says for 1.x and above), which I realise is an appeal to authority but...

image

I discovered this was a problem for me when I noticed that code compiled in sbt was working as expected, but identical code compiled through Mill resulted in runtime errors.

Currently all you've got is a boolean flag, so being consistent with sbt is easy enough, just set it to true as in the PR - however that is a bit of a magic value. Inferring the right version based on Scala.js version will be a marginally more involved change, but I'd also be ok with it being a setting the user had to provide to avoid ambiguity.

@lolgab
Copy link
Member

lolgab commented Jan 11, 2022

I think that for now we can change the default as you did.
Changing for a single version of ScalaJS is not possible for how Mill works. But I don't think it is a problem to change the default in 0.6 I don't think anybody still uses 0.6.

In the future we could change mill to have esVersion and deprecate the option.

@lefou
Copy link
Member

lefou commented Jan 11, 2022

Changing for a single version of ScalaJS is not possible for how Mill works.

Why? We can just depend on scalaJS target and if the version is high enough (> 1.6 or even > 1.x) we can set it to ECMAScript2015.

In the future we could change mill to have esVersion and deprecate the option.

We should do this now. The change is simple and we are still before a 0.10 release, so for adding and deprecating API this is the best time.

@lefou lefou closed this as completed in 4535159 Jan 11, 2022
@lefou lefou added this to the 0.10.0 milestone Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants