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 'package:analyzer/dart/element/element.dart'; | 5 import 'package:analyzer/dart/element/element.dart'; |
6 import 'package:analyzer/dart/element/type.dart'; | 6 import 'package:analyzer/dart/element/type.dart'; |
7 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; | 7 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; |
8 import 'package:analyzer/src/generated/utilities_dart.dart'; | 8 import 'package:analyzer/src/generated/utilities_dart.dart'; |
9 | 9 |
10 import '../js_ast/js_ast.dart' as JS; | 10 import '../js_ast/js_ast.dart' as JS; |
11 import 'compiler.dart' show CompilerOptions; | 11 import 'compiler.dart' show CompilerOptions; |
12 import 'js_interop.dart'; | 12 import 'js_interop.dart'; |
13 | 13 |
14 /// Mixin with logic to generate [TypeRef]s out of [DartType]s. | 14 /// Mixin with logic to generate [TypeRef]s out of [DartType]s. |
15 abstract class JsTypeRefCodegen { | 15 abstract class JsTypeRefCodegen { |
16 final _resolved = <DartType, JS.TypeRef>{}; | 16 final _resolved = <DartType, JS.TypeRef>{}; |
17 | 17 |
18 // Mixin dependencies: | 18 // Mixin dependencies: |
19 CompilerOptions get options; | 19 CompilerOptions get options; |
20 TypeProvider get types; | 20 TypeProvider get types; |
21 LibraryElement get dartJSLibrary; | 21 LibraryElement get dartJSLibrary; |
22 JS.Identifier get namedArgumentTemp; | 22 JS.Identifier get namedArgumentTemp; |
23 JS.Identifier emitLibraryName(LibraryElement e); | 23 JS.Identifier emitLibraryName(LibraryElement e); |
24 | 24 |
25 /// Finds the qualified path to the type. | 25 /// Finds the qualified path to the type. |
26 JS.TypeRef _emitTopLevelTypeRef(DartType type) { | 26 JS.TypeRef _emitTopLevelTypeRef(DartType type) { |
27 var e = type.element; | 27 var e = type.element; |
28 return new JS.TypeRef.qualified( | 28 return new JS.TypeRef.qualified([ |
29 [emitLibraryName(e.library), new JS.Identifier(getJSExportName(e))]); | 29 emitLibraryName(e.library), |
| 30 new JS.Identifier(getJSExportName(e) ?? e.name) |
| 31 ]); |
30 } | 32 } |
31 | 33 |
32 JS.TypeRef emitTypeRef(DartType type) { | 34 JS.TypeRef emitTypeRef(DartType type) { |
33 if (!options.closure) return null; | 35 if (!options.closure) return null; |
34 | 36 |
35 return _resolved.putIfAbsent(type, () { | 37 return _resolved.putIfAbsent(type, () { |
36 if (type == null) new JS.TypeRef.unknown(); | 38 if (type == null) new JS.TypeRef.unknown(); |
37 // TODO(ochafik): Consider calling _loader.declareBeforeUse(type.element). | 39 // TODO(ochafik): Consider calling _loader.declareBeforeUse(type.element). |
38 if (type.isBottom || type.isDynamic) new JS.TypeRef.any(); | 40 if (type.isBottom || type.isDynamic) new JS.TypeRef.any(); |
39 if (type.isVoid) return new JS.TypeRef.void_(); | 41 if (type.isVoid) return new JS.TypeRef.void_(); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 : null); | 121 : null); |
120 case 'JsObject': | 122 case 'JsObject': |
121 return new JS.TypeRef.object(); | 123 return new JS.TypeRef.object(); |
122 case 'JsFunction': | 124 case 'JsFunction': |
123 return new JS.TypeRef.function(); | 125 return new JS.TypeRef.function(); |
124 } | 126 } |
125 } | 127 } |
126 return null; | 128 return null; |
127 } | 129 } |
128 } | 130 } |
OLD | NEW |