Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions lib/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,48 +297,40 @@ function parsePropertyValue(prop, val, opt = {}) {
break;
}
case AST_TYPES.FUNCTION: {
const css = cssTree
.generate(item)
.replace(/\)(?!\)|\s|,)/g, ") ")
.trim();
const raw = itemCount === 1 ? val : css;
const raw = itemCount === 1 ? val : cssTree.generate(item).replace(/\)(?!\)|\s|,)/g, ") ");
// Remove "${name}(" from the start and ")" from the end
const itemValue = raw.slice(name.length + 1, -1).trim();
const itemValue = raw.trim().slice(name.length + 1, -1);
if (name === "calc") {
if (children.size === 1) {
const child = children.first;
if (child.type === AST_TYPES.NUMBER) {
values.push({
type: AST_TYPES.CALC,
isNumber: true,
value: `${parseFloat(child.value)}`,
name,
raw
isNumber: true,
value: `${parseFloat(child.value)}`
});
} else {
values.push({
type: AST_TYPES.CALC,
isNumber: false,
value: `${asciiLowercase(itemValue)}`,
name,
raw
isNumber: false,
value: asciiLowercase(itemValue)
});
}
} else {
values.push({
type: AST_TYPES.CALC,
isNumber: false,
value: asciiLowercase(itemValue),
name,
raw
isNumber: false,
value: asciiLowercase(itemValue)
});
}
} else {
values.push({
type,
name,
value: asciiLowercase(itemValue),
raw
value: caseSensitive ? itemValue : asciiLowercase(itemValue)
});
}
break;
Expand Down
28 changes: 14 additions & 14 deletions lib/utils/propertyDescriptors.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function createGenericPropertyDescriptor(property, { caseSensitive, dimensionTyp
const parsedValue = parsers.parsePropertyValue(property, v, {
caseSensitive
});
const priority = this._priorities.get(property) ?? "";
if (Array.isArray(parsedValue)) {
if (parsedValue.length === 1) {
const {
Expand All @@ -43,7 +44,7 @@ function createGenericPropertyDescriptor(property, { caseSensitive, dimensionTyp
const [{ name, type, value: itemValue }] = parsedValue;
switch (type) {
case AST_TYPES.CALC: {
this._setProperty(property, `${name}(${itemValue})`);
this._setProperty(property, `${name}(${itemValue})`, priority);
break;
}
case AST_TYPES.DIMENSION: {
Expand All @@ -58,11 +59,11 @@ function createGenericPropertyDescriptor(property, { caseSensitive, dimensionTyp
} else {
val = parsers.serializeDimension(parsedValue, dimensionType);
}
this._setProperty(property, val);
this._setProperty(property, val, priority);
break;
}
case AST_TYPES.HASH: {
this._setProperty(property, parsers.serializeColor(parsedValue));
this._setProperty(property, parsers.serializeColor(parsedValue), priority);
break;
}
case AST_TYPES.NUMBER: {
Expand All @@ -76,12 +77,12 @@ function createGenericPropertyDescriptor(property, { caseSensitive, dimensionTyp
} else if (percentageType) {
val = parsers.serializePercentage(parsedValue, percentageType);
}
this._setProperty(property, val);
this._setProperty(property, val, priority);
break;
}
case AST_TYPES.GLOBAL_KEYWORD:
case AST_TYPES.IDENTIFIER: {
this._setProperty(property, name);
this._setProperty(property, name, priority);
break;
}
case AST_TYPES.PERCENTAGE: {
Expand All @@ -96,36 +97,35 @@ function createGenericPropertyDescriptor(property, { caseSensitive, dimensionTyp
numericType = lengthType;
}
if (numericType) {
this._setProperty(property, parsers.resolveNumericValue(parsedValue, numericType));
this._setProperty(property, parsers.resolveNumericValue(parsedValue, numericType), priority);
}
break;
}
case AST_TYPES.STRING: {
this._setProperty(property, parsers.serializeString(parsedValue));
this._setProperty(property, parsers.serializeString(parsedValue), priority);
break;
}
case AST_TYPES.URL: {
this._setProperty(property, parsers.serializeURL(parsedValue));
this._setProperty(property, parsers.serializeURL(parsedValue), priority);
break;
}
case AST_TYPES.FUNCTION:
default: {
if (colorType) {
this._setProperty(property, parsers.serializeColor(parsedValue));
this._setProperty(property, parsers.serializeColor(parsedValue), priority);
} else if (imageType) {
this._setProperty(property, parsers.serializeGradient(parsedValue));
this._setProperty(property, parsers.serializeGradient(parsedValue), priority);
} else {
this._setProperty(property, value);
this._setProperty(property, value, priority);
}
}
}
} else {
// Set the prepared value for lists containing multiple values.
this._setProperty(property, value);
this._setProperty(property, value, priority);
}
} else if (typeof parsedValue === "string") {
// Empty string.
this._setProperty(property, parsedValue);
this._setProperty(property, parsedValue, priority);
}
}
},
Expand Down
80 changes: 40 additions & 40 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
],
"main": "./lib/index.js",
"dependencies": {
"@asamuzakjp/css-color": "^4.1.1",
"@asamuzakjp/css-color": "^4.1.2",
"@csstools/css-syntax-patches-for-csstree": "^1.0.26",
"css-tree": "^3.1.0",
"lru-cache": "^11.2.5"
},
"devDependencies": {
"@domenic/eslint-config": "^4.1.0",
"@webref/css": "^8.2.3",
"@webref/css": "^8.2.4",
"eslint": "^9.39.2",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-prettier": "^5.5.5",
Expand Down
Loading