Skip to main content

New site for Dart news and articles

For the latest Dart news, visit our new blog at  https://medium.com/dartlang .

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: https://github.com/kevmoo/dartlib/commit/3f2e3466091b71277967038cb686a5595639b5e5
"""

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!