Changeset 2268 for FCKpackager/trunk

Show
Ignore:
Timestamp:
2008-07-23 14:29:20 (4 months ago)
Author:
fredck
Message:

Fixed #1422 : Multiple variables declared in a single "var" statement are now properly renamed by the compressor.
This fix impacted also in the renaming of nested functions.

Location:
FCKpackager/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • FCKpackager/trunk/fckpackager.php

    r2243 r2268  
    1 #!/usr/bin/php -q 
     1#!/usr/bin/php -q 
    22<?php 
    33/* 
     
    224224                        $processed = $this->_ProcessVars( $processed, $this->_Parameters ) ; 
    225225 
    226                 $numVarMatches = preg_match_all( '/\bvar\b\s+([\w_][\w\d_]+)/', $processed, $varsMatches ) ; 
     226                // Match "var" declarations. 
     227                $numVarMatches = preg_match_all( '/\bvar\b\s+((?:({(?:(?>[^{}]*)|(?2))*})|[^;])+?)(?=(?:\bin\b)|;)/', $processed, $varsMatches ) ; 
    227228 
    228229                if ( $numVarMatches > 0 ) 
     
    232233                        for ( $i = 0 ; $i < $numVarMatches ; $i++ ) 
    233234                        { 
    234                                 $vars[] = $varsMatches[1][$i] ; 
     235                                $varsMatch = $varsMatches[1][$i]; 
     236                                 
     237                                // Removed all (...), [...] and {...} blocks from the var 
     238                                // statement to avoid problems with commas inside them. 
     239                                $varsMatch = preg_replace( '/(\((?:(?>[^\(\)]*)|(?1))*\))+/', '', $varsMatch ) ; 
     240                                $varsMatch = preg_replace( '/(\[(?:(?>[^\[\]]*)|(?1))*\])+/', '', $varsMatch ) ; 
     241                                $varsMatch = preg_replace( '/({(?:(?>[^{}]*)|(?1))*})+/', '', $varsMatch ) ; 
     242                                 
     243                                $numVarNameMatches = preg_match_all( '/(?:^|,)\s*([^\s=,]+)/', $varsMatch, $varNameMatches ) ; 
     244                                 
     245                                for ( $j = 0 ; $j < $numVarNameMatches ; $j++ ) 
     246                                { 
     247                                        $vars[] = $varNameMatches[1][$j] ; 
     248                                } 
    235249                        } 
    236250 
     
    246260                { 
    247261                        if ( strlen( $var) > 1 ) 
    248                                 $source = preg_replace( '/(?<!\w|\d|\.)' . $var . '(?!\w|\d)/', $this->_GetVarName(), $source ) ; 
     262                                $source = preg_replace( '/(?<!\w|\d|\.)' . preg_quote( $var ) . '(?!\w|\d)/', $this->_GetVarName(), $source ) ; 
    249263                } 
    250264 
     
    262276                $var = $this->_VarPrefix . $this->_VarChars[ $this->_LastCharIndex++ ] ; 
    263277 
    264                 if ( preg_match( '/(?<!\w|\d|\.)' . $var . '(?!\w|\d)/', $this->_Function ) ) 
     278                if ( preg_match( '/(?<!\w|\d|\.)' . preg_quote( $var ) . '(?!\w|\d)/', $this->_Function ) ) 
    265279                        return $this->_GetVarName() ; 
    266280                else 
     
    285299 
    286300?> 
     301 
    287302<?php 
    288303 
     
    405420                        $parameters = preg_split( '/\s*,\s*/', trim( $match[1] ) ) ; 
    406421 
    407                 $funcProcessor = new FCKFunctionProcessor( $match[0], $parameters, false ) ; 
    408  
    409                 return $funcProcessor->Process() ; 
    410         } 
    411 } 
    412  
    413 ?> 
     422                $hasfuncProcessor = isset( $GLOBALS['funcProcessor'] ) ; 
     423 
     424                if ( $hasfuncProcessor != TRUE ) 
     425                        $GLOBALS['funcProcessor'] = new FCKFunctionProcessor( $match[0], $parameters, false ) ; 
     426                else 
     427                { 
     428                        $GLOBALS['funcProcessor']->_Function = $match[0]; 
     429                        $GLOBALS['funcProcessor']->_Parameters = $parameters; 
     430                } 
     431 
     432                $processed = $GLOBALS['funcProcessor']->Process() ; 
     433                 
     434                $processed = substr_replace( $processed, '', 0, 8 ) ; 
     435 
     436                $processed = FCKJavaScriptCompressor::_ProcessFunctions( $processed ) ; 
     437 
     438                if ( $hasfuncProcessor != TRUE ) 
     439                        unset( $GLOBALS['funcProcessor'] ) ; 
     440                 
     441                return 'function'. $processed ; 
     442        } 
     443} 
     444 
     445?> 
     446 
    414447<?php 
    415448 
     
    771804 
    772805?> 
     806 
    773807<?php 
    774808 
  • FCKpackager/trunk/_source/includes/fckfunctionprocessor.inc

    r2078 r2268  
    5757                        $processed = $this->_ProcessVars( $processed, $this->_Parameters ) ; 
    5858 
    59                 $numVarMatches = preg_match_all( '/\bvar\b\s+([\w_][\w\d_]+)/', $processed, $varsMatches ) ; 
     59                // Match "var" declarations. 
     60                $numVarMatches = preg_match_all( '/\bvar\b\s+((?:({(?:(?>[^{}]*)|(?2))*})|[^;])+?)(?=(?:\bin\b)|;)/', $processed, $varsMatches ) ; 
    6061 
    6162                if ( $numVarMatches > 0 ) 
     
    6566                        for ( $i = 0 ; $i < $numVarMatches ; $i++ ) 
    6667                        { 
    67                                 $vars[] = $varsMatches[1][$i] ; 
     68                                $varsMatch = $varsMatches[1][$i]; 
     69                                 
     70                                // Removed all (...), [...] and {...} blocks from the var 
     71                                // statement to avoid problems with commas inside them. 
     72                                $varsMatch = preg_replace( '/(\((?:(?>[^\(\)]*)|(?1))*\))+/', '', $varsMatch ) ; 
     73                                $varsMatch = preg_replace( '/(\[(?:(?>[^\[\]]*)|(?1))*\])+/', '', $varsMatch ) ; 
     74                                $varsMatch = preg_replace( '/({(?:(?>[^{}]*)|(?1))*})+/', '', $varsMatch ) ; 
     75                                 
     76                                $numVarNameMatches = preg_match_all( '/(?:^|,)\s*([^\s=,]+)/', $varsMatch, $varNameMatches ) ; 
     77                                 
     78                                for ( $j = 0 ; $j < $numVarNameMatches ; $j++ ) 
     79                                { 
     80                                        $vars[] = $varNameMatches[1][$j] ; 
     81                                } 
    6882                        } 
    6983 
     
    7993                { 
    8094                        if ( strlen( $var) > 1 ) 
    81                                 $source = preg_replace( '/(?<!\w|\d|\.)' . $var . '(?!\w|\d)/', $this->_GetVarName(), $source ) ; 
     95                                $source = preg_replace( '/(?<!\w|\d|\.)' . preg_quote( $var ) . '(?!\w|\d)/', $this->_GetVarName(), $source ) ; 
    8296                } 
    8397 
     
    95109                $var = $this->_VarPrefix . $this->_VarChars[ $this->_LastCharIndex++ ] ; 
    96110 
    97                 if ( preg_match( '/(?<!\w|\d|\.)' . $var . '(?!\w|\d)/', $this->_Function ) ) 
     111                if ( preg_match( '/(?<!\w|\d|\.)' . preg_quote( $var ) . '(?!\w|\d)/', $this->_Function ) ) 
    98112                        return $this->_GetVarName() ; 
    99113                else 
  • FCKpackager/trunk/_source/includes/fckjavascriptcompressor.inc

    r2241 r2268  
    140140                        $parameters = preg_split( '/\s*,\s*/', trim( $match[1] ) ) ; 
    141141 
    142                 $funcProcessor = new FCKFunctionProcessor( $match[0], $parameters, false ) ; 
     142                $hasfuncProcessor = isset( $GLOBALS['funcProcessor'] ) ; 
    143143 
    144                 return $funcProcessor->Process() ; 
     144                if ( $hasfuncProcessor != TRUE ) 
     145                        $GLOBALS['funcProcessor'] = new FCKFunctionProcessor( $match[0], $parameters, false ) ; 
     146                else 
     147                { 
     148                        $GLOBALS['funcProcessor']->_Function = $match[0]; 
     149                        $GLOBALS['funcProcessor']->_Parameters = $parameters; 
     150                } 
     151 
     152                $processed = $GLOBALS['funcProcessor']->Process() ; 
     153                 
     154                $processed = substr_replace( $processed, '', 0, 8 ) ; 
     155 
     156                $processed = FCKJavaScriptCompressor::_ProcessFunctions( $processed ) ; 
     157 
     158                if ( $hasfuncProcessor != TRUE ) 
     159                        unset( $GLOBALS['funcProcessor'] ) ; 
     160                 
     161                return 'function'. $processed ; 
    145162        } 
    146163}