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 library dev_compiler.src.codegen.js_codegen; | 5 library dev_compiler.src.codegen.js_codegen; |
6 | 6 |
7 import 'dart:collection' show HashSet, HashMap; | 7 import 'dart:collection' show HashSet, HashMap; |
8 | 8 |
9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; | 9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; |
10 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator; | 10 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator; |
(...skipping 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1044 // Get the original declaring element. If we had a property accessor, this | 1044 // Get the original declaring element. If we had a property accessor, this |
1045 // indirects back to a (possibly synthetic) field. | 1045 // indirects back to a (possibly synthetic) field. |
1046 var element = accessor; | 1046 var element = accessor; |
1047 if (element is PropertyAccessorElement) element = accessor.variable; | 1047 if (element is PropertyAccessorElement) element = accessor.variable; |
1048 var name = element.name; | 1048 var name = element.name; |
1049 | 1049 |
1050 // library member | 1050 // library member |
1051 if (element.enclosingElement is CompilationUnitElement && | 1051 if (element.enclosingElement is CompilationUnitElement && |
1052 (element.library != libraryInfo.library || | 1052 (element.library != libraryInfo.library || |
1053 element is TopLevelVariableElement && !element.isConst)) { | 1053 element is TopLevelVariableElement && !element.isConst)) { |
1054 return js.call('#.#', [_libraryName(element.library), name]); | 1054 var memberName = _emitMemberName(name, isStatic: true); |
| 1055 return js.call('#.#', [_libraryName(element.library), memberName]); |
1055 } | 1056 } |
1056 | 1057 |
1057 // Unqualified class member. This could mean implicit-this, or implicit | 1058 // Unqualified class member. This could mean implicit-this, or implicit |
1058 // call to a static from the same class. | 1059 // call to a static from the same class. |
1059 if (element is ClassMemberElement && element is! ConstructorElement) { | 1060 if (element is ClassMemberElement && element is! ConstructorElement) { |
1060 bool isStatic = element.isStatic; | 1061 bool isStatic = element.isStatic; |
1061 var type = element.enclosingElement.type; | 1062 var type = element.enclosingElement.type; |
1062 var member = _emitMemberName(name, isStatic: isStatic, type: type); | 1063 var member = _emitMemberName(name, isStatic: isStatic, type: type); |
1063 | 1064 |
1064 // For static methods, we add the raw type name, without generics or | 1065 // For static methods, we add the raw type name, without generics or |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1501 _exportsVar, | 1502 _exportsVar, |
1502 _properties.map(_emitTopLevelProperty) | 1503 _properties.map(_emitTopLevelProperty) |
1503 ])); | 1504 ])); |
1504 _properties.clear(); | 1505 _properties.clear(); |
1505 } | 1506 } |
1506 | 1507 |
1507 @override | 1508 @override |
1508 visitConstructorName(ConstructorName node) { | 1509 visitConstructorName(ConstructorName node) { |
1509 var typeName = _visit(node.type); | 1510 var typeName = _visit(node.type); |
1510 if (node.name != null) { | 1511 if (node.name != null) { |
1511 return js.call('#.#', [typeName, _emitMemberName(node.name.name)]); | 1512 return js.call( |
| 1513 '#.#', [typeName, _emitMemberName(node.name.name, isStatic: true)]); |
1512 } | 1514 } |
1513 return typeName; | 1515 return typeName; |
1514 } | 1516 } |
1515 | 1517 |
1516 @override | 1518 @override |
1517 visitInstanceCreationExpression(InstanceCreationExpression node) { | 1519 visitInstanceCreationExpression(InstanceCreationExpression node) { |
1518 var newExpr = js.call( | 1520 var newExpr = js.call( |
1519 'new #(#)', [_visit(node.constructorName), _visit(node.argumentList)]); | 1521 'new #(#)', [_visit(node.constructorName), _visit(node.argumentList)]); |
1520 if (node.isConst) return _const(node, newExpr); | 1522 if (node.isConst) return _const(node, newExpr); |
1521 return newExpr; | 1523 return newExpr; |
(...skipping 989 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2511 // TODO(jmesserly): validate the library. See issue #135. | 2513 // TODO(jmesserly): validate the library. See issue #135. |
2512 bool _isJsNameAnnotation(DartObjectImpl value) => value.type.name == 'JsName'; | 2514 bool _isJsNameAnnotation(DartObjectImpl value) => value.type.name == 'JsName'; |
2513 | 2515 |
2514 bool _isJsPeerInterface(DartObjectImpl value) => | 2516 bool _isJsPeerInterface(DartObjectImpl value) => |
2515 value.type.name == 'JsPeerInterface'; | 2517 value.type.name == 'JsPeerInterface'; |
2516 | 2518 |
2517 // TODO(jacobr): we would like to do something like the following | 2519 // TODO(jacobr): we would like to do something like the following |
2518 // but we don't have summary support yet. | 2520 // but we don't have summary support yet. |
2519 // bool _supportJsExtensionMethod(AnnotatedNode node) => | 2521 // bool _supportJsExtensionMethod(AnnotatedNode node) => |
2520 // _getAnnotation(node, "SupportJsExtensionMethod") != null; | 2522 // _getAnnotation(node, "SupportJsExtensionMethod") != null; |
OLD | NEW |