* 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) {
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*';
* @return string
*/
public static function stripComments($script) {
- return preg_replace(":^\\s*//[^\n]+$:m", "", $script);
+ return preg_replace("#^\\s*//[^\n]*$(?:\r\n|\n)?#m", "", $script);
}
/**
*
* @param string $js
* @return mixed
+ * @throws Exception
*/
public static function decode($js) {
$js = trim($js);
*
* @param $js
* @return array
- * @throws \Exception
+ * @throws Exception
*/
public static function getRawProps($js) {
$js = trim($js);