(ast: CssNode, syntax: string | undefined)
| 98 | ]); |
| 99 | |
| 100 | const 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 | |
| 139 | const getSyntaxMatchErrorSyntax = (error: Error | null | undefined) => { |
| 140 | if (error != null && "syntax" in error && typeof error.syntax === "string") { |
no test coverage detected