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

Token name can be an empty string #195

Open
romainmenke opened this issue Dec 7, 2022 · 5 comments
Open

Token name can be an empty string #195

romainmenke opened this issue Dec 7, 2022 · 5 comments

Comments

@romainmenke
Copy link
Contributor

The current specification does not require token names to be strings with a non-zero length.

https://tr.designtokens.org/format/#name-and-value

{
  "": { "$value": "3rem" },
  "other": { "$value": "{}" }
}

This parses just fine :

const json = `{
  "": { "$value": "3rem" },
  "other": { "$value": "{}" }
}`;

console.log(JSON.parse(json));
// { '': { '$value': '3rem' }, other: { '$value': '{}' } }

Is this intended?

@ilikescience
Copy link

Interesting! It's funny that JSON allows for this.

My feeling is that token names have to be non-zero. I can't imagine a use case for a token called "" ... but open to possibilities if we can think of them.

@romainmenke
Copy link
Contributor Author

My feeling is that token names have to be non-zero.

I agree.


This is allowed in today's specification text, but is really awkward.

{
  "": {
    "": {
      "": {
        "": { "$value": "3rem" }
      }
    }
  }
}

Token ... has value 3rem

@srouse
Copy link

srouse commented Jan 9, 2023

I found this useful for stepped tokens where the middle value represents what people think of as the color:

{
  “color”: {
    “primary”: {
	…
        “04”: { "$value": “#aa0000” },
        “05”: { "$value": “#bb0000” },
	"": { "$value": “#bb0000” },
        “06”: { "$value": “#cc0000” },
	…
    }
  }
}

Which can be transformed into:

…
color-primary-04: #aa0000;
color-primary-05: #bb0000;
color-primary: #bb0000;
color-primary-06: #cc0000;
…

@romainmenke
Copy link
Contributor Author

romainmenke commented Jan 9, 2023

@srouse That looks like a bug in your translation tool :/

I don't understand why it would convert this to color-primary.
It should be color-primary- when following the naming logic for the other tokens.
Now you have a naming conflict between a specific token and a token group.


It does illustrate why it is important for the specification to be explicit about allowing this or not. It is an edge case that should not be overlooked by implementers.

@kevinmpowell
Copy link
Contributor

Related to #200

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

5 participants