MCPcopy Create free account
hub / github.com/webstudio-is/webstudio / canFallbackToCssMath

Function canFallbackToCssMath

packages/css-data/src/parse-css-value.ts:100–137  ·  view source on GitHub ↗
(ast: CssNode, syntax: string | undefined)

Source from the content-addressed store, hash-verified

98]);
99
100const canFallbackToCssMath = (ast: CssNode, syntax: string | undefined) => {
101 if (syntax === undefined) {
102 return false;
103 }
104
105 let hasCssNumericType = false;
106 try {
107 definitionSyntax.walk(definitionSyntax.parse(syntax), (node) => {
108 if (
109 node.type === "Type" &&
110 "name" in node &&
111 cssNumericTypeNames.has(node.name)
112 ) {
113 hasCssNumericType = true;
114 }
115 });
116 } catch {
117 return false;
118 }
119 if (hasCssNumericType === false) {
120 return false;
121 }
122
123 let hasCssNumericFunction = false;
124 let hasUnknownIdentifier = false;
125 walk(ast, (node) => {
126 if (node.type === "Function" && cssNumericFunctionNames.has(node.name)) {
127 hasCssNumericFunction = true;
128 }
129 if (
130 node.type === "Identifier" &&
131 cssMathConstants.has(node.name.toLowerCase()) === false
132 ) {
133 hasUnknownIdentifier = true;
134 }
135 });
136 return hasCssNumericFunction && hasUnknownIdentifier === false;
137};
138
139const getSyntaxMatchErrorSyntax = (error: Error | null | undefined) => {
140 if (error != null && "syntax" in error && typeof error.syntax === "string") {

Callers 1

isValidDeclarationFunction · 0.85

Calls 2

hasMethod · 0.80
walkFunction · 0.50

Tested by

no test coverage detected