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

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

Issue 930263002: dart2js: Avoid escaping in strings if it's not necessary. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix bad semicolon. Created 5 years, 10 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
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_backend/constant_emitter.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 72b4507081ebca30903142b36121319d01c75640..125a5d1c2d4d6951b0fb7fc4e89b765a1bb913b8 100644
--- a/pkg/compiler/lib/src/js/builder.dart
+++ b/pkg/compiler/lib/src/js/builder.dart
@@ -298,9 +298,32 @@ class JsBuilder {
LiteralString escapedString(String value) {
// Start by escaping the backslashes.
String escaped = value.replaceAll('\\', '\\\\');
Lasse Reichstein Nielsen 2015/02/23 13:25:05 Why not combine the backslash-escaping in the othe
floitsch 2015/02/23 16:56:41 Done.
+ // 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.
Lasse Reichstein Nielsen 2015/02/23 13:25:05 Technically, you don't have to escape \b, \t, \f a
floitsch 2015/02/23 16:56:41 Yes. My initial patch (that wasn't using this func
sra1 2015/02/23 17:47:27 I think we can have more than one version of this
- escaped = escaped.replaceAllMapped(new RegExp('\n|"|\b|\t|\v'), (match) {
+ escaped = escaped.replaceAllMapped(
+ new RegExp('\n|"|\b|\t|\v|\u2028|\u2029'), (match) {
sra1 2015/02/23 17:47:27 new RegExp -> static variable.
floitsch 2015/02/23 18:16:45 It reads less nice, but done. Called "_stringEscap
Lasse Reichstein Nielsen 2015/02/24 14:14:21 How about: new RegExp(r'[\n\b\t\v"\u2028\u2029]'
floitsch 2015/02/24 20:49:44 Done.
switch (match.group(0)) {
case "\n" : return r"\n";
case "\"" : return r'\"';
@@ -308,6 +331,8 @@ class JsBuilder {
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";
}
});
Lasse Reichstein Nielsen 2015/02/23 13:25:05 Does this have a measurable performance impact? Be
floitsch 2015/02/23 16:56:41 I tried with a string of 500000 \u2029 characters
LiteralString result = string(escaped);
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_backend/constant_emitter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698