scss-variable-extractor 1.6.4 → 1.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierignore +7 -0
- package/.prettierrc.json +18 -0
- package/.scssextractrc.example.json +31 -35
- package/MULTI-APP-GUIDE.md +262 -0
- package/README.md +1283 -778
- package/THEME-GUIDE.md +289 -0
- package/bin/cli.js +1002 -652
- package/jest.config.js +7 -12
- package/multi-app.example.json +44 -0
- package/package.json +50 -45
- package/src/analyzer.js +285 -285
- package/src/angular-parser.js +383 -381
- package/src/bootstrap-migrator.js +694 -661
- package/src/config.js +87 -91
- package/src/generator.js +220 -219
- package/src/index.js +37 -29
- package/src/multi-app-analyzer.js +612 -0
- package/src/ng-refactorer.js +654 -578
- package/src/parser.js +424 -421
- package/src/refactorer.js +329 -322
- package/src/scanner.js +63 -55
- package/src/style-organizer.js +500 -504
- package/src/theme-utils.js +432 -0
- package/test/analyzer.test.js +107 -107
- package/test/angular-parser.test.js +230 -230
- package/test/bootstrap-migrator.test.js +230 -213
- package/test/generator.test.js +139 -149
- package/test/multi-app-analyzer.test.js +216 -0
- package/test/ng-refactorer-global.test.js +140 -0
- package/test/ng-refactorer.test.js +191 -184
- package/test/parser.test.js +131 -131
- package/test/refactorer-edge-cases.test.js +385 -353
- package/test/refactorer.test.js +277 -257
- package/test/scanner.test.js +34 -32
- package/test/style-organizer.test.js +106 -106
- package/test/theme-utils.test.js +140 -0
|
@@ -1,353 +1,385 @@
|
|
|
1
|
-
const { refactorFile } = require('../src/refactorer');
|
|
2
|
-
|
|
3
|
-
describe('Refactorer Edge Cases', () => {
|
|
4
|
-
test('should handle rgba() color functions without partial replacements', () => {
|
|
5
|
-
const scss = `
|
|
6
|
-
.component {
|
|
7
|
-
background: rgba(255, 100, 50, 0.5);
|
|
8
|
-
color: rgba(100, 100, 100, 1);
|
|
9
|
-
}
|
|
10
|
-
`;
|
|
11
|
-
|
|
12
|
-
const analysis = {
|
|
13
|
-
colors: [
|
|
14
|
-
|
|
15
|
-
],
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
],
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
// Should replace complete rgba function
|
|
36
|
-
expect(result.content).toContain('background: $color-primary-light');
|
|
37
|
-
|
|
38
|
-
// Should NOT do partial replacements inside rgba()
|
|
39
|
-
expect(result.content).toContain('rgba(100, 100, 100, 1)'); // Not rgba($spacing-xxl, $spacing-xxl, $spacing-xxl, 1)
|
|
40
|
-
expect(result.content).not.toContain('rgba($spacing-xxl');
|
|
41
|
-
expect(result.content).not.toContain('rgba(255, $spacing-xxl');
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test('should handle calc() expressions without partial replacements', () => {
|
|
45
|
-
const scss = `
|
|
46
|
-
.component {
|
|
47
|
-
width: calc(100% - 16px);
|
|
48
|
-
height: calc(50vh + 8px);
|
|
49
|
-
margin: calc(16px / 2);
|
|
50
|
-
}
|
|
51
|
-
`;
|
|
52
|
-
|
|
53
|
-
const analysis = {
|
|
54
|
-
colors: [],
|
|
55
|
-
spacing: [
|
|
56
|
-
{ value: '16px', suggestedName: '$spacing-md' },
|
|
57
|
-
{ value: '8px', suggestedName: '$spacing-sm' }
|
|
58
|
-
],
|
|
59
|
-
fontSizes: [],
|
|
60
|
-
fontWeights: [],
|
|
61
|
-
fontFamilies: [],
|
|
62
|
-
borderRadius: [],
|
|
63
|
-
shadows: [],
|
|
64
|
-
zIndex: [],
|
|
65
|
-
sizing: [],
|
|
66
|
-
lineHeight: [],
|
|
67
|
-
opacity: [],
|
|
68
|
-
transitions: []
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const result = refactorFile(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
],
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
1
|
+
const { refactorFile } = require('../src/refactorer');
|
|
2
|
+
|
|
3
|
+
describe('Refactorer Edge Cases', () => {
|
|
4
|
+
test('should handle rgba() color functions without partial replacements', () => {
|
|
5
|
+
const scss = `
|
|
6
|
+
.component {
|
|
7
|
+
background: rgba(255, 100, 50, 0.5);
|
|
8
|
+
color: rgba(100, 100, 100, 1);
|
|
9
|
+
}
|
|
10
|
+
`;
|
|
11
|
+
|
|
12
|
+
const analysis = {
|
|
13
|
+
colors: [{ value: 'rgba(255, 100, 50, 0.5)', suggestedName: '$color-primary-light' }],
|
|
14
|
+
spacing: [{ value: '100px', suggestedName: '$spacing-xxl' }],
|
|
15
|
+
fontSizes: [],
|
|
16
|
+
fontWeights: [],
|
|
17
|
+
fontFamilies: [],
|
|
18
|
+
borderRadius: [],
|
|
19
|
+
shadows: [],
|
|
20
|
+
zIndex: [],
|
|
21
|
+
sizing: [],
|
|
22
|
+
lineHeight: [],
|
|
23
|
+
opacity: [{ value: '0.5', suggestedName: '$opacity-half' }],
|
|
24
|
+
transitions: [],
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const result = refactorFile(
|
|
28
|
+
scss,
|
|
29
|
+
analysis,
|
|
30
|
+
'/libs/styles/_variables.scss',
|
|
31
|
+
'/app/test.scss',
|
|
32
|
+
{}
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
// Should replace complete rgba function
|
|
36
|
+
expect(result.content).toContain('background: $color-primary-light');
|
|
37
|
+
|
|
38
|
+
// Should NOT do partial replacements inside rgba()
|
|
39
|
+
expect(result.content).toContain('rgba(100, 100, 100, 1)'); // Not rgba($spacing-xxl, $spacing-xxl, $spacing-xxl, 1)
|
|
40
|
+
expect(result.content).not.toContain('rgba($spacing-xxl');
|
|
41
|
+
expect(result.content).not.toContain('rgba(255, $spacing-xxl');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('should handle calc() expressions without partial replacements', () => {
|
|
45
|
+
const scss = `
|
|
46
|
+
.component {
|
|
47
|
+
width: calc(100% - 16px);
|
|
48
|
+
height: calc(50vh + 8px);
|
|
49
|
+
margin: calc(16px / 2);
|
|
50
|
+
}
|
|
51
|
+
`;
|
|
52
|
+
|
|
53
|
+
const analysis = {
|
|
54
|
+
colors: [],
|
|
55
|
+
spacing: [
|
|
56
|
+
{ value: '16px', suggestedName: '$spacing-md' },
|
|
57
|
+
{ value: '8px', suggestedName: '$spacing-sm' },
|
|
58
|
+
],
|
|
59
|
+
fontSizes: [],
|
|
60
|
+
fontWeights: [],
|
|
61
|
+
fontFamilies: [],
|
|
62
|
+
borderRadius: [],
|
|
63
|
+
shadows: [],
|
|
64
|
+
zIndex: [],
|
|
65
|
+
sizing: [],
|
|
66
|
+
lineHeight: [],
|
|
67
|
+
opacity: [],
|
|
68
|
+
transitions: [],
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const result = refactorFile(
|
|
72
|
+
scss,
|
|
73
|
+
analysis,
|
|
74
|
+
'/libs/styles/_variables.scss',
|
|
75
|
+
'/app/test.scss',
|
|
76
|
+
{}
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
// calc() values should be protected from replacement (safe zone)
|
|
80
|
+
const content = result.content;
|
|
81
|
+
|
|
82
|
+
// Values inside calc() should NOT be replaced
|
|
83
|
+
expect(content).toContain('calc(100% - 16px)');
|
|
84
|
+
expect(content).toContain('calc(50vh + 8px)');
|
|
85
|
+
expect(content).toContain('calc(16px / 2)');
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('should handle negative values correctly', () => {
|
|
89
|
+
const scss = `
|
|
90
|
+
.component {
|
|
91
|
+
margin: -16px;
|
|
92
|
+
top: -8px;
|
|
93
|
+
z-index: -1;
|
|
94
|
+
}
|
|
95
|
+
`;
|
|
96
|
+
|
|
97
|
+
const analysis = {
|
|
98
|
+
colors: [],
|
|
99
|
+
spacing: [
|
|
100
|
+
{ value: '16px', suggestedName: '$spacing-md' },
|
|
101
|
+
{ value: '8px', suggestedName: '$spacing-sm' },
|
|
102
|
+
],
|
|
103
|
+
fontSizes: [],
|
|
104
|
+
fontWeights: [],
|
|
105
|
+
fontFamilies: [],
|
|
106
|
+
borderRadius: [],
|
|
107
|
+
shadows: [],
|
|
108
|
+
zIndex: [{ value: '1', suggestedName: '$z-index-1' }],
|
|
109
|
+
sizing: [],
|
|
110
|
+
lineHeight: [],
|
|
111
|
+
opacity: [],
|
|
112
|
+
transitions: [],
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const result = refactorFile(
|
|
116
|
+
scss,
|
|
117
|
+
analysis,
|
|
118
|
+
'/libs/styles/_variables.scss',
|
|
119
|
+
'/app/test.scss',
|
|
120
|
+
{}
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
// Negative values should be protected (safe zone) to prevent -$variable syntax
|
|
124
|
+
expect(result.content).toContain('margin: -16px');
|
|
125
|
+
expect(result.content).toContain('top: -8px');
|
|
126
|
+
expect(result.content).toContain('z-index: -1');
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test('should handle multiple values in shorthand properties', () => {
|
|
130
|
+
const scss = `
|
|
131
|
+
.component {
|
|
132
|
+
margin: 16px 8px;
|
|
133
|
+
padding: 16px 8px 16px 8px;
|
|
134
|
+
border-radius: 4px 2px;
|
|
135
|
+
}
|
|
136
|
+
`;
|
|
137
|
+
|
|
138
|
+
const analysis = {
|
|
139
|
+
colors: [],
|
|
140
|
+
spacing: [
|
|
141
|
+
{ value: '16px', suggestedName: '$spacing-md' },
|
|
142
|
+
{ value: '8px', suggestedName: '$spacing-sm' },
|
|
143
|
+
],
|
|
144
|
+
fontSizes: [],
|
|
145
|
+
fontWeights: [],
|
|
146
|
+
fontFamilies: [],
|
|
147
|
+
borderRadius: [
|
|
148
|
+
{ value: '4px', suggestedName: '$border-radius-sm' },
|
|
149
|
+
{ value: '2px', suggestedName: '$border-radius-xs' },
|
|
150
|
+
],
|
|
151
|
+
shadows: [],
|
|
152
|
+
zIndex: [],
|
|
153
|
+
sizing: [],
|
|
154
|
+
lineHeight: [],
|
|
155
|
+
opacity: [],
|
|
156
|
+
transitions: [],
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
const result = refactorFile(
|
|
160
|
+
scss,
|
|
161
|
+
analysis,
|
|
162
|
+
'/libs/styles/_variables.scss',
|
|
163
|
+
'/app/test.scss',
|
|
164
|
+
{}
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
// Should replace individual values in shorthand
|
|
168
|
+
expect(result.content).toContain('$spacing-md');
|
|
169
|
+
expect(result.content).toContain('$spacing-sm');
|
|
170
|
+
expect(result.content).toContain('$border-radius-sm');
|
|
171
|
+
expect(result.content).toContain('$border-radius-xs');
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test('should not replace values in CSS custom properties', () => {
|
|
175
|
+
const scss = `
|
|
176
|
+
:root {
|
|
177
|
+
--primary-color: #1976d2;
|
|
178
|
+
--spacing: 16px;
|
|
179
|
+
}
|
|
180
|
+
.component {
|
|
181
|
+
color: var(--primary-color);
|
|
182
|
+
padding: var(--spacing);
|
|
183
|
+
}
|
|
184
|
+
`;
|
|
185
|
+
|
|
186
|
+
const analysis = {
|
|
187
|
+
colors: [{ value: '#1976d2', suggestedName: '$color-primary' }],
|
|
188
|
+
spacing: [{ value: '16px', suggestedName: '$spacing-md' }],
|
|
189
|
+
fontSizes: [],
|
|
190
|
+
fontWeights: [],
|
|
191
|
+
fontFamilies: [],
|
|
192
|
+
borderRadius: [],
|
|
193
|
+
shadows: [],
|
|
194
|
+
zIndex: [],
|
|
195
|
+
sizing: [],
|
|
196
|
+
lineHeight: [],
|
|
197
|
+
opacity: [],
|
|
198
|
+
transitions: [],
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
const result = refactorFile(
|
|
202
|
+
scss,
|
|
203
|
+
analysis,
|
|
204
|
+
'/libs/styles/_variables.scss',
|
|
205
|
+
'/app/test.scss',
|
|
206
|
+
{}
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
// CSS custom property declarations should be replaced (they're like SCSS variables)
|
|
210
|
+
// But var() references should be preserved
|
|
211
|
+
expect(result.content).toContain('var(--primary-color)');
|
|
212
|
+
expect(result.content).toContain('var(--spacing)');
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
test('should not replace values in attribute selectors', () => {
|
|
216
|
+
const scss = `
|
|
217
|
+
[data-size="16"] {
|
|
218
|
+
padding: 16px;
|
|
219
|
+
}
|
|
220
|
+
[data-color="#1976d2"] {
|
|
221
|
+
color: #1976d2;
|
|
222
|
+
}
|
|
223
|
+
`;
|
|
224
|
+
|
|
225
|
+
const analysis = {
|
|
226
|
+
colors: [{ value: '#1976d2', suggestedName: '$color-primary' }],
|
|
227
|
+
spacing: [{ value: '16px', suggestedName: '$spacing-md' }],
|
|
228
|
+
fontSizes: [],
|
|
229
|
+
fontWeights: [],
|
|
230
|
+
fontFamilies: [],
|
|
231
|
+
borderRadius: [],
|
|
232
|
+
shadows: [],
|
|
233
|
+
zIndex: [],
|
|
234
|
+
sizing: [],
|
|
235
|
+
lineHeight: [],
|
|
236
|
+
opacity: [],
|
|
237
|
+
transitions: [],
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
const result = refactorFile(
|
|
241
|
+
scss,
|
|
242
|
+
analysis,
|
|
243
|
+
'/libs/styles/_variables.scss',
|
|
244
|
+
'/app/test.scss',
|
|
245
|
+
{}
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
// Should replace in property values (outside attribute selectors)
|
|
249
|
+
expect(result.content).toContain('padding: $spacing-md');
|
|
250
|
+
expect(result.content).toContain('color: $color-primary');
|
|
251
|
+
|
|
252
|
+
// Should NOT replace in attribute selector values (safe zone)
|
|
253
|
+
expect(result.content).toContain('[data-size="16"]');
|
|
254
|
+
expect(result.content).toContain('[data-color="#1976d2"]');
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
test('should handle transform functions', () => {
|
|
258
|
+
const scss = `
|
|
259
|
+
.component {
|
|
260
|
+
transform: translate(10px, 20px);
|
|
261
|
+
transform: rotate(45deg);
|
|
262
|
+
transform: scale(2);
|
|
263
|
+
}
|
|
264
|
+
`;
|
|
265
|
+
|
|
266
|
+
const analysis = {
|
|
267
|
+
colors: [],
|
|
268
|
+
spacing: [
|
|
269
|
+
{ value: '10px', suggestedName: '$spacing-xs' },
|
|
270
|
+
{ value: '20px', suggestedName: '$spacing-sm' },
|
|
271
|
+
],
|
|
272
|
+
fontSizes: [],
|
|
273
|
+
fontWeights: [],
|
|
274
|
+
fontFamilies: [],
|
|
275
|
+
borderRadius: [],
|
|
276
|
+
shadows: [],
|
|
277
|
+
zIndex: [{ value: '2', suggestedName: '$z-index-2' }],
|
|
278
|
+
sizing: [],
|
|
279
|
+
lineHeight: [],
|
|
280
|
+
opacity: [],
|
|
281
|
+
transitions: [],
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
const result = refactorFile(
|
|
285
|
+
scss,
|
|
286
|
+
analysis,
|
|
287
|
+
'/libs/styles/_variables.scss',
|
|
288
|
+
'/app/test.scss',
|
|
289
|
+
{}
|
|
290
|
+
);
|
|
291
|
+
|
|
292
|
+
// Transform function arguments should be protected (safe zone)
|
|
293
|
+
const content = result.content;
|
|
294
|
+
expect(content).toContain('translate(10px, 20px)');
|
|
295
|
+
expect(content).toContain('scale(2)');
|
|
296
|
+
expect(content).toContain('rotate(45deg)');
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
test('should handle keyframe percentages', () => {
|
|
300
|
+
const scss = `
|
|
301
|
+
@keyframes fade {
|
|
302
|
+
0% { opacity: 0; }
|
|
303
|
+
50% { opacity: 0.5; }
|
|
304
|
+
100% { opacity: 1; }
|
|
305
|
+
}
|
|
306
|
+
`;
|
|
307
|
+
|
|
308
|
+
const analysis = {
|
|
309
|
+
colors: [],
|
|
310
|
+
spacing: [],
|
|
311
|
+
fontSizes: [],
|
|
312
|
+
fontWeights: [],
|
|
313
|
+
fontFamilies: [],
|
|
314
|
+
borderRadius: [],
|
|
315
|
+
shadows: [],
|
|
316
|
+
zIndex: [],
|
|
317
|
+
sizing: [],
|
|
318
|
+
lineHeight: [],
|
|
319
|
+
opacity: [
|
|
320
|
+
{ value: '0', suggestedName: '$opacity-transparent' },
|
|
321
|
+
{ value: '0.5', suggestedName: '$opacity-half' },
|
|
322
|
+
{ value: '1', suggestedName: '$opacity-full' },
|
|
323
|
+
],
|
|
324
|
+
transitions: [],
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
const result = refactorFile(
|
|
328
|
+
scss,
|
|
329
|
+
analysis,
|
|
330
|
+
'/libs/styles/_variables.scss',
|
|
331
|
+
'/app/test.scss',
|
|
332
|
+
{}
|
|
333
|
+
);
|
|
334
|
+
|
|
335
|
+
// Keyframe selectors (0%, 50%, 100%) should not be replaced
|
|
336
|
+
expect(result.content).toContain('0%');
|
|
337
|
+
expect(result.content).toContain('50%');
|
|
338
|
+
expect(result.content).toContain('100%');
|
|
339
|
+
|
|
340
|
+
// But opacity values should be replaced
|
|
341
|
+
expect(result.content).toContain('opacity: $opacity-transparent');
|
|
342
|
+
expect(result.content).toContain('opacity: $opacity-half');
|
|
343
|
+
expect(result.content).toContain('opacity: $opacity-full');
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
test('should handle comments containing values', () => {
|
|
347
|
+
const scss = `
|
|
348
|
+
/* Primary color is #1976d2 */
|
|
349
|
+
.component {
|
|
350
|
+
color: #1976d2; // Use #1976d2 for brand
|
|
351
|
+
padding: 16px; /* 16px is our standard spacing */
|
|
352
|
+
}
|
|
353
|
+
`;
|
|
354
|
+
|
|
355
|
+
const analysis = {
|
|
356
|
+
colors: [{ value: '#1976d2', suggestedName: '$color-primary' }],
|
|
357
|
+
spacing: [{ value: '16px', suggestedName: '$spacing-md' }],
|
|
358
|
+
fontSizes: [],
|
|
359
|
+
fontWeights: [],
|
|
360
|
+
fontFamilies: [],
|
|
361
|
+
borderRadius: [],
|
|
362
|
+
shadows: [],
|
|
363
|
+
zIndex: [],
|
|
364
|
+
sizing: [],
|
|
365
|
+
lineHeight: [],
|
|
366
|
+
opacity: [],
|
|
367
|
+
transitions: [],
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
const result = refactorFile(
|
|
371
|
+
scss,
|
|
372
|
+
analysis,
|
|
373
|
+
'/libs/styles/_variables.scss',
|
|
374
|
+
'/app/test.scss',
|
|
375
|
+
{}
|
|
376
|
+
);
|
|
377
|
+
|
|
378
|
+
// Should replace in actual property values
|
|
379
|
+
expect(result.content).toContain('color: $color-primary');
|
|
380
|
+
expect(result.content).toContain('padding: $spacing-md');
|
|
381
|
+
|
|
382
|
+
// Comments will likely be replaced too (current behavior)
|
|
383
|
+
// This might be acceptable or we could add comment detection to safe zones
|
|
384
|
+
});
|
|
385
|
+
});
|