-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: no unnecessary type change in resolveMath
- Loading branch information
1 parent
aac4e47
commit 2e8576e
Showing
5 changed files
with
110 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@tokens-studio/sd-transforms': patch | ||
--- | ||
|
||
resolveMath no longer unnecessarily changes the token type to number if the token value is a string without any expressions to resolve. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { expect } from '@esm-bundle/chai'; | ||
import StyleDictionary from 'style-dictionary'; | ||
import { promises } from 'fs'; | ||
import path from 'path'; | ||
import { cleanup, init } from './utils.js'; | ||
|
||
const outputDir = 'test/integration/tokens/'; | ||
const outputFileName = 'vars.css'; | ||
const outputFilePath = path.resolve(outputDir, outputFileName); | ||
|
||
const cfg = { | ||
source: ['test/integration/tokens/output-references.tokens.json'], | ||
platforms: { | ||
css: { | ||
transforms: ['ts/resolveMath', 'name/cti/kebab'], | ||
prefix: 'sd', | ||
buildPath: outputDir, | ||
files: [ | ||
{ | ||
destination: outputFileName, | ||
format: 'css/variables', | ||
options: { | ||
outputReferences: true, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}; | ||
|
||
let dict: StyleDictionary.Core | undefined; | ||
|
||
describe('outputReferences integration', () => { | ||
beforeEach(() => { | ||
if (dict) { | ||
cleanup(dict); | ||
} | ||
dict = init(cfg); | ||
}); | ||
|
||
afterEach(() => { | ||
if (dict) { | ||
cleanup(dict); | ||
} | ||
}); | ||
|
||
it('supports outputReferences with resolveMath', async () => { | ||
const file = await promises.readFile(outputFilePath, 'utf-8'); | ||
console.log(file); | ||
expect(file).to.include(`--sd-my-base-token: 11;`); | ||
expect(file).to.include(`--sd-my-reference-token: var(--sd-my-base-token);`); | ||
}); | ||
|
||
// Pending Style-Dictionary v3 release with the new outputReferences fixes | ||
it.skip('supports outputReferences with resolveMath when evaluating an expression', async () => { | ||
const file = await promises.readFile(outputFilePath, 'utf-8'); | ||
expect(file).to.include(`--sd-transformed-base-token: 4;`); | ||
expect(file).to.include(`--sd-transformed-reference-token: 5 * var(--sd-my-base-token);`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"my": { | ||
"base": { | ||
"token": { | ||
"value": "11", | ||
"type": "spacing" | ||
} | ||
}, | ||
"reference": { | ||
"token": { | ||
"value": "{my.base.token}", | ||
"type": "spacing" | ||
} | ||
} | ||
}, | ||
"transformed": { | ||
"base": { | ||
"token": { | ||
"value": "4", | ||
"type": "spacing" | ||
} | ||
}, | ||
"reference": { | ||
"token": { | ||
"value": "{my.base.token} * 5", | ||
"type": "spacing" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters