Index: lib/src/codegen/js_codegen.dart |
diff --git a/lib/src/codegen/js_codegen.dart b/lib/src/codegen/js_codegen.dart |
index 36e1f829f9faea7db0d69c705eb92a89378fcfbd..1cc53aba4e8aed2659ed6a7b9dcdffe931e21861 100644 |
--- a/lib/src/codegen/js_codegen.dart |
+++ b/lib/src/codegen/js_codegen.dart |
@@ -86,6 +86,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ClosureAnnotator { |
final _moduleItems = <JS.Statement>[]; |
final _temps = new HashMap<Element, JS.TemporaryId>(); |
final _qualifiedIds = new List<Tuple2<Element, JS.MaybeQualifiedId>>(); |
+ final _topLevelExtensionNames = new Set<String>(); |
/// The name for the library's exports inside itself. |
/// `exports` was chosen as the most similar to ES module patterns. |
@@ -159,6 +160,10 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ClosureAnnotator { |
// Flush any unwritten fields/properties. |
_flushLibraryProperties(_moduleItems); |
+ if (_topLevelExtensionNames.isNotEmpty) { |
Jennifer Messerly
2016/02/02 00:22:56
I don't think this should be needed at the top-lev
ochafik
2016/02/03 19:58:49
Great point! Leaving todo for follow up refactorin
|
+ _moduleItems.add(_emitExtensionNamesDeclaration( |
+ _topLevelExtensionNames.map(js.string).toList())); |
+ } |
// Mark all qualified names as qualified or not, depending on if they need |
// to be loaded lazily or not. |
@@ -658,6 +663,13 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ClosureAnnotator { |
} |
} |
+ JS.Statement _emitExtensionNamesDeclaration(List<JS.Expression> names) => |
+ js.statement('dart.defineExtensionNames(#)', |
+ [new JS.ArrayInitializer(names.toList(), multiline: true)]); |
+ |
+ JS.Expression _emitExtensionName(String name) => |
+ js.call('dartx.#', _propertyName(name)); |
+ |
/// Emit class members that need to come after the class declaration, such |
/// as static fields. See [_emitClassMethods] for things that are emitted |
/// inside the ES6 `class { ... }` node. |
@@ -681,8 +693,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ClosureAnnotator { |
} |
} |
if (dartxNames.isNotEmpty) { |
- body.add(js.statement('dart.defineExtensionNames(#)', |
- [new JS.ArrayInitializer(dartxNames, multiline: true)])); |
+ body.add(_emitExtensionNamesDeclaration(dartxNames)); |
} |
} |
@@ -3391,8 +3402,19 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ClosureAnnotator { |
bool unary: false, |
bool isStatic: false, |
bool allowExtensions: true}) { |
- // Static members skip the rename steps. |
- if (isStatic) return _propertyName(name); |
+ // Static members skip the rename steps, except for Function properties. |
+ if (isStatic) { |
+ if (options.closure) { |
+ // Avoid colliding with Function properties, which might be desirable |
+ // in general but is critical to work around a Closure ES6->ES5 bug |
+ // (https://github.com/google/closure-compiler/issues/1460). |
+ if (invalidStaticFieldName(name, closureCompiler: true)) { |
Jennifer Messerly
2016/01/28 20:03:36
I still don't understand why were are using extens
Jennifer Messerly
2016/02/02 00:22:56
We chatted about this, decided extension method sy
ochafik
2016/02/03 19:58:49
Done.
ochafik
2016/02/03 19:58:49
Acknowledged.
|
+ _topLevelExtensionNames.add(name); |
+ return _emitExtensionName(name); |
+ } |
+ } |
+ return _propertyName(name); |
+ } |
if (name.startsWith('_')) { |
return _privateNames.putIfAbsent( |
@@ -3419,7 +3441,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ClosureAnnotator { |
if (allowExtensions && |
_extensionTypes.contains(baseType.element) && |
!_isObjectProperty(name)) { |
- return js.call('dartx.#', _propertyName(name)); |
+ return _emitExtensionName(name); |
} |
return _propertyName(name); |