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

Side by Side Diff: lib/src/compiler/code_generator.dart

Issue 1989663002: fix #470, string interpolation now respects Dart toString (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « lib/runtime/dart_sdk.js ('k') | test/browser/language_tests.js » ('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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 import 'dart:collection' show HashMap, HashSet; 5 import 'dart:collection' show HashMap, HashSet;
6 import 'dart:math' show min, max; 6 import 'dart:math' show min, max;
7 7
8 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; 8 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator;
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/token.dart' show Token, TokenType; 10 import 'package:analyzer/dart/ast/token.dart' show Token, TokenType;
(...skipping 4170 matching lines...) Expand 10 before | Expand all | Expand 10 after
4181 4181
4182 @override 4182 @override
4183 JS.LiteralString visitSimpleStringLiteral(SimpleStringLiteral node) => 4183 JS.LiteralString visitSimpleStringLiteral(SimpleStringLiteral node) =>
4184 js.escapedString(node.value, node.isSingleQuoted ? "'" : '"'); 4184 js.escapedString(node.value, node.isSingleQuoted ? "'" : '"');
4185 4185
4186 @override 4186 @override
4187 JS.Expression visitAdjacentStrings(AdjacentStrings node) => 4187 JS.Expression visitAdjacentStrings(AdjacentStrings node) =>
4188 _visitListToBinary(node.strings, '+'); 4188 _visitListToBinary(node.strings, '+');
4189 4189
4190 @override 4190 @override
4191 JS.TemplateString visitStringInterpolation(StringInterpolation node) { 4191 JS.Expression visitStringInterpolation(StringInterpolation node) {
4192 // Assuming we implement toString() on our objects, we can avoid calling it 4192 return new JS.TaggedTemplate(
4193 // in most cases. Builtin types may differ though. We could handle this with 4193 js.call('dart.str'), new JS.TemplateString(_visitList(node.elements)));
4194 // a tagged template.
4195 return new JS.TemplateString(_visitList(node.elements));
4196 } 4194 }
4197 4195
4198 @override 4196 @override
4199 String visitInterpolationString(InterpolationString node) { 4197 String visitInterpolationString(InterpolationString node) {
4200 // TODO(jmesserly): this call adds quotes, and then we strip them off. 4198 // TODO(jmesserly): this call adds quotes, and then we strip them off.
4201 var str = js.escapedString(node.value, '`').value; 4199 var str = js.escapedString(node.value, '`').value;
4202 return str.substring(1, str.length - 1); 4200 return str.substring(1, str.length - 1);
4203 } 4201 }
4204 4202
4205 @override 4203 @override
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
4494 } 4492 }
4495 4493
4496 bool isLibraryPrefix(Expression node) => 4494 bool isLibraryPrefix(Expression node) =>
4497 node is SimpleIdentifier && node.staticElement is PrefixElement; 4495 node is SimpleIdentifier && node.staticElement is PrefixElement;
4498 4496
4499 LibraryElement _getLibrary(AnalysisContext c, String uri) => 4497 LibraryElement _getLibrary(AnalysisContext c, String uri) =>
4500 c.computeLibraryElement(c.sourceFactory.forUri(uri)); 4498 c.computeLibraryElement(c.sourceFactory.forUri(uri));
4501 4499
4502 bool _isDartRuntime(LibraryElement l) => 4500 bool _isDartRuntime(LibraryElement l) =>
4503 l.isInSdk && l.source.uri.toString() == 'dart:_runtime'; 4501 l.isInSdk && l.source.uri.toString() == 'dart:_runtime';
OLDNEW
« no previous file with comments | « lib/runtime/dart_sdk.js ('k') | test/browser/language_tests.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698