X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FUtils%2FJS.php;h=27e52d0d1ffb0c86acaaa11ecd4a949654563178;hb=f5dcb5a9424a1840698730ce717182df438a5f8f;hp=bcd80dd79967e5223b3518c738dc511554206d31;hpb=1d94337f066e139c2118ae6cd497d0a36b5087e1;p=civicrm-core.git diff --git a/CRM/Utils/JS.php b/CRM/Utils/JS.php index bcd80dd799..27e52d0d1f 100644 --- a/CRM/Utils/JS.php +++ b/CRM/Utils/JS.php @@ -54,13 +54,15 @@ class CRM_Utils_JS { * Note that you can only dedupe closures if they are directly adjacent and * have exactly the same parameters. * + * Also dedupes the "use strict" directive as it is only meaningful at the beginning of a closure. + * * @param array $scripts * Javascript source. * @param array $localVars * Ordered list of JS vars to identify the start of a closure. * @param array $inputVals * Ordered list of input values passed into the closure. - * @return string + * @return string[] * Javascript source. */ public static function dedupeClosures($scripts, $localVars, $inputVals) { @@ -70,7 +72,7 @@ class CRM_Utils_JS { return preg_quote($v, '/'); }, $localVars)); $opening .= '\)\s*\{'; - $opening = '/^' . $opening . '/'; + $opening = '/^' . $opening . '\s*(?:"use strict";\s|\'use strict\';\s)?/'; // Example closing: })(angular, CRM.$, CRM._); $closing = '\}\s*\)\s*\(\s*'; @@ -107,7 +109,7 @@ class CRM_Utils_JS { * @return string */ public static function stripComments($script) { - return preg_replace(":^\\s*//[^\n]+$:m", "", $script); + return preg_replace("#^\\s*//[^\n]*$(?:\r\n|\n)?#m", "", $script); } /** @@ -124,6 +126,7 @@ class CRM_Utils_JS { * * @param string $js * @return mixed + * @throws Exception */ public static function decode($js) { $js = trim($js); @@ -187,7 +190,7 @@ class CRM_Utils_JS { * * @param $js * @return array - * @throws \Exception + * @throws Exception */ public static function getRawProps($js) { $js = trim($js);