From 76cb9c2a39d477a64824a985ade40507e3bbade1 Mon Sep 17 00:00:00 2001 From: Adam Mathes Date: Fri, 13 Feb 2026 21:34:48 -0800 Subject: feat(vanilla): add testing infrastructure and tests (NK-wjnczv) --- .../css-tree/lib/syntax/node/FeatureFunction.js | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 vanilla/node_modules/css-tree/lib/syntax/node/FeatureFunction.js (limited to 'vanilla/node_modules/css-tree/lib/syntax/node/FeatureFunction.js') diff --git a/vanilla/node_modules/css-tree/lib/syntax/node/FeatureFunction.js b/vanilla/node_modules/css-tree/lib/syntax/node/FeatureFunction.js new file mode 100644 index 0000000..5869479 --- /dev/null +++ b/vanilla/node_modules/css-tree/lib/syntax/node/FeatureFunction.js @@ -0,0 +1,63 @@ +import { + Function as FunctionToken, + RightParenthesis +} from '../../tokenizer/index.js'; + +export const name = 'FeatureFunction'; +export const structure = { + kind: String, + feature: String, + value: ['Declaration', 'Selector'] +}; + +function getFeatureParser(kind, name) { + const featuresOfKind = this.features[kind] || {}; + const parser = featuresOfKind[name]; + + if (typeof parser !== 'function') { + this.error(`Unknown feature ${name}()`); + } + + return parser; +} + +export function parse(kind = 'unknown') { + const start = this.tokenStart; + const functionName = this.consumeFunctionName(); + const valueParser = getFeatureParser.call(this, kind, functionName.toLowerCase()); + + this.skipSC(); + + const value = this.parseWithFallback( + () => { + const startValueToken = this.tokenIndex; + const value = valueParser.call(this); + + if (this.eof === false && + this.isBalanceEdge(startValueToken) === false) { + this.error(); + } + + return value; + }, + () => this.Raw(null, false) + ); + + if (!this.eof) { + this.eat(RightParenthesis); + } + + return { + type: 'FeatureFunction', + loc: this.getLocation(start, this.tokenStart), + kind, + feature: functionName, + value + }; +} + +export function generate(node) { + this.token(FunctionToken, node.feature + '('); + this.node(node.value); + this.token(RightParenthesis, ')'); +} -- cgit v1.2.3