SlimIt is a JavaScript minifier written in Python. The project compiles JavaScript into more compact code so that it downloads and runs faster.
Using lexer in your project
>>> from slimit.lexer import Lexer
>>> lexer = Lexer()
>>> lexer.input('a = 1;')
>>> for token in lexer:
... print token
...
LexToken(ID,'a',1,0)
LexToken(EQ,'=',1,2)
LexToken(NUMBER,'1',1,4)
LexToken(SEMI,';',1,5)
You can get one token at a time using token method:
>>> lexer.input('a = 1;')
>>> while True:
... token = lexer.token()
... if not token:
... break
... print token
...
LexToken(ID,'a',1,0)
LexToken(EQ,'=',1,2)
LexToken(NUMBER,'1',1,4)
LexToken(SEMI,';',1,5)
LexToken instance has different attributes:
>>> lexer.input('a = 1;')
>>> token = lexer.token()
>>> token.type, token.value, token.lineno, token.lexpos
('ID', 'a', 1, 0)
Installation:
Using pip:
sudo pip install slimit
Using easy_install:
sudo easy_install slimit
What is new in this release:
- Bug fix: https://github.com/rspivak/slimit/pull/45 Fix syntax error in the output of for statement with some form of expressions
What is new in version 0.7.4:
- Bug fix: https://github.com/rspivak/slimit/issues/34 'class' is reserved keyword now
What is new in version 0.7.3:
- Bug fix (unary op in FOR init): https://github.com/rspivak/slimit/pull/33
What is new in version 0.7.2:
- Added support for get/set properties: https://github.com/rspivak/slimit/issues/32
What is new in version 0.7.1:
- Function call support in FOR init section: https://github.com/rspivak/slimit/pull/31
What is new in version 0.7:
- Multiline string support: https://github.com/rspivak/slimit/issues/24
What is new in version 0.6.1:
- Added command-line option -t/--mangle-toplevel to turn on global scope name mangling. As of this version it's off by default: https://github.com/rspivak/slimit/issues/27
- Removed dependency on a 'distribute' package
- Bug fix: https://github.com/rspivak/slimit/issues/26
- Bug fix: https://github.com/rspivak/slimit/issues/25
What is new in version 0.6:
- Added optimization: foo["bar"] ==> foo.bar
- Added base class for custom AST node visitors
- Documentation updates
- Bug fix: https://github.com/rspivak/slimit/issues/22
- Bug fix: https://github.com/rspivak/slimit/issues/21
What is new in version 0.5.5:
- Bugfix: https://github.com/rspivak/slimit/issues/7
Requirements:
- Python
Comments not found