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

Browser prefix is operator #45

Closed

Conversation

donotknow
Copy link

@donotknow donotknow commented Feb 17, 2018

Which issue # if any, does this resolve?
#38

Please check one:

  • New tests created for this change
  • Tests updated for this change

More information on my comment in the original issue #38 (comment).

donotknow added a commit to donotknow/lesshint that referenced this pull request Feb 17, 2018
Update lesshint to work with shellscape/postcss-values-parser#45, which
will return a number for +5 instead of an operator and a number.

So, check both operators and numbers, ignore any numbers that don’t
start with an operator (+-*/), allow the node to be the last node (no
nextElement), and use a whitespace regex to check the none spacing
instead of the exact value.
if ((!this.current.nodes.length || (this.current.last && this.current.last.type === 'operator')) && this.nextToken[0] === 'word') {
return this.word();
}
if (this.nextToken[0] === 'word') {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so why don't we want this parsed different in loose mode?

Copy link
Author

@donotknow donotknow Feb 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loose mode just means you aren’t compliant CSS, right? It doesn’t mean that this:

https://github.com/shellscape/postcss-values-parser/pull/45/files#diff-cc37320af8aeb8b7582dad90cc114e55R219

-16px -1px -1px 16px

…should be parsed as 3 operators and 4 numbers, it should be four numbers.

But, I mostly leave that question to you as the maintainer. Did I misunderstand that test?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jwilsson please weigh in here. I recall that we implemented loose mode specifically for less and scss. Will removing how this is processed in loose mode have negative consequences?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a matching PR to update less here: lesshint/lesshint#458 (which will need to be updated to bump versions pending a release of this repo). I didn’t realize this was the parser for other things, @jwilsson LMK what else might need to be updated in the same manner as lesshint, I’d prefer to rig up updates to all the repos as part of this review.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know. This might require a major version, as it's going to break some expected functionality.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the idea behind loose mode was to target CSS-like languages (such as Less/SCSS).

I definitely think we should tag a major after this one is merged, I know that at least Prettier is using this library (and that's a pretty large project) so we probably wouldn't want to change the behaviour unexpectedly.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lemme see if I can loop those folks into this. I'll have to comb through the commits to figure out who that was, but we'll get this in once we get some more eyes on it.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evilebottnawi can you comment as to whether or not this will impact prettier?

@@ -209,15 +209,15 @@ describe('Parser → Number : Loose', () => {
},
{
test: '5+5',
expected: { value: '5', unit: '', length: 3 }
expected: { value: '+5', unit: '', length: 2 }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shellscape break, 5+5 should be as 5 + 5

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evilebottnawi thanks for taking a look. can you elaborate? I'm not sure what you mean there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shellscape It is difficult to say for sure, since we have rather complicated logic around +, - and
/. I will test this branch tomorrow and leave feedback here 👍

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@alexander-akait
Copy link
Contributor

@shellscape also if it is major change, let's open issue for discussion before release. Some improvement for prettier will be great 👍

@shellscape
Copy link
Owner

@evilebottnawi indeed. this would be a major version change. please do create an issue for discussing what you would like to see improved!

@alexander-akait
Copy link
Contributor

alexander-akait commented Feb 28, 2018

@shellscape
Break:

  1. calc (should be ignore, by spec +/- should have space, but if somebody write incorrectly we should output as is):
-   prop75: calc(100%+2px) calc(100% +2px) calc(100%+ 2px) calc(100% + 2px);
-   prop76: calc(100%-2px) calc(100% -2px) calc(100%- 2px) calc(100% - 2px);
+   prop75: calc(100% +2px) calc(100% +2px) calc(100%+ 2px) calc(100% + 2px);
+   prop76: calc(100% -2px) calc(100% -2px) calc(100%- 2px) calc(100% - 2px);
  1. We use parser for some at-rules (example @mixin $(theme)-color). But can/should be fixed inside prettier.
-   @mixin $(theme)-colors;
+   @mixin $(theme) -colors;
  1. Handle scss/less syntax around math operations:
a {
  prop57: round(1.5)+2 round(1.5) +2 round(1.5)+ 2 round(1.5) + 2;
  prop58: 2+round(1.5) 2 +round(1.5) 2+ round(1.5) 2 + round(1.5);
  prop59: (round(1.5)+2) (round(1.5) +2) (round(1.5)+ 2) (round(1.5) + 2);
  prop60: (2+round(1.5)) (2 +round(1.5)) (2+ round(1.5)) (2 + round(1.5));
  prop61: $width+2 $width +2 $width+ 2 $width + 2;
  prop62: 2+$width 2 +$width 2+ $width 2 + $width;
  prop63: ($width+2) ($width +2) ($width+ 2) ($width + 2);
  prop64: (2+$width) (2 +$width) (2+ $width) (2 + $width);
  prop65: @width+2 @width +2 @width+ 2 @width + 2;
}
-   prop57: round(1.5) + 2 round(1.5) + 2 round(1.5) + 2 round(1.5) + 2;
-   prop58: 2 + round(1.5) 2 + round(1.5) 2 + round(1.5) 2 + round(1.5);
-   prop59: (round(1.5) + 2) (round(1.5) + 2) (round(1.5) + 2) (round(1.5) + 2);
-   prop60: (2 + round(1.5)) (2 + round(1.5)) (2 + round(1.5)) (2 + round(1.5));
-   prop61: $width + 2 $width + 2 $width + 2 $width + 2;
-   prop62: 2 + $width 2 + $width 2 + $width 2 + $width;
-   prop63: ($width + 2) ($width + 2) ($width + 2) ($width + 2);
-   prop64: (2 + $width) (2 + $width) (2 + $width) (2 + $width);
-   prop65: @width+2 @width + 2 @width+ 2 @width + 2;
+   prop57: round(1.5) +2 round(1.5) +2 round(1.5) + 2 round(1.5) + 2;
+   prop58: 2 +round(1.5) 2 +round(1.5) 2 + round(1.5) 2 + round(1.5);
+   prop59: (round(1.5) +2) (round(1.5) +2) (round(1.5) + 2) (round(1.5) + 2);
+   prop60: (2 +round(1.5)) (2 +round(1.5)) (2 + round(1.5)) (2 + round(1.5));
+   prop61: $width +2 $width +2 $width + 2 $width + 2;
+   prop62: 2 +$width 2 +$width 2 + $width 2 + $width;
+   prop63: ($width +2) ($width +2) ($width + 2) ($width + 2);
+   prop64: (2 +$width) (2 +$width) (2 + $width) (2 + $width);
+   prop65: @width+2 @width +2 @width+ 2 @width + 2;

From spec in short form:

Note: While scaling can be specified without any spaces, like lightness(*150%), adding/subtracting must be done with spaces after the +/-, or else the +/- will be interpreted as part of the number by the CSS parser.

I.e. - some + 2 -> should be interpreted as operator

@alexander-akait
Copy link
Contributor

alexander-akait commented Feb 28, 2018

I think we should avoid behavior in this PR in loose mode, to allow reformat + and / for scss/less/postcss-plugins syntax

@shellscape
Copy link
Owner

@evilebottnawi are your comments new requests/feedback in general for this module or do they pertain to this Pull Request?

@alexander-akait
Copy link
Contributor

@shellscape to this

@shellscape
Copy link
Owner

@donotknow & @evilebottnawi can you two work through this so we can merge something that doesn't cause issues for other consumers (like prettier) but fixes the issue that lesshint is currently running into?

@alexander-akait
Copy link
Contributor

@donotknow can we use this logic only in not loose mode ?

@shellscape
Copy link
Owner

This has been fixed in next and will be released in a beta later today.

@shellscape shellscape closed this Feb 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants