Skip to content

Commit 606af51

Browse files
W3C Syntax refactor to allow value & type token names/groups (#1100)
* feat: allow use of value/type/description as token names/groupnames in W3C syntax * chore: rename from W3C to Dtcg
1 parent cd9f484 commit 606af51

File tree

72 files changed

+1055
-615
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1055
-615
lines changed

.changeset/cuddly-cheetahs-drum.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'style-dictionary': minor
3+
---
4+
5+
Rename `typeW3CDelegate` utility function to `typeDtcgDelegate`, as using "W3C" is highly discouraged when the standard isn't a W3C standard yet.

.changeset/grumpy-peaches-flow.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
'style-dictionary': patch
33
---
44

5-
Fix small issue in type w3c delegate utility type tracking.
5+
Fix small issue in type DTCG delegate utility type tracking.

.changeset/neat-zoos-reflect.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'style-dictionary': minor
3+
---
4+
5+
Support the use of "value"/"type"/"description" as token names or token group names, at the sacrifice of now no longer being able to combine non-DTCG and DTCG syntax within the same token dictionary.

.changeset/ninety-geckos-build.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
'style-dictionary': patch
33
---
44

5-
Expose typeW3CDelegate utility. Don't take "value" into account anymore to determine that it's a design token, use $value.
5+
Expose `typeDtcgDelegate` utility. Don't take `value` into account anymore to determine that it's a design token, use `$value`.

.changeset/rich-pianos-walk.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
'style-dictionary': minor
33
---
44

5-
Support W3C Draft specification for Design Tokens, by adding support for $value, $type and $description properties.
5+
Support Design Token Community Group Draft specification for Design Tokens, by adding support for $value, $type and $description properties.

CHANGELOG.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222

2323
### Patch Changes
2424

25-
- 0c1a36f: Fix small issue in type w3c delegate utility type tracking.
26-
- 0c1a36f: Expose typeW3CDelegate utility. Don't take "value" into account anymore to determine that it's a design token, use $value.
25+
- 0c1a36f: Fix small issue in type DTCG delegate utility type tracking.
26+
- 0c1a36f: Expose `typeDtcgDelegate` utility. Don't take `value` into account anymore to determine that it's a design token, use `$value`.
2727

2828
## 4.0.0-prerelease.9
2929

3030
### Minor Changes
3131

32-
- 294fd0e: Support W3C Draft specification for Design Tokens, by adding support for $value, $type and $description properties.
32+
- 294fd0e: Support Design Token Community Group Draft specification for Design Tokens, by adding support for $value, $type and $description properties.
3333

3434
### Patch Changes
3535

__integration__/__snapshots__/customFormats.test.snap.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,8 @@ snapshots["inline custom with new args should match snapshot"] =
962962
},
963963
"options": {
964964
"otherOption": "Test",
965-
"showFileHeader": true
965+
"showFileHeader": true,
966+
"usesDtcg": false
966967
}
967968
}`;
968969
/* end snapshot inline custom with new args should match snapshot */
@@ -1893,7 +1894,8 @@ snapshots["register custom format with new args should match snapshot"] =
18931894
},
18941895
"options": {
18951896
"otherOption": "Test",
1896-
"showFileHeader": true
1897+
"showFileHeader": true,
1898+
"usesDtcg": false
18971899
}
18981900
}`;
18991901
/* end snapshot register custom format with new args should match snapshot */

__integration__/w3c-forward-compat.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('integration', () => {
2929
* - $type special property & inherits from ancestors
3030
* - $description special property
3131
*/
32-
describe('W3C DTCG draft spec forward compatibility', async () => {
32+
describe('DTCG draft spec forward compatibility', async () => {
3333
const sd = new StyleDictionary({
3434
tokens: {
3535
colors: {
@@ -58,14 +58,14 @@ describe('integration', () => {
5858
type: 'value',
5959
matcher: (token) => token.$type === 'color',
6060
transformer: (token) => {
61-
return Color(token.$value).toRgbString();
61+
return Color(sd.options.usesDtcg ? token.$value : token.value).toRgbString();
6262
},
6363
},
6464
'custom/add/px': {
6565
type: 'value',
6666
matcher: (token) => token.$type === 'dimension',
6767
transformer: (token) => {
68-
return `${token.$value}px`;
68+
return `${sd.options.usesDtcg ? token.$value : token.value}px`;
6969
},
7070
},
7171
},

__tests__/StyleDictionary.test.js

+13
Original file line numberDiff line numberDiff line change
@@ -326,4 +326,17 @@ describe('StyleDictionary class + extend method', () => {
326326
expect(sd.tokens.dimensions.nested.deep.lg.$type).to.equal('dimension');
327327
expect(sd.tokens.dimensions.nope.$type).to.equal('spacing');
328328
});
329+
330+
it('should detect usage of DTCG draft spec tokens', async () => {
331+
const sd = new StyleDictionary({
332+
tokens: {
333+
datalist: {
334+
key: { color: { $value: '#222' } },
335+
value: { color: { $value: '#000' } },
336+
},
337+
},
338+
});
339+
await sd.hasInitialized;
340+
expect(sd.options.usesDtcg).to.be.true;
341+
});
329342
});

__tests__/buildFile.test.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,25 @@ describe('buildFile', () => {
3939
});
4040

4141
it('should error if format doesnt exist or isnt a function', () => {
42-
expect(buildFile.bind(null, { destination: '__tests__output/test.txt' }, {}, {})).to.throw(
42+
expect(buildFile.bind(null, { destination: '__tests__output/test.txt' }, {}, {}, {})).to.throw(
4343
'Please enter a valid file format',
4444
);
4545
expect(
46-
buildFile.bind(null, { destination: '__tests__output/test.txt', format: {} }, {}, {}),
46+
buildFile.bind(null, { destination: '__tests__output/test.txt', format: {} }, {}, {}, {}),
4747
).to.throw('Please enter a valid file format');
4848
expect(
49-
buildFile.bind(null, { destination: '__tests__/__output/test.txt', format: [] }, {}, {}),
49+
buildFile.bind(null, { destination: '__tests__/__output/test.txt', format: [] }, {}, {}, {}),
5050
).to.throw('Please enter a valid file format');
5151
});
5252

5353
it('should error if destination doesnt exist or isnt a string', () => {
54-
expect(buildFile.bind(null, { format }, {}, {})).to.throw('Please enter a valid destination');
55-
expect(buildFile.bind(null, { format, destination: [] }, {}, {})).to.throw(
54+
expect(buildFile.bind(null, { format }, {}, {}, {})).to.throw(
5655
'Please enter a valid destination',
5756
);
58-
expect(buildFile.bind(null, { format, destination: {} }, {}, {})).to.throw(
57+
expect(buildFile.bind(null, { format, destination: [] }, {}, {}, {})).to.throw(
58+
'Please enter a valid destination',
59+
);
60+
expect(buildFile.bind(null, { format, destination: {} }, {}, {}, {})).to.throw(
5961
'Please enter a valid destination',
6062
);
6163
});
@@ -81,7 +83,7 @@ describe('buildFile', () => {
8183

8284
it('should generate warning messages for output name collisions', () => {
8385
GroupMessages.clear(PROPERTY_NAME_COLLISION_WARNINGS);
84-
buildFile({ destination, format }, {}, dictionary);
86+
buildFile({ destination, format }, {}, dictionary, {});
8587

8688
const collisions = dictionary.allTokens
8789
.map(
@@ -107,7 +109,7 @@ describe('buildFile', () => {
107109

108110
it('should not warn users if the format is a nested format', () => {
109111
const consoleStub = stubMethod(console, 'log');
110-
buildFile({ destination, format: nestedFormat }, {}, dictionary);
112+
buildFile({ destination, format: nestedFormat }, {}, dictionary, {});
111113
expect(consoleStub.calledWith(chalk.bold.green(`✔︎ ${destination}`))).to.be.true;
112114
});
113115
});
@@ -137,6 +139,7 @@ describe('buildFile', () => {
137139
},
138140
{},
139141
dictionary,
142+
{},
140143
);
141144
expect(fileExists('__tests__/__output/test.emptyTokens')).to.be.false;
142145
});
@@ -151,6 +154,7 @@ describe('buildFile', () => {
151154
buildPath: '__tests__/__output/',
152155
},
153156
{},
157+
{},
154158
);
155159
expect(fileExists('__tests__/__output/test.txt')).to.be.true;
156160
});

__tests__/buildFiles.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,17 @@ describe('buildFiles', () => {
104104
});
105105

106106
it('should work without buildPath', () => {
107-
buildFiles(dictionary, platform);
107+
buildFiles(dictionary, platform, {});
108108
expect(fileExists('__tests__/__output/test.json')).to.be.true;
109109
});
110110

111111
it('should work with buildPath', () => {
112-
buildFiles(dictionary, platformWithBuildPath);
112+
buildFiles(dictionary, platformWithBuildPath, {});
113113
expect(fileExists('__tests__/__output/test.json')).to.be.true;
114114
});
115115

116116
it('should work with a filter', () => {
117-
buildFiles(dictionary, platformWithFilter);
117+
buildFiles(dictionary, platformWithFilter, {});
118118
expect(fileExists('__tests__/__output/test.json')).to.be.true;
119119
const output = JSON.parse(fs.readFileSync(resolve('__tests__/__output/test.json')));
120120
expect(output).to.have.property('bingo');

__tests__/cleanDir.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ describe('cleanDir', () => {
3434
{ destination: 'test.txt', format },
3535
{ buildPath: '__tests__/__output/extradir1/extradir2/' },
3636
{},
37+
{},
3738
);
3839
cleanFile(
3940
{ destination: 'test.txt', format },

__tests__/cleanDirs.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ describe('cleanDirs', () => {
5555
});
5656

5757
it('should delete without buildPath', () => {
58-
buildFiles(dictionary, platform);
58+
buildFiles(dictionary, platform, {});
5959
cleanFiles(platform);
6060
cleanDirs(platform);
6161
expect(dirExists('__tests__/__output/extradir1/extradir2')).to.be.false;
6262
expect(dirExists('__tests__/__output/extradir1')).to.be.false;
6363
});
6464

6565
it('should delete with buildPath', () => {
66-
buildFiles(dictionary, platformWithBuildPath);
66+
buildFiles(dictionary, platformWithBuildPath, {});
6767
cleanFiles(platformWithBuildPath);
6868
cleanDirs(platformWithBuildPath);
6969
expect(dirExists('__tests__/__output/extradir1/extradir2')).to.be.false;

__tests__/cleanFile.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('cleanFile', () => {
2929
});
3030

3131
it('should delete a file properly', () => {
32-
buildFile({ destination: 'test.txt', format }, { buildPath: '__tests__/__output/' }, {});
32+
buildFile({ destination: 'test.txt', format }, { buildPath: '__tests__/__output/' }, {}, {});
3333
cleanFile({ destination: 'test.txt', format }, { buildPath: '__tests__/__output/' }, {});
3434
expect(fileExists('__tests__/__output/test.txt')).to.be.false;
3535
});

__tests__/cleanFiles.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ describe('cleanFiles', () => {
5454
});
5555

5656
it('should delete without buildPath', () => {
57-
buildFiles(dictionary, platform);
57+
buildFiles(dictionary, platform, {});
5858
cleanFiles(platform);
5959
expect(fileExists('__tests__/__output/test.json')).to.be.false;
6060
});
6161

6262
it('should delete with buildPath', () => {
63-
buildFiles(dictionary, platformWithBuildPath);
63+
buildFiles(dictionary, platformWithBuildPath, {});
6464
cleanFiles(platformWithBuildPath);
6565
expect(fileExists('__tests__/t__/__output/test.json')).to.be.false;
6666
});

__tests__/common/formatHelpers/__snapshots__/createPropertyFormatter.test.snap.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,21 @@ snapshots["common formatHelpers createPropertyFormatter commentStyle allows over
3434
$color-green: #00FF00;`;
3535
/* end snapshot common formatHelpers createPropertyFormatter commentStyle allows overriding formatting commentStyle 2 */
3636

37-
snapshots["common formatHelpers createPropertyFormatter commentStyle supports W3C spec $description property for comments 1"] =
37+
snapshots["common formatHelpers createPropertyFormatter commentStyle supports DTCG spec $description property for comments 1"] =
3838
` --color-red: #FF0000; /* Foo bar qux red */`;
39-
/* end snapshot common formatHelpers createPropertyFormatter commentStyle supports W3C spec $description property for comments 1 */
39+
/* end snapshot common formatHelpers createPropertyFormatter commentStyle supports DTCG spec $description property for comments 1 */
4040

41-
snapshots["common formatHelpers createPropertyFormatter commentStyle supports W3C spec $description property for comments 2"] =
41+
snapshots["common formatHelpers createPropertyFormatter commentStyle supports DTCG spec $description property for comments 2"] =
4242
` --color-green: #00FF00; /* Foo bar qux green */`;
43-
/* end snapshot common formatHelpers createPropertyFormatter commentStyle supports W3C spec $description property for comments 2 */
43+
/* end snapshot common formatHelpers createPropertyFormatter commentStyle supports DTCG spec $description property for comments 2 */
4444

45-
snapshots["common formatHelpers createPropertyFormatter commentStyle supports W3C spec $description property for comments 3"] =
45+
snapshots["common formatHelpers createPropertyFormatter commentStyle supports DTCG spec $description property for comments 3"] =
4646
` /**
4747
* Foo
4848
* bar
4949
* qux
5050
* blue
5151
*/
5252
--color-blue: #0000FF;`;
53-
/* end snapshot common formatHelpers createPropertyFormatter commentStyle supports W3C spec $description property for comments 3 */
53+
/* end snapshot common formatHelpers createPropertyFormatter commentStyle supports DTCG spec $description property for comments 3 */
5454

__tests__/common/formatHelpers/createPropertyFormatter.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ describe('common', () => {
359359
await expect(sassRed).to.matchSnapshot(2);
360360
});
361361

362-
it('supports W3C spec $description property for comments', async () => {
362+
it('supports DTCG spec $description property for comments', async () => {
363363
const descriptionDictionary = {
364364
color: {
365365
red: {

0 commit comments

Comments
 (0)