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

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

Issue 952643002: Revert "dart2js: Avoid escaping in strings if it's not necessary." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 b6a90a2fa95552ef4fc140918a9304b9295a635e..5d8da87f88b6f1de2f453fef6bdced2bf29cbec8 100644
--- a/pkg/compiler/lib/src/js/builder.dart
+++ b/pkg/compiler/lib/src/js/builder.dart
@@ -289,46 +289,20 @@ class JsBuilder {
return new Template.withStatementResult(ast);
}
- static RegExp _stringEscapeRegExp =
- new RegExp('\\\\|\n|"|\b|\t|\v|\u2028|\u2029');
-
/// Creates a literal js string from [value].
LiteralString escapedString(String value) {
- // 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
- //
+ // Start by escaping the backslashes.
+ String escaped = value.replaceAll('\\', '\\\\');
// Do not escape unicode characters and ' because they are allowed in the
// string literal anyway.
- String escaped = value.replaceAllMapped(_stringEscapeRegExp, (Match match) {
+ escaped = escaped.replaceAllMapped(new RegExp('\n|"|\b|\t|\v'), (match) {
switch (match.group(0)) {
- case "\\" : return r"\\";
case "\n" : return r"\n";
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);
« 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