Skip to content

Commit 3a34c91

Browse files
author
Florian Videau
committed
fixed support for JavaScript template literals in JsfunctionsScanner
1 parent a601718 commit 3a34c91

1 file changed

Lines changed: 30 additions & 2 deletions

File tree

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
}

0 commit comments

Comments
 (0)