Javascript execution tree?

29 lượt xem
Chuyển tới thư đầu tiên chưa đọc

Alan Halls

chưa đọc,
13:54:54 12 thg 5, 201712/5/17
đến phantomjs
I am working on a WYSIWIG animation editor for designing sliders / ad banners that includes a lot of dependencies. I am hoping to run a report on the code that helps me identify the important things. I have a couple cool starts that will search through javascript for all functions and return each function by parts:
https://regex101.com/r/sXrHLI/1

Then some PHP that will sort it by size:
http://stackoverflow.com/questions/43925320/sort-preg-match-all-by-named-group-size

A thought is that by identifying large functions that aren't being used, we can remove them. My next step is to identify the function tree of what functions are invoked on document load, and then which are loaded and invoked on actions such as clicks / mouseovers and so on.

While I have this handy function that tells me all functions loaded in the DOM, it isn't enough:

var functionArray;
$(document).ready(function(){
    var objs = [];
    for (var obj in window){
        if(window.hasOwnProperty(obj) && typeof window[obj] === 'function') objs.push(obj);
    };
    console.log(obj));
});

PhantomJS looks like it might be right for this, I am looking for a solution that I can use to emulate page load - now here is where my knowledge of terminology fails me, am I looking for "Call Stack", do I need a interpreter, framework, engine or a parser?

I next need to emulate a click / hover event on all elements, or all elements that match something like this regex:
(?|\$\(['"](\.\w*)["']|getElementsByClassName\('(\w*)'\))
(?|\$\(['"](\#\w*)["']|getElementsById\('(\w*)'\))

to find any events that trigger functions so I can make a master list of functions that need to be in the final code.
Trả lời tất cả
Trả lời tác giả
Chuyển tiếp
0 tin nhắn mới