Skip to content

Elm 0.19.2: U+2028 and U+2029 are no longer escaped in char literals #2360

Description

@lydell

SSCCE:

module Main exposing (main)
import Html
main = Html.text (String.fromChar '\u{2028}' ++ String.fromChar '\u{2029}')
make --output=elm.js src/Main.elm
tail elm.js

Elm 0.19.1:

};
var $elm$virtual_dom$VirtualDom$text = _VirtualDom_text;
var $elm$html$Html$text = $elm$virtual_dom$VirtualDom$text;
var $author$project$Main$main = $elm$html$Html$text(
	_Utils_ap(
		$elm$core$String$fromChar(
			_Utils_chr('\u2028')),
		$elm$core$String$fromChar(
			_Utils_chr('\u2029'))));
_Platform_export({'Main':{'init':_VirtualDom_init($author$project$Main$main)(0)(0)}});}(this));

Elm 0.19.2:

};
var $elm$virtual_dom$VirtualDom$text = _VirtualDom_text;
var $elm$html$Html$text = $elm$virtual_dom$VirtualDom$text;
var $author$project$Main$main = $elm$html$Html$text(
	_Utils_ap(
		$elm$core$String$fromChar(
			_Utils_chr('
')),
		$elm$core$String$fromChar(
			_Utils_chr('
'))));
_Platform_export({'Main':{'init':_VirtualDom_init($author$project$Main$main)(0)(0)}});}(this));

Note _Utils_chr('\u2029') vs _Utils_chr('
'). Elm 0.19.1 used an escape in the output, while Elm 0.19.2 used the literal character. (The character is not visible on GitHub, but if you copy the text to a text editor you can inspect it.)

The thing with U+2028 and U+2029 is that they used to not be allowed in string literals in JavaScript, until ES2019:

ECMAScript 2019 … allowing U+2028 (LINE SEPARATOR) and U+2029 (PARAGRAPH SEPARATOR) in string literals to align with JSON.

Elm now outputting the literal character means:

  • The generated Elm JavaScript is no longer ES5 compatible.
  • (Very) old browsers and (very) old Node.js can no longer run all Elm code.
  • Tools used on Elm’s JavaScript that use a parser that does not allow those two characters now fail.

Example of code that deals with U+2028 and U+2029: https://github.com/dillonkearns/elm-markdown/blob/6b8d7e50745812bab0f2db8ab73de59c31c9a33b/src/Markdown/InlineParser.elm#L655-L659

Example of a tool that now breaks: https://github.com/hmsk/vite-plugin-elm/blob/b527ad9821fdb2933b7f1e7d29213422ae6da746/src/assetsInjector.ts#L57
(This tool should not arbitrarily require ES2015, but it is an example of what can happen in the wild from a small thing like this.)

(Issue found by @simonh1000 on Slack – I helped diagnose the problem and write the issue.)

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions