-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
Fix parsing of !important - take 2 #124
Conversation
@@ -24,7 +30,7 @@ module.exports = class LessStringifier extends Stringifier { | |||
if (node.nodes) { | |||
this.block(node, name + params + important); | |||
} else { | |||
const end = (node.raws.between || '') + important + (semicolon ? ';' : ''); | |||
const end = important + (semicolon ? ';' : '') + (node.raws.between || ''); |
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'm not 100% satisfied with this. There's one stringify test ("mixin with !important") that's failing without it so I thought I'd leave it in for the sake of discussion.
I haven't been able to find any downsides to it yet, though. But let me know what you think and we'll take it from there.
lib/LessStringifier.js
Outdated
const important = node.raws.important || ''; | ||
let important = ''; | ||
|
||
if (node.important && node.raws.important) { |
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.
maybe I'm not reading the code above correctly, but in what scenario will node.raws.important
be populated when node.important
is falsy?
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.
True, that check can be simplified.
I've simplified the |
@jwilsson there's a typo in the circle ci configs that I used across most of my repos, and I've had to incrementally clean it. Circle used to permit the use of duplicate version keys in the yaml, but introduced a "fix" that started throwing errors. I'll update that on master, and you can merge master to resolve it and get CI working again. |
Codecov Report
@@ Coverage Diff @@
## master #124 +/- ##
==========================================
+ Coverage 95.74% 96.05% +0.31%
==========================================
Files 8 8
Lines 188 203 +15
==========================================
+ Hits 180 195 +15
Misses 8 8
Continue to review full report at Codecov.
|
So the tests are exactly what we needed. I wasn't quite sure about the direction of your solution though. I've been trying to follow the mantra that the PostCSS maintainers have shifted towards, in getting the tokens array setup before parsing/processing methods take over. It's a little different than string examination post-process. Here's my proposal to go the tokens route: postcss-less/lib/LessParser.js Lines 116 to 137 in d96075d
Granted it could probably use a little polish, but it passes the tests you've added on this PR, and doesn't need Stringifier modification. Thoughts? |
@shellscape Cool! I'd love to learn some more about it. Have you seen any blog post, issue comment, etc. from the PostCSS maintainers? Or is the best way to learn more just reading the PostCSS code more closely? I left one small comment on your solution, but otherwise I think it looks great! Especially since we don't need any stringifier changes. Edit: Forgot to mention, feel free to close this one and merge your changes as you see fit. |
OK, cool. I didn't want to go opening a new PR with this one pending until you had a chance to comment on the alternative direction. This stuff is no joke to work on and I'd bet you had some time into yours. With regard to following the PostCSS methods; I gleaned that stuff from the code itself. There were some issues for the last major that went into some detail in comments about the token-first parsing deal as well. Nothing official, but just absorbed. Picked up most of that while doing the last rewrite to support v7. FWIW I'm hoping to go the same route with postcss-values-parser because it's so much easier to maintain going that route. Parsers are hard! On your suggestion, closing this one and will open a new PR on the other branch. |
Which issue # if any, does this resolve?
#118
Please check one:
This PR:
This should be a better approach to it than #119, the logic is mostly from core
postcss
. I'm hoping to find a way to consolidate it to one solution across both libraries.