PHP 클래스 MatthiasMullie\Minify\JS

This source file can be used to minify Javascript files. The class is documented in the file itself. If you find any bugs help me out and report them. Reporting can be done by sending an email to [email protected]. If you report a bug, make sure you give me enough information (include your code). License Copyright (c) 2012, Matthias Mullie. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. This software is provided by the author "as is" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall the author be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.
저자: Matthias Mullie ([email protected])
저자: Tijs Verkoyen ([email protected])
상속: extends Minify
파일 보기 프로젝트 열기: matthiasmullie/minify 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$keywordsAfter string[] ..> before them. Some end of lines are not the end of a statement, like when continued by one of these keywords on the newline. E.g.: we shouldn't insert a ; before this instanceof variable instanceof String Will be loaded from /data/js/keywords_after.txt
$keywordsBefore string[] ..> after them. Some end of lines are not the end of a statement, like with these keywords. E.g.: we shouldn't insert a ; after this else else console.log('this is quite fine') Will be loaded from /data/js/keywords_before.txt
$keywordsReserved string[] Will be loaded from /data/js/keywords_reserved.txt.
$operators string[] Will be loaded from /data/js/operators.txt
$operatorsAfter string[] ..> before them. Some end of lines are not the end of a statement, like when continued by one of these operators on the newline. Note: Most operators are fine, we've only removed ), ], ++ and --. ++ & -- have to be joined with the value they're in-/decrementing. ) & ] are "special" in that they have lots or usecases. () for example is used for function calls, for grouping, in if () and for (), ... Will be loaded from /data/js/operators_after.txt
$operatorsBefore string[] ..> after them. Some end of lines are not the end of a statement, like with these operators. Note: Most operators are fine, we've only removed !, ++ and --. There can't be a newline separating ! and whatever it is negating. ++ & -- have to be joined with the value they're in-/decrementing. Will be loaded from /data/js/operators_before.txt

공개 메소드들

메소드 설명
__construct ( )
execute ( string[optional] $path = null ) : string Minify the data.

보호된 메소드들

메소드 설명
extractRegex ( ) JS can have /-delimited regular expressions, like: /ab+c/.match(string).
getKeywordsForRegex ( array $keywords, string $delimiter = '/' ) : string[] We'll strip whitespace around certain keywords with regular expressions.
getOperatorsForRegex ( array $operators, string $delimiter = '/' ) : string[] We'll strip whitespace around certain operators with regular expressions.
propertyNotation ( string $content ) : string Replaces all occurrences of array['key'] by array.key.
shortenBools ( string $content ) : string Replaces true & false by !0 and !1.
stripComments ( ) Strip comments from source code.
stripWhitespace ( string $content ) : string Strip whitespace.

메소드 상세

__construct() 공개 메소드

public __construct ( )

execute() 공개 메소드

Perform JS optimizations.
public execute ( string[optional] $path = null ) : string
$path string[optional]
리턴 string The minified data

extractRegex() 보호된 메소드

The content inside the regex can contain characters that may be confused for JS code: e.g. it could contain whitespace it needs to match & we don't want to strip whitespace in there. The regex can be pretty simple: we don't have to care about comments, (which also use slashes) because stripComments() will have stripped those already. This method will replace all string content with simple REGEX# placeholder text, so we've rid all regular expressions from characters that may be misinterpreted. Original regex content will be saved in $this->extracted and after doing all other minifying, we can restore the original content via restoreRegex()
protected extractRegex ( )

getKeywordsForRegex() 보호된 메소드

This will prepare the given array by escaping all characters.
protected getKeywordsForRegex ( array $keywords, string $delimiter = '/' ) : string[]
$keywords array
$delimiter string
리턴 string[]

getOperatorsForRegex() 보호된 메소드

This will prepare the given array by escaping all characters.
protected getOperatorsForRegex ( array $operators, string $delimiter = '/' ) : string[]
$operators array
$delimiter string
리턴 string[]

propertyNotation() 보호된 메소드

Replaces all occurrences of array['key'] by array.key.
protected propertyNotation ( string $content ) : string
$content string
리턴 string

shortenBools() 보호된 메소드

Replaces true & false by !0 and !1.
protected shortenBools ( string $content ) : string
$content string
리턴 string

stripComments() 보호된 메소드

Strip comments from source code.
protected stripComments ( )

stripWhitespace() 보호된 메소드

We won't strip *all* whitespace, but as much as possible. The thing that we'll preserve are newlines we're unsure about. JavaScript doesn't require statements to be terminated with a semicolon. It will automatically fix missing semicolons with ASI (automatic semi- colon insertion) at the end of line causing errors (without semicolon.) Because it's sometimes hard to tell if a newline is part of a statement that should be terminated or not, we'll just leave some of them alone.
protected stripWhitespace ( string $content ) : string
$content string The content to strip the whitespace for
리턴 string

프로퍼티 상세

$keywordsAfter 보호되어 있는 프로퍼티

..> before them. Some end of lines are not the end of a statement, like when continued by one of these keywords on the newline. E.g.: we shouldn't insert a ; before this instanceof variable instanceof String Will be loaded from /data/js/keywords_after.txt
protected string[] $keywordsAfter
리턴 string[]

$keywordsBefore 보호되어 있는 프로퍼티

..> after them. Some end of lines are not the end of a statement, like with these keywords. E.g.: we shouldn't insert a ; after this else else console.log('this is quite fine') Will be loaded from /data/js/keywords_before.txt
protected string[] $keywordsBefore
리턴 string[]

$keywordsReserved 보호되어 있는 프로퍼티

Will be loaded from /data/js/keywords_reserved.txt.
또한 보기: https://mathiasbynens.be/notes/reserved-keywords
protected string[] $keywordsReserved
리턴 string[]

$operators 보호되어 있는 프로퍼티

Will be loaded from /data/js/operators.txt
또한 보기: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators
protected string[] $operators
리턴 string[]

$operatorsAfter 보호되어 있는 프로퍼티

..> before them. Some end of lines are not the end of a statement, like when continued by one of these operators on the newline. Note: Most operators are fine, we've only removed ), ], ++ and --. ++ & -- have to be joined with the value they're in-/decrementing. ) & ] are "special" in that they have lots or usecases. () for example is used for function calls, for grouping, in if () and for (), ... Will be loaded from /data/js/operators_after.txt
또한 보기: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators
protected string[] $operatorsAfter
리턴 string[]

$operatorsBefore 보호되어 있는 프로퍼티

..> after them. Some end of lines are not the end of a statement, like with these operators. Note: Most operators are fine, we've only removed !, ++ and --. There can't be a newline separating ! and whatever it is negating. ++ & -- have to be joined with the value they're in-/decrementing. Will be loaded from /data/js/operators_before.txt
또한 보기: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators
protected string[] $operatorsBefore
리턴 string[]