-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Fixing import by reference #2729
Conversation
SomMeri
commented
Nov 20, 2015
- refactored how import reference works
- refactored to-css-visitor (this is side product, it was getting complicated)
- fixes issues Extend within (reference) imported files. #1851, Namespace imported less code does not get properly referenced, when there's a (reference) keyword. #1896, Extend from @import (reference) #1878, A file imported by reference and then normally #2716, When using an @import (reference), mixins that contain an & selector get added to the compiled output improperly #1968, Cannot put import by reference inside of a mixin #2162 (similar to Namespace imported less code does not get properly referenced, when there's a (reference) keyword. #1896)
Wow, nice work! |
👍 |
@matthew-dean @seven-phases-max Thank you. This took more then one attempt to get it fully (I hope) working. If nobody objects, I am going to merge it in sometimes next week. |
This comment describes how changes in pull requests are supposed to work. ---- Relevant less.js workflow before changes (this is visible in transform-tree.js): Phase 1: eval - solves imports, mixins calls and detached rulesets calls
Phase 2: JoinSelectorVisitor - joins selectors (paths) in nested rulesets with selectors in their parents Phase 3: ExtendVisitor - process all extends Phase 4: ToCSSVisitor - each visitX function in ToCSSVisitor is responsible for returning its own css equivalent.
The end result should be valid css tree which is then converted into text. -------- New properties:
Visibility blocks are placed on nodes imported by reference. Blocks are NOT placed on their childs, only the root of imported tree has visibility block. Adding visibility block on node means: "this node is root of tree that replaced imported by reference" or alternatively "this node came from one more import by reference then its parent". Property isVisible can return one of three values:
Note: isVisible matters only for selector up until we hit the phase 4. - ToCSSVisitor. -------- New visibility evaluation
Phase 2: JoinSelectorVisitor (e.g. selectors in nested rulesets) - no change New Phase 2.5: Starting from root of ast, everything up to first visibility block is marked as "visible". Nodes with visibility block and their child are left unmodified. Important outcome: each selector and extends now knows whether it came from visible part of the tree or or from something hidden being import by reference. Phase 3: ExtendVisitor
Phase 4: ToCSSVisitor - In addition to generating its own css equivalent, each visitX function is now also responsible for setting replacements
New visitX methods logic:
|
Just curious, does this alter the structure of the AST in any significant way? I was going to start work on a postcss-less plugin that would convert the Less AST into PostCSS nodes so that you could use less in a PostCSS pipeline. |
Also, I know that @lukeapage is working on refactoring the Less lib into ES6 + Babel, so with all that refactoring, might be good to coordinate. |
One more thing, this might be a good opportunity to clean up our PRs at the same time and either merge or reject. |
@matthew-dean It does not alter structure at all, just adds two new properties to |
@SomMeri 👍 |
I merged the pull request in. |