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 2161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2172 ])); | 2172 ])); |
2173 } else if (param.kind == ParameterKind.POSITIONAL) { | 2173 } else if (param.kind == ParameterKind.POSITIONAL) { |
2174 body.add(js.statement('if (# === void 0) # = #;', | 2174 body.add(js.statement('if (# === void 0) # = #;', |
2175 [jsParam, jsParam, _defaultParamValue(param)])); | 2175 [jsParam, jsParam, _defaultParamValue(param)])); |
2176 } | 2176 } |
2177 } | 2177 } |
2178 | 2178 |
2179 // TODO(jmesserly): various problems here, see: | 2179 // TODO(jmesserly): various problems here, see: |
2180 // https://github.com/dart-lang/dev_compiler/issues/116 | 2180 // https://github.com/dart-lang/dev_compiler/issues/116 |
2181 var paramType = param.element.type; | 2181 var paramType = param.element.type; |
2182 if (node is MethodDeclaration && _unsoundCovariant(paramType, true)) { | 2182 if (node is MethodDeclaration && |
| 2183 (param.element.isCovariant || _unsoundCovariant(paramType, true)) && |
| 2184 !_inWhitelistCode(node)) { |
2183 var castType = _emitType(paramType, | 2185 var castType = _emitType(paramType, |
2184 nameType: options.nameTypeTests || options.hoistTypeTests, | 2186 nameType: options.nameTypeTests || options.hoistTypeTests, |
2185 hoistType: options.hoistTypeTests); | 2187 hoistType: options.hoistTypeTests); |
2186 if (!_inWhitelistCode(node)) { | 2188 body.add(js.statement('#._check(#);', [castType, jsParam])); |
2187 body.add(js.statement('#._check(#);', [castType, jsParam])); | |
2188 } | |
2189 } | 2189 } |
2190 } | 2190 } |
2191 return body.isEmpty ? null : _statement(body); | 2191 return body.isEmpty ? null : _statement(body); |
2192 } | 2192 } |
2193 | 2193 |
2194 /// Given a type [t], return whether or not t is unsoundly covariant. | 2194 /// Given a type [t], return whether or not t is unsoundly covariant. |
2195 /// If [contravariant] is true, then t appears in a contravariant | 2195 /// If [contravariant] is true, then t appears in a contravariant |
2196 /// position. | 2196 /// position. |
2197 bool _unsoundCovariant(DartType t, bool contravariant) { | 2197 bool _unsoundCovariant(DartType t, bool contravariant) { |
2198 if (t is TypeParameterType) { | 2198 if (t is TypeParameterType) { |
(...skipping 3252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5451 } | 5451 } |
5452 | 5452 |
5453 bool isLibraryPrefix(Expression node) => | 5453 bool isLibraryPrefix(Expression node) => |
5454 node is SimpleIdentifier && node.staticElement is PrefixElement; | 5454 node is SimpleIdentifier && node.staticElement is PrefixElement; |
5455 | 5455 |
5456 LibraryElement _getLibrary(AnalysisContext c, String uri) => | 5456 LibraryElement _getLibrary(AnalysisContext c, String uri) => |
5457 c.computeLibraryElement(c.sourceFactory.forUri(uri)); | 5457 c.computeLibraryElement(c.sourceFactory.forUri(uri)); |
5458 | 5458 |
5459 bool _isDartRuntime(LibraryElement l) => | 5459 bool _isDartRuntime(LibraryElement l) => |
5460 l.isInSdk && l.source.uri.toString() == 'dart:_runtime'; | 5460 l.isInSdk && l.source.uri.toString() == 'dart:_runtime'; |
OLD | NEW |