I am building a project which requires the AST generated by esprima-python to work. However, for the following code snippet, I’m getting this error:
/**
* Helper function to fuse consecutive values in an array equal to the specified value.
* @param {string[]} arr The input array
* @param {any} value The value to fuse on.
* @param {Map<string, any>} mapping The mapping from input domain to value.
*/
function fuse(arr, value, mapping) {
const fused = [];
let i = 0;
while (i < arr.length) {
fused.push(arr[i])
if ((mapping.get(arr[i]) ?? value) !== value) {
++i;
continue;
}
while (i < arr.length && (mapping.get(arr[i]) ?? value) === value) {
++i;
}
}
return fused;
}
File "/home/aksha/.pyenv/versions/3.12.0rc3/lib/python3.12/site-packages/esprima/parser.py", line 237, in throwUnexpectedToken
raise self.unexpectedTokenError(token, message)
esprima.error_handler.Error: Line 214: Unexpected token ?
This error persists for other files where ‘??’ is present. Could someone help me troubleshoot this?
I tried a very simple script:
import esprima
obj = esprima.parse(open('./test/code_from_transformers.js').read(), options={
'esnext': True, 'jsx': True, 'classProperties': True, 'sourceType': 'module', 'comment': True
})
print(obj)
That generated the error shown above.
Thank you.
New contributor
Akshath Raghav is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.