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

Side by Side Diff: lib/src/js/builder.dart

Issue 1347453002: fix a few more codegen issues: (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: run the tests too Created 5 years, 3 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 // Utilities for building JS ASTs at runtime. Contains a builder class 5 // Utilities for building JS ASTs at runtime. Contains a builder class
6 // and a parser that parses part of the language. 6 // and a parser that parses part of the language.
7 7
8 part of js_ast; 8 part of js_ast;
9 9
10 10
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 } 291 }
292 292
293 Template statementTemplateYielding(Node ast) { 293 Template statementTemplateYielding(Node ast) {
294 return new Template.withStatementResult(ast); 294 return new Template.withStatementResult(ast);
295 } 295 }
296 296
297 /// Creates a literal js string from [value]. 297 /// Creates a literal js string from [value].
298 LiteralString escapedString(String value, [String quote = '"']) { 298 LiteralString escapedString(String value, [String quote = '"']) {
299 // Start by escaping the backslashes. 299 // Start by escaping the backslashes.
300 String escaped = value.replaceAll('\\', '\\\\'); 300 String escaped = value.replaceAll('\\', '\\\\');
301 // Do not escape unicode characters and ' because they are allowed in the 301
302 // string literal anyway. 302 // http://www.ecma-international.org/ecma-262/6.0/#sec-literals-string-liter als
303 var re = new RegExp('\n|\r|$quote|\b|\f|\t|\v'); 303 // > All code points may appear literally in a string literal except for the
304 // > closing quote code points, U+005C (REVERSE SOLIDUS),
305 // > U+000D (CARRIAGE RETURN), U+2028 (LINE SEPARATOR),
306 // > U+2029 (PARAGRAPH SEPARATOR), and U+000A (LINE FEED).
307 var re = new RegExp('\n|\r|$quote|\b|\f|\t|\v|\u2028|\u2029');
304 escaped = escaped.replaceAllMapped(re, (m) { 308 escaped = escaped.replaceAllMapped(re, (m) {
305 switch (m.group(0)) { 309 switch (m.group(0)) {
306 case "\n" : return r"\n"; 310 case "\n" : return r"\n";
307 case "\r" : return r"\r"; 311 case "\r" : return r"\r";
312 case "\u2028": return r"\u2028";
313 case "\u2029": return r"\u2029";
308 // Quotes are only replaced if they conflict with the containing quote 314 // Quotes are only replaced if they conflict with the containing quote
309 case '"': return r'\"'; 315 case '"': return r'\"';
310 case "'": return r"\'"; 316 case "'": return r"\'";
311 case "`": return r"\`"; 317 case "`": return r"\`";
318 // TODO(jmesserly): these don't need to be escaped for correctness,
319 // but they are conventionally escaped.
312 case "\b" : return r"\b"; 320 case "\b" : return r"\b";
313 case "\t" : return r"\t"; 321 case "\t" : return r"\t";
314 case "\f" : return r"\f"; 322 case "\f" : return r"\f";
315 case "\v" : return r"\v"; 323 case "\v" : return r"\v";
316 } 324 }
317 }); 325 });
318 LiteralString result = new LiteralString('$quote$escaped$quote'); 326 LiteralString result = new LiteralString('$quote$escaped$quote');
319 // We don't escape quotes of a different style under the assumption that the 327 // We don't escape quotes of a different style under the assumption that the
320 // string is wrapped into quotes. Verify that assumption. 328 // string is wrapped into quotes. Verify that assumption.
321 assert(result.value.codeUnitAt(0) == quote.codeUnitAt(0)); 329 assert(result.value.codeUnitAt(0) == quote.codeUnitAt(0));
(...skipping 1246 matching lines...) Expand 10 before | Expand all | Expand 10 after
1568 expectCategory(RSQUARE); 1576 expectCategory(RSQUARE);
1569 return expr; 1577 return expr;
1570 } else if (acceptCategory(HASH)) { 1578 } else if (acceptCategory(HASH)) {
1571 return parseInterpolatedExpression(); 1579 return parseInterpolatedExpression();
1572 } else { 1580 } else {
1573 error('Expected property name'); 1581 error('Expected property name');
1574 return null; 1582 return null;
1575 } 1583 }
1576 } 1584 }
1577 } 1585 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698