Static analysis: tell if two Javascript functions are the same

I am looking for a way using static analysis of two JavaScript functions to determine if they are the same. Let me define a few definitions of "the same."

Level 1: . The functions are the same, with the exception of possible different spaces, for example. TABS, CR, LF and SPACES.

Level 2 Functions may have different spaces, such as level 1, but may also have different variable names.

Level 3


For the first level, I think I could just remove all (non-literal, which can be hard) spaces from each line containing two JS function definitions, and then compare the lines.

For the second level, I think I will need to use something like the SpiderMonkey parser to create two parsing trees, and then write a comparer that walks the trees and allows the variables to have different names.


[Edit] William makes a good point below. I mean the same thing. Now I am looking for some practical strategies, especially regarding the use of parsing trees.

+3
source share
3 answers

Recreate:

To state my proposal for the definition of identical functions, we can offer the following stream:

1: , ; {, ; } . ; , :

2: , , , , (, JS; ); ; 4 , . vSNN, v - , S - , NN - , .

; , , :

3: "sNN", " s , NN - , . ; , , :

4: , , , , ( p_strlen() c_strlen() 1. , , , , .


:

, , "", " ".

, , :

, ( , , ,...) .

, . , ( Pascal/C, ). p_strlen(str) . c_strlen(str) .

, , , : () .


:

, ( , , ), () , , .

( ) ; , Hard, , , , .


: , ; .

+3

1 .

2, , 1? , , var1, var2, ... varX.

, ... var i var j , . , , , .

+1

. (Semantic Designs) Smart Differencer. ( JavaScript), , ( ). , , ""; 10E17 , 1E18.

, " ". , , . (, , , ,...) , , . , , . -.

; , , . , , , ; . , (, ). , ( - 1980 , , - ).

More work than you might expect.

+1
source

All Articles