Skip to content

Commit aaf7d25

Browse files
authored
Merge pull request #214 from f22217/master
Add support for Javascript template literals
2 parents a601718 + 1152e95 commit aaf7d25

14 files changed

Lines changed: 117 additions & 27 deletions

src/Utils/JsFunctionsScanner.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ public function getFunctions(array $constants = [])
4949
break 2;
5050
}
5151
break;
52+
53+
case 'back-tick':
54+
if ($next !== '`') {
55+
break 2;
56+
}
57+
break;
5258
}
5359

5460
$prev = $char;
@@ -69,6 +75,7 @@ public function getFunctions(array $constants = [])
6975
switch ($this->status()) {
7076
case 'simple-quote':
7177
case 'double-quote':
78+
case 'back-tick':
7279
case 'line-comment':
7380
break;
7481

@@ -97,6 +104,7 @@ public function getFunctions(array $constants = [])
97104
case 'line-comment':
98105
case 'block-comment':
99106
case 'double-quote':
107+
case 'back-tick':
100108
break;
101109

102110
default:
@@ -114,6 +122,7 @@ public function getFunctions(array $constants = [])
114122
case 'line-comment':
115123
case 'block-comment':
116124
case 'simple-quote':
125+
case 'back-tick':
117126
break;
118127

119128
default:
@@ -122,13 +131,31 @@ public function getFunctions(array $constants = [])
122131
}
123132
break;
124133

134+
case '`':
135+
switch ($this->status()) {
136+
case 'back-tick':
137+
$this->upStatus();
138+
break;
139+
140+
case 'line-comment':
141+
case 'block-comment':
142+
case 'simple-quote':
143+
case 'double-quote':
144+
break;
145+
146+
default:
147+
$this->downStatus('back-tick');
148+
break;
149+
}
150+
break;
151+
125152
case '(':
126153
switch ($this->status()) {
127154
case 'simple-quote':
128155
case 'double-quote':
156+
case 'back-tick':
129157
case 'line-comment':
130158
case 'block-comment':
131-
case 'line-comment':
132159
break;
133160

134161
default:
@@ -176,6 +203,7 @@ public function getFunctions(array $constants = [])
176203
switch ($this->status()) {
177204
case 'double-quote':
178205
case 'simple-quote':
206+
case 'back-tick':
179207
break;
180208

181209
default:
@@ -246,7 +274,7 @@ protected function upStatus()
246274
*/
247275
protected static function prepareArgument($argument)
248276
{
249-
if ($argument && ($argument[0] === '"' || $argument[0] === "'")) {
277+
if ($argument && in_array($argument[0], ['"', "'", '`'], true)) {
250278
return static::convertString(substr($argument, 1, -1));
251279
}
252280
}

tests/AssetsTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ public function testVueJs()
422422
{
423423
$translations = static::get('vuejs/input', 'VueJs');
424424

425-
$countTranslations = 32;
425+
$countTranslations = 34;
426426
$countTranslated = 0;
427427
$countHeaders = 8;
428428

@@ -501,4 +501,4 @@ public function testPhpCode4()
501501
$this->runTestFormat('phpcode4/YamlDictionary', $countTranslations, $countTranslated);
502502
}
503503

504-
}
504+
}

tests/assets/vuejs/Csv.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ some-context,js-action,
2121
,t-singular2,
2222
,t-v-bind,
2323
context,t-action,
24+
,back-tick-in-tag,
2425
,t-v-text,
2526
,t-text,
2627
,t-singular,
@@ -36,6 +37,7 @@ context,t-action,
3637
,t-spaces-expr2,
3738
,t-p1(parentheses),
3839
context2,t-action2,
40+
,back-tick-in-mustache,
3941
,t-tag-2,
4042
,v-translate-attribute,
4143
,v-translate-attribute-single,

tests/assets/vuejs/CsvDictionary.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ multi-occurrence,
1212
t-singular2,
1313
t-v-bind,
1414
t-action,
15+
back-tick-in-tag,
1516
t-v-text,
1617
t-text,
1718
t-singular,
@@ -27,6 +28,7 @@ t-spaces-expr,
2728
t-spaces-expr2,
2829
t-p1(parentheses),
2930
t-action2,
31+
back-tick-in-mustache,
3032
t-tag-2,
3133
v-translate-attribute,
3234
v-translate-attribute-single,

tests/assets/vuejs/Jed.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
"context\\u0004t-action": [
4848
""
4949
],
50+
"back-tick-in-tag": [
51+
""
52+
],
5053
"t-v-text": [
5154
""
5255
],
@@ -92,6 +95,9 @@
9295
"context2\\u0004t-action2": [
9396
""
9497
],
98+
"back-tick-in-mustache": [
99+
""
100+
],
95101
"t-tag-2": [
96102
""
97103
],

tests/assets/vuejs/Json

Whitespace-only changes.

tests/assets/vuejs/Json.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
"t-v-bind": [
4343
""
4444
],
45+
"back-tick-in-tag": [
46+
""
47+
],
4548
"t-v-text": [
4649
""
4750
],
@@ -84,6 +87,9 @@
8487
"t-p1(parentheses)": [
8588
""
8689
],
90+
"back-tick-in-mustache": [
91+
""
92+
],
8793
"t-tag-2": [
8894
""
8995
],

tests/assets/vuejs/JsonDictionary.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"t-singular2": "",
1414
"t-v-bind": "",
1515
"t-action": "",
16+
"back-tick-in-tag": "",
1617
"t-v-text": "",
1718
"t-text": "",
1819
"t-singular": "",
@@ -28,6 +29,7 @@
2829
"t-spaces-expr2": "",
2930
"t-p1(parentheses)": "",
3031
"t-action2": "",
32+
"back-tick-in-mustache": "",
3133
"t-tag-2": "",
3234
"v-translate-attribute": "",
3335
"v-translate-attribute-single": ""

tests/assets/vuejs/PhpArray.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@
6565
array (
6666
0 => '',
6767
),
68+
'back-tick-in-tag' =>
69+
array (
70+
0 => '',
71+
),
6872
't-v-text' =>
6973
array (
7074
0 => '',
@@ -121,6 +125,10 @@
121125
array (
122126
0 => '',
123127
),
128+
'back-tick-in-mustache' =>
129+
array (
130+
0 => '',
131+
),
124132
't-tag-2' =>
125133
array (
126134
0 => '',

tests/assets/vuejs/Po.po

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,34 @@ msgstr ""
99
"Project-Id-Version: \n"
1010
"Report-Msgid-Bugs-To: \n"
1111

12-
#: ./tests/assets/vuejs/input.vue:51
12+
#: ./tests/assets/vuejs/input.vue:55
1313
msgid "js-expr1"
1414
msgstr ""
1515

16-
#: ./tests/assets/vuejs/input.vue:51
16+
#: ./tests/assets/vuejs/input.vue:55
1717
msgid "js-expr2"
1818
msgstr ""
1919

20-
#: ./tests/assets/vuejs/input.vue:53
20+
#: ./tests/assets/vuejs/input.vue:57
2121
msgid "js-alert"
2222
msgstr ""
2323

24-
#: ./tests/assets/vuejs/input.vue:56
24+
#: ./tests/assets/vuejs/input.vue:60
2525
msgid "js-single"
2626
msgid_plural "js-plural"
2727
msgstr[0] ""
2828

29-
#: ./tests/assets/vuejs/input.vue:60
29+
#: ./tests/assets/vuejs/input.vue:64
3030
msgid "js-obj-single"
3131
msgid_plural "js-obj-plural"
3232
msgstr[0] ""
3333

34-
#: ./tests/assets/vuejs/input.vue:63
34+
#: ./tests/assets/vuejs/input.vue:67
3535
msgctxt "some-context"
3636
msgid "js-action"
3737
msgstr ""
3838

39-
#: ./tests/assets/vuejs/input.vue:65
39+
#: ./tests/assets/vuejs/input.vue:69
4040
msgid "<span>js-return</span><br>"
4141
msgstr ""
4242

@@ -73,7 +73,11 @@ msgctxt "context"
7373
msgid "t-action"
7474
msgstr ""
7575

76-
#: ./tests/assets/vuejs/input.vue:43
76+
#: ./tests/assets/vuejs/input.vue:37
77+
msgid "back-tick-in-tag"
78+
msgstr ""
79+
80+
#: ./tests/assets/vuejs/input.vue:47
7781
msgid "t-v-text"
7882
msgstr ""
7983

@@ -136,15 +140,19 @@ msgctxt "context2"
136140
msgid "t-action2"
137141
msgstr ""
138142

139-
#: ./tests/assets/vuejs/input.vue:37
143+
#: ./tests/assets/vuejs/input.vue:38
144+
msgid "back-tick-in-mustache"
145+
msgstr ""
146+
147+
#: ./tests/assets/vuejs/input.vue:41
140148
msgid "t-tag-2"
141149
msgstr ""
142150

143-
#: ./tests/assets/vuejs/input.vue:39
151+
#: ./tests/assets/vuejs/input.vue:43
144152
msgid "v-translate-attribute"
145153
msgstr ""
146154

147-
#: ./tests/assets/vuejs/input.vue:41
155+
#: ./tests/assets/vuejs/input.vue:45
148156
msgid "v-translate-attribute-single"
149157
msgid_plural "v-translate-attribute-plural"
150158
msgstr[0] ""

0 commit comments

Comments
 (0)