Skip to content

Commit 1257434

Browse files
domenicclaude
andauthored
Always return arrays from parsePropertyValue
The inArray parameter caused cache thrashing: CSSStyleDeclaration.js called without it (caching strings) while property files called with inArray: true (expecting arrays). When the cached type didn't match what a caller needed, it would recompute and overwrite, causing the next different-type caller to also miss. By always returning arrays, all callers can share the same cached results. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent bb4a949 commit 1257434

77 files changed

Lines changed: 144 additions & 228 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

lib/parsers.js

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ const resolveCalc = (val, opt = { format: "specifiedValue" }) => {
252252
* @returns {string|Array<object>|undefined} The parsed value.
253253
*/
254254
const parsePropertyValue = (prop, val, opt = {}) => {
255-
const { caseSensitive, inArray } = opt;
255+
const { caseSensitive } = opt;
256256
val = prepareValue(val);
257257
if (val === "" || hasVarFunc(val)) {
258258
return val;
@@ -269,38 +269,26 @@ const parsePropertyValue = (prop, val, opt = {}) => {
269269
const cachedValue = lruCache.get(cacheKey);
270270
if (cachedValue === false) {
271271
return;
272-
} else if (inArray) {
273-
if (Array.isArray(cachedValue)) {
274-
return cachedValue;
275-
}
276-
} else if (typeof cachedValue === "string") {
272+
} else if (cachedValue !== undefined) {
277273
return cachedValue;
278274
}
279275
let parsedValue;
280276
const lowerCasedValue = asciiLowercase(val);
281277
if (GLOBAL_KEYS.has(lowerCasedValue)) {
282-
if (inArray) {
278+
parsedValue = [
279+
{
280+
type: AST_TYPES.GLOBAL_KEYWORD,
281+
name: lowerCasedValue
282+
}
283+
];
284+
} else if (SYS_COLORS.has(lowerCasedValue)) {
285+
if (/^(?:(?:-webkit-)?(?:[a-z][a-z\d]*-)*color|border)$/i.test(prop)) {
283286
parsedValue = [
284287
{
285-
type: AST_TYPES.GLOBAL_KEYWORD,
288+
type: AST_TYPES.IDENTIFIER,
286289
name: lowerCasedValue
287290
}
288291
];
289-
} else {
290-
parsedValue = lowerCasedValue;
291-
}
292-
} else if (SYS_COLORS.has(lowerCasedValue)) {
293-
if (/^(?:(?:-webkit-)?(?:[a-z][a-z\d]*-)*color|border)$/i.test(prop)) {
294-
if (inArray) {
295-
parsedValue = [
296-
{
297-
type: AST_TYPES.IDENTIFIER,
298-
name: lowerCasedValue
299-
}
300-
];
301-
} else {
302-
parsedValue = lowerCasedValue;
303-
}
304292
} else {
305293
parsedValue = false;
306294
}
@@ -312,7 +300,7 @@ const parsePropertyValue = (prop, val, opt = {}) => {
312300
const { error, matched } = cssTree.lexer.matchProperty(prop, ast);
313301
if (error || !matched) {
314302
parsedValue = false;
315-
} else if (inArray) {
303+
} else {
316304
const obj = cssTree.toPlainObject(ast);
317305
const items = obj.children;
318306
const values = [];
@@ -391,8 +379,6 @@ const parsePropertyValue = (prop, val, opt = {}) => {
391379
}
392380
}
393381
parsedValue = values;
394-
} else {
395-
parsedValue = val;
396382
}
397383
} catch {
398384
parsedValue = false;

lib/properties/backgroundAttachment.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ module.exports.parse = (v, opt = {}) => {
1414
const parsedValues = [];
1515
for (const val of values) {
1616
const value = parsers.parsePropertyValue(property, val, {
17-
globalObject,
18-
inArray: true
17+
globalObject
1918
});
2019
if (Array.isArray(value) && value.length === 1) {
2120
const parsedValue = parsers.resolveKeywordValue(value);

lib/properties/backgroundClip.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ module.exports.parse = (v, opt = {}) => {
1414
const parsedValues = [];
1515
for (const val of values) {
1616
const value = parsers.parsePropertyValue(property, val, {
17-
globalObject,
18-
inArray: true
17+
globalObject
1918
});
2019
if (Array.isArray(value) && value.length === 1) {
2120
const parsedValue = parsers.resolveKeywordValue(value);

lib/properties/backgroundColor.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ module.exports.parse = (v, opt = {}) => {
1111
return v;
1212
}
1313
const value = parsers.parsePropertyValue(property, v, {
14-
globalObject,
15-
inArray: true
14+
globalObject
1615
});
1716
if (Array.isArray(value) && value.length === 1) {
1817
return parsers.resolveColorValue(value);

lib/properties/backgroundImage.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ module.exports.parse = (v, opt = {}) => {
1414
const parsedValues = [];
1515
for (const val of values) {
1616
const value = parsers.parsePropertyValue(property, val, {
17-
globalObject,
18-
inArray: true
17+
globalObject
1918
});
2019
if (Array.isArray(value) && value.length === 1) {
2120
const parsedValue = parsers.resolveGradientUrlValue(value);

lib/properties/backgroundOrigin.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ module.exports.parse = (v, opt = {}) => {
1414
const parsedValues = [];
1515
for (const val of values) {
1616
const value = parsers.parsePropertyValue(property, val, {
17-
globalObject,
18-
inArray: true
17+
globalObject
1918
});
2019
if (Array.isArray(value) && value.length === 1) {
2120
const parsedValue = parsers.resolveKeywordValue(value);

lib/properties/backgroundPosition.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ module.exports.parse = (v, opt = {}) => {
2222
const parsedValues = [];
2323
for (const val of values) {
2424
const value = parsers.parsePropertyValue(property, val, {
25-
globalObject,
26-
inArray: true
25+
globalObject
2726
});
2827
if (Array.isArray(value) && value.length) {
2928
const [part1, part2, part3, part4] = value;

lib/properties/backgroundRepeat.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ module.exports.parse = (v, opt = {}) => {
1717
const parsedValues = [];
1818
for (const val of values) {
1919
const value = parsers.parsePropertyValue(property, val, {
20-
globalObject,
21-
inArray: true
20+
globalObject
2221
});
2322
if (Array.isArray(value) && value.length) {
2423
let parsedValue = "";

lib/properties/backgroundSize.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ module.exports.parse = (v, opt = {}) => {
1717
const parsedValues = [];
1818
for (const val of values) {
1919
const value = parsers.parsePropertyValue(property, val, {
20-
globalObject,
21-
inArray: true
20+
globalObject
2221
});
2322
if (Array.isArray(value) && value.length) {
2423
if (value.length === 1) {

lib/properties/border.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ module.exports.parse = (v, opt = {}) => {
4545
const parsedValues = new Map();
4646
for (const val of values) {
4747
const value = parsers.parsePropertyValue(property, val, {
48-
globalObject,
49-
inArray: true
48+
globalObject
5049
});
5150
if (Array.isArray(value) && value.length === 1) {
5251
const parsedValue = parsers.resolveBorderShorthandValue(value, subProps, parsedValues);

0 commit comments

Comments
 (0)