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

Side by Side Diff: pkg/compiler/lib/src/js_backend/constant_emitter.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: Use charsets. 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/compiler/lib/src/js/builder.dart ('k') | tests/compiler/dart2js/string_escapes2_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of js_backend; 5 part of js_backend;
6 6
7 class ConstantEmitter { 7 class ConstantEmitter {
8 ConstantReferenceEmitter _referenceEmitter; 8 ConstantReferenceEmitter _referenceEmitter;
9 ConstantLiteralEmitter _literalEmitter; 9 ConstantLiteralEmitter _literalEmitter;
10 10
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 } 280 }
281 } 281 }
282 282
283 /** 283 /**
284 * Write the contents of the quoted string to a [CodeBuffer] in 284 * Write the contents of the quoted string to a [CodeBuffer] in
285 * a form that is valid as JavaScript string literal content. 285 * a form that is valid as JavaScript string literal content.
286 * The string is assumed quoted by double quote characters. 286 * The string is assumed quoted by double quote characters.
287 */ 287 */
288 @override 288 @override
289 jsAst.Expression visitString(StringConstantValue constant, [_]) { 289 jsAst.Expression visitString(StringConstantValue constant, [_]) {
290 StringBuffer sb = new StringBuffer(); 290 return js.escapedString(constant.primitiveValue.slowToString());
291 writeJsonEscapedCharsOn(constant.primitiveValue.slowToString(), sb);
292 return new jsAst.LiteralString('"$sb"');
293 } 291 }
294 292
295 @override 293 @override
296 jsAst.Expression visitList(ListConstantValue constant, [_]) { 294 jsAst.Expression visitList(ListConstantValue constant, [_]) {
297 List<jsAst.Expression> elements = _array(constant.entries); 295 List<jsAst.Expression> elements = _array(constant.entries);
298 jsAst.ArrayInitializer array = new jsAst.ArrayInitializer(elements); 296 jsAst.ArrayInitializer array = new jsAst.ArrayInitializer(elements);
299 jsAst.Expression value = makeConstantListTemplate.instantiate([array]); 297 jsAst.Expression value = makeConstantListTemplate.instantiate([array]);
300 return maybeAddTypeArguments(constant.type, value); 298 return maybeAddTypeArguments(constant.type, value);
301 } 299 }
302 300
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 [value, argumentList]); 442 [value, argumentList]);
445 } 443 }
446 return value; 444 return value;
447 } 445 }
448 446
449 @override 447 @override
450 jsAst.Expression visitDeferred(DeferredConstantValue constant, [_]) { 448 jsAst.Expression visitDeferred(DeferredConstantValue constant, [_]) {
451 return constantEmitter.reference(constant.referenced); 449 return constantEmitter.reference(constant.referenced);
452 } 450 }
453 } 451 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js/builder.dart ('k') | tests/compiler/dart2js/string_escapes2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698