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

fix: only restore subvalues with refs in objects and arrays #35

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mihkeleidast
Copy link
Contributor

Hey again 👋

We have a transform that replaces the numeric font-weights with the corresponding keyword. In one special case, the weight itself is not a separate token reference, it is defined directly in a typography style object.

Source is something like this:

{
  "small": {
    "value": {
      "fontFamily": "{fontFamily.code}",
      "fontWeight": "700",
      "lineHeight": "{size.lineHeight.xsmall}",
      "fontSize": "{size.font.xsmall}"
    }
  }
}

Expected output is:

{
  "small": {
    "value": {
      "fontFamily": "{fontFamily.code}",
      "fontWeight": "Bold",
      "lineHeight": "{size.lineHeight.xsmall}",
      "fontSize": "{size.font.xsmall}"
    }
  }
}

Now, our transform correctly replaces this inside of the object, but the refs restoring function ignores that, as it blindly replaces the entire object when any of the object keys are using refs.

So here's a fix for that, should recursively manage deeper object values as well, if they are a thing.

@changeset-bot
Copy link

changeset-bot bot commented Jun 1, 2023

🦋 Changeset detected

Latest commit: 7f055ec

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@divriots/style-dictionary-to-figma Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@@ -74,7 +74,7 @@ describe('trim-name', () => {
original: {
value: ['{shadow.core.4}', 'pre-transformed-shadow-2'],
},
value: ['{shadow.core.4}', 'pre-transformed-shadow-2'],
value: ['{shadow.core.4}', '0 0 2px rgba(0,0,0,0.6)'],
Copy link
Contributor Author

@mihkeleidast mihkeleidast Jun 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this expected object was faulty before, as it also reverted the transform done on the original value.

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

Successfully merging this pull request may close these issues.

1 participant