Commit
Author: Wannes Salomé [mail@wannessalome.nl]
Committer: GitHub [noreply@github.com] Mon, 16 Oct 2023 17:33:42 +0000
Hash: 4827b30c8569b2faf10d2dc3a371a125d4ad930d
Timestamp: Mon, 16 Oct 2023 17:33:42 +0000 (1 year ago)

+61 -10 +/-3 browse
fix referencing of elastic easing (#428)
fix referencing of elastic easing (#428)

* fix referencing of elastic easing

* add test that checks if references are valid
1diff --git a/src/props.easing.css b/src/props.easing.css
2index d0d0362..9e90ebb 100644
3--- a/src/props.easing.css
4+++ b/src/props.easing.css
5 @@ -44,11 +44,11 @@
6 --ease-elastic-3: var(--ease-elastic-out-3);
7 --ease-elastic-4: var(--ease-elastic-out-4);
8 --ease-elastic-5: var(--ease-elastic-out-5);
9- --ease-squish-1: var(--elastic-in-out-1);
10- --ease-squish-2: var(--elastic-in-out-2);
11- --ease-squish-3: var(--elastic-in-out-3);
12- --ease-squish-4: var(--elastic-in-out-4);
13- --ease-squish-5: var(--elastic-in-out-5);
14+ --ease-squish-1: var(--ease-elastic-in-out-1);
15+ --ease-squish-2: var(--ease-elastic-in-out-2);
16+ --ease-squish-3: var(--ease-elastic-in-out-3);
17+ --ease-squish-4: var(--ease-elastic-in-out-4);
18+ --ease-squish-5: var(--ease-elastic-in-out-5);
19 --ease-spring-1: linear(
20 0, 0.006, 0.025 2.8%, 0.101 6.1%, 0.539 18.9%, 0.721 25.3%, 0.849 31.5%,
21 0.937 38.1%, 0.968 41.8%, 0.991 45.7%, 1.006 50.1%, 1.015 55%, 1.017 63.9%,
22 diff --git a/src/props.easing.js b/src/props.easing.js
23index bb583ec..bfaf0e0 100644
24--- a/src/props.easing.js
25+++ b/src/props.easing.js
26 @@ -53,11 +53,11 @@ export default {
27 '--ease-elastic-4': 'var(--ease-elastic-out-4)',
28 '--ease-elastic-5': 'var(--ease-elastic-out-5)',
29
30- '--ease-squish-1': 'var(--elastic-in-out-1)',
31- '--ease-squish-2': 'var(--elastic-in-out-2)',
32- '--ease-squish-3': 'var(--elastic-in-out-3)',
33- '--ease-squish-4': 'var(--elastic-in-out-4)',
34- '--ease-squish-5': 'var(--elastic-in-out-5)',
35+ '--ease-squish-1': 'var(--ease-elastic-in-out-1)',
36+ '--ease-squish-2': 'var(--ease-elastic-in-out-2)',
37+ '--ease-squish-3': 'var(--ease-elastic-in-out-3)',
38+ '--ease-squish-4': 'var(--ease-elastic-in-out-4)',
39+ '--ease-squish-5': 'var(--ease-elastic-in-out-5)',
40
41 '--ease-spring-1': `linear(
42 0, 0.006, 0.025 2.8%, 0.101 6.1%, 0.539 18.9%, 0.721 25.3%, 0.849 31.5%,
43 diff --git a/test/basic.test.cjs b/test/basic.test.cjs
44index 917fe98..4719fb3 100644
45--- a/test/basic.test.cjs
46+++ b/test/basic.test.cjs
47 @@ -56,4 +56,55 @@ test('Should produce optional mask props', async t => {
48 test('Should produce typings files', async t => {
49 t.assert(fs.existsSync('./dist/open-props.module.d.ts'))
50 t.assert(fs.existsSync('./src/props.sizes.d.ts'))
51+ })
52+
53+ test('References should be valid', async t => {
54+ const formatter = new Intl.ListFormat();
55+ const defined = new Set();
56+ const referenced = new Set();
57+ const referencedBy = new Map();
58+
59+ for (const [prop, value] of Object.entries(OpenProps)) {
60+ // Add all defined variables to the defined set
61+ defined.add(prop)
62+
63+ if (typeof value !== 'string') {
64+ continue;
65+ }
66+
67+ // Find all references to other variables: var(...)
68+ const matches = value.matchAll(/var\(([^)]+)\)/g);
69+
70+ if (!matches) {
71+ continue;
72+ }
73+
74+ // Add all references to the referenced set
75+ // Map all references to the prop that references them
76+ for (const matchArray of matches) {
77+ const reference = matchArray[1];
78+
79+ referenced.add(reference);
80+
81+ if (!prop.startsWith('--')) {
82+ continue;
83+ }
84+
85+ if (!referencedBy.has(reference)) {
86+ referencedBy.set(reference, new Set());
87+ }
88+
89+ referencedBy.get(reference).add(prop);
90+ }
91+ }
92+
93+ // Check that all referenced variables are defined
94+ for (const reference of referenced) {
95+ const referencing = formatter.format(Array.from(referencedBy.get(reference)));
96+
97+ t.assert(
98+ defined.has(reference),
99+ `Variable with name ${reference} was referenced by variable ${referencing}, but is not defined`
100+ );
101+ }
102 })
103\ No newline at end of file