| Index: pkg/compiler/lib/src/js/builder.dart
|
| diff --git a/pkg/compiler/lib/src/js/builder.dart b/pkg/compiler/lib/src/js/builder.dart
|
| index 5d8da87f88b6f1de2f453fef6bdced2bf29cbec8..37ef7d10c01471fe955980f46d52fdf84aa72d77 100644
|
| --- a/pkg/compiler/lib/src/js/builder.dart
|
| +++ b/pkg/compiler/lib/src/js/builder.dart
|
| @@ -289,20 +289,47 @@ class JsBuilder {
|
| return new Template.withStatementResult(ast);
|
| }
|
|
|
| + static RegExp _stringEscapeRegExp =
|
| + new RegExp(r'["\\\n\r\b\t\v' + '\u2028\u2029]');
|
| +
|
| /// Creates a literal js string from [value].
|
| LiteralString escapedString(String value) {
|
| - // Start by escaping the backslashes.
|
| - String escaped = value.replaceAll('\\', '\\\\');
|
| + // Relevant sections of ECMA-262:
|
| + //
|
| + // 7.3 Line Terminators
|
| + // LineTerminator ::
|
| + // <LF>
|
| + // <CR>
|
| + // <LS>
|
| + // <PS>
|
| + //
|
| + // 7.8.4 String Literals
|
| + // StringLiteral ::
|
| + // " DoubleStringCharacters? "
|
| + // ' SingleStringCharacters? '
|
| + //
|
| + // DoubleStringCharacters ::
|
| + // DoubleStringCharacter DoubleStringCharacters?
|
| + //
|
| + // DoubleStringCharacter ::
|
| + // SourceCharacter but not one of " or \ or LineTerminator
|
| + // \ EscapeSequence
|
| + // LineContinuation
|
| + //
|
| // Do not escape unicode characters and ' because they are allowed in the
|
| // string literal anyway.
|
| - escaped = escaped.replaceAllMapped(new RegExp('\n|"|\b|\t|\v'), (match) {
|
| + String escaped = value.replaceAllMapped(_stringEscapeRegExp, (Match match) {
|
| switch (match.group(0)) {
|
| + case "\\" : return r"\\";
|
| case "\n" : return r"\n";
|
| + case "\r" : return r"\r";
|
| case "\"" : return r'\"';
|
| case "\b" : return r"\b";
|
| case "\t" : return r"\t";
|
| case "\f" : return r"\f";
|
| case "\v" : return r"\v";
|
| + case "\u2028" : return r"\u2028";
|
| + case "\u2029" : return r"\u2029";
|
| }
|
| });
|
| LiteralString result = string(escaped);
|
|
|