-
Notifications
You must be signed in to change notification settings - Fork 26
Qualified exports and inheritance for Closure #319
Conversation
3fe7460
to
45bf215
Compare
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project, in which case you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
45bf215
to
a8bc162
Compare
CLAs look good, thanks! |
@ochafik were you familiar with Why As an aside, I don't think there's any problem with One more high level comment: I may try and resurrect ES6 Module AST nodes. I had created some nodes for ES6 Module/ModuleItem/Import/Export. The idea is that js_codegen could emit these high level nodes, then we can lower them appropriately. That would give you an easy way to make tweaks to how the module layout looks in Closure. |
Hey John, thanks for the comments! Unfortunately Re/ Re/ modules, I've played with |
oh sorry... I didn't explain that well. I meant we could use that pattern for most things, regardless of closure or not-closure. Naturally we would avoid it for Object.
yeah agree it's more readable. Maybe we should do it always? Yeah, good point, we can keep it a temp. As long as it's okay w/ Closure if it gets renamed sometimes (e.g.
not sure I follow this. I don't think we can switch to goog.module, it seems to put us at odds with the rest of the JS ecosystem we're trying to interop with. Maybe you mean only for closure output? |
yeah definitely. I think you would only need to force it to qualify Object/Error/Symbol? I'm wondering if we could tackle this with something really simple ... like tweak |
went ahead and did it: https://codereview.chromium.org/1341963003/ |
Aside: it might be worth refactoring out a high level class node. Like ClassInfo/Builder. So we can represent concepts of a generic class and method signatures, without containing the policy of exactly how those get emitted. Ideally that could be in its own CL, so we can review the refactoring without any changes in output or new features. |
I'm about to look at super mixins, which might involve tweaking how classes are generated. Discussing with @leafpetersen ... it sounds like it would be good to merge this first, that way we won't cause merge conflicts. Plus the classbuilder refactor is really nice IMO and will likely help. Thanks @ochafik! we should definitely keep discussing the backend design (e.g. your design doc) but I think whatever we choose this pull req is a step in the right direction. |
Qualified exports and inheritance for Closure
doh, it looks like this may have broken Travis, possibly(?) due to the language tests we added in the meantime. I'm going to see if I can reproduce locally, hopefully it's easy to fix and doesn't need a rollback. |
the only failure seems to be language private2_test.dart:
it looks like we generate the |
Doh, I think this is a bit tricky to fix, at least for me... It appears the changes to _maybeQualifiedName regressed our support for lazy class definitions somewhat broadly. I'm not sure how to fix it in the new code, as the logic for name qualification is now rather complex (and appears to take into account whether the class is public or private, and whether the expression is a LiteralString, and whether it's a local type, which were not previously considered). Maybe we need to abstract name qualification totally ... that's what MaybeQualifiedId was supposed to be doing, but maybe it doesn't adequately address Closure's use case. Hopefully we can find a simpler way to force Closure to always qualify all public names (if that is the desired behavior). I may try and borrow some of the code here around class building, though. Apologies in advance for any merge headaches :| |
Hey guys, I know this is a big chunk of changes, sorry about that! (introducing properly qualified exports without doing some refactoring otherwise ended up in very unmaintainable code :-S).
This fixes two blockers for issue #312 (redefining
Object
class and other similar collisions with JS classes, and extending a non-qualifier class expression such asdart.mixin(...)
).Biggest changes in js_codegen.dart:
--closure
: declarations are now emitted by method_emitDecl
, which knows when to export things, andexports
is renamed to the lib's temp name (e.g.mylib.Foo = class Foo {}
instead ofclass Foo {}; exports.Foo = Foo
)._ClassBuilder
helper (accumulates body, statements & preludes, then gets composed to top-level statements / lazy wrappers in one go). This makes it easier to switch to fully-qualified names in all the statements that go with a class definition. Updated the lazy class logic accordingly.visitClassDeclaration
to make it (hopefully) easier to read with the new builder mechanismThis gives minor changes in generated code: shuffled symbols & JS iterator method moved to the end of classes (+ some exports.References are now local (fixed)).