WALA icon indicating copy to clipboard operation
WALA copied to clipboard

On support of `let` in JavaScript analysis

Open RichardHoOoOo opened this issue 4 years ago • 3 comments
trafficstars

If I use the JSCallGraphDriver under WALA-start to build a call graph for the following JS code

foo((a) => {
  let b = "";
});

an exception with the following message will show

Exception in thread "main" com.ibm.wala.util.WalaException: front end errors:
error in test.js:
[SEVERE] missing ; before statement: test.js@2:   let b = "";
end of front end errors

at com.ibm.wala.cast.util.Util.checkForFrontEndErrors(Util.java:36)
at com.ibm.wala.examples.analysis.js.JSCallGraphBuilderUtil.makeCG(JSCallGraphBuilderUtil.java:223)
at com.ibm.wala.examples.analysis.js.JSCallGraphBuilderUtil.makeScriptCGBuilder(JSCallGraphBuilderUtil.java:92)
at com.ibm.wala.examples.analysis.js.JSCallGraphBuilderUtil.makeScriptCG(JSCallGraphBuilderUtil.java:147)
at com.ibm.wala.examples.analysis.js.JSCallGraphBuilderUtil.makeScriptCG(JSCallGraphBuilderUtil.java:138)
at com.ibm.wala.examples.drivers.JSCallGraphDriver.main(JSCallGraphDriver.java:29)

If I remove the let keyword like this

foo((a) => {
  b = "";
});

The output seems correct

3 = invoke 2@1 exception:4
6 = invoke 5@3 exception:7
7 = invoke 9@7 11,12 exception:13
Call graph stats:
  Nodes: 108
  Edges: 107
  Methods: 4
  Bytecode Bytes: 0

Since let keyword is common in real cases, can WALA fix this issue or how can I work around it?

RichardHoOoOo avatar Nov 04 '21 06:11 RichardHoOoOo

You may use babel to downgrade the code.

xiaofen9 avatar Nov 04 '21 18:11 xiaofen9

@xiaofen9 Thanks for your solution. Yes it is a good idea.

RichardHoOoOo avatar Nov 05 '21 07:11 RichardHoOoOo

We should support let if our JS parser Rhino exposes it in a proper way. It's not a huge departure from extant JS variables. Will look into it when I get some time, or contributions are welcome!

msridhar avatar Dec 03 '21 00:12 msridhar