2121class Compiler
2222{
2323 use DyiadeTrait;
24+ use InterpolationTrait;
2425
2526 /**
2627 * @const string
@@ -42,9 +43,15 @@ class Compiler
4243 */
4344 protected $ arrayShortSyntax ;
4445
45- public function __construct (JsPhpize $ engine )
46+ /**
47+ * @var string
48+ */
49+ protected $ filename ;
50+
51+ public function __construct (JsPhpize $ engine , $ filename = null )
4652 {
4753 $ this ->engine = $ engine ;
54+ $ this ->filename = $ filename ;
4855 $ this ->setPrefixes ($ engine ->getVarPrefix (), $ engine ->getConstPrefix ());
4956 $ this ->arrayShortSyntax = $ engine ->getOption ('arrayShortSyntax ' , false );
5057 }
@@ -138,12 +145,25 @@ function ($pair) use ($visitNode, $indent) {
138145 protected function visitConstant (Constant $ constant )
139146 {
140147 $ value = $ constant ->value ;
141- if ($ constant ->type === 'string ' && mb_substr ($ constant ->value , 0 , 1 ) === '" ' ) {
142- $ value = str_replace ('$ ' , '\\$ ' , $ value );
148+
149+ if ($ constant ->type === 'string ' ) {
150+ if (substr ($ value , 0 , 1 ) === '` ' ) {
151+ return implode (
152+ ' . ' ,
153+ iterator_to_array ($ this ->readInterpolation (substr ($ value , 1 , -1 )))
154+ );
155+ }
156+
157+ if (mb_substr ($ constant ->value , 0 , 1 ) === '" ' ) {
158+ return str_replace ('$ ' , '\\$ ' , $ value );
159+ }
143160 }
161+
144162 if ($ constant ->type === 'regexp ' ) {
145- $ regExp = $ this ->engine ->getHelperName ('regExp ' );
146- $ value = $ this ->helperWrap ($ regExp , [var_export ($ value , true )]);
163+ return $ this ->helperWrap (
164+ $ this ->engine ->getHelperName ('regExp ' ),
165+ [var_export ($ value , true )]
166+ );
147167 }
148168
149169 return $ value ;
@@ -217,6 +237,7 @@ protected function visitFunctionCall(FunctionCall $functionCall, $indent)
217237 $ staticCall = $ name . '( ' . $ arguments . ') ' ;
218238
219239 $ functions = str_replace (["\n" , "\t" , "\r" , ' ' ], '' , static ::STATIC_CALL_FUNCTIONS );
240+
220241 if ($ applicant === 'new ' || in_array ($ name , explode (', ' , $ functions ))) {
221242 return $ staticCall ;
222243 }
@@ -270,6 +291,7 @@ public function visitNode(Node $node, $indent)
270291 get_class ($ node )
271292 );
272293 $ php = method_exists ($ this , $ method ) ? $ this ->$ method ($ node , $ indent ) : '' ;
294+
273295 if ($ node instanceof Value) {
274296 $ php = $ node ->getBefore () . $ php . $ node ->getAfter ();
275297 }
0 commit comments