othree / yajs.vim

YAJS.vim: Yet Another JavaScript Syntax for Vim
http://www.vim.org/scripts/script.php?script_id=4974
Vim License
688 stars 41 forks source link

Switch Statement + case + Expression + Block syntax = Bad Highlight #104

Closed timoxley closed 8 years ago

timoxley commented 8 years ago

Syntax highlight is broken if anything other than a variable is used in a case statement:

image

It appears that the RHS of a case can be any JS expression:

image

For now, if yajs only supported the first case in the example I think you'd be covering most of your bases… it's the only other case pattern I have in my codebase and IMO the other forms are likely to be much rarer.

switch (Animal) {
  case Ani.mal: {
    const thing = 'what'
    break
  }
}

switch (Animal) {
  case Animal(): {
    const thing = 'what'
    break
  }
}

switch (Animal) {
  case (Animal): {
    const thing = 'what'
    break
  }
}

Related to #103

othree commented 8 years ago

Of course it should accept all RHS expression. The problem is I can't make the following : be recognized if I just allow all RHS expression(or I will produce lots of duplicated code). Vim syntax system can't look forward~

othree commented 8 years ago

Finally figure out : is not an operator. So much easy to use region for this case.

timoxley commented 8 years ago

:dancer: Great stuff, works perfectly.