Changeset 2371

Show
Ignore:
Timestamp:
2008-08-20 15:07:30 (3 months ago)
Author:
fredck
Message:

Added the PACKAGER_RENAME feature to CKPackager.

Location:
CKEditor/branches/prototype
Files:
14 modified

Legend:

Unmodified
Added
Removed
  • CKEditor/branches/prototype/ckeditor.pack

    r2366 r2371  
    3030                { 
    3131                        output : 'ckeditor_basic.js', 
     32                        wrap : true, 
    3233                        files : 
    3334                                [ 
     
    4243                { 
    4344                        output : 'ckeditor.js', 
     45                        wrap : true, 
    4446                        files : 
    4547                                [ 
  • CKEditor/branches/prototype/_dev/packager/ckpackager/includes/packagefile.js

    r2366 r2371  
    1818        this.renameGlobals = false; 
    1919        this.compactJavascript = true; 
     20        this.wrap = false; 
    2021        this.files = []; 
    2122}; 
     
    4142 
    4243                var compressed = this.compactJavascript ? 
    43                         CKPACKAGER.scriptCompressor.compress( source, this.renameGlobals, this.constants, this.noCheck ) : 
     44                        CKPACKAGER.scriptCompressor.compress( source, this.renameGlobals, this.constants, this.noCheck, this.wrap ) : 
    4445                        source; 
    4546 
  • CKEditor/branches/prototype/_dev/packager/ckpackager/includes/packager.js

    r2366 r2371  
    5858                                        packFile.compactJavascript = packDefinition.compactJavascript; 
    5959 
     60                                if ( typeof packDefinition.wrap != 'undefined' ) 
     61                                        packFile.wrap = packDefinition.wrap; 
     62 
    6063                                var files = packDefinition.files; 
    6164 
  • CKEditor/branches/prototype/_dev/packager/ckpackager/includes/scope.js

    r2366 r2371  
    144144                this.declaredNames[ name ] = 1; 
    145145        }; 
     146 
     147        CKPACKAGER.scope.prototype.addRenamedRef = function( name ) 
     148        { 
     149                return this.names[ name ] = getNextName( this ); 
     150        }; 
    146151})(); 
  • CKEditor/branches/prototype/_dev/packager/ckpackager/includes/scriptcompressor.js

    r2370 r2371  
    2424                output, 
    2525                outputSize = 0, 
    26                 maxSize = 2000; 
     26                maxSize = 2500; 
    2727 
    2828        var lang = {}; 
     
    156156        isReserved.words = { 'break':1,'else':1,'new':1,'var':1,'case':1,'finally':1,'return':1,'void':1,'catch':1,'for':1,'switch':1,'while':1,'continue':1,'function':1,'this':1,'with':1,'default':1,'if':1,'throw':1,'delete':1,'in':1,'try':1,'do':1,'instanceof':1,'typeof':1,'abstract':1,'enum':1,'int':1,'short':1,'boolean':1,'export':1,'interface':1,'static':1,'byte':1,'extends':1,'long':1,'super':1,'char':1,'final':1,'native':1,'synchronized':1,'class':1,'float':1,'package':1,'throws':1,'const':1,'goto':1,'private':1,'transient':1,'debugger':1,'implements':1,'protected':1,'volatile':1,'double':1,'import':1,'public':1 }; 
    157157 
     158        var getPropParts = function( propNode, parts ) 
     159        { 
     160                if ( !parts ) 
     161                        parts = []; 
     162 
     163                var owner               = propNode.getFirstChild(), 
     164                        property        = propNode.getLastChild(); 
     165                 
     166                if ( owner ) 
     167                { 
     168                        if ( owner.getType() == Token.GETPROP ) 
     169                                getPropParts( owner, parts ); 
     170                        else 
     171                                parts.push( owner ); 
     172 
     173                        parts.push( property ); 
     174                } 
     175                else 
     176                        parts.push( propNode ); 
     177                 
     178                return parts; 
     179        }; 
     180 
    158181        var writeNode = function( node, opt ) 
    159182        { 
     
    349372                                        isFunctionCall = ( childType == Token.FUNCTION || childType == Token.SETPROP || childType == Token.SETELEM ); 
    350373 
     374                                if ( childType == Token.NAME && child.getString() == 'PACKAGER_RENAME' ) 
     375                                { 
     376                                        var renamed = child.getNext(), 
     377                                                renamedRef = '', 
     378                                                parts = getPropParts( renamed ); 
     379 
     380                                        for ( var i = 0 ; i < parts.length ; i++ ) 
     381                                        { 
     382                                                if ( i > 0 ) 
     383                                                        renamedRef += '.'; 
     384                                                renamedRef += parts[ i ].getString(); 
     385                                        } 
     386                                         
     387                                        // print( '[' + renamedRef + ']' ); 
     388                                         
     389                                        out( 'var ', scope.addRenamedRef( renamedRef ), '=' ); 
     390                                        writeNode( renamed ); 
     391                                         
     392                                        scope.declareName( renamedRef ); 
     393                                         
     394                                        break; 
     395                                } 
     396 
    351397                                if ( isFunctionCall ) 
    352398                                        out( '(' ); 
     
    595641                                        name = child.getNext().getString(), 
    596642                                        finalName = name; 
    597  
    598                                 // Build the full name, like Obj.Prop1.Prop2 
    599                                 while ( child ) 
    600                                 { 
    601                                         if ( child.getType() == Token.NAME ) 
    602                                         { 
    603                                                 name = child.getString() + '.' + name; 
    604                                                 finalName = scope.getNewName( child.getString() ) + '.' + finalName; 
     643                                 
     644                                // Get all parts that compose this node (part1.part2.partN). 
     645                                var parts = getPropParts( node ), 
     646                                        startAt = 0, 
     647                                        names = []; 
     648                                 
     649                                // Get all part names form the start. 
     650                                for ( var i = 0 ; i < parts.length ; i++ ) 
     651                                { 
     652                                        var part = parts[ i ], 
     653                                                partType = part.getType(); 
     654                                        if ( partType == Token.NAME || partType == Token.STRING ) 
     655                                                names.push( String( part.getString() ) ); 
     656                                        else 
    605657                                                break; 
    606                                         } 
    607  
    608                                         if ( child.getType() == Token.GETPROP ) 
    609                                         { 
    610                                                 child = child.getFirstChild(); 
    611                                                 name = child.getNext().getString() + '.' + name; 
    612  
    613                                                 if ( child ) 
    614                                                         finalName = name; 
    615                                                 else 
    616                                                         finalName = scope.getNewName( child.getNext().getString() ) + '.' + finalName; 
    617  
    618                                                 continue; 
    619                                         } 
    620  
    621                                         var parenthesis = !!precedence[ child.getType() ]; 
    622  
    623                                         if ( parenthesis ) 
    624                                                 out( '(' ); 
    625  
    626                                         writeNode( child ); 
    627  
    628                                         if ( parenthesis ) 
    629                                                 out( ')' ); 
    630  
    631                                         finalName = '.' + finalName; 
    632  
    633                                         child = null; 
    634                                         break; 
    635                                 } 
    636  
    637                                 // Check if the full name is a constant. 
    638                                 if ( child && constantList[ name ] ) 
    639                                 { 
    640                                         out( constantList[ name ] ); 
    641                                         break; 
    642                                 } 
    643                                 else 
    644                                         out( finalName ); 
     658                                } 
     659 
     660                                // Check if the name parts are to be replaced. 
     661                                for ( var i = names.length ; i > 0 ; i-- ) 
     662                                { 
     663                                        // Build the full name (e.g. Obj.prop1.prop2). 
     664                                        var fullName = i == 1 ? names[ 0 ] : names.slice( 0, i ).join( '.' ); 
     665                                         
     666                                        // If we have a property composed by names only. 
     667                                        if ( i == parts.length && typeof constantList[ fullName ] != 'undefined' ) 
     668                                        { 
     669                                                out( constantList[ fullName ] ) 
     670                                                return true; 
     671                                        } 
     672                                         
     673                                        var newName = scope.getNewName( fullName ); 
     674                                                 
     675                                        // If a new names is available. 
     676                                        if ( newName != fullName ) 
     677                                        { 
     678                                                // Send the new name. 
     679                                                out( newName ); 
     680                                                 
     681                                                // Removed the replaced names from the parts list. 
     682                                                startAt = i;                                             
     683                                                break; 
     684                                        } 
     685                                } 
     686                                 
     687                                for ( var i = startAt ; i < parts.length ; i++ ) 
     688                                { 
     689                                        var part = parts[ i ], 
     690                                                partType = part.getType(), 
     691                                                parenthesis = !!precedence[ partType ]; 
     692 
     693                                        if ( i > 0 ) 
     694                                                out( '.' ); 
     695                                         
     696                                        if ( partType == Token.STRING ) 
     697                                                out( part.getString() ); 
     698                                        else 
     699                                        { 
     700                                                if ( parenthesis ) 
     701                                                        out( '(' ); 
     702 
     703                                                writeNode( part ); 
     704 
     705                                                if ( parenthesis ) 
     706                                                        out( ')' ); 
     707                                        } 
     708                                } 
    645709 
    646710                                break; 
     
    10371101        var regexLib = 
    10381102        { 
    1039                 packagerRemove : Pattern.compile( '(?m-s:^.*?@Packager\.Remove\.Start).*?(?m-s:@Packager\.Remove\.End.*?$\n?)', Pattern.DOTALL ), 
    1040                 packagerRemoveLine : Pattern.compile( '^.*@Packager\.RemoveLine.*$\n?', Pattern.MULTILINE ) 
     1103                packagerRemove : Pattern.compile( '(?m-s:^.*?@Packager\\.Remove\\.Start).*?(?m-s:@Packager\\.Remove\\.End.*?$)', Pattern.DOTALL ), 
     1104                packagerRemoveLine : Pattern.compile( '^.*@Packager\\.RemoveLine.*$', Pattern.MULTILINE ), 
     1105                packagerRename : Pattern.compile( '^.*PACKAGER_RENAME\\(\\s*([^\\s]+).*$', Pattern.MULTILINE ) 
    10411106        }; 
    10421107 
     
    10591124//              script = script.replace( /^.*@Packager\.RemoveLine.*/gm, '' ); 
    10601125 
     1126                script = String( regexLib.packagerRename.matcher( script ).replaceAll( 'PACKAGER_RENAME($1);' ) ); 
     1127 
    10611128                return script; 
    10621129        }; 
     
    10741141        CKPACKAGER.scriptCompressor = 
    10751142        { 
    1076                 compress : function( script, renameGlobals, constants, noCheck ) 
     1143                compress : function( script, renameGlobals, constants, noCheck, wrap ) 
    10771144                { 
    10781145                        script = preProcess( script ); 
     
    10841151                        ignoreSiblings = false; 
    10851152                        isLoop = false; 
     1153                         
     1154                        if ( wrap ) 
     1155                                script = '(function(){' + script + '})();'; 
    10861156 
    10871157                        var compilerEnv = new CompilerEnvirons(), 
     
    10901160                                scriptNode = parser.parse( script, null, 1 ); 
    10911161 
    1092                         noGlobals = !renameGlobals; 
     1162                        noGlobals = !wrap && !renameGlobals; 
    10931163                        constantList = constants || {}; 
    10941164 
  • CKEditor/branches/prototype/_dev/packager/ckpackager/test/test.js

    r2370 r2371  
    252252                 
    253253                [       "a=b+c*1;", 
    254                         "a=b+ +c;" ] 
     254                        "a=b+ +c;" ], 
     255                 
     256                [       "function(){\n// PACKAGER_RENAME( CKEDITOR )\nCKEDITOR.env={ie:true};\n// PACKAGER_RENAME( CKEDITOR.env )\n// PACKAGER_RENAME( CKEDITOR.env.ie )\nif (CKEDITOR&&CKEDITOR.env&&CKEDITOR.env.ie){go();}}", 
     257                        "function(){var a=CKEDITOR;a.env={ie:true};var b=a.env;var c=b.ie;if(a&&b&&c)go();}" ] 
     258 
    255259        ]; 
    256260 
  • CKEditor/branches/prototype/_source/core/ckeditor_base.js

    r2214 r2371  
    124124                                        // Relative path. 
    125125                                        else 
    126                                                 path = location.href.match( /^[^\?]*\// )[0] + path; 
     126                                                path = location.href.match( /^[^\?]*\/(?:)/ )[0] + path; 
    127127                                } 
    128128 
     
    159159        })(); 
    160160} 
     161 
     162// PACKAGER_RENAME( CKEDITOR ) 
  • CKEditor/branches/prototype/_source/core/dom/document.js

    r2261 r2371  
    4444        this.$ = domDocument; 
    4545}; 
     46 
     47// PACKAGER_RENAME( CKEDITOR.dom.document ) 
    4648 
    4749CKEDITOR.dom.document.prototype = new CKEDITOR.dom.domObject(); 
  • CKEditor/branches/prototype/_source/core/dom/element.js

    r2352 r2371  
    5555}; 
    5656 
     57// PACKAGER_RENAME( CKEDITOR.dom.element ) 
     58 
    5759/** 
    5860 * The the {@link CKEDITOR.dom.element} representing and element. If the 
  • CKEditor/branches/prototype/_source/core/dom.js

    r2147 r2371  
    3434CKEDITOR.dom = 
    3535{}; 
     36 
     37// PACKAGER_RENAME( CKEDITOR.dom ) 
  • CKEditor/branches/prototype/_source/core/dtd.js

    r2343 r2371  
    201201            "<b>this is a <a>link</a></b><a> test</a>". 
    202202*/ 
     203 
     204// PACKAGER_RENAME( CKEDITOR.dtd ) 
  • CKEditor/branches/prototype/_source/core/env.js

    r2341 r2371  
    139139        })(); 
    140140} 
     141 
     142// PACKAGER_RENAME( CKEDITOR.env ) 
     143// PACKAGER_RENAME( CKEDITOR.env.ie ) 
  • CKEditor/branches/prototype/_source/core/tools.js

    r2365 r2371  
    362362        } 
    363363}; 
     364 
     365// PACKAGER_RENAME( CKEDITOR.tools ) 
  • CKEditor/branches/prototype/_source/core/ui.js

    r2278 r2371  
    3939        return this; 
    4040}; 
     41 
     42// PACKAGER_RENAME( CKEDITOR.ui ) 
    4143 
    4244CKEDITOR.ui.prototype =