scss-variable-extractor 1.6.2 → 1.6.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scss-variable-extractor",
3
- "version": "1.6.2",
3
+ "version": "1.6.3",
4
4
  "description": "Analyzes Angular SCSS files and extracts repeated hardcoded values into reusable variables",
5
5
  "bin": {
6
6
  "scss-extract": "./bin/cli.js"
package/src/refactorer.js CHANGED
@@ -153,6 +153,15 @@ function isInSafeZone(content, position, matchedValue) {
153
153
  return true;
154
154
  }
155
155
 
156
+ // Prevent replacement within hex colors
157
+ if (/[0-9a-fA-F]/.test(charBefore) || /[0-9a-fA-F]/.test(charAfter)) {
158
+ // Look back further to check if we're in a hex color
159
+ const lookBehind = content.substring(Math.max(0, position - 10), position);
160
+ if (/#[0-9a-fA-F]*$/.test(lookBehind)) {
161
+ return true;
162
+ }
163
+ }
164
+
156
165
  // Prevent replacement if it would create invalid variable concatenation
157
166
  if (charBefore === '$' || charAfter === '$') {
158
167
  return true;
@@ -167,4 +167,45 @@ describe('Refactorer', () => {
167
167
  expect(result.content).not.toContain('76$spacing-sm');
168
168
  expect(result.content).not.toContain('$z-index23');
169
169
  });
170
+
171
+ test('should not replace characters within hex colors', () => {
172
+ const scss = `
173
+ .component {
174
+ background: #a2dab1;
175
+ border-color: #ff2244;
176
+ color: #333;
177
+ }
178
+ `;
179
+
180
+ const analysis = {
181
+ colors: [
182
+ { value: '#a2dab1', suggestedName: '$color-success' },
183
+ { value: '#333', suggestedName: '$color-text' }
184
+ ],
185
+ spacing: [],
186
+ fontSizes: [],
187
+ fontWeights: [],
188
+ fontFamilies: [],
189
+ borderRadius: [],
190
+ shadows: [],
191
+ zIndex: [
192
+ { value: '2', suggestedName: '$z-index-2' }
193
+ ],
194
+ sizing: [],
195
+ lineHeight: [],
196
+ opacity: [],
197
+ transitions: []
198
+ };
199
+
200
+ const result = refactorFile(scss, analysis, '/libs/styles/_variables.scss', '/app/test.scss', {});
201
+
202
+ // Should replace complete hex colors
203
+ expect(result.content).toContain('background: $color-success');
204
+ expect(result.content).toContain('color: $color-text');
205
+
206
+ // Should NOT replace digits within hex colors
207
+ expect(result.content).toContain('#ff2244'); // Not #ff$z-index-2$z-index-244
208
+ expect(result.content).not.toContain('#a$z-index-2dab1');
209
+ expect(result.content).not.toContain('#ff$z-index-2');
210
+ });
170
211
  });