Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(400)

Unified Diff: lib/src/js/builder.dart

Issue 1347453002: fix a few more codegen issues: (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: run the tests too Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: lib/src/js/builder.dart
diff --git a/lib/src/js/builder.dart b/lib/src/js/builder.dart
index f215da214a6795ed463467790084834a2988e91d..affcffea42abfd1fce7a66b1907516ee87968bb1 100644
--- a/lib/src/js/builder.dart
+++ b/lib/src/js/builder.dart
@@ -298,17 +298,25 @@ class JsBuilder {
LiteralString escapedString(String value, [String quote = '"']) {
// Start by escaping the backslashes.
String escaped = value.replaceAll('\\', '\\\\');
- // Do not escape unicode characters and ' because they are allowed in the
- // string literal anyway.
- var re = new RegExp('\n|\r|$quote|\b|\f|\t|\v');
+
+ // http://www.ecma-international.org/ecma-262/6.0/#sec-literals-string-literals
+ // > All code points may appear literally in a string literal except for the
+ // > closing quote code points, U+005C (REVERSE SOLIDUS),
+ // > U+000D (CARRIAGE RETURN), U+2028 (LINE SEPARATOR),
+ // > U+2029 (PARAGRAPH SEPARATOR), and U+000A (LINE FEED).
+ var re = new RegExp('\n|\r|$quote|\b|\f|\t|\v|\u2028|\u2029');
escaped = escaped.replaceAllMapped(re, (m) {
switch (m.group(0)) {
case "\n" : return r"\n";
case "\r" : return r"\r";
+ case "\u2028": return r"\u2028";
+ case "\u2029": return r"\u2029";
// Quotes are only replaced if they conflict with the containing quote
case '"': return r'\"';
case "'": return r"\'";
case "`": return r"\`";
+ // TODO(jmesserly): these don't need to be escaped for correctness,
+ // but they are conventionally escaped.
case "\b" : return r"\b";
case "\t" : return r"\t";
case "\f" : return r"\f";

Powered by Google App Engine
This is Rietveld 408576698