Skip to content

Instantly share code, notes, and snippets.

@lydell
Last active April 25, 2024 19:25
Show Gist options
  • Save lydell/50d7d83e4262ff790c4c157f06dc9115 to your computer and use it in GitHub Desktop.
Save lydell/50d7d83e4262ff790c4c157f06dc9115 to your computer and use it in GitHub Desktop.
Elm output – ES5 or ES3? (It’s ES5)

For those interested in ES5 vs ES3 … it’s ES5. Trying to parse as ES3 chokes here:

var _String_filter = F2(function(isGood, str)
{
	var arr = [];
	var len = str.length;
	var i = 0;
	while (i < len)
	{
		var char = str[i];

Parsing error: The keyword 'char' is reserved

Renaming those, it chokes on:

var _Bytes_read_string = F3(function(len, bytes, offset)
{
	var string = '';
	var end = offset + len;
	for (; offset < end;)
	{
		var byte = bytes.getUint8(offset++);

Parsing error: The keyword 'byte' is reserved

But fixing those, it parsed!

Naming a record field char seems to work too. (Ah, the compiler supports avoiding ES3-only reserved words: https://github.com/elm/compiler/blob/2f6dd29258e880dbb7effd57a829a0470d8da48b/compiler/src/Generate/JavaScript/Name.hs#L134-L147)

Here’s an ES5 method usage:

function _String_trim(str)
{
	return str.trim();
}

It can still be polyfilled though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment