This project is read-only.

I would like to "tamper" the AST from typescript at compile time.

Topics: General
Oct 3, 2012 at 10:09 AM

For example i have my own implementation of multicast "delegates'" and i would love to be able to write


   obj.MyEvent += subscriber.handler;


and to generate actually:

   obj.MyEvent.add(new Delegate(subscriber, subscriber.handler));


Please don't comment the saneness of the events approach, just the principle of the question.

i would like a moment where the "type information" for the nodes in AST is available...

Is there a recommended way to do this?

Oct 3, 2012 at 4:35 PM
Edited Oct 3, 2012 at 4:37 PM


I managed to modify tsc.js to obtain something like this, tampering "BinaryExpression.emit".

The hack is usable only if i declare obj.MyEvent : any...

I must change also BinaryExpression.typeCheck to fit my needs...

Oct 5, 2012 at 4:56 PM

TypeScript doesn't currently allow you to overload operators like '+='.  The only thing that comes to mind here would be to do some kind of pre-processing magic (that was type-aware?).