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

Analyse ternary expressions when detecting unused CSS #696

Closed
Rich-Harris opened this issue Jul 7, 2017 · 3 comments
Closed

Analyse ternary expressions when detecting unused CSS #696

Rich-Harris opened this issue Jul 7, 2017 · 3 comments

Comments

@Rich-Harris
Copy link
Member

In 1.24, Svelte will warn on unused selectors, but cases like this result in a false negative:

<button class='{{active ? "active" : "inactive"}}'>click me</button>

<style>
  .active {...}
  .inactive {...}
  .irrelevant {...}
</style>

It's actually not very hard to determine that the button has two possible classes — active and inactive — and optimise accordingly.

@PaulBGD
Copy link
Member

PaulBGD commented Jul 7, 2017

What if the class is computed by a compute function?

@Rich-Harris
Copy link
Member Author

In some cases we could do it:

export default {
  computed: {
    buttonClass(active) {
      return active ? 'active' : 'inactive';
    }
  }
};

It would require a bit more machinery, but we can determine that the return value of buttonClass must be either active or inactive.

In some cases it would be much harder:

import buttonClass from './buttonClass.js';

export default {
  computed: {
    buttonClass(active) {
      return buttonClass(active);
    }
  }
};

The same goes for helper functions. Inline expressions are definitely easier though.

@Rich-Harris
Copy link
Member Author

Inline expressions are now handled. Have left computed/helper equivalents at least for the time being

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

No branches or pull requests

2 participants