Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

frvge
Copy link
Contributor

@frvge frvge commented May 28, 2017

…anymore.

Maybe I shouldn't throw the SyntaxError though. What do you think?

@frvge frvge requested a review from XhmikosR May 28, 2017 00:52
@XhmikosR
Copy link
Member

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) {
Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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);

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..

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.

@tophf
Copy link
Contributor

tophf commented Jan 15, 2018

Some functions can be empty according to the spec e.g. all filter: functions like invert() is a valid CSS which does nothing, though (at least in compliant browsers, for example Chrome recently fixed their crbug.com/798683). In my rewrite of CSSLint+parserlib for Stylus I've added ValidationTypes.functions and ValidationTypes.functionsMayBeEmpty which consists of 10 filter functions (blur, brightness, contrast, drop-shadow, grayscale, hue-rotate, invert, opacity, saturate, sepia) and 'content' function.

@XhmikosR XhmikosR removed their request for review January 22, 2021 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants