Skip to content

Error "data did not match any variant of untagged enum ValueOrVec" when visiting a style rule with border: none #408

@lxsmnsyc

Description

@lxsmnsyc

Repro: https://lightningcss.dev/playground/index.html#%7B%22minify%22%3Atrue%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%5Cn%20%20.toggle%20%7B%5Cn%20%20%20%20color%3A%20red%3B%5Cn%20%20%20%20border%3A%20none%3B%5Cn%20%20%7D%22%2C%22visitorEnabled%22%3Atrue%2C%22visitor%22%3A%22%7B%5Cn%20%20Rule(rule)%20%7B%5Cn%20%20%20%20if%20(rule.type%20%3D%3D%3D%20'style')%20%7B%5Cn%20%20%20%20%20%20return%20rule%5Cn%20%20%20%20%7D%5Cn%20%20%7D%5Cn%7D%22%2C%22unusedSymbols%22%3A%5B%5D%2C%22version%22%3A%22local%22%7D

For some reason, a style with border: none throws ERROR: data did not match any variant of untagged enum ValueOrVec on visitor even when untouched. Commenting border: none and the output works fine. I'm not sure which other properties has this behavior.

I'm trying to modify selectors but this issue, which is kinda unrelated to my goal, serves as a huge blocker.

Edit:
After experimenting a bit, it seems that border: none's AST is

{
  property: 'border',
  value: { width: { type: 'medium' }, style: 'none', color: 'currentcolor' }
}

whereas in the type definitions, currentcolor is defined as

export type CurrentColor = {
  type: "currentcolor";
};

so the correct output must be

{
  property: 'border',
  value: {
    width: {
      type: 'medium'
    },
    style: 'none',
    color: {
      type: 'currentcolor'
    }
  }
}

on the contrary, the color property is defined as a union of object types so it can never be string. The issue here is at the AST generation.

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