public function execute($path = null)
{
$content = '';
// loop files
foreach ($this->data as $source => $js) {
/*
* Combine js: separating the scripts by a ;
* I'm also adding a newline: it will be eaten when whitespace is
* stripped, but we need to make sure we're not just appending
* a new script right after a previous script that ended with a
* singe-line comment on the last line (in which case it would also
* be seen as part of that comment)
*/
$content .= $js . "\n;";
}
/*
* Let's first take out strings, comments and regular expressions.
* All of these can contain JS code-like characters, and we should make
* sure any further magic ignores anything inside of these.
*
* Consider this example, where we should not strip any whitespace:
* var str = "a test";
*
* Comments will be removed altogether, strings and regular expressions
* will be replaced by placeholder text, which we'll restore later.
*/
$this->extractStrings('\'"`');
$this->stripComments();
$this->extractRegex();
$content = $this->replace($content);
$content = $this->propertyNotation($content);
$content = $this->shortenBools($content);
$content = $this->stripWhitespace($content);
/*
* Earlier, we extracted strings & regular expressions and replaced them
* with placeholder text. This will restore them.
*/
$content = $this->restoreExtractedData($content);
return $content;
}