Index: lib/src/compiler/js_typeref_codegen.dart |
diff --git a/lib/src/codegen/js_typeref_codegen.dart b/lib/src/compiler/js_typeref_codegen.dart |
similarity index 82% |
rename from lib/src/codegen/js_typeref_codegen.dart |
rename to lib/src/compiler/js_typeref_codegen.dart |
index 7aa4c0a2e7d0786aef798846670d9a045c99ad7c..b43692d09b699aff46e20be3de8e47248b99a06f 100644 |
--- a/lib/src/codegen/js_typeref_codegen.dart |
+++ b/lib/src/compiler/js_typeref_codegen.dart |
@@ -7,8 +7,8 @@ import 'package:analyzer/dart/element/type.dart'; |
import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; |
import 'package:analyzer/src/generated/utilities_dart.dart'; |
-import '../js/js_ast.dart' as JS; |
-import '../options.dart'; |
+import '../js_ast/js_ast.dart' as JS; |
+import 'compiler.dart' show CompilerOptions; |
import 'js_interop.dart'; |
/// Mixin with logic to generate [TypeRef]s out of [DartType]s. |
@@ -16,23 +16,17 @@ abstract class JsTypeRefCodegen { |
final _resolved = <DartType, JS.TypeRef>{}; |
// Mixin dependencies: |
- CodegenOptions get options; |
+ CompilerOptions get options; |
TypeProvider get types; |
+ LibraryElement get dartJSLibrary; |
JS.Identifier get namedArgumentTemp; |
- LibraryElement get currentLibrary; |
JS.Identifier emitLibraryName(LibraryElement e); |
/// Finds the qualified path to the type. |
JS.TypeRef _emitTopLevelTypeRef(DartType type) { |
var e = type.element; |
- if (e.library == currentLibrary) { |
- return new JS.TypeRef.named(type.name); |
- } else { |
- return new JS.TypeRef.qualified([ |
- emitLibraryName(e.library), |
- new JS.Identifier(getJSExportName(e, types) ?? type.name) |
- ]); |
- } |
+ return new JS.TypeRef.qualified( |
+ [emitLibraryName(e.library), new JS.Identifier(getJSExportName(e))]); |
} |
JS.TypeRef emitTypeRef(DartType type) { |
@@ -114,20 +108,18 @@ abstract class JsTypeRefCodegen { |
/// Special treatment of types from dart:js |
/// TODO(ochafik): Is this the right thing to do? And what about package:js? |
JS.TypeRef _getDartJsTypeRef(DartType type) { |
- switch (type.element.source.uri.toString()) { |
- case 'dart:js': |
- switch (type.name) { |
- case 'JsArray': |
- return new JS.TypeRef.array( |
- type is InterfaceType && type.typeArguments.length == 1 |
- ? emitTypeRef(type.typeArguments.single) |
- : null); |
- case 'JsObject': |
- return new JS.TypeRef.object(); |
- case 'JsFunction': |
- return new JS.TypeRef.function(); |
- } |
- break; |
+ if (type.element.library == dartJSLibrary) { |
+ switch (type.name) { |
+ case 'JsArray': |
+ return new JS.TypeRef.array( |
+ type is InterfaceType && type.typeArguments.length == 1 |
+ ? emitTypeRef(type.typeArguments.single) |
+ : null); |
+ case 'JsObject': |
+ return new JS.TypeRef.object(); |
+ case 'JsFunction': |
+ return new JS.TypeRef.function(); |
+ } |
} |
return null; |
} |