Skip to content

Commit c382f9a

Browse files
authored
postcss-design-tokens : prevent stack overflow (csstools#584)
1 parent 109ee10 commit c382f9a

9 files changed

Lines changed: 36 additions & 2 deletions

File tree

.github/ISSUE_TEMPLATE/css-issue.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ body:
7272
- PostCSS Custom Media Queries
7373
- PostCSS Custom Properties
7474
- PostCSS Custom Selectors
75+
- PostCSS Design Tokens
7576
- PostCSS Dir Pseudo Class
7677
- PostCSS Double Position Gradients
7778
- PostCSS Env Function

.github/ISSUE_TEMPLATE/plugin-issue.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ body:
7474
- PostCSS Custom Media Queries
7575
- PostCSS Custom Properties
7676
- PostCSS Custom Selectors
77+
- PostCSS Design Tokens
7778
- PostCSS Dir Pseudo Class
7879
- PostCSS Double Position Gradients
7980
- PostCSS Env Function

.github/labeler.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@
6868
- plugins/postcss-custom-selectors/**
6969
- experimental/postcss-custom-selectors/**
7070

71+
"plugins/postcss-design-tokens":
72+
- plugins/postcss-design-tokens/**
73+
- experimental/postcss-design-tokens/**
74+
7175
"plugins/postcss-dir-pseudo-class":
7276
- plugins/postcss-dir-pseudo-class/**
7377
- experimental/postcss-dir-pseudo-class/**

plugins/postcss-design-tokens/.tape.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,8 @@ postcssTape(plugin)({
113113
importAtRuleName: 'tokens'
114114
}
115115
},
116+
'issue-583': {
117+
message: 'A meaningful error message is given and no stack overflow.',
118+
warnings: 1
119+
},
116120
});

plugins/postcss-design-tokens/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changes to PostCSS Design Tokens
22

3+
### 1.1.1 (Unreleased)
4+
5+
- Prevent stack overflow failures when importing files with format `style-dictionary3` that are not of that format.
6+
37
### 1.1.0 (Aug 2, 2022)
48

59
- Added `valueFunctionName` option to control the `design-token` function name.

plugins/postcss-design-tokens/src/data-formats/style-dictionary/v3/group.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,20 @@ export type StyleDictionaryV3TokenGroup = {
77
}
88

99
function extractTokens(node: StyleDictionaryV3TokenGroup, path: Array<string>, filePath: string): Map<string, StyleDictionaryV3TokenValue> {
10-
const result: Map<string,StyleDictionaryV3TokenValue> = new Map();
10+
const result: Map<string, StyleDictionaryV3TokenValue> = new Map();
1111
for (const key in node) {
1212
if (Object.hasOwnProperty.call(node, key)) {
13+
if (
14+
typeof node[key] !== 'object' ||
15+
Array.isArray(node[key]) &&
16+
node[key] === null
17+
) {
18+
throw new Error(`Parsing error at "${[...path, key].join('.')}"`);
19+
}
20+
1321
const child = Object(node[key]);
1422
if (!child) {
15-
throw new Error('Parsing error');
23+
throw new Error(`Parsing error at "${[...path, key].join('.')}"`);
1624
}
1725

1826
if (typeof child['value'] !== 'undefined') {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@design-tokens url('./tokens/issue-583.json') format('style-dictionary3');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"color": {
3+
"internal": {
4+
"neutrals": {
5+
"darkest": "#1E1E1E",
6+
"lightest": "#FFFFFF"
7+
}
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)