Hi Yegor,
This is about the --output-type=dart option, right? We often call
that "dart2dart". It would be great if you could report these bugs,
but dart2dart is on the back-burner right now, so you'll have to be
patient. Sorry.
Cheers,
Peter
On Wed, Jun 26, 2013 at 7:41 PM, Yegor Jbanov <
yjb...@google.com> wrote:
> Thanks, Peter. I think I can live without it in the short term, at least
> until we get to some complicated scenarios. I ran some experiments and found
> behavior that I think should be fixed.
>
> Unused fields are not tree-shaken off, sensitive to type annotations
>
> INPUT:
>
> main() {
> print(new Foo().hello);
> }
>
> class Bar {
> String txt = " World";
> }
>
> class Foo {
> String _hello;
> Bar _world; // never initialized
> String get hello {
> if (_hello == null) {
> _hello = "Hello";
> }
> return _hello;
> }
> String get world {
> if (_world == null) {
> _world = new Bar();
> }
> return _world.txt;
> }
> }
>
> OUTPUT (reformatted):
>
> main(){
> print(new Foo().hello);
> }
>
> class Bar{} // Expected Bar to be gone.
> // However, it will be gone if I change type of _world to
> "var".
> // Nice to see txt tree-shaken off.
>
> class Foo{
> String _hello; // Used, so it stays.
> Bar _world; // Not used, expected to be gone
> String get hello{
> if(_hello==null) {
> _hello="Hello";
> }
> return _hello;
> }
> }
>
> Impact on our app: auto-generated code (e.g.
>
https://github.com/google/streamy-dart). We are generating code from a
> number of API discovery documents and that produces a lot of code. We'd like
> to rely on the tree shaker to only pull in code that is actually used. We
> would also like to keep type annotations for code completion (otherwise the
> code generator doesn't add much value).
>
> Zero-effect code not tree-shaken off
>
> INPUT:
>
> main() {
> new Foo(); // Has no effect
> }
>
> class Foo {}
>
> OUTPUT (reformatted):
>
> main(){
> new Foo();
> }
>
> class Foo{}
>
> Impact on our app: again it's mostly auto-generated code. In it we define
> lots of fields, some of which are initialized. However, if a field is not
> used, its initialization is a noop and should be shaken off.
>
> Let me know if any of this makes sense. I'll file bugs.
>
> Thanks,
>
> Yegor