About ECMAScript supported by elm

Hey.
Is the outputs from Elm base on ES3?

I found the articles is

I tried to look it up, but I wasn’t sure, so I asked here.

1 Like

I ran some compiled Elm JS through ESLint, with no rules enabled. That only checks syntax. And it’s possible to specify the wanted ECMAScript version, which then just checks syntax for that version.

The following sets the version to ES3:

{
  "parserOptions": {
    "ecmaVersion": 3
  }
}

I get this error when running npx eslint path/to/compiled/elm.js:

910:7  error  Parsing error: The keyword 'char' is reserved

But when I replace all instances of char with xchar, no errors are reported. So besides a few usages of the name char, the output is syntactically valid ES3 – at least my small example app. I haven’t checked if it actually runs in an ES3 environment though – the code might use some ES5 standard methods.

Setting ecmaVersion": 5 parses the code out of the box. I don’t have a source, but I’m confident the output is valid ES5 at least – that’s from experience. According to Caniuse, IE8 supported only ES3, IE9 partially supported ES5 and IE10 supported ES5 fully. I have never tried Elm code in such old browsers. But I did try it in IE11 back in the day.

1 Like

@lydell

Thanks for the reply!

It’s so helpful to be able to specify the version of ECMAScript in eslint and know the version of ECMAScript in the js that elm outputs.

Thanks for going into so much detail!
It is amazing to me that elm is working so perfectly with es3 equivalent javascript.

Thanks for your research, it’s very helpful.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.