问题
I need to do mapper between dart and JS object. I don't like to write "unncessary' code so I would like DartEditor wrote it for me :)
What i would like to write:
DartInvoice extends jsw.TypedProxy {
@Parser(attributName="invoice")
String number;
@Parser(attributName=amount)
Number sum;
}
What i would like to achieve:
DartInvoice extends jsw.TypedProxy {
set number(String number) => toJs.set('invoice' : number);
String number => toJs.get(invoice);
set sum(Number sum) => toJs.set('amount' : sum);
Number get sum => toJs.get(amount);
}
The question is :) how dart or dart editor can help me? Tell me what i should read. :)
回答1:
I started the js_wrapping_generator project to do something like that but its not quite ready for prime time. I used the analyzer package to parse dart files an generate other files.
You can have a look at dart_generator.dart to have a sample.
The current version is based on a simple AST and I'm working on a new version based on a resolved AST to simplify templating even more.
来源:https://stackoverflow.com/questions/19991745/code-generator-for-dart