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

Negative numbers skipped over by size/rem transform #1408

Open
Tenga opened this issue Dec 9, 2024 · 1 comment
Open

Negative numbers skipped over by size/rem transform #1408

Tenga opened this issue Dec 9, 2024 · 1 comment

Comments

@Tenga
Copy link
Contributor

Tenga commented Dec 9, 2024

Description

When a value of a dimension token that would normally be transformed by the size/rem encounters a negative number, it's skipped and not transformed. size/px for example, doesn't seem to have this issue.

From what I can tell, this issue is due to a check in size/rem, that is specific to that transform.

Reproduction

Input file

{
  "typography": {
    "letterSpacing": {
      "$type": "dimension",
      "test1": {
        "$value": -1
      },
      "test2": {
        "$value": 1
      }
    }
  }
}

json/nested output with size/rem

{
  "typography": {
    "letterSpacing": {
      "test1": -1,
      "test2": "1rem"
    }
  }
}

json/nested output with size/px

{
  "typography": {
    "letterSpacing": {
      "test1": "-1px",
      "test2": "1px"
    }
  }
}
@jorenbroekema
Copy link
Collaborator

https://developer.mozilla.org/en-US/docs/Web/CSS/number#examples we could add +-e as valid number characters in the regex so it doesn't false-positively think there is already a unit.

That said, I think doing parseFloat removes units from stringified numbers already which kinda means we may not need to worry about doing a check whether the value already has a unit. It gets stripped anyways by parseFloat. This is why size/px works and isn't bugged. We should add plenty of tests though to ensure we don't make false assumptions about the parseFloat stripping units behavior

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants