Loading ...
Sorry, an error occurred while loading the content.

3040Re: return statement flagged as syntax error

Expand Messages
  • octavpo
    Oct 3, 2012
    • 0 Attachment
      That doesn't really address my issue. If the 'Expected' messages could be considered advice, the "Unreachable '=' after 'return'" message is clearly wrong, as the assignment is very reachable. Besides, why does the advice go away when I put the assignment in parentheses? I don't think that makes it better style. Moreover JSLint stops checking my code right after that line, while if I add parentheses it checks all the way to the end. So it really looks like a bug.

      --- In jslint_com@yahoogroups.com, "douglascrockford" <douglas@...> wrote:
      >
      > --- In jslint_com@yahoogroups.com, "octavpo" <octav@> wrote:
      >
      > > I have a statement in one of my functions:
      > >
      > > return serverInstanceId = response;
      > >
      > > JSLint flags it as:
      > >
      > > Expected ';' and instead saw '='.
      > > Unreachable '=' after 'return'.
      > > Expected '=' at column 9, not column 33.
      > > Expected an identifier and instead saw '='.
      > >
      > > It seems it doesn't accept assignments inside return expressions. However assignments are expressions in JS, so this should be a valid statement. I would agree this might be considered bad style, and it could be flagged as such, but that's another matter. The messages indicate it just doesn't accept it as valid syntax. However if I put the assignment in () the messages are gone. So it seems to me this is a bug in JSLint's grammar.
      >
      >
      > I recommend that you follow JSLint's advice and fix the code that you would agree is bad.
      >
    • Show all 10 messages in this topic