| Index: sdk/lib/_internal/compiler/implementation/js/builder.dart
|
| diff --git a/sdk/lib/_internal/compiler/implementation/js/builder.dart b/sdk/lib/_internal/compiler/implementation/js/builder.dart
|
| index ab05952753b919add5299320118378f664d213a3..f7c74e493ea826e60ce068a531cd9dbe68e1e673 100644
|
| --- a/sdk/lib/_internal/compiler/implementation/js/builder.dart
|
| +++ b/sdk/lib/_internal/compiler/implementation/js/builder.dart
|
| @@ -45,6 +45,36 @@ class JsBuilder {
|
| return call(source, expression);
|
| }
|
|
|
| + /// Creates a litteral js string from [value].
|
| + LiteralString escapedString(String value) {
|
| + // Do not escape unicode characters and ' because they are allowed in the
|
| + // string literal anyway.
|
| + String escaped =
|
| + value.replaceAllMapped(new RegExp('\n|"|\\|\0|\b|\t|\v'), (match) {
|
| + switch (match.group(0)) {
|
| + case "\n" : return r"\n";
|
| + case "\\" : return r"\\";
|
| + case "\"" : return r'\"';
|
| + case "\0" : return r"\0";
|
| + case "\b" : return r"\b";
|
| + case "\t" : return r"\t";
|
| + case "\f" : return r"\f";
|
| + case "\v" : return r"\v";
|
| + }
|
| + });
|
| + LiteralString result = string(escaped);
|
| + // We don't escape ' under the assumption that the string is wrapped
|
| + // into ". Verify that assumption.
|
| + assert(result.value.codeUnitAt(0) == '"');
|
| + return result;
|
| + }
|
| +
|
| + /// Creates a litteral js string from [value].
|
| + ///
|
| + /// Note that this function only puts quotes around [value]. It does not do
|
| + /// any escaping, so use only when you can guarantee that [value] does not
|
| + /// contain newlines or backslashes. For escaping the string use
|
| + /// [escapedString].
|
| LiteralString string(String value) => new LiteralString('"$value"');
|
|
|
| LiteralNumber number(num value) => new LiteralNumber('$value');
|
|
|