This runs stripComments BEFORE dedupeClosures so that comments don't interfere with the deduping.
Also fixes stripComments to remove the line break as well as the comment line.
* @return string
*/
public static function stripComments($script) {
- return preg_replace(":^\\s*//[^\n]+$:m", "", $script);
+ return preg_replace("#^\\s*//[^\n]*$(?:\r\n|\n)?#m", "", $script);
}
/**
public function digestJs($files) {
$scripts = [];
foreach ($files as $file) {
- $scripts[] = file_get_contents($file);
+ $scripts[] = \CRM_Utils_JS::stripComments(file_get_contents($file));
}
$scripts = \CRM_Utils_JS::dedupeClosures(
$scripts,
['angular', '$', '_'],
['angular', 'CRM.$', 'CRM._']
);
- // This impl of stripComments currently adds 10-20ms and cuts ~7%
- return \CRM_Utils_JS::stripComments(implode("\n", $scripts));
+ return implode("\n", $scripts);
}
/**
// $scope.myOrder.setDir('field2', '');
// HTML: <tr ng-repeat="... | order:myOrder.get()">...</tr>
.service('CrmUiOrderCtrl', function(){
- //
function CrmUiOrderCtrl(defaults){
this.values = defaults;
}
$cases = [];
$cases[] = [
"a();\n//# sourceMappingURL=../foo/bar/baz.js\nb();",
- "a();\n\nb();",
+ "a();\nb();",
];
$cases[] = [
"// foo\na();",
- "\na();",
+ "a();",
+ ];
+ $cases[] = [
+ "// foo\n //\na();",
+ "a();",
];
$cases[] = [
"b();\n // foo",
];
$cases[] = [
"/// foo\na();\n\t \t//bar\nb();\n// whiz",
- "\na();\n\nb();\n",
+ "a();\nb();\n",
];
$cases[] = [
"alert('//# sourceMappingURL=../foo/bar/baz.js');\n//zoop\na();",
- "alert('//# sourceMappingURL=../foo/bar/baz.js');\n\na();",
+ "alert('//# sourceMappingURL=../foo/bar/baz.js');\na();",
];
return $cases;
}