Search code examples
javascriptecmascript-2016

Should I put a semicolon after ES7 decorators?


Jetbrains Webstorm keeps showing "Unterminated statement" for the code below.

@connect(props)
class NavBar extends Component {...}

But the message vanishes as I put a semicolon right after the decorator. I was just wondering if I have to put a semicolon after the decorators.

@connect(props);
class NavBar extends Component {...}

Solution

  • No, you should not. According to the draft grammar, decorators are expressions that are part of a method or class definition. They are no statements, and must not end in semicolons.

    Imo, using semicolons there would visually separate the decorator from the decoratee, which looks odd - especially if not even the decorated value ends in a semicolon. Looks like WebStorm just doesn't understand decorator syntax yet.