- 
                Notifications
    You must be signed in to change notification settings 
- Fork 15
Add option to eliminate unused classes from DOM #32
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
          
     Open
      
      
            sjoqvist
  wants to merge
  3
  commits into
  css-modules:master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
sjoqvist:empty-locals
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            3 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      
    File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
          
            1 change: 1 addition & 0 deletions
          
          1 
        
  ...-cases/error-composes-not-defined-class-option-exportEmptyLocals-false/expected.error.txt
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1 @@ | ||
| referenced class name "otherClassName" in composes not found | 
        
          
          
            3 changes: 3 additions & 0 deletions
          
          3 
        
  test/test-cases/error-composes-not-defined-class-option-exportEmptyLocals-false/options.js
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| module.exports = { | ||
| exportEmptyLocals: false, | ||
| }; | 
        
          
          
            3 changes: 3 additions & 0 deletions
          
          3 
        
  test/test-cases/error-composes-not-defined-class-option-exportEmptyLocals-false/source.css
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| :local(.className) { | ||
| composes: otherClassName; | ||
| } | 
        
          
          
            34 changes: 34 additions & 0 deletions
          
          34 
        
  test/test-cases/options-exportEmptyLocals-false/expected.css
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* leaf node with contents */ | ||
| ._input__layer1A { | ||
| color: red; | ||
| } | ||
|  | ||
| ._input__layer2A /* doesn't add anything new */ { | ||
| } | ||
|  | ||
| ._input__layer1B { | ||
| /* totally empty, except for this comment */ | ||
| } | ||
|  | ||
| ._input__layer2B { | ||
| background: blue; | ||
| } | ||
|  | ||
| ._input__layer3 { | ||
| } | ||
|  | ||
| ._input__foo > ._input__bar { | ||
| } | ||
|  | ||
| ._input__baz > ._input__qux { | ||
| font-style: italic; | ||
| } | ||
|  | ||
| :export { | ||
| layer1A: _input__layer1A; | ||
| layer2A: _input__layer1A; | ||
| layer2B: _input__layer2B; | ||
| layer3: _input__layer1A _input__layer2B; | ||
| baz: _input__baz; | ||
| qux: _input__qux; | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| module.exports = { | ||
| exportEmptyLocals: false, | ||
| }; | 
        
          
          
            29 changes: 29 additions & 0 deletions
          
          29 
        
  test/test-cases/options-exportEmptyLocals-false/source.css
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* leaf node with contents */ | ||
| :local(.layer1A) { | ||
| color: red; | ||
| } | ||
|  | ||
| :local(.layer2A) /* doesn't add anything new */ { | ||
| composes: layer1A; | ||
| } | ||
|  | ||
| :local(.layer1B) { | ||
| /* totally empty, except for this comment */ | ||
| } | ||
|  | ||
| :local(.layer2B) { | ||
| background: blue; | ||
| composes: layer1B; | ||
| } | ||
|  | ||
| :local(.layer3) { | ||
| composes: layer2A; | ||
| composes: layer2B; | ||
| } | ||
|  | ||
| :local(.foo) /* empty */ > :local(.bar) { | ||
| } | ||
|  | ||
| :local(.baz) /* non-empty */ > :local(.qux) { | ||
| font-style: italic; | ||
| } | ||
        
          
          
            37 changes: 37 additions & 0 deletions
          
          37 
        
  test/test-cases/options-exportEmptyLocals-true/expected.css
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /* leaf node with contents */ | ||
| ._input__layer1A { | ||
| color: red; | ||
| } | ||
|  | ||
| ._input__layer2A /* doesn't add anything new */ { | ||
| } | ||
|  | ||
| ._input__layer1B { | ||
| /* totally empty, except for this comment */ | ||
| } | ||
|  | ||
| ._input__layer2B { | ||
| background: blue; | ||
| } | ||
|  | ||
| ._input__layer3 { | ||
| } | ||
|  | ||
| ._input__foo > ._input__bar { | ||
| } | ||
|  | ||
| ._input__baz > ._input__qux { | ||
| font-style: italic; | ||
| } | ||
|  | ||
| :export { | ||
| layer1A: _input__layer1A; | ||
| layer2A: _input__layer2A _input__layer1A; | ||
| layer1B: _input__layer1B; | ||
| layer2B: _input__layer2B _input__layer1B; | ||
| layer3: _input__layer3 _input__layer2A _input__layer1A _input__layer2B _input__layer1B; | ||
| foo: _input__foo; | ||
| bar: _input__bar; | ||
| baz: _input__baz; | ||
| qux: _input__qux; | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* leaf node with contents */ | ||
| :local(.layer1A) { | ||
| color: red; | ||
| } | ||
|  | ||
| :local(.layer2A) /* doesn't add anything new */ { | ||
| composes: layer1A; | ||
| } | ||
|  | ||
| :local(.layer1B) { | ||
| /* totally empty, except for this comment */ | ||
| } | ||
|  | ||
| :local(.layer2B) { | ||
| background: blue; | ||
| composes: layer1B; | ||
| } | ||
|  | ||
| :local(.layer3) { | ||
| composes: layer2A; | ||
| composes: layer2B; | ||
| } | ||
|  | ||
| :local(.foo) /* empty */ > :local(.bar) { | ||
| } | ||
|  | ||
| :local(.baz) /* non-empty */ > :local(.qux) { | ||
| font-style: italic; | ||
| } | 
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
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.
Let's add couple tests:
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.
Sounds good. Do you separate test cases or should everything go in these existing files?
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.
Let's add them here
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've now force-pushed changes. I had to add the invalid composes in a separate directory, but the other tests were added to the original files. Not entirely sure if I got all your suggestions for tests correctly, but please have a look and let me know.
Some comments are removed, but that's what the current code does as well and I've made the tests reflect that. Since I added the
trueor "default" tests in a separate commit before the other changes, you can check out that commit and runyarn testto confirm it if you wish. You can also see that only the:exportblocks differ:diff test/test-cases/options-exportEmptyLocals-{true,false}/expected.cssAlso, I should mention that I had overlooked the fact that comments can go inside the declaration blocks, so it was good that you pointed that out and I've updated the code accordingly. Let me know if there are any other special cases that I'm unaware of.