-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parse function breaks when there’s a line ending in a string #100
Comments
No, never mind, if an actual newline character occur inside a string token and actual new line, Node.js doesn't even like it either.
ES5 (which is what slimit supports) doesn't have multiline strings like Python does, so fortunately for the parsers, this is a a valid syntax error in the provided ES5 script which the parser correctly provided. However, if you meant to an escaped sequence representing the newline, this will then work (note the raw string prefix >>> from slimit.parser import Parser
>>> print(Parser().parse(r'var i = "test\nvalue"').to_ecma())
var i = "test\nvalue"; |
Well I had this problem when trying to scrape information out of a working JavaScript code on a high-traffic website. |
Can you please provide the link to the example that choked? |
Anyway, I do see what you mean - I had mistakenly used my patched version of slimit that correctly reported that as a parsing error. Anyway, the correct behavior with that input should throw a SyntaxError exception, which my patched version (and To make things most clear, this is the input JavaScript with the invalid syntax: var i = "test
value" Assume that input is assigned to >>> from slimit.parser import Parser
>>> parser = Parser()
>>> node = parser.parse(program)
Illegal character '"' at 1:8 after LexToken(EQ,'=',1,6)
Illegal character '"' at 1:19 after LexToken(ID,'value',1,14)
>>> print(node.to_ecma())
var i = test;
value; This changed the program entirely, as slimit erroneously fully parsed the input without raising an error and produced an incorrect AST, and this is where my initial confusion lied (when I saw the output which I then used as input, then I noticed the quotes on the original input). The correct behavior is implemented in >>> from calmjs.parse import es5
>>> es5(program)
Traceback (most recent call last):
...
calmjs.parse.exceptions.ECMASyntaxError: Illegal character '"' at 1:9 after '=' at 1:7 |
Well, I’m probably mistaken: this should have been a non-working JavaScript extract among the working ones, because I have the same kind of error with newlines inside strings in my web browser’s console. |
The behavior is the same with
\r
.The text was updated successfully, but these errors were encountered: