Skip to content

Convert css properties to shorthands when css vars are used.  #154

@nicksrandall

Description

@nicksrandall

Currently, parcel-css will covert css properties to shorthand notation when it is safe to do so:

.should-collapse {
  border-left-style: none;
  border-left-width: 0;
  border-left-color: #333;
  border-top-style: none;
  border-top-width: 0;
  border-top-color: #333;
  border-right-style: none;
  border-right-width: 0;
  border-right-color: #333;
  border-bottom-style: none;
  border-bottom-width: 0;
  border-bottom-color: #333;
}

becomes

.should-collapse {
  border: none;
}

See: https://parcel-css.vercel.app/#%7B%22minify%22%3Afalse%2C%22nesting%22%3Atrue%2C%22customMedia%22%3Atrue%2C%22cssModules%22%3Afalse%2C%22analyzeDependencies%22%3Afalse%2C%22targets%22%3A%7B%22chrome%22%3A6225920%7D%2C%22source%22%3A%22.should-collapse%20%7B%5Cn%20%20border-left-style%3A%20none%3B%5Cn%20%20border-left-width%3A%200%3B%5Cn%20%20border-left-color%3A%20%23333%3B%5Cn%20%20border-top-style%3A%20none%3B%5Cn%20%20border-top-width%3A%200%3B%5Cn%20%20border-top-color%3A%20%23333%3B%5Cn%20%20border-right-style%3A%20none%3B%5Cn%20%20border-right-width%3A%200%3B%5Cn%20%20border-right-color%3A%20%23333%3B%5Cn%20%20border-bottom-style%3A%20none%3B%5Cn%20%20border-bottom-width%3A%200%3B%5Cn%20%20border-bottom-color%3A%20%23333%3B%5Cn%7D%22%2C%22unusedSymbols%22%3A%5B%5D%2C%22version%22%3A%22local%22%7D

But when the above is changed to use css variables:

.should-collapse {
  border-left-style: none;
  border-left-width: 0;
  border-left-color: var(--theme-colors-gray-200);
  border-top-style: none;
  border-top-width: 0;
  border-top-color: var(--theme-colors-gray-200);
  border-right-style: none;
  border-right-width: 0;
  border-right-color: var(--theme-colors-gray-200);
  border-bottom-style: none;
  border-bottom-width: 0;
  border-bottom-color: var(--theme-colors-gray-200);
}

The conversion to shorthand does not happen (but I think it should).

See: https://parcel-css.vercel.app/#%7B%22minify%22%3Afalse%2C%22nesting%22%3Atrue%2C%22customMedia%22%3Atrue%2C%22cssModules%22%3Afalse%2C%22analyzeDependencies%22%3Afalse%2C%22targets%22%3A%7B%22chrome%22%3A6225920%7D%2C%22source%22%3A%22.should-collapse%20%7B%5Cn%20%20border-left-style%3A%20none%3B%5Cn%20%20border-left-width%3A%200%3B%5Cn%20%20border-left-color%3A%20var(--theme-colors-gray-200)%3B%5Cn%20%20border-top-style%3A%20none%3B%5Cn%20%20border-top-width%3A%200%3B%5Cn%20%20border-top-color%3A%20var(--theme-colors-gray-200)%3B%5Cn%20%20border-right-style%3A%20none%3B%5Cn%20%20border-right-width%3A%200%3B%5Cn%20%20border-right-color%3A%20var(--theme-colors-gray-200)%3B%5Cn%20%20border-bottom-style%3A%20none%3B%5Cn%20%20border-bottom-width%3A%200%3B%5Cn%20%20border-bottom-color%3A%20var(--theme-colors-gray-200)%3B%5Cn%7D%22%2C%22unusedSymbols%22%3A%5B%5D%2C%22version%22%3A%22local%22%7D

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions