MediaWiki REL1_32
jsminplus.php File Reference

JSMinPlus version 1.4. More...

Go to the source code of this file.

Classes

class  JSCompilerContext
 
class  JSMinPlus
 
class  JSNode
 
class  JSParser
 
class  JSToken
 
class  JSTokenizer
 

Variables

const DECLARED_FORM 0
 
const EXPRESSED_FORM 1
 
const JS_ARRAY_INIT 107
 
const JS_BLOCK 101
 
const JS_CALL 104
 
const JS_FOR_IN 103
 
const JS_GETTER 110
 
const JS_GROUP 112
 
const JS_INDEX 106
 
const JS_LABEL 102
 
const JS_LIST 113
 
const JS_MINIFIED 999
 
const JS_NEW_WITH_ARGS 105
 
const JS_OBJECT_INIT 108
 
const JS_PROPERTY_INIT 109
 
const JS_SCRIPT 100
 
const JS_SETTER 111
 
const KEYWORD_BREAK 'break'
 
const KEYWORD_CASE 'case'
 
const KEYWORD_CATCH 'catch'
 
const KEYWORD_CONST 'const'
 
const KEYWORD_CONTINUE 'continue'
 
const KEYWORD_DEBUGGER 'debugger'
 
const KEYWORD_DEFAULT 'default'
 
const KEYWORD_DELETE 'delete'
 
const KEYWORD_DO 'do'
 
const KEYWORD_ELSE 'else'
 
const KEYWORD_ENUM 'enum'
 
const KEYWORD_FALSE 'false'
 
const KEYWORD_FINALLY 'finally'
 
const KEYWORD_FOR 'for'
 
const KEYWORD_FUNCTION 'function'
 
const KEYWORD_IF 'if'
 
const KEYWORD_IN 'in'
 
const KEYWORD_INSTANCEOF 'instanceof'
 
const KEYWORD_NEW 'new'
 
const KEYWORD_NULL 'null'
 
const KEYWORD_RETURN 'return'
 
const KEYWORD_SWITCH 'switch'
 
const KEYWORD_THIS 'this'
 
const KEYWORD_THROW 'throw'
 
const KEYWORD_TRUE 'true'
 
const KEYWORD_TRY 'try'
 
const KEYWORD_TYPEOF 'typeof'
 
const KEYWORD_VAR 'var'
 
const KEYWORD_VOID 'void'
 
const KEYWORD_WHILE 'while'
 
const KEYWORD_WITH 'with'
 
const OP_AND '&&'
 
const OP_ASSIGN '='
 
const OP_BITWISE_AND '&'
 
const OP_BITWISE_NOT '~'
 
const OP_BITWISE_OR '|'
 
const OP_BITWISE_XOR '^'
 
const OP_COLON ':'
 
const OP_COMMA ','
 
const OP_CONDCOMMENT_END '@*/'
 
const OP_DECREMENT '--'
 
const OP_DIV '/'
 
const OP_DOT '.'
 
const OP_EQ '=='
 
const OP_GE '>='
 
const OP_GT '>'
 
const OP_HOOK '?'
 
const OP_INCREMENT '++'
 
const OP_LE '<='
 
const OP_LEFT_BRACKET '['
 
const OP_LEFT_CURLY '{'
 
const OP_LEFT_PAREN '('
 
const OP_LSH '<<'
 
const OP_LT '<'
 
const OP_MINUS '-'
 
const OP_MOD '%'
 
const OP_MUL '*'
 
const OP_NE '!='
 
const OP_NOT '!'
 
const OP_OR '||'
 
const OP_PLUS '+'
 
const OP_RIGHT_BRACKET ']'
 
const OP_RIGHT_CURLY '}'
 
const OP_RIGHT_PAREN ')'
 
const OP_RSH '>>'
 
const OP_SEMICOLON ';'
 
const OP_STRICT_EQ '==='
 
const OP_STRICT_NE '!=='
 
const OP_UNARY_MINUS 'U-'
 
const OP_UNARY_PLUS 'U+'
 
const OP_URSH '>>>'
 
const STATEMENT_FORM 2
 
const TOKEN_CONDCOMMENT_END 8
 
const TOKEN_CONDCOMMENT_START 7
 
const TOKEN_END 1
 
const TOKEN_IDENTIFIER 3
 
const TOKEN_NEWLINE 6
 
const TOKEN_NUMBER 2
 
const TOKEN_REGEXP 5
 
const TOKEN_STRING 4
 

Detailed Description

JSMinPlus version 1.4.

Minifies a javascript file using a javascript parser

This implements a PHP port of Brendan Eich's Narcissus open source javascript engine (in javascript) References: https://en.wikipedia.org/wiki/Narcissus_(JavaScript_engine) Narcissus sourcecode: https://mxr.mozilla.org/mozilla/source/js/narcissus/ JSMinPlus weblog: https://crisp.tweakblogs.net/blog/cat/716

Tino Zijdel crisp.nosp@m.@twe.nosp@m.akers.nosp@m..net

Usage: $minified = JSMinPlus::minify($script [, $filename])

Versionlog (see also changelog.txt): 23-07-2011 - remove dynamic creation of OP_* and KEYWORD_* defines and declare them on top reduce memory footprint by minifying by block-scope some small byte-saving and performance improvements 12-05-2009 - fixed hook:colon precedence, fixed empty body in loop and if-constructs 18-04-2009 - fixed crashbug in PHP 5.2.9 and several other bugfixes 12-04-2009 - some small bugfixes and performance improvements 09-04-2009 - initial open sourced version 1.0

Latest version of this script: http://files.tweakers.net/jsminplus/jsminplus.zip

Definition in file jsminplus.php.

Variable Documentation

◆ DECLARED_FORM

const DECLARED_FORM 0

◆ EXPRESSED_FORM

const EXPRESSED_FORM 1

Definition at line 95 of file jsminplus.php.

Referenced by JSParser\Expression().

◆ JS_ARRAY_INIT

const JS_ARRAY_INIT 107

Definition at line 84 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ JS_BLOCK

const JS_BLOCK 101

Definition at line 78 of file jsminplus.php.

Referenced by JSMinPlus\parseTree(), JSParser\Statement(), and JSParser\Statements().

◆ JS_CALL

const JS_CALL 104

Definition at line 81 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ JS_FOR_IN

const JS_FOR_IN 103

Definition at line 80 of file jsminplus.php.

Referenced by JSMinPlus\parseTree(), and JSParser\Statement().

◆ JS_GETTER

const JS_GETTER 110

Definition at line 87 of file jsminplus.php.

Referenced by JSParser\FunctionDefinition(), and JSMinPlus\parseTree().

◆ JS_GROUP

const JS_GROUP 112

Definition at line 89 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ JS_INDEX

const JS_INDEX 106

Definition at line 83 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ JS_LABEL

const JS_LABEL 102

Definition at line 79 of file jsminplus.php.

Referenced by JSMinPlus\parseTree(), and JSParser\Statement().

◆ JS_LIST

const JS_LIST 113

Definition at line 90 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ JS_MINIFIED

const JS_MINIFIED 999

Definition at line 92 of file jsminplus.php.

Referenced by JSMinPlus\parseTree(), and JSParser\Script().

◆ JS_NEW_WITH_ARGS

const JS_NEW_WITH_ARGS 105

Definition at line 82 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ JS_OBJECT_INIT

const JS_OBJECT_INIT 108

Definition at line 85 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ JS_PROPERTY_INIT

const JS_PROPERTY_INIT 109

Definition at line 86 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ JS_SCRIPT

const JS_SCRIPT 100

Definition at line 77 of file jsminplus.php.

Referenced by JSMinPlus\parseTree(), and JSParser\Script().

◆ JS_SETTER

const JS_SETTER 111

Definition at line 88 of file jsminplus.php.

Referenced by JSParser\FunctionDefinition().

◆ KEYWORD_BREAK

const KEYWORD_BREAK 'break'

Definition at line 142 of file jsminplus.php.

Referenced by JSMinPlus\parseTree(), and JSParser\Statement().

◆ KEYWORD_CASE

const KEYWORD_CASE 'case'

Definition at line 143 of file jsminplus.php.

Referenced by JSMinPlus\parseTree(), and JSParser\Statement().

◆ KEYWORD_CATCH

const KEYWORD_CATCH 'catch'

Definition at line 144 of file jsminplus.php.

Referenced by JSParser\Statement().

◆ KEYWORD_CONST

const KEYWORD_CONST 'const'

Definition at line 145 of file jsminplus.php.

Referenced by JSMinPlus\parseTree(), JSParser\Statement(), and JSParser\Variables().

◆ KEYWORD_CONTINUE

const KEYWORD_CONTINUE 'continue'

Definition at line 146 of file jsminplus.php.

Referenced by JSMinPlus\parseTree(), and JSParser\Statement().

◆ KEYWORD_DEBUGGER

const KEYWORD_DEBUGGER 'debugger'

Definition at line 147 of file jsminplus.php.

Referenced by JSMinPlus\parseTree(), and JSParser\Statement().

◆ KEYWORD_DEFAULT

const KEYWORD_DEFAULT 'default'

Definition at line 148 of file jsminplus.php.

Referenced by JSParser\Statement().

◆ KEYWORD_DELETE

const KEYWORD_DELETE 'delete'

Definition at line 149 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ KEYWORD_DO

const KEYWORD_DO 'do'

Definition at line 150 of file jsminplus.php.

Referenced by JSMinPlus\parseTree(), and JSParser\Statement().

◆ KEYWORD_ELSE

const KEYWORD_ELSE 'else'

Definition at line 151 of file jsminplus.php.

Referenced by JSParser\Statement().

◆ KEYWORD_ENUM

const KEYWORD_ENUM 'enum'

Definition at line 152 of file jsminplus.php.

◆ KEYWORD_FALSE

const KEYWORD_FALSE 'false'

Definition at line 153 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ KEYWORD_FINALLY

const KEYWORD_FINALLY 'finally'

Definition at line 154 of file jsminplus.php.

Referenced by JSParser\Statement().

◆ KEYWORD_FOR

const KEYWORD_FOR 'for'

Definition at line 155 of file jsminplus.php.

Referenced by JSMinPlus\parseTree(), and JSParser\Statement().

◆ KEYWORD_FUNCTION

const KEYWORD_FUNCTION 'function'

◆ KEYWORD_IF

const KEYWORD_IF 'if'

Definition at line 157 of file jsminplus.php.

Referenced by JSMinPlus\parseTree(), and JSParser\Statement().

◆ KEYWORD_IN

const KEYWORD_IN 'in'

Definition at line 158 of file jsminplus.php.

Referenced by JSParser\Expression(), JSMinPlus\parseTree(), and JSParser\Statement().

◆ KEYWORD_INSTANCEOF

const KEYWORD_INSTANCEOF 'instanceof'

Definition at line 159 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ KEYWORD_NEW

const KEYWORD_NEW 'new'

Definition at line 160 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ KEYWORD_NULL

const KEYWORD_NULL 'null'

Definition at line 161 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ KEYWORD_RETURN

const KEYWORD_RETURN 'return'

Definition at line 162 of file jsminplus.php.

Referenced by JSMinPlus\parseTree(), and JSParser\Statement().

◆ KEYWORD_SWITCH

const KEYWORD_SWITCH 'switch'

Definition at line 163 of file jsminplus.php.

Referenced by JSMinPlus\parseTree(), and JSParser\Statement().

◆ KEYWORD_THIS

const KEYWORD_THIS 'this'

Definition at line 164 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ KEYWORD_THROW

const KEYWORD_THROW 'throw'

Definition at line 165 of file jsminplus.php.

Referenced by JSMinPlus\parseTree(), and JSParser\Statement().

◆ KEYWORD_TRUE

const KEYWORD_TRUE 'true'

Definition at line 166 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ KEYWORD_TRY

const KEYWORD_TRY 'try'

Definition at line 167 of file jsminplus.php.

Referenced by JSMinPlus\parseTree(), and JSParser\Statement().

◆ KEYWORD_TYPEOF

const KEYWORD_TYPEOF 'typeof'

Definition at line 168 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ KEYWORD_VAR

const KEYWORD_VAR 'var'

Definition at line 169 of file jsminplus.php.

Referenced by JSMinPlus\parseTree(), and JSParser\Statement().

◆ KEYWORD_VOID

const KEYWORD_VOID 'void'

Definition at line 170 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ KEYWORD_WHILE

const KEYWORD_WHILE 'while'

Definition at line 171 of file jsminplus.php.

Referenced by JSMinPlus\parseTree(), and JSParser\Statement().

◆ KEYWORD_WITH

const KEYWORD_WITH 'with'

Definition at line 172 of file jsminplus.php.

Referenced by JSMinPlus\parseTree(), and JSParser\Statement().

◆ OP_AND

const OP_AND '&&'

Definition at line 104 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ OP_ASSIGN

const OP_ASSIGN '='

◆ OP_BITWISE_AND

const OP_BITWISE_AND '&'

Definition at line 107 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ OP_BITWISE_NOT

const OP_BITWISE_NOT '~'

Definition at line 128 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ OP_BITWISE_OR

const OP_BITWISE_OR '|'

Definition at line 105 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ OP_BITWISE_XOR

const OP_BITWISE_XOR '^'

Definition at line 106 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ OP_COLON

const OP_COLON ':'

Definition at line 102 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSParser\Statement().

◆ OP_COMMA

const OP_COMMA ','

◆ OP_CONDCOMMENT_END

const OP_CONDCOMMENT_END '@*/'

Definition at line 136 of file jsminplus.php.

◆ OP_DECREMENT

const OP_DECREMENT '--'

Definition at line 121 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ OP_DIV

const OP_DIV '/'

Definition at line 125 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ OP_DOT

const OP_DOT '.'

Definition at line 129 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ OP_EQ

const OP_EQ '=='

Definition at line 109 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ OP_GE

const OP_GE '>='

Definition at line 118 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ OP_GT

const OP_GT '>'

Definition at line 119 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ OP_HOOK

const OP_HOOK '?'

Definition at line 101 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ OP_INCREMENT

const OP_INCREMENT '++'

Definition at line 120 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ OP_LE

const OP_LE '<='

Definition at line 114 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ OP_LEFT_BRACKET

const OP_LEFT_BRACKET '['

Definition at line 130 of file jsminplus.php.

Referenced by JSParser\Expression().

◆ OP_LEFT_CURLY

const OP_LEFT_CURLY '{'

◆ OP_LEFT_PAREN

const OP_LEFT_PAREN '('

◆ OP_LSH

const OP_LSH '<<'

Definition at line 113 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ OP_LT

const OP_LT '<'

Definition at line 115 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ OP_MINUS

const OP_MINUS '-'

Definition at line 123 of file jsminplus.php.

Referenced by JSParser\Expression(), JSTokenizer\get(), and JSMinPlus\parseTree().

◆ OP_MOD

const OP_MOD '%'

Definition at line 126 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ OP_MUL

const OP_MUL '*'

Definition at line 124 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ OP_NE

const OP_NE '!='

Definition at line 112 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ OP_NOT

const OP_NOT '!'

Definition at line 127 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ OP_OR

const OP_OR '||'

Definition at line 103 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ OP_PLUS

const OP_PLUS '+'

Definition at line 122 of file jsminplus.php.

Referenced by JSParser\Expression(), JSTokenizer\get(), and JSMinPlus\parseTree().

◆ OP_RIGHT_BRACKET

const OP_RIGHT_BRACKET ']'

Definition at line 131 of file jsminplus.php.

Referenced by JSParser\Expression().

◆ OP_RIGHT_CURLY

const OP_RIGHT_CURLY '}'

◆ OP_RIGHT_PAREN

const OP_RIGHT_PAREN ')'

◆ OP_RSH

const OP_RSH '>>'

Definition at line 117 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ OP_SEMICOLON

const OP_SEMICOLON ';'

Definition at line 99 of file jsminplus.php.

Referenced by JSParser\Expression(), JSMinPlus\parseTree(), and JSParser\Statement().

◆ OP_STRICT_EQ

const OP_STRICT_EQ '==='

Definition at line 108 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ OP_STRICT_NE

const OP_STRICT_NE '!=='

Definition at line 111 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ OP_UNARY_MINUS

const OP_UNARY_MINUS 'U-'

Definition at line 139 of file jsminplus.php.

Referenced by JSParser\Expression(), JSTokenizer\get(), and JSMinPlus\parseTree().

◆ OP_UNARY_PLUS

const OP_UNARY_PLUS 'U+'

Definition at line 138 of file jsminplus.php.

Referenced by JSParser\Expression(), JSTokenizer\get(), and JSMinPlus\parseTree().

◆ OP_URSH

const OP_URSH '>>>'

Definition at line 116 of file jsminplus.php.

Referenced by JSParser\Expression(), and JSMinPlus\parseTree().

◆ STATEMENT_FORM

const STATEMENT_FORM 2

Definition at line 96 of file jsminplus.php.

Referenced by JSParser\Statement().

◆ TOKEN_CONDCOMMENT_END

const TOKEN_CONDCOMMENT_END 8

◆ TOKEN_CONDCOMMENT_START

const TOKEN_CONDCOMMENT_START 7

◆ TOKEN_END

const TOKEN_END 1

◆ TOKEN_IDENTIFIER

◆ TOKEN_NEWLINE

const TOKEN_NEWLINE 6

Definition at line 73 of file jsminplus.php.

Referenced by JSTokenizer\get(), JSTokenizer\peek(), and JSParser\Statement().

◆ TOKEN_NUMBER

const TOKEN_NUMBER 2

Definition at line 69 of file jsminplus.php.

Referenced by JSParser\Expression(), JSTokenizer\get(), and JSMinPlus\parseTree().

◆ TOKEN_REGEXP

const TOKEN_REGEXP 5

Definition at line 72 of file jsminplus.php.

Referenced by JSParser\Expression(), JSTokenizer\get(), and JSMinPlus\parseTree().

◆ TOKEN_STRING

const TOKEN_STRING 4

Definition at line 71 of file jsminplus.php.

Referenced by JSParser\Expression(), JSTokenizer\get(), and JSMinPlus\parseTree().