From 8e0e6970a1ffbb4230910706744468253fbfc25e Mon Sep 17 00:00:00 2001 From: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> Date: Mon, 6 Feb 2023 22:28:56 +0900 Subject: [PATCH] Refactor to reuse parsed CSSTree node in `declaration-property-value-no-unknown` According to the [CSSTree doc](https://github.com/csstree/csstree/blob/v2.3.1/README.md#usage), it is likely a typical case to pass a node to `lexer.matchProperty()`. --- lib/rules/declaration-property-value-no-unknown/index.js | 8 +++++--- patches/@types+css-tree+2.0.1.patch | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/rules/declaration-property-value-no-unknown/index.js b/lib/rules/declaration-property-value-no-unknown/index.js index 97f8c9f80b..0ae887c33c 100644 --- a/lib/rules/declaration-property-value-no-unknown/index.js +++ b/lib/rules/declaration-property-value-no-unknown/index.js @@ -84,10 +84,12 @@ const rule = (primary, secondaryOptions) => { if (isPropIgnored(prop, value)) return; + let cssTreeValueNode; + try { - const valueNode = parse(value, { context: 'value' }); + cssTreeValueNode = parse(value, { context: 'value' }); - if (containsUnsupportedMathFunction(valueNode)) return; + if (containsUnsupportedMathFunction(cssTreeValueNode)) return; } catch (e) { result.warn(`Cannot parse property value "${value}"`, { node: decl, @@ -97,7 +99,7 @@ const rule = (primary, secondaryOptions) => { return; } - const { error } = forkedLexer.matchProperty(prop, value); + const { error } = forkedLexer.matchProperty(prop, cssTreeValueNode); if (!error) return; diff --git a/patches/@types+css-tree+2.0.1.patch b/patches/@types+css-tree+2.0.1.patch index 4c1fbcb5c7..7c7c0910ee 100644 --- a/patches/@types+css-tree+2.0.1.patch +++ b/patches/@types+css-tree+2.0.1.patch @@ -17,7 +17,7 @@ index 2e4ed18..7f096c6 100755 +}; + +declare class Lexer { -+ matchProperty(propertyName: string, value: string): MatchResult; ++ matchProperty(propertyName: string, value: CssNode | string): MatchResult; +} + +export function fork(extension: Record>): { lexer: Lexer };