%PDF- %PDF-
Direktori : /proc/self/root/usr/src/node-v0.10.4/deps/v8/tools/ |
Current File : //proc/self/root/usr/src/node-v0.10.4/deps/v8/tools/jsmin.pyc |
� 4�fQc @ s, d Z d d l Z d e f d � � YZ d S( s� A JavaScript minifier. It is far from being a complete JS parser, so there are many valid JavaScript programs that will be ruined by it. Another strangeness is that it accepts $ and % as parts of identifiers. It doesn't merge lines or strip out blank lines in order to ease debugging. Variables at the top scope are properties of the global object so we can't rename them. It is assumed that you introduce variables with var as if JavaScript followed C++ scope rules around curly braces, so the declaration must be above the first use. Use as: import jsmin minifier = JavaScriptMinifier() program1 = minifier.JSMinify(program1) program2 = minifier.JSMinify(program2) i����Nt JavaScriptMinifierc B s_ e Z d Z d � Z d � Z d � Z d � Z d � Z d � Z d � Z d � Z d � Z RS( sB An object that you can feed code snippets to to get them minified.c C s? i t d 6t d 6| _ d | _ t | _ i | _ d | _ d S( Nt dot ini ( t Truet seen_identifierst identifier_countert Falset in_commentt mapt nesting( t self( ( s, /usr/src/node-v0.10.4/deps/v8/tools/jsmin.pyt __init__5 s c C s | j d � } t | j | <d S( s� Records identifiers or keywords that we see in use. (So we can avoid renaming variables to these strings.) Args: m: The match object returned by re.search. Returns: Nothing. i N( t groupR R ( R t mt identifier( ( s, /usr/src/node-v0.10.4/deps/v8/tools/jsmin.pyt LookAtIdentifier? s c C s | j d 7_ d S( s Called when we encounter a '{'.i N( R ( R ( ( s, /usr/src/node-v0.10.4/deps/v8/tools/jsmin.pyt PushL s c C s7 | j d 8_ | j d k r3 i | _ d | _ n d S( s Called when we encounter a '}'.i i N( R R R ( R ( ( s, /usr/src/node-v0.10.4/deps/v8/tools/jsmin.pyt PopP s c C sE | j d � } | d k r) | j � | S| d k rC | j � | St j d | � rY | St j d | � } | r� | | j � } t j d | � } d d j t | j | � � St j d | � } | r'| j d � } | j d � } t j d | � } | j � | d d j t | j | � � d S| | j k rA| j | S| S( s� Rewrites bits of the program selected by a regexp. These can be curly braces, literal strings, function declarations and var declarations. (These last two must be on one line including the opening curly brace of the function for their variables to be renamed). Args: m: The match object returned by re.search. Returns: The string that should replace the match in the rewritten program. i t {t }s ["'/]s var t ,s (function\b[^(]*)\((.*)\)\{$i i t (s ){( R R R t ret matcht endt splitt joinR t FindNewName( R R t matched_textt var_namest up_to_argst args( ( s, /usr/src/node-v0.10.4/deps/v8/tools/jsmin.pyt DeclarationY s0 %c C s2 | d k r t | d � S| d 8} t | d � S( s- A single-digit base-52 encoding using a-zA-Z.i ia iA ( t chr( R t number( ( s, /usr/src/node-v0.10.4/deps/v8/tools/jsmin.pyt CharFromNumber� s c C s� d } | | j k r | j | S| j d k r3 | Sx{ t r� | j d } | j d } | j | � } | d k r� | j | d � | } n | j d 7_ | | j k r6 Pq6 q6 W| | j | <| S( s� Finds a new 1-character or 2-character name for a variable. Enters it into the mapping table for this scope. Args: var_name: The name of the variable before renaming. Returns: The new name of the variable. t i i4 i ( R R R R R# R ( R t var_namet new_identifiert identifier_first_chart identifier_second_char( ( s, /usr/src/node-v0.10.4/deps/v8/tools/jsmin.pyR � s c C sd | j d � } | j d � } t j d | � r4 | St j d | � rJ | St j d | � r` | S| S( sQ Returns literal strings unchanged, replaces other inputs with group 2. Other inputs are replaced with the contents of capture 1. This is either a single space or an empty string. Args: m: The match object returned by re.search. Returns: The string that should be inserted instead of the matched text. i i s '.*'$s ".*"$s /.+/$( R R R ( R R t entire_matcht replacement( ( s, /usr/src/node-v0.10.4/deps/v8/tools/jsmin.pyt RemoveSpaces� s c C s5 g } xt j d | � D]} | j d d � } | j r� t j d | � } | rn | | j � } t | _ q� | j d � q n | j s� t j d d | � } t j d d | � } t j d | � } | r� | | j � } t | _ q� n t j d d | � } t j d d | � } d } d } d } t j d j | | | d g � | j | � } t j d j | | | d g � | j | � } | j d k r�t j d | j | � n d } t j d | � r�d } n d } d | } t j d j | | | d d d | | g � | j | � } | j | � q Wd j | � d S( sC The main entry point. Takes a text and returns a compressed version. The compressed version hopefully does the same thing. Line breaks are preserved. Args: text: The text of the code snippet as a multiline string. Returns: The compressed text of the code snippet as a multiline string. s \ns t s \*/R$ s /\*.*?\*/s //.*s /\*s ^ +s +$s "(?:[^"\\]|\\.)*"s '(?:[^'\\]|\\.)*'s? (?<![\w$'\")\]])/(?:(?=\()|(?:[^()/\\]|\\.)+)(?:\([^/\\]|\\.)*/t |s ( )+s* (?<![a-zA-Z_0-9$%]) | (?![a-zA-Z_0-9$%])()i s ([a-zA-Z0-9_$%]+)s# \bfunction( [\w$%]+)?\([\w$%,]+\)\{s \?s (?![:\w$%])s (?<![.\w$%])[\w$%]+s \{s \}s \bvar [\w$%,]+s ( R R t replaceR t searchR R t appendt subt startR R R+ R R R ( R t textt new_linest lineR t double_quoted_stringt single_quoted_stringt slash_quoted_regexpt function_declaration_regexpt block_trailing_colont variable_use_regexp( ( s, /usr/src/node-v0.10.4/deps/v8/tools/jsmin.pyt JSMinify� sj ( t __name__t __module__t __doc__R R R R R R# R R+ R<