Compare two structurally similar JS files for equivalent functionality?

Viewed 45

Is there a method to compare two javascript files for equivalent functionality? E.g.:

const foo = 1
console.log(foo)

and

const bar = 1
console.log(bar)

would be considered functionally equivalent.

I don't need to determine equivalence in all situations. Handling basic name changes is enough for my current use case (and probably solves most if not all future use cases).

My only thought is to maybe use a minifier with predictable naming obfuscation. Like, the first name encountered is always transliterated to v1, the 2nd to v2, etc. I realize I could create instrument a parser or something and could do that eventually, but I was hoping to find an existing solution.

1 Answers

I would recommend finding a code plagiarism tool like this one to check for similarity.

I know some people who found out that our Java 2 professor's tool could handle changing variable names, but I don't know what he used....

Related