redstone-dart / redstone

A metadata driven microframework for Dart.
http://redstone-dart.github.io/redstone
MIT License
342 stars 42 forks source link

Transformer problem with async/await #58

Closed RobertBlackhart closed 9 years ago

RobertBlackhart commented 9 years ago

There appears to be an issue when using the client-side transformer and the main() method is declared as async. This is the (minimal) source code needed to produce a problem:

import 'package:redstone_mapper/mapper_factory.dart';

main() async
{
    bootstrapMapper();
}

And it produces this stack trace:

Exception: Uncaught Error: No top-level method 'bootstrapMapper' declared.

NoSuchMethodError: method not found: 'bootstrapMapper'
Receiver: top-level
Arguments: [...]
Stack Trace:
#0      NoSuchMethodError._throwNew (dart:core-patch/errors_patch.dart:173)
#1      main.<main_async_body> (http://localhost:8080/main.dart:7:2)
#2      Future.Future.<anonymous closure> (dart:async/future.dart:118)
#3      Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:12)
#4      _Timer._Timer.<anonymous closure> (dart:html:41761)

Removing the redstone_mapper from the transformers section of the pubspec.yaml file also removes this problem. I took a quick look at what the transformer was trying to do to see if there was something I could quickly fix, but I'm not smart enough to know how. Hopefully given this information a fix wouldn't be too hard for you to implement.

luizmineo commented 9 years ago

Thanks for reporting this! I'll take a look and let you know.

luizmineo commented 9 years ago

It seems that the analyzer and code_transformers packages aren't playing nice with async/await yet, but for now it's possible to use the async_await transformer to solve this issue. Just include it in your pubspec.yaml:

dependencies:
  redstone_mapper: any
  async_await:
    git: git@github.com:dart-lang/async_await.git
transformers:
- async_await
- redstone_mapper

Also, you need to include an import to the dart:async library, in every library that uses async/await:

import 'dart:async';

Let me know if that helps

RobertBlackhart commented 9 years ago

Thanks for the mention. I did run across that package when compiling my code to js but didn't think to use it to fix the non compiled problem as well.

That does solve the problem, thanks.

On Wed, Dec 24, 2014, 2:57 PM Luiz Henrique Farcic Mineo < notifications@github.com> wrote:

It seems that the analyzer and code_transformers packages aren't playing nice with async/await yet, but for now it's possible to use the async_await transformer to solve this issue. Just include it in your pubspec.yaml:

dependencies: async_await: git: git@github.com:dart-lang/async_await.gittransformers:- async_await- redstone_mapper

Also, you need to include an import to the dart:async library, to every library that uses async/await:

import 'dart:async';

Let me know if that helps

— Reply to this email directly or view it on GitHub https://github.com/luizmineo/redstone.dart/issues/58#issuecomment-68071907 .

luizmineo commented 9 years ago

Cool! I'm closing this issue for now, but let me know if you find any other problem.