@@ -92,6 +92,7 @@ class LightnCandy {
92
92
// RegExps
93
93
const VARNAME_SEARCH = '/( \\[[^ \\]]+ \\]|[^ \\[ \\] \\.]+)/ ' ;
94
94
const EXTENDED_COMMENT_SEARCH = '/{{!--.*?--}}/s ' ;
95
+ const IS_SUBEXP_SEARCH = '/^\(.+\)$/ ' ;
95
96
96
97
// Positions of matched token
97
98
const POS_LOTHER = 1 ;
@@ -506,7 +507,7 @@ protected static function readPartial($name, &$context) {
506
507
return static ::compilePartial ($ name , $ context , $ cnt );
507
508
}
508
509
509
- if (preg_match (' /^\(.+\)$/ ' , $ name )) {
510
+ if (preg_match (static :: IS_SUBEXP_SEARCH , $ name )) {
510
511
if ($ context ['flags ' ]['runpart ' ]) {
511
512
$ context ['usedFeature ' ]['dynpartial ' ]++;
512
513
return ;
@@ -991,7 +992,7 @@ protected static function compileSubExpression($subExpression, &$context) {
991
992
* @return array<string> variable names
992
993
*/
993
994
protected static function getVariableNameOrSubExpression ($ var , &$ context , $ ishelper = false ) {
994
- if (isset ($ var [0 ]) && preg_match (' /^\(.+\)$/ ' , $ var [0 ])) {
995
+ if (isset ($ var [0 ]) && preg_match (static :: IS_SUBEXP_SEARCH , $ var [0 ])) {
995
996
return static ::compileSubExpression ($ var [0 ], $ context );
996
997
}
997
998
return static ::getVariableName ($ var , $ context , $ ishelper );
@@ -1706,7 +1707,7 @@ protected static function compileSection(&$token, &$context, &$vars, $named) {
1706
1707
switch ($ token [self ::POS_OP ]) {
1707
1708
case '> ' :
1708
1709
// mustache spec: ignore missing partial
1709
- if (!isset ($ context ['usedPartial ' ][$ vars [0 ][0 ]])) {
1710
+ if (( $ context [ ' usedFeature ' ][ ' dynpartial ' ] === 0 ) && !isset ($ context ['usedPartial ' ][$ vars [0 ][0 ]])) {
1710
1711
return $ context ['ops ' ]['seperator ' ];
1711
1712
}
1712
1713
$ p = array_shift ($ vars );
@@ -1716,8 +1717,13 @@ protected static function compileSection(&$token, &$context, &$vars, $named) {
1716
1717
$ v = static ::getVariableNames ($ vars , $ context , true );
1717
1718
$ tag = "> $ p [0 ] " .implode (' ' , $ v [1 ]);
1718
1719
if ($ context ['flags ' ]['runpart ' ]) {
1720
+ if (preg_match (static ::IS_SUBEXP_SEARCH , $ p [0 ])) {
1721
+ $ p = static ::compileSubExpression ($ p [0 ], $ context )[0 ];
1722
+ } else {
1723
+ $ p = "' $ p [0 ]' " ;
1724
+ }
1719
1725
$ sp = $ context ['tokens ' ]['partialind ' ] ? ", ' {$ context ['tokens ' ]['partialind ' ]}' " : '' ;
1720
- return $ context ['ops ' ]['seperator ' ] . static ::getFuncName ($ context , 'p ' , $ tag ) . "\$cx, ' $ p [ 0 ] ' , $ v [0 ]$ sp) {$ context ['ops ' ]['seperator ' ]}" ;
1726
+ return $ context ['ops ' ]['seperator ' ] . static ::getFuncName ($ context , 'p ' , $ tag ) . "\$cx, $ p , $ v [0 ]$ sp) {$ context ['ops ' ]['seperator ' ]}" ;
1721
1727
} else {
1722
1728
if ($ named || $ v [0 ] !== 'array(array($in),array()) ' ) {
1723
1729
$ context ['error ' ][] = "Do not support {{ {$ tag }}}, you should do compile with LightnCandy::FLAG_RUNTIMEPARTIAL flag " ;
0 commit comments