Closed nicolafio closed 1 year ago
This property was never documented nor is it a default property of SyntaxError
. The bug is more that the property was there.
How are you able to infer the row and column then? Doesn't seem possible other than using regular expressions on the stack trace.
The same way one would do when getting a SyntaxError
from a call to eval
.
One way would be to use a library which parses the source for you again when a SyntaxError
was thrown and gives more details about the error.
I found a problem from starting in version 3.9.8. If we instantiate
NodeVM
like followsand run this code
The
SyntaxError
error that gets thrown doesn't have a.loc
attribute any more, which we relied on to find exactly where the syntax error was in the code.The specific example script to reproduce this regression is the following, which tries to retrieve the
.loc
attribute:Content of test.js
```js const { NodeVM } = require("vm2"); const nodeVm = new NodeVM({ wrapper: "commonjs", console: "off", eval: false, wasm: false, }); const code = ` invalid varName = 'test'; module.exports = () => {} `; try { nodeVm.run(code, "example.js"); } catch (e) { console.log(e.loc); } ```And what follow are the results on the command line using the versions of
vm2
from 3.9.7 up to 3.9.11. With version 3.9.7, we correctly fetch thePosition
object, while in later versions we getundefined
.