Wednesday, August 22, 2012

Easy regex to update to new getter syntax

Posted by Seth Ladd

Just spotted this gem from the Dart mailing list. Community member Kevin Moore offers this bit of advice for handling the syntax change for getters:


This saved me a lot of code spelunking, so I wanted to share.

Find: (get\s+[_a-zA-Z0-9]+)(\(\))(\s+(=>|\{))
Replace: $1$3

Make sure you have regex search on.
Works great in Sublime. I think the same syntax works in Textmate and likely other editors.

Nice results:

With this tip, you'll change (old code):

TInput get input() => _input;

to (new code):

TInput get input => _input;

As of 11156 the VM runs the new syntax and dart2js warns if you're NOT using it. So now is a good time to update.

Thanks Kevin!