-
Notifications
You must be signed in to change notification settings - Fork 82
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
Fixes #229. Throws syntax error for empty functions and doesnt block … #230
base: master
Are you sure you want to change the base?
Conversation
Hmm, this can be a breaking change as far as I can tell. On the other hand not throwing an error can be bad too. Not sure how to proceed. If you need this for CSS Lint I guess we should merge it. I'm just not sure about any other projects that depend on parer-lib. |
@@ -1986,6 +1986,11 @@ Parser.prototype = function() { | |||
functionText = tokenStream.token().value; | |||
this._readWhitespace(); | |||
expr = this._expr(true); | |||
if (expr === null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could remove this, and only go with the proposed fix in the while-loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't help you here. I'm not so much familiar with the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nschonni , do you have a preference on how to proceed? The list of dependent packages of parserlib is at https://www.npmjs.com/browse/depended/parserlib , so that's not too many.
if (expr === null) { | ||
// the FUNCTION is set if there's a ( . It doesn't check for a closing ) in identOrFunctionToken in TokenStream.. | ||
// if there's nothing between the brackets, expr is null | ||
throw new SyntaxError("Expected an expression in the function on line " + tokenStream.token().startLine + ", col " + tokenStream.token().startCol + ".", tokenStream.token().startLine, tokenStream.token().startCol); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to emit the line number message yourself; all the other SyntaxErrors in this code just pass them as the second and third arguments. Following that practice will simplify this line a lot.
@@ -1986,6 +1986,11 @@ Parser.prototype = function() { | |||
functionText = tokenStream.token().value; | |||
this._readWhitespace(); | |||
expr = this._expr(true); | |||
if (expr === null) { | |||
// the FUNCTION is set if there's a ( . It doesn't check for a closing ) in identOrFunctionToken in TokenStream.. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit confusingly worded. Perhaps this:
"The FUNCTION token has already checked that there is an opening (."
Or omit this line of comment entirely. The level of commenting in the line below is normal for other similar situations in the codebase.
Some functions can be empty according to the spec e.g. all |
…anymore.
Maybe I shouldn't throw the SyntaxError though. What do you think?