Index: lib/src/codegen/js_codegen.dart |
diff --git a/lib/src/codegen/js_codegen.dart b/lib/src/codegen/js_codegen.dart |
index 95fcf811ffe8cdd8a3dd926da67403e1f569c24b..d3f5b351cd2f6efbdfb47d019447cfeb084e3dfd 100644 |
--- a/lib/src/codegen/js_codegen.dart |
+++ b/lib/src/codegen/js_codegen.dart |
@@ -109,7 +109,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor { |
if (unit.directives.isNotEmpty) { |
var libraryDir = unit.directives.first; |
if (libraryDir is LibraryDirective) { |
- var jsName = getAnnotationValue(libraryDir, _isJsNameAnnotation); |
+ var jsName = findAnnotation(libraryDir.element, _isJsNameAnnotation); |
jsDefaultValue = getConstantField(jsName, 'name', types.stringType); |
} |
} |
@@ -328,7 +328,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor { |
// If we've already emitted this class, skip it. |
var classElem = node.element; |
var type = classElem.type; |
- var jsName = getAnnotationValue(node, _isJsNameAnnotation); |
+ var jsName = findAnnotation(classElem, _isJsNameAnnotation); |
if (jsName != null) return _emitJsType(node.name.name, jsName); |
@@ -349,7 +349,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor { |
_classHeritage(classElem), _emitClassMethods(node, ctors, fields)); |
String jsPeerName; |
- var jsPeer = getAnnotationValue(node, _isJsPeerInterface); |
+ var jsPeer = findAnnotation(classElem, _isJsPeerInterface); |
if (jsPeer != null) { |
jsPeerName = getConstantField(jsPeer, 'name', types.stringType); |
} |
@@ -474,7 +474,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor { |
jsMethods.add(_emitImplicitConstructor(node, fields)); |
} |
- bool hasJsPeer = getAnnotationValue(node, _isJsPeerInterface) != null; |
+ bool hasJsPeer = findAnnotation(element, _isJsPeerInterface) != null; |
bool hasIterator = false; |
for (var m in node.members) { |
@@ -1404,7 +1404,12 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor { |
JS.Expression _emitSet(Expression lhs, Expression rhs) { |
if (lhs is IndexExpression) { |
- return _emitSend(_getTarget(lhs), '[]=', [lhs.index, rhs]); |
+ var target = _getTarget(lhs); |
+ if (_useNativeJsIndexer(target.staticType)) { |
+ return js.call( |
+ '#[#] = #', [_visit(target), _visit(lhs.index), _visit(rhs)]); |
+ } |
+ return _emitSend(target, '[]=', [lhs.index, rhs]); |
} |
Expression target = null; |
@@ -2195,9 +2200,18 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor { |
@override |
visitIndexExpression(IndexExpression node) { |
- return _emitSend(_getTarget(node), '[]', [node.index]); |
+ var target = _getTarget(node); |
+ if (_useNativeJsIndexer(target.staticType)) { |
+ return new JS.PropertyAccess(_visit(target), _visit(node.index)); |
+ } |
+ return _emitSend(target, '[]', [node.index]); |
} |
+ // TODO(jmesserly): ideally we'd check the method and see if it is marked |
+ // `external`, but that doesn't work because it isn't in the element model. |
+ bool _useNativeJsIndexer(DartType type) => |
+ findAnnotation(type.element, _isJsNameAnnotation) != null; |
+ |
/// Gets the target of a [PropertyAccess] or [IndexExpression]. |
/// Those two nodes are special because they're both allowed on left side of |
/// an assignment expression and cascades. |