Coffeescript SyntaxError:意外的LOGIC

时间:2014-04-09 14:12:48

标签: coffeescript

我刚刚在Atom上设置了coffeelint。我得到了很多像这样的警告:

if HelpersValidators.isNotEmpty(email) and HelpersValidators.isNotEmpty(password) and HelpersValidators.isEmail(email) and HelpersValidators.areValidPasswords(password, passwordConfirm)
   ...

=> Line exceeds maximum allowed length

所以我做的是:

if HelpersValidators.isNotEmpty(email)
  and HelpersValidators.isNotEmpty(password)
  and HelpersValidators.isEmail(email)
  and HelpersValidators.areValidPasswords(password, passwordConfirm)

但是现在,我收到以下错误,我无法解决它。

=> SyntaxError: unexpected LOGIC

那么如何构建这个条件使它出现在几行上呢?

1 个答案:

答案 0 :(得分:1)

你不能在CoffeeScript中使用逻辑运算符开始换行,所以你应该在and运算符之后折叠行,而不是在它之前:

if HelpersValidators.isNotEmpty(email) and
   HelpersValidators.isNotEmpty(password) and
   HelpersValidators.isEmail(email) and
   HelpersValidators.areValidPasswords(password, passwordConfirm)
  // do something

if HelpersValidators.isNotEmpty(email) and
  HelpersValidators.isNotEmpty(password) and
  HelpersValidators.isEmail(email) and
  HelpersValidators.areValidPasswords(password, passwordConfirm)
    // do something