| 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 2019 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2030 if (accessor is PropertyAccessorElement) element = accessor.variable; | 2030 if (accessor is PropertyAccessorElement) element = accessor.variable; |
| 2031 | 2031 |
| 2032 _loader.declareBeforeUse(element); | 2032 _loader.declareBeforeUse(element); |
| 2033 | 2033 |
| 2034 // type literal | 2034 // type literal |
| 2035 if (element is TypeDefiningElement) { | 2035 if (element is TypeDefiningElement) { |
| 2036 var typeName = _emitTypeName(fillDynamicTypeArgs(element.type)); | 2036 var typeName = _emitTypeName(fillDynamicTypeArgs(element.type)); |
| 2037 | 2037 |
| 2038 // If the type is a type literal expression in Dart code, wrap the raw | 2038 // If the type is a type literal expression in Dart code, wrap the raw |
| 2039 // runtime type in a "Type" instance. | 2039 // runtime type in a "Type" instance. |
| 2040 if (!_isInForeignJS && | 2040 if (!_isInForeignJS && _isTypeLiteral(node)) { |
| 2041 node.parent is! MethodInvocation && | |
| 2042 node.parent is! PrefixedIdentifier && | |
| 2043 node.parent is! PropertyAccess) { | |
| 2044 typeName = js.call('dart.wrapType(#)', typeName); | 2041 typeName = js.call('dart.wrapType(#)', typeName); |
| 2045 } | 2042 } |
| 2046 | 2043 |
| 2047 return typeName; | 2044 return typeName; |
| 2048 } | 2045 } |
| 2049 | 2046 |
| 2050 // library member | 2047 // library member |
| 2051 if (element.enclosingElement is CompilationUnitElement) { | 2048 if (element.enclosingElement is CompilationUnitElement) { |
| 2052 return _emitTopLevelName(element); | 2049 return _emitTopLevelName(element); |
| 2053 } | 2050 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2081 } | 2078 } |
| 2082 | 2079 |
| 2083 // If this is one of our compiler's temporary variables, return its JS form. | 2080 // If this is one of our compiler's temporary variables, return its JS form. |
| 2084 if (element is TemporaryVariableElement) { | 2081 if (element is TemporaryVariableElement) { |
| 2085 return element.jsVariable; | 2082 return element.jsVariable; |
| 2086 } | 2083 } |
| 2087 | 2084 |
| 2088 return new JS.Identifier(name); | 2085 return new JS.Identifier(name); |
| 2089 } | 2086 } |
| 2090 | 2087 |
| 2088 /// Returns `true` if the type name referred to by [node] is used in a |
| 2089 /// position where it should evaluate as a type literal -- an object of type |
| 2090 /// Type. |
| 2091 bool _isTypeLiteral(SimpleIdentifier node) { |
| 2092 var parent = node.parent; |
| 2093 |
| 2094 // Static member call. |
| 2095 if (parent is MethodInvocation || parent is PropertyAccess) return false; |
| 2096 |
| 2097 // An expression like "a.b". |
| 2098 if (parent is PrefixedIdentifier) { |
| 2099 // In "a.b", "b" may be a type literal, but "a", is not. |
| 2100 if (node != parent.identifier) return false; |
| 2101 |
| 2102 // If the prefix expression is itself used as an invocation, like |
| 2103 // "a.b.c", then "b" is not a type literal. |
| 2104 var grand = parent.parent; |
| 2105 if (grand is MethodInvocation || grand is PropertyAccess) return false; |
| 2106 |
| 2107 return true; |
| 2108 } |
| 2109 |
| 2110 // In any other context, it's a type literal. |
| 2111 return true; |
| 2112 } |
| 2113 |
| 2091 JS.Identifier _emitParameter(ParameterElement element, | 2114 JS.Identifier _emitParameter(ParameterElement element, |
| 2092 {bool declaration: false}) { | 2115 {bool declaration: false}) { |
| 2093 // initializing formal parameter, e.g. `Point(this._x)` | 2116 // initializing formal parameter, e.g. `Point(this._x)` |
| 2094 // TODO(jmesserly): type ref is not attached in this case. | 2117 // TODO(jmesserly): type ref is not attached in this case. |
| 2095 if (element.isInitializingFormal && element.isPrivate) { | 2118 if (element.isInitializingFormal && element.isPrivate) { |
| 2096 /// Rename private names so they don't shadow the private field symbol. | 2119 /// Rename private names so they don't shadow the private field symbol. |
| 2097 /// The renamer would handle this, but it would prefer to rename the | 2120 /// The renamer would handle this, but it would prefer to rename the |
| 2098 /// temporary used for the private symbol. Instead rename the parameter. | 2121 /// temporary used for the private symbol. Instead rename the parameter. |
| 2099 return _initializingFormalTemps.putIfAbsent( | 2122 return _initializingFormalTemps.putIfAbsent( |
| 2100 element, () => new JS.TemporaryId(element.name.substring(1))); | 2123 element, () => new JS.TemporaryId(element.name.substring(1))); |
| (...skipping 2175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4276 } | 4299 } |
| 4277 | 4300 |
| 4278 bool isLibraryPrefix(Expression node) => | 4301 bool isLibraryPrefix(Expression node) => |
| 4279 node is SimpleIdentifier && node.staticElement is PrefixElement; | 4302 node is SimpleIdentifier && node.staticElement is PrefixElement; |
| 4280 | 4303 |
| 4281 LibraryElement _getLibrary(AnalysisContext c, String uri) => | 4304 LibraryElement _getLibrary(AnalysisContext c, String uri) => |
| 4282 c.computeLibraryElement(c.sourceFactory.forUri(uri)); | 4305 c.computeLibraryElement(c.sourceFactory.forUri(uri)); |
| 4283 | 4306 |
| 4284 bool _isDartRuntime(LibraryElement l) => | 4307 bool _isDartRuntime(LibraryElement l) => |
| 4285 l.isInSdk && l.source.uri.toString() == 'dart:_runtime'; | 4308 l.isInSdk && l.source.uri.toString() == 'dart:_runtime'; |
| OLD | NEW |