slimit icon indicating copy to clipboard operation
slimit copied to clipboard

Syntatically wrong callback function validation check succeeds even though it would fail in a browser.

Open krishnanand opened this issue 6 years ago • 2 comments

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?

krishnanand avatar Jun 06 '18 22:06 krishnanand

This is definitely a bug, and thank you for finding this issue so I can fix it in my fork.

metatoaster avatar Aug 07 '18 01:08 metatoaster

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.

metatoaster avatar Aug 07 '18 08:08 metatoaster