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

Unified Diff: sdk/lib/_internal/compiler/implementation/js/builder.dart

Issue 177543002: Constrain type annotations with deferred types. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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
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..ccff49c5f0dcaf24dcce65574f7416f3ee5c553a 100644
--- a/sdk/lib/_internal/compiler/implementation/js/builder.dart
+++ b/sdk/lib/_internal/compiler/implementation/js/builder.dart
@@ -45,6 +45,32 @@ 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 "\\n";
floitsch 2014/02/28 12:58:15 use raw strings. case "\n": return r"\n";
sigurdm 2014/03/03 13:18:49 Done.
+ case "\\" : return "\\\\";
+ case "\"" : return "\\\"";
+ case "\0" : return "\\0";
+ case "\b" : return "\\b";
+ case "\t" : return "\\t";
+ case "\f" : return "\\f";
+ case "\v" : return "\\v";
+ }
+ });
+ return new LiteralString('"$escaped"');
floitsch 2014/02/28 12:58:15 LiteralString result = string(escaped); // We don'
sigurdm 2014/03/03 13:18:49 Done.
sigurdm 2014/03/03 13:18:49 Done.
+ }
+
+ /// 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');

Powered by Google App Engine
This is Rietveld 408576698