slimit
slimit copied to clipboard
Syntatically wrong callback function validation check succeeds even though it would fail in a browser.
This is my test case
code = 'function callbackFn(activate, options) {\n if (true)\n}' # The if block does not have any brackets or any body.
parser = slimit.parser.Parser()
ast = parser.parse(code)
nodes = list(ast)
root = nodes[0]
return isinstance(root, slimit.ast.FuncDecl) . # This returns True
Am I doing this incorrectly? If yes, how do I validate the string?
This is definitely a bug, and thank you for finding this issue so I can fix it in my fork.
If you are still trying to make this work and haven't solve this with another library yet because you want something like slimit, I just made a release of my fork of slimit (as calmjs.parse-1.1.0
) and this now works also:
>>> from calmjs.parse import es5
>>> code = 'function callbackFn(activate, options) {\n if (true)\n}'
>>> es5(code)
Traceback (most recent call last):
...
calmjs.parse.exceptions.ECMASyntaxError: Unexpected '}' at 3:1 after '\n' at 2:12
You may just simply catch SyntaxError
as ECMASyntaxError
inherits it.