<commit_before><?php
class Kwf_Assets_Dependency_File_Js extends Kwf_Assets_Dependency_File
{
    private $_parsedElementsCache;
    private $_contentsCache;

    public function getMimeType()
    {
        return 'text/javascript';
    }
//
    public function __construct($fileName)
    {
        parent::__construct($fileName);
    }

    protected function _getRawContents($language)
    {
        return parent::getContents($language);
    }

    public function warmupCaches()
    {
        $fileName = $this->getFileNameWithType();

        $pathType = $this->getType();
        $useTrl = !in_array($pathType, array('ext', 'ext4', 'extensible', 'ravenJs', 'jquery', 'tinymce', 'mediaelement', 'mustache', 'modernizr'));
        $buildFile = sys_get_temp_dir().'/kwf-uglifyjs/'.$fileName.'.'.md5(file_get_contents($this->getAbsoluteFileName()));
        if (!file_exists("$buildFile.min.js")) {

            $dir = substr($buildFile, 0, strrpos($buildFile, '/'));
            if (!file_exists($dir)) mkdir($dir, 0777, true);
            file_put_contents($buildFile, $this->_getRawContents(null));
            $uglifyjs = Kwf_Config::getValue('server.uglifyjs');
            $cmd = "$uglifyjs ";
            $cmd .= "--source-map ".escapeshellarg("$buildFile.min.js.map.json").' ';
            $cmd .= "--prefix 2 ";
            $cmd .= "--output ".escapeshellarg("$buildFile.min.js").' ';
            $cmd .= escapeshellarg($buildFile);
            $out = array();
            system($cmd, $retVal);
            if ($retVal) {
                throw new Kwf_Exception("uglifyjs failed");
            }
            $contents = file_get_contents("$buildFile.min.js");
            $contents = str_replace("\n//# sourceMappingURL=$buildFile.min.js.map.json", '', $contents);

            $mapData = json_decode(file_get_contents("$buildFile.min.js.map.json"), true);
            if (count($mapData['sources']) > 1) {
                throw new Kwf_Exception("uglifyjs must not return multiple sources, ".count($mapData['sources'])." returned for '$this'");
            }
            unset($mapData['file']);
            $mapData['sources'][0] = $this->getFileNameWithType();
            file_put_contents("$buildFile.min.js.map.json", json_encode($mapData));

            $map = new Kwf_Assets_Util_SourceMap(file_get_contents("$buildFile.min.js.map.json"), $contents);


            if (strpos($contents, '.cssClass') !== false) {
                $cssClass = $this->_getComponentCssClass();
                if ($cssClass) {
                    if (preg_match_all('#\'\.cssClass([\s\'\.])#', $contents, $m)) {
                        foreach ($m[0] as $k=>$i) {
                            $map->stringReplace($i, '\'.'.$cssClass.$m[1][$k]);
                        }
                    }
                }
            }

            if ($pathType == 'ext2') {
                $map->stringReplace('../images/', '/assets/ext2/resources/images/');
            } else if ($pathType == 'mediaelement') {
                $map->stringReplace('url(', 'url(/assets/mediaelement/build/');
            }<commit_msg>show uglifyjs error message if any<commit_after><?php
class Kwf_Assets_Dependency_File_Js extends Kwf_Assets_Dependency_File
{
    private $_parsedElementsCache;
    private $_contentsCache;

    public function getMimeType()
    {
        return 'text/javascript';
    }
//
    public function __construct($fileName)
    {
        parent::__construct($fileName);
    }

    protected function _getRawContents($language)
    {
        return parent::getContents($language);
    }

    public function warmupCaches()
    {
        $fileName = $this->getFileNameWithType();

        $pathType = $this->getType();
        $useTrl = !in_array($pathType, array('ext', 'ext4', 'extensible', 'ravenJs', 'jquery', 'tinymce', 'mediaelement', 'mustache', 'modernizr'));
        $buildFile = sys_get_temp_dir().'/kwf-uglifyjs/'.$fileName.'.'.md5(file_get_contents($this->getAbsoluteFileName()));
        if (!file_exists("$buildFile.min.js")) {

            $dir = substr($buildFile, 0, strrpos($buildFile, '/'));
            if (!file_exists($dir)) mkdir($dir, 0777, true);
            file_put_contents($buildFile, $this->_getRawContents(null));
            $uglifyjs = Kwf_Config::getValue('server.uglifyjs');
            $cmd = "$uglifyjs ";
            $cmd .= "--source-map ".escapeshellarg("$buildFile.min.js.map.json").' ';
            $cmd .= "--prefix 2 ";
            $cmd .= "--output ".escapeshellarg("$buildFile.min.js").' ';
            $cmd .= escapeshellarg($buildFile);
            $cmd .= " 2>&1";
            $out = array();
            exec($cmd, $out, $retVal);
            if ($retVal) {
                throw new Kwf_Exception("uglifyjs failed: ".implode("\n", $out));
            }
            $contents = file_get_contents("$buildFile.min.js");
            $contents = str_replace("\n//# sourceMappingURL=$buildFile.min.js.map.json", '', $contents);

            $mapData = json_decode(file_get_contents("$buildFile.min.js.map.json"), true);
            if (count($mapData['sources']) > 1) {
                throw new Kwf_Exception("uglifyjs must not return multiple sources, ".count($mapData['sources'])." returned for '$this'");
            }
            unset($mapData['file']);
            $mapData['sources'][0] = $this->getFileNameWithType();
            file_put_contents("$buildFile.min.js.map.json", json_encode($mapData));

            $map = new Kwf_Assets_Util_SourceMap(file_get_contents("$buildFile.min.js.map.json"), $contents);


            if (strpos($contents, '.cssClass') !== false) {
                $cssClass = $this->_getComponentCssClass();
                if ($cssClass) {
                    if (preg_match_all('#\'\.cssClass([\s\'\.])#', $contents, $m)) {
                        foreach ($m[0] as $k=>$i) {
                            $map->stringReplace($i, '\'.'.$cssClass.$m[1][$k]);
                        }
                    }
                }
            }

            if ($pathType == 'ext2') {
                $map->stringReplace('../images/', '/assets/ext2/resources/images/');
            } else if ($pathType == 'mediaelement') {
                $map->stringReplace('url(', 'url(/assets/mediaelement/build/');
            }
{'fraction_non_alphanumeric': 0.1740858505564388, 'fraction_numerical': 0.0047694753577106515, 'mean_word_length': 2.206422018348624, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7199666', 'n_tokens_mistral': 1934, 'n_tokens_neox': 1865, 'n_words': 296}