3 ms·
> White space significant, good luck minifying it Would it be hard to define an alternate representation of Python code that uses curly braces instead of white
by tzs 6y ago
> White space significant, good luck minifying it
Would it be hard to define an alternate representation of Python code that uses curly braces instead of white space to use over the wire for delivery of front-end Python (with curly braces that occur in the original Python code escaped)?
This code, for example:
def func(foo, bar):
if foo < bar:
foo += bar
return foo * 3
might become on the wire:
def func(foo, bar):{if foo < bar:{foo += bar}return foo * 3}
That could then be subject to the usual minimization approaches.
Going back from curly representation to significant white space is easy and fast, although you could probably build your tokenizer so that it never even has to bother. That could make the client side handling of this essentially free.
- dfox 6y agoBoth CPython's parser and Python language grammar works in terms of indents/dedents being represented by brace-like tokens, so this is trivially possible transformation.