By understanding the Abstract Syntax Tree (AST) better, optimizing for semantic simplicity, and prettifying deliver better results and code for manual review.
check
Step
01
Resolve references
Using a custom Javascript interpreter, the tree is walked and references are resolved.
check
Improved semantic understanding for the analysis engine.
check
Improved user experience when reading the code, better showing the intent of the code.
check
Step
02
Iterative optimization process
jswzl has a library of optimizers which transforms the code to better show intent, and undoing certain minification to improve semantic clarity.
Example: Collapsing string operations
fingerprint
1
var apiHost = "https://api.example.com";
2
var apiBasePath = "api/";
3
var requestPath = `{apiHost}{apiBasePath}` + "v1/".concat("users");
3
var requestPath = `https://api.example.com/api/v1/users`;
check
Step
03
Code is prettified
The code is prettified, making it easier to read for a human.
fingerprint
1
if (isValid(input)) { process(input); } else { showError(); }
1
if (isValid(input)) {
2
process(input);
3
} else {
4
showError();
5
);
01
- Optimizers
fingerprint
Optimizer highlights
These are just some examples of the many optimizations employed by jswzl to make analysis easier.
JSON.parse
When a JSON.parse call is made with a static value, it's converted directly into its object form, making reference resolution easier.
1
var x = JSON.parse("{'foo':'bar'}");
1
var x = {'foo':'bar'};
String simplification
Strings can be concatenated together in multiple ways. Here we see how the simplify the expression to its resolved form.
1
var v1 = "v1/";
2
var api = v1 + "api/"
2
var api = "v1/api/";
But what if it can't resolve the variable? It can also turn it into a Template Literal instead:
1
var api = v1 + "api/"
1
var api = "{v1}/api/";
But you can combine strings in many different ways. No matter, it'll all be simplfied down!
1
var api = `{v1.concat("api/")}` + "".concat(['us', 'ers/'])