Index: pkg/dev_compiler/lib/src/compiler/code_generator.dart |
diff --git a/pkg/dev_compiler/lib/src/compiler/code_generator.dart b/pkg/dev_compiler/lib/src/compiler/code_generator.dart |
index 221d94ca9bdec9c773ecbd8bd8371ab22c711948..ea967056be45400965b7d5d4b487a958c0e92977 100644 |
--- a/pkg/dev_compiler/lib/src/compiler/code_generator.dart |
+++ b/pkg/dev_compiler/lib/src/compiler/code_generator.dart |
@@ -4481,7 +4481,9 @@ class CodeGenerator extends GeneralizingAstVisitor |
context: expr); |
} |
- return _emitSend(expr, op.lexeme[0], []); |
+ var operatorName = op.lexeme; |
+ if (operatorName == '-') operatorName = 'unary-'; |
Bob Nystrom
2016/10/20 21:01:13
Is "unary-" just used as a magic string for _emitM
Jennifer Messerly
2016/10/20 22:45:04
it's not. It's defined by the Dart language spec a
|
+ return _emitSend(expr, operatorName, []); |
} |
// Cascades can contain [IndexExpression], [MethodInvocation] and |
@@ -4714,7 +4716,7 @@ class CodeGenerator extends GeneralizingAstVisitor |
JS.Expression _emitSend( |
Expression target, String name, List<Expression> args) { |
var type = getStaticType(target); |
- var memberName = _emitMemberName(name, unary: args.isEmpty, type: type); |
+ var memberName = _emitMemberName(name, type: type); |
if (isDynamicInvoke(target)) { |
if (_inWhitelistCode(target)) { |
var vars = <JS.MetaLetVariable, JS.Expression>{}; |
@@ -5226,7 +5228,6 @@ class CodeGenerator extends GeneralizingAstVisitor |
} |
return _emitMemberName(name, |
type: (e.enclosingElement as ClassElement).type, |
- unary: e.parameters.isEmpty, |
isStatic: e.isStatic, |
useExtension: useExtension); |
} |
@@ -5266,17 +5267,14 @@ class CodeGenerator extends GeneralizingAstVisitor |
/// This follows the same pattern as ECMAScript 6 Map: |
/// <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map> |
/// |
- /// Unary minus looks like: `x['unary-']()`. Note that [unary] must be passed |
+ /// Unary minus looks like: `x._negate()`. Note that [unary] must be passed |
Bob Nystrom
2016/10/20 21:01:13
Can you update the part of the doc around "[unary]
Jennifer Messerly
2016/10/20 22:45:04
Done.
|
/// for this transformation to happen, otherwise binary minus is assumed. |
/// |
/// Equality is a bit special, it is generated via the Dart `equals` runtime |
/// helper, that checks for null. The user defined method is called '=='. |
/// |
JS.Expression _emitMemberName(String name, |
- {DartType type, |
- bool unary: false, |
- bool isStatic: false, |
- bool useExtension}) { |
+ {DartType type, bool isStatic: false, bool useExtension}) { |
// Static members skip the rename steps. |
if (isStatic) return _propertyName(name); |
@@ -5284,16 +5282,16 @@ class CodeGenerator extends GeneralizingAstVisitor |
return _emitPrivateNameSymbol(currentLibrary, name); |
} |
+ // When generating synthetic names, we use _ as the prefix, since Dart names |
+ // won't have this (eliminated above), nor will static names reach here. |
if (name == '[]') { |
kevmoo
2016/10/20 20:06:03
better as a switch, no?
Jennifer Messerly
2016/10/20 20:12:14
I tend to find Dart's C-style switch clunky, e.g.
Bob Nystrom
2016/10/20 21:01:13
If it was my code, I'd probably use switch () to h
|
- name = 'get'; |
+ name = '_get'; |
} else if (name == '[]=') { |
- name = 'set'; |
- } else if (name == '-' && unary) { |
- name = 'unary-'; |
+ name = '_set'; |
+ } else if (name == 'unary-') { |
+ name = '_negate'; |
} else if (name == 'constructor' || name == 'prototype') { |
- // This uses an illegal (in Dart) character for a member, avoiding the |
- // conflict. We could use practically any character for this. |
- name = '+$name'; |
+ name = '_$name'; |
} |
var result = _propertyName(name); |