Skip to content

Question about what qualifies as a value #85

@AKST

Description

@AKST

Hi, so I wrote a PostCSS plugin for responsive values, and where you define a couple of branches for a value for different media queries with intended use looking like this

@value fontSize: media-value(
  case: "a" as: "18px",
  case: "b" as: "16px",
  case: "c" as: "16px",
  case: "d" as: "14px",
  else: "14px",
);

.fontDef {
  font-size: fontSize;
}

I would have expected without adding my plugin css modules would have copied the value of fontSize into the rule fontDef and you would have output like:

.fontDef {
  font-size: media-value(
    case: "a" as: "18px",
    case: "b" as: "16px",
    case: "c" as: "16px",
    case: "d" as: "14px",
    else: "14px",
  );
}

So when my plugin passed over it, it could expand the value over the rule so I would get

.fontDef {
  font-size: 14px;
}

@media a { .fontDef { font-size: 18px; } }
@media b { .fontDef { font-size: 16px; } }
@media c { .fontDef { font-size: 16px; } }
@media d { .fontDef { font-size: 14px; } }

But it turns out the CSS remains completely untransformed from the original CSS, am I missing something? Is because the value defined is too gnarly for CSS Modules to interpret?


Update

So it turns out if I remove all new lines from the value the output is correct. So if it's like this....

@value fontSize: media-value(case: "a" as: "18px", case: "b" as: "16px", case: "c" as: "16px", case: "d" as: "14px", else: "14px");

.fontDef {
  font-size: fontSize;
}

CSS Modules transforms the value into this

.fontDef {
  font-size: media-value(case: "a" as: "18px", case: "b" as: "16px", case: "c" as: "16px", case: "d" as: "14px", else: "14px");
}

Questions! (Update 2)

  1. Does this qualify as a bug? If so are you open to pull requests :)
  2. Would a valid workaround be...
    • Having a plugin in the before plugin group, to strip the newlines from @value AtRules
    • Then having the original PostCSS Plugin in the after plugin group in the config to operate on the version with new lines stripped
    • Would this work in the mean time?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions