The example in this paper describes how Python formats the compressed JS file. Share to everyone for your reference. The specific analysis is as follows:
The script can be compressed after the JS file format for some restore, of course, will not be perfect, temporarily do not deal with grammar problems, just to facilitate reading JS code
Lines = open ("Unformated.js"). ReadLines () [0].split (";") #一般压缩后的文件所有代码都在一行里 # Set the index as appropriate, and in my case line No. 0 is the source code. indent = 0formatted = []for line in lines: newline = [] for char in line : newline.append (char) if char== ' { ': #{is the basis for indentation indent+=1 newline.append ("\ n") newline.append ("\ T" *indent) if char== "}": indent- =1 newline.append ("\ n") newline.append ("\ T" *indent) formatted.append ("\ T" *indent+ "". Join (newline ) Open ("Formated.js", "W"). Writelines ("; \ n". Join (formatted))
Hopefully this article will help you with Python programming.