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; |
11 import 'package:analyzer/dart/element/element.dart'; | 11 import 'package:analyzer/dart/element/element.dart'; |
12 import 'package:analyzer/dart/element/type.dart'; | 12 import 'package:analyzer/dart/element/type.dart'; |
13 import 'package:analyzer/src/dart/ast/token.dart' show StringToken; | 13 import 'package:analyzer/src/dart/ast/token.dart' show StringToken; |
14 //TODO(leafp): Remove deprecated dependency | 14 import 'package:analyzer/src/dart/element/element.dart' |
15 //ignore: DEPRECATED_MEMBER_USE | 15 show LocalVariableElementImpl; |
16 import 'package:analyzer/src/generated/element.dart' | 16 import 'package:analyzer/src/dart/element/type.dart' show DynamicTypeImpl; |
17 show DynamicTypeImpl, LocalVariableElementImpl; | |
18 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext; | 17 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext; |
19 import 'package:analyzer/src/generated/resolver.dart' | 18 import 'package:analyzer/src/generated/resolver.dart' |
20 show TypeProvider, NamespaceBuilder; | 19 show TypeProvider, NamespaceBuilder; |
21 import 'package:analyzer/src/generated/type_system.dart' | 20 import 'package:analyzer/src/generated/type_system.dart' |
22 show StrongTypeSystemImpl; | 21 show StrongTypeSystemImpl; |
23 import 'package:analyzer/src/summary/summarize_elements.dart' | 22 import 'package:analyzer/src/summary/summarize_elements.dart' |
24 show PackageBundleAssembler; | 23 show PackageBundleAssembler; |
25 import 'package:analyzer/src/task/strong/info.dart' show DynamicInvoke; | 24 import 'package:analyzer/src/task/strong/info.dart' show DynamicInvoke; |
26 import 'package:source_maps/source_maps.dart'; | 25 import 'package:source_maps/source_maps.dart'; |
27 import 'package:path/path.dart' show separator; | 26 import 'package:path/path.dart' show separator; |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 | 283 |
285 // Optional: lower module format. Otherwise just return it. | 284 // Optional: lower module format. Otherwise just return it. |
286 switch (options.moduleFormat) { | 285 switch (options.moduleFormat) { |
287 case ModuleFormat.legacy: | 286 case ModuleFormat.legacy: |
288 return new LegacyModuleBuilder().build(module); | 287 return new LegacyModuleBuilder().build(module); |
289 case ModuleFormat.node: | 288 case ModuleFormat.node: |
290 return new NodeModuleBuilder().build(module); | 289 return new NodeModuleBuilder().build(module); |
291 case ModuleFormat.es6: | 290 case ModuleFormat.es6: |
292 return module; | 291 return module; |
293 } | 292 } |
| 293 return null; // unreachable. It is here to suppress a bogus Analyzer message |
294 } | 294 } |
295 | 295 |
296 List<String> _getJSName(Element e) { | 296 List<String> _getJSName(Element e) { |
297 if (findAnnotation(e.library, isPublicJSAnnotation) == null) { | 297 if (findAnnotation(e.library, isPublicJSAnnotation) == null) { |
298 return null; | 298 return null; |
299 } | 299 } |
300 | 300 |
301 var libraryJSName = getAnnotationName(e.library, isPublicJSAnnotation); | 301 var libraryJSName = getAnnotationName(e.library, isPublicJSAnnotation); |
302 var libraryPrefix = <String>[]; | 302 var libraryPrefix = <String>[]; |
303 if (libraryJSName != null && libraryJSName.isNotEmpty) { | 303 if (libraryJSName != null && libraryJSName.isNotEmpty) { |
(...skipping 1858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2162 | 2162 |
2163 JS.Expression _emitFunctionTagged(JS.Expression fn, DartType type, | 2163 JS.Expression _emitFunctionTagged(JS.Expression fn, DartType type, |
2164 {topLevel: false}) { | 2164 {topLevel: false}) { |
2165 var lazy = topLevel && !_typeIsLoaded(type); | 2165 var lazy = topLevel && !_typeIsLoaded(type); |
2166 var typeRep = _emitFunctionType(type, definite: true); | 2166 var typeRep = _emitFunctionType(type, definite: true); |
2167 if (lazy) { | 2167 if (lazy) { |
2168 return js.call('dart.lazyFn(#, () => #)', [fn, typeRep]); | 2168 return js.call('dart.lazyFn(#, () => #)', [fn, typeRep]); |
2169 } else { | 2169 } else { |
2170 return js.call('dart.fn(#, #)', [fn, typeRep]); | 2170 return js.call('dart.fn(#, #)', [fn, typeRep]); |
2171 } | 2171 } |
2172 throw 'Function has non function type: $type'; | |
2173 } | 2172 } |
2174 | 2173 |
2175 /// Emits an arrow FunctionExpression node. | 2174 /// Emits an arrow FunctionExpression node. |
2176 /// | 2175 /// |
2177 /// This should be used for all places in Dart's AST where FunctionExpression | 2176 /// This should be used for all places in Dart's AST where FunctionExpression |
2178 /// appears and the function is actually in an Expression context. These | 2177 /// appears and the function is actually in an Expression context. These |
2179 /// correspond to arrow functions in Dart. | 2178 /// correspond to arrow functions in Dart. |
2180 /// | 2179 /// |
2181 /// Contrast with [_emitFunction]. | 2180 /// Contrast with [_emitFunction]. |
2182 @override | 2181 @override |
(...skipping 2791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4974 } | 4973 } |
4975 | 4974 |
4976 bool isLibraryPrefix(Expression node) => | 4975 bool isLibraryPrefix(Expression node) => |
4977 node is SimpleIdentifier && node.staticElement is PrefixElement; | 4976 node is SimpleIdentifier && node.staticElement is PrefixElement; |
4978 | 4977 |
4979 LibraryElement _getLibrary(AnalysisContext c, String uri) => | 4978 LibraryElement _getLibrary(AnalysisContext c, String uri) => |
4980 c.computeLibraryElement(c.sourceFactory.forUri(uri)); | 4979 c.computeLibraryElement(c.sourceFactory.forUri(uri)); |
4981 | 4980 |
4982 bool _isDartRuntime(LibraryElement l) => | 4981 bool _isDartRuntime(LibraryElement l) => |
4983 l.isInSdk && l.source.uri.toString() == 'dart:_runtime'; | 4982 l.isInSdk && l.source.uri.toString() == 'dart:_runtime'; |
OLD | NEW |