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

Side by Side Diff: lib/src/codegen/js_codegen.dart

Issue 1013223002: coverage: increase coverage of js_codegen (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 9 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) 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 library dev_compiler.src.codegen.js_codegen; 5 library dev_compiler.src.codegen.js_codegen;
6 6
7 import 'dart:collection' show HashSet; 7 import 'dart:collection' show HashSet;
8 import 'dart:io' show Directory, File; 8 import 'dart:io' show Directory, File;
9 9
10 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; 10 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator;
(...skipping 1606 matching lines...) Expand 10 before | Expand all | Expand 10 after
1617 return list; 1617 return list;
1618 } 1618 }
1619 1619
1620 @override 1620 @override
1621 visitMapLiteral(MapLiteral node) { 1621 visitMapLiteral(MapLiteral node) {
1622 var entries = node.entries; 1622 var entries = node.entries;
1623 var mapArguments = null; 1623 var mapArguments = null;
1624 if (entries.isEmpty) return js.call('dart.map()'); 1624 if (entries.isEmpty) return js.call('dart.map()');
1625 1625
1626 // Use JS object literal notation if possible, otherwise use an array. 1626 // Use JS object literal notation if possible, otherwise use an array.
1627 if (entries.every((e) => e.key is SimpleStringLiteral)) { 1627 // We could do this any time all keys are non-nullable String type.
1628 // For now, support StringLiteral as the common non-nullable String case.
1629 if (entries.every((e) => e.key is StringLiteral)) {
1628 var props = []; 1630 var props = [];
1629 for (var e in entries) { 1631 for (var e in entries) {
1630 var key = (e.key as SimpleStringLiteral).value; 1632 props.add(new JS.Property(_visit(e.key), _visit(e.value)));
1631 var value = _visit(e.value);
1632 props.add(new JS.Property(js.escapedString(key), value));
1633 } 1633 }
1634 mapArguments = new JS.ObjectInitializer(props); 1634 mapArguments = new JS.ObjectInitializer(props);
1635 } else { 1635 } else {
1636 var values = []; 1636 var values = [];
1637 for (var e in entries) { 1637 for (var e in entries) {
1638 values.add(_visit(e.key)); 1638 values.add(_visit(e.key));
1639 values.add(_visit(e.value)); 1639 values.add(_visit(e.value));
1640 } 1640 }
1641 mapArguments = new JS.ArrayInitializer(values); 1641 mapArguments = new JS.ArrayInitializer(values);
1642 } 1642 }
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
2039 2039
2040 // TODO(jmesserly): in many cases marking the end will be unncessary. 2040 // TODO(jmesserly): in many cases marking the end will be unncessary.
2041 printer.mark(_location(node.end)); 2041 printer.mark(_location(node.end));
2042 } 2042 }
2043 2043
2044 String _getIdentifier(AstNode node) { 2044 String _getIdentifier(AstNode node) {
2045 if (node is SimpleIdentifier) return node.name; 2045 if (node is SimpleIdentifier) return node.name;
2046 return null; 2046 return null;
2047 } 2047 }
2048 } 2048 }
OLDNEW
« no previous file with comments | « .gitignore ('k') | test/codegen/expect/map_keys.js » ('j') | test/codegen_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698