Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,15 @@ Object* foo = bar->baz;
```
Switching to var from const or let is unsupported, since it's assumed to be an unlikely case.

* Comparison to false vs negation operator
``` javascript
if (foo == false) { }
if (!foo) {}

if (foo.has(bar) === false) {}
if (!foo.has(bar)) {}
```

### Coffeescript arrows

``` coffeescript
Expand Down
9 changes: 9 additions & 0 deletions doc/switch.txt
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,15 @@ ES6-style variable declaraions (g:switch_builtins.javascript_es6_declarations)
<
Switching to var from const or let is unsupported, since it's assumed to be an unlikely case.

Comparison to false vs negation operator (g:switch_builtins.javascript_not_expression)
>
if (foo == false) { }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the regex, I think this should be a ===.

if (!foo) {}

if (foo.has(bar) === false) {}
if (!foo.has(bar)) {}
<

Coffeescript ~

Arrows (g:switch_builtins.coffee_arrow):
Expand Down
5 changes: 5 additions & 0 deletions plugin/switch.vim
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ let g:switch_builtins =
\ '\<let\s\+': 'const ',
\ '\<const\s\+': 'let ',
\ },
\ 'javascript_not_expression': {
\ '\<\([a-zA-z.()]\+\) === false': '!\1',
\ '!\<\([a-zA-z.()]\+\)': '\1 === false',
\ },
\ 'coffee_arrow': {
\ '^\(.*\)->': '\1=>',
\ '^\(.*\)=>': '\1->',
Expand Down Expand Up @@ -205,6 +209,7 @@ autocmd FileType javascript let b:switch_definitions =
\ g:switch_builtins.javascript_function,
\ g:switch_builtins.javascript_arrow_function,
\ g:switch_builtins.javascript_es6_declarations,
\ g:switch_builtins.javascript_not_expression,
\ ]

autocmd FileType coffee let b:switch_definitions =
Expand Down