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

Side by Side Diff: pkg/compiler/lib/src/js_backend/constant_emitter.dart

Issue 1520033002: js_ast: Better escaping of strings in preparation for utf8 file encoding (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « no previous file | pkg/js_ast/lib/src/builder.dart » ('j') | pkg/js_ast/test/string_escape_test.dart » ('J')
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 typedef jsAst.Expression _ConstantReferenceGenerator(ConstantValue constant); 7 typedef jsAst.Expression _ConstantReferenceGenerator(ConstantValue constant);
8 8
9 typedef jsAst.Expression _ConstantListGenerator(jsAst.Expression array); 9 typedef jsAst.Expression _ConstantListGenerator(jsAst.Expression array);
10 10
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 } 146 }
147 } 147 }
148 148
149 /** 149 /**
150 * Write the contents of the quoted string to a [CodeBuffer] in 150 * Write the contents of the quoted string to a [CodeBuffer] in
151 * a form that is valid as JavaScript string literal content. 151 * a form that is valid as JavaScript string literal content.
152 * The string is assumed quoted by double quote characters. 152 * The string is assumed quoted by double quote characters.
153 */ 153 */
154 @override 154 @override
155 jsAst.Expression visitString(StringConstantValue constant, [_]) { 155 jsAst.Expression visitString(StringConstantValue constant, [_]) {
156 StringBuffer sb = new StringBuffer(); 156 return js.escapedString(constant.primitiveValue.slowToString(),
157 writeJsonEscapedCharsOn(constant.primitiveValue.slowToString(), sb); 157 ascii: true);
158 return new jsAst.LiteralString('"$sb"');
159 } 158 }
160 159
161 @override 160 @override
162 jsAst.Expression visitList(ListConstantValue constant, [_]) { 161 jsAst.Expression visitList(ListConstantValue constant, [_]) {
163 List<jsAst.Expression> elements = constant.entries 162 List<jsAst.Expression> elements = constant.entries
164 .map(constantReferenceGenerator) 163 .map(constantReferenceGenerator)
165 .toList(growable: false); 164 .toList(growable: false);
166 jsAst.ArrayInitializer array = new jsAst.ArrayInitializer(elements); 165 jsAst.ArrayInitializer array = new jsAst.ArrayInitializer(elements);
167 jsAst.Expression value = makeConstantList(array); 166 jsAst.Expression value = makeConstantList(array);
168 return maybeAddTypeArguments(constant.type, value); 167 return maybeAddTypeArguments(constant.type, value);
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 [value, argumentList]); 319 [value, argumentList]);
321 } 320 }
322 return value; 321 return value;
323 } 322 }
324 323
325 @override 324 @override
326 jsAst.Expression visitDeferred(DeferredConstantValue constant, [_]) { 325 jsAst.Expression visitDeferred(DeferredConstantValue constant, [_]) {
327 return constantReferenceGenerator(constant.referenced); 326 return constantReferenceGenerator(constant.referenced);
328 } 327 }
329 } 328 }
OLDNEW
« no previous file with comments | « no previous file | pkg/js_ast/lib/src/builder.dart » ('j') | pkg/js_ast/test/string_escape_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698