Skip to content

Commit 8f002ef

Browse files
committed
Add docs for constant folding
1 parent dde9d4d commit 8f002ef

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SECONDS_IN_A_DAY = 60 * 60 * 24
2+
SECONDS_IN_A_WEEK = SECONDS_IN_A_DAY * 7
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Constant Folding
2+
================
3+
4+
This transform evaluates constant expressions with literal operands when minifying and replaces the expression with the resulting value, if the value is shorter than the expression.
5+
6+
There are some limitations, notably the division and power operators are not evaluated.
7+
8+
This will be most effective with numeric literals.
9+
10+
This transform is always safe and enabled by default. Disable by passing the ``constant_folding=False`` argument to the :func:`python_minifier.minify` function,
11+
or passing ``--no-constant-folding`` to the pyminify command.
12+
13+
Example
14+
-------
15+
16+
Input
17+
~~~~~
18+
19+
.. literalinclude:: constant_folding.py
20+
21+
Output
22+
~~~~~~
23+
24+
.. literalinclude:: constant_folding.min.py
25+
:language: python

docs/source/transforms/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ They can be enabled or disabled through the minify function, or passing options
1919
convert_posargs_to_args
2020
preserve_shebang
2121
remove_explicit_return_none
22+
constant_folding
2223

2324
.. toctree::
2425
:caption: Disabled by default

0 commit comments

Comments
 (0)