-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat(variables-scss): Add debug option for exporter #DS-1505
- Loading branch information
1 parent
e8b7bea
commit 35824e2
Showing
8 changed files
with
112 additions
and
61 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
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
[ | ||
{ | ||
"key": "generateDisclaimer", | ||
"key": "generateOriginalDataFiles", | ||
"type": "boolean", | ||
"default": false, | ||
"title": "Show Generated File Disclaimer", | ||
"description": "When enabled, a disclaimer showing the fact that the file was generated automatically and should not be changed manually will appear in all style styles" | ||
"title": "Generate Original Data Files", | ||
"description": "When enabled, the original data files will be generated in the output directory" | ||
} | ||
] |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"generateDisclaimer": true | ||
"generateOriginalDataFiles": false | ||
} |
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
Large diffs are not rendered by default.
Oops, something went wrong.
42 changes: 42 additions & 0 deletions
42
exporters/variables-scss/src/helpers/__tests__/safeStringify.test.ts
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,42 @@ | ||
import { safeStringify } from '../safeStringify'; | ||
|
||
type CircularObject = { [key: string]: CircularObject | unknown }; | ||
|
||
describe('safeStringify', () => { | ||
it('should stringify a simple object', () => { | ||
const obj = { key: 'value', number: 42 }; | ||
const result = safeStringify(obj); | ||
|
||
expect(result).toBe(JSON.stringify(obj, null, 2)); | ||
}); | ||
|
||
it('should handle circular references in objects', () => { | ||
const obj: CircularObject = { key: 'value' }; | ||
obj.self = obj; // Introduce circular reference | ||
|
||
const result = safeStringify(obj); | ||
|
||
expect(result).toContain('"self": "CIRCULAR_REFERENCE"'); | ||
}); | ||
|
||
it('should handle nested objects with no circular references', () => { | ||
const obj = { outer: { inner: { key: 'value' } } }; | ||
const result = safeStringify(obj); | ||
|
||
expect(result).toBe(JSON.stringify(obj, null, 2)); | ||
}); | ||
|
||
it('should handle arrays within objects', () => { | ||
const obj = { list: [1, 2, 3] }; | ||
const result = safeStringify(obj); | ||
|
||
expect(result).toBe(JSON.stringify(obj, null, 2)); | ||
}); | ||
|
||
it('should handle null values', () => { | ||
const obj = { key: null }; | ||
const result = safeStringify(obj); | ||
|
||
expect(result).toBe(JSON.stringify(obj, null, 2)); | ||
}); | ||
}); |
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,20 @@ | ||
export const safeStringify = (obj: object) => { | ||
let cache: string[] | null = []; | ||
const str = JSON.stringify( | ||
obj, | ||
(key, value) => { | ||
if (typeof value === 'object' && value !== null) { | ||
if (cache?.includes(value)) { | ||
return 'CIRCULAR_REFERENCE'; | ||
} | ||
cache?.push(value); | ||
} | ||
|
||
return value; | ||
}, | ||
2, | ||
); | ||
cache = null; | ||
|
||
return str; | ||
}; |
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