Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1603)

Unified Diff: lib/src/compiler/code_generator.dart

Issue 1949733002: fix #543, export of properties should now work (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/runtime/dart_sdk.js ('k') | test/codegen/expect/unittest.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/compiler/code_generator.dart
diff --git a/lib/src/compiler/code_generator.dart b/lib/src/compiler/code_generator.dart
index 1276c85eaeaeed3e9b6f4a7bbe8d4cff67e002fc..5ead352115b82325576bf32ee045bd4f854c9bc8 100644
--- a/lib/src/compiler/code_generator.dart
+++ b/lib/src/compiler/code_generator.dart
@@ -91,6 +91,8 @@ class CodeGenerator extends GeneralizingAstVisitor
final _hasDeferredSupertype = new HashSet<ClassElement>();
+ final _eagerTopLevelFields = new HashSet<Element>.identity();
+
/// The type provider from the current Analysis [context].
final TypeProvider types;
@@ -380,15 +382,34 @@ class CodeGenerator extends GeneralizingAstVisitor
var exportedNames =
new NamespaceBuilder().createExportNamespaceForDirective(element);
+ var libraryName = emitLibraryName(currentLibrary);
+
// TODO(jmesserly): we could collect all of the names for bulk re-export,
// but this is easier to implement for now.
void emitExport(Element export, {String suffix: ''}) {
var name = _emitTopLevelName(export, suffix: suffix);
- _moduleItems.add(js.statement(
- '#.# = #;', [emitLibraryName(currentLibrary), name.selector, name]));
+
+ if (export is TypeDefiningElement || export is FunctionElement ||
+ _eagerTopLevelFields.contains(export)) {
+ // classes, typedefs, functions, and eager init fields can be assigned
+ // directly.
+ // TODO(jmesserly): we don't know about eager init fields from other
+ // modules we import, so we will never go down this code path for them.
+ _moduleItems
+ .add(js.statement('#.# = #;', [libraryName, name.selector, name]));
+ } else {
+ // top-level fields, getters, setters need to copy the property
+ // descriptor.
+ _moduleItems.add(js.statement('dart.export(#, #, #);',
+ [libraryName, name.receiver, name.selector]));
+ }
}
for (var export in exportedNames.definedNames.values) {
+ if (export is PropertyAccessorElement) {
+ export = (export as PropertyAccessorElement).variable;
+ }
+
// Don't allow redefining names from this library.
if (currentNames.containsKey(export.name)) continue;
@@ -2770,6 +2791,10 @@ class CodeGenerator extends GeneralizingAstVisitor
// TODO(jmesserly): we don't track dependencies correctly for these.
var isJSTopLevel = field.isFinal && _isFinalJSDecl(field);
if (eagerInit || isJSTopLevel) {
+ // Remember that we emitted it this way, so re-export can take advantage
+ // of this fact.
+ _eagerTopLevelFields.add(element);
+
return annotate(
js.statement('# = #;', [_emitTopLevelName(element), jsInit]),
field,
« no previous file with comments | « lib/runtime/dart_sdk.js ('k') | test/codegen/expect/unittest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698