OLD | NEW |
---|---|
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 4926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4937 if (isConst) return _cacheConst(emitList); | 4937 if (isConst) return _cacheConst(emitList); |
4938 return emitList(); | 4938 return emitList(); |
4939 } | 4939 } |
4940 | 4940 |
4941 @override | 4941 @override |
4942 visitMapLiteral(MapLiteral node) { | 4942 visitMapLiteral(MapLiteral node) { |
4943 // TODO(jmesserly): we can likely make these faster. | 4943 // TODO(jmesserly): we can likely make these faster. |
4944 JS.Expression emitMap() { | 4944 JS.Expression emitMap() { |
4945 var entries = node.entries; | 4945 var entries = node.entries; |
4946 var mapArguments = null; | 4946 var mapArguments = null; |
4947 var typeArgs = node.typeArguments; | 4947 var type = node.staticType as InterfaceType; |
4948 if (entries.isEmpty && typeArgs == null) { | 4948 var typeArgs = type.typeArguments; |
4949 var reifyTypeArgs = typeArgs != null && typeArgs.any((t) => !t.isDynamic); | |
Jennifer Messerly
2016/08/05 13:48:32
typeArguments should never be null on an Interface
vsm
2016/08/05 14:15:03
Removed - thanks!
| |
4950 if (entries.isEmpty && !reifyTypeArgs) { | |
4949 mapArguments = []; | 4951 mapArguments = []; |
4950 } else if (entries.every((e) => e.key is StringLiteral)) { | 4952 } else if (entries.every((e) => e.key is StringLiteral)) { |
4951 // Use JS object literal notation if possible, otherwise use an array. | 4953 // Use JS object literal notation if possible, otherwise use an array. |
4952 // We could do this any time all keys are non-nullable String type. | 4954 // We could do this any time all keys are non-nullable String type. |
4953 // For now, support StringLiteral as the common non-nullable String case . | 4955 // For now, support StringLiteral as the common non-nullable String case . |
4954 var props = <JS.Property>[]; | 4956 var props = <JS.Property>[]; |
4955 for (var e in entries) { | 4957 for (var e in entries) { |
4956 props.add(new JS.Property(_visit(e.key), _visit(e.value))); | 4958 props.add(new JS.Property(_visit(e.key), _visit(e.value))); |
4957 } | 4959 } |
4958 mapArguments = new JS.ObjectInitializer(props); | 4960 mapArguments = new JS.ObjectInitializer(props); |
4959 } else { | 4961 } else { |
4960 var values = <JS.Expression>[]; | 4962 var values = <JS.Expression>[]; |
4961 for (var e in entries) { | 4963 for (var e in entries) { |
4962 values.add(_visit(e.key)); | 4964 values.add(_visit(e.key)); |
4963 values.add(_visit(e.value)); | 4965 values.add(_visit(e.value)); |
4964 } | 4966 } |
4965 mapArguments = new JS.ArrayInitializer(values); | 4967 mapArguments = new JS.ArrayInitializer(values); |
4966 } | 4968 } |
4967 var types = <JS.Expression>[]; | 4969 var types = <JS.Expression>[]; |
4968 if (typeArgs != null) { | 4970 if (reifyTypeArgs) { |
4969 types.addAll(typeArgs.arguments.map((e) => _emitType(e.type))); | 4971 types.addAll(typeArgs.map((e) => _emitType(e))); |
4970 } | 4972 } |
4971 return js.call('dart.map(#, #)', [mapArguments, types]); | 4973 return js.call('dart.map(#, #)', [mapArguments, types]); |
4972 } | 4974 } |
4973 if (node.constKeyword != null) return _emitConst(emitMap); | 4975 if (node.constKeyword != null) return _emitConst(emitMap); |
4974 return emitMap(); | 4976 return emitMap(); |
4975 } | 4977 } |
4976 | 4978 |
4977 @override | 4979 @override |
4978 JS.LiteralString visitSimpleStringLiteral(SimpleStringLiteral node) => | 4980 JS.LiteralString visitSimpleStringLiteral(SimpleStringLiteral node) => |
4979 js.escapedString(node.value, node.isSingleQuoted ? "'" : '"'); | 4981 js.escapedString(node.value, node.isSingleQuoted ? "'" : '"'); |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5365 } | 5367 } |
5366 | 5368 |
5367 bool isLibraryPrefix(Expression node) => | 5369 bool isLibraryPrefix(Expression node) => |
5368 node is SimpleIdentifier && node.staticElement is PrefixElement; | 5370 node is SimpleIdentifier && node.staticElement is PrefixElement; |
5369 | 5371 |
5370 LibraryElement _getLibrary(AnalysisContext c, String uri) => | 5372 LibraryElement _getLibrary(AnalysisContext c, String uri) => |
5371 c.computeLibraryElement(c.sourceFactory.forUri(uri)); | 5373 c.computeLibraryElement(c.sourceFactory.forUri(uri)); |
5372 | 5374 |
5373 bool _isDartRuntime(LibraryElement l) => | 5375 bool _isDartRuntime(LibraryElement l) => |
5374 l.isInSdk && l.source.uri.toString() == 'dart:_runtime'; | 5376 l.isInSdk && l.source.uri.toString() == 'dart:_runtime'; |
OLD | NEW |