Skip to content

Commit e8f338d

Browse files
committed
Switch javascript string style
1 parent df58397 commit e8f338d

File tree

5 files changed

+34
-0
lines changed

5 files changed

+34
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ definitions with their patterns and replacements, look at the file
477477
Object* foo = bar.baz;
478478
Object* foo = bar->baz;
479479
```
480+
480481
### JavaScript
481482

482483
* Function definitions:
@@ -502,6 +503,13 @@ Object* foo = bar->baz;
502503
```
503504
Switching to var from const or let is unsupported, since it's assumed to be an unlikely case.
504505

506+
* String styles:
507+
```javascript
508+
const foo = "${bar}/baz"
509+
const foo = `${bar}/baz`
510+
const foo = '${bar}/baz'
511+
```
512+
505513
### CoffeeScript arrows
506514

507515
``` coffeescript

doc/switch.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,13 @@ ES6-style variable declaraions (g:switch_builtins.javascript_es6_declarations)
652652
<
653653
Switching to var from const or let is unsupported, since it's assumed to be an unlikely case.
654654

655+
String styles (g:switch_builtings.javascript_string_style)
656+
>
657+
const foo = "${bar}/baz"
658+
const foo = `${bar}/baz`
659+
const foo = '${bar}/baz'
660+
<
661+
655662
Coffeescript ~
656663

657664
Arrows (g:switch_builtins.coffee_arrow):

ftplugin/javascript/switch.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ let b:switch_definitions =
77
\ g:switch_builtins.javascript_function,
88
\ g:switch_builtins.javascript_arrow_function,
99
\ g:switch_builtins.javascript_es6_declarations,
10+
\ g:switch_builtins.javascript_string_style,
1011
\ ]

plugin/switch.vim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ let g:switch_builtins =
146146
\ '\<let\s\+': 'const ',
147147
\ '\<const\s\+': 'let ',
148148
\ },
149+
\ 'javascript_string_style': {
150+
\ '`\(\%([^"\\]\|\\.\)*\)`': '''\1''',
151+
\ '''\(\%([^''\\]\|\\.\)*\)''': '"\1"',
152+
\ '"\(\%([^"\\]\|\\.\)*\)"': '`\1`',
153+
\ },
149154
\ 'coffee_arrow': {
150155
\ '^\(.*\)->': '\1=>',
151156
\ '^\(.*\)=>': '\1->',

spec/plugin/javascript_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,17 @@
104104
something.forEach(function(one) { });
105105
EOF
106106
end
107+
108+
specify "string type" do
109+
set_file_contents 'const foo = "bar?"'
110+
111+
vim.search('bar').switch
112+
assert_file_contents 'const foo = `bar?`'
113+
114+
vim.switch
115+
assert_file_contents "const foo = 'bar?'"
116+
117+
vim.switch
118+
assert_file_contents 'const foo = "bar?"'
119+
end
107120
end

0 commit comments

Comments
 (0)