Skip to content

Commit 7515db5

Browse files
authored
Remove workaround for csstree
w3c/webref#1647 has been fixed.
1 parent 12bb650 commit 7515db5

4 files changed

Lines changed: 19 additions & 32 deletions

File tree

lib/parsers.js

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const {
77
const { next: syntaxes } = require("@csstools/css-syntax-patches-for-csstree");
88
const csstree = require("css-tree");
99
const { LRUCache } = require("lru-cache");
10+
const propertyDefinitions = require("./generated/propertyDefinitions");
1011
const { asciiLowercase } = require("./utils/strings");
1112

1213
// CSS global keywords
@@ -155,19 +156,13 @@ const parseCSS = (val, opt) => cssTree.parse(prepareValue(val), opt);
155156
* @returns {boolean} True if the value is valid, false otherwise.
156157
*/
157158
const isValidPropertyValue = (prop, val) => {
159+
if (!propertyDefinitions.has(prop)) {
160+
return false;
161+
}
158162
val = prepareValue(val);
159163
if (val === "") {
160164
return true;
161165
}
162-
// cssTree.lexer does not support deprecated system colors
163-
// @see https://github.com/w3c/webref/issues/1519#issuecomment-3120290261
164-
// @see https://github.com/w3c/webref/issues/1647
165-
if (SYS_COLORS.has(asciiLowercase(val))) {
166-
if (/^(?:-webkit-)?(?:[a-z][a-z\d]*-)*color$/i.test(prop)) {
167-
return true;
168-
}
169-
return false;
170-
}
171166
const cacheKey = `isValidPropertyValue_${prop}_${val}`;
172167
const cachedValue = lruCache.get(cacheKey);
173168
if (typeof cachedValue === "boolean") {
@@ -243,6 +238,9 @@ const resolveCalc = (val, opt = { format: "specifiedValue" }) => {
243238
* @returns {string|Array<object>|undefined} The parsed value.
244239
*/
245240
const parsePropertyValue = (prop, val, opt = {}) => {
241+
if (!propertyDefinitions.has(prop)) {
242+
return;
243+
}
246244
const { caseSensitive } = opt;
247245
val = prepareValue(val);
248246
if (val === "" || hasVarFunc(val)) {
@@ -272,17 +270,6 @@ const parsePropertyValue = (prop, val, opt = {}) => {
272270
name: lowerCasedValue
273271
}
274272
];
275-
} else if (SYS_COLORS.has(lowerCasedValue)) {
276-
if (/^(?:(?:-webkit-)?(?:[a-z][a-z\d]*-)*color|border)$/i.test(prop)) {
277-
parsedValue = [
278-
{
279-
type: AST_TYPES.IDENTIFIER,
280-
name: lowerCasedValue
281-
}
282-
];
283-
} else {
284-
parsedValue = false;
285-
}
286273
} else {
287274
try {
288275
const ast = parseCSS(val, {

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
"main": "./lib/CSSStyleDeclaration.js",
1818
"dependencies": {
1919
"@asamuzakjp/css-color": "^4.1.1",
20-
"@csstools/css-syntax-patches-for-csstree": "^1.0.21",
20+
"@csstools/css-syntax-patches-for-csstree": "^1.0.24",
2121
"css-tree": "^3.1.0",
2222
"lru-cache": "^11.2.4"
2323
},
2424
"devDependencies": {
2525
"@domenic/eslint-config": "^4.0.1",
26-
"@webref/css": "^8.1.1",
26+
"@webref/css": "^8.1.3",
2727
"eslint": "^9.39.1",
2828
"eslint-config-prettier": "^10.1.8",
2929
"eslint-plugin-prettier": "^5.5.4",

test/parsers.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,11 +1465,11 @@ describe("isValidPropertyValue", () => {
14651465
assert.strictEqual(output, true);
14661466
});
14671467

1468-
it("should return true", () => {
1468+
it("should return false", () => {
14691469
const input = "canvas";
14701470
const output = parsers.isValidPropertyValue("-webkit-border-after-color", input);
14711471

1472-
assert.strictEqual(output, true);
1472+
assert.strictEqual(output, false);
14731473
});
14741474

14751475
it("should return false", () => {

0 commit comments

Comments
 (0)