|
8 | 8 | The above copyright notice and this permission notice shall be |
9 | 9 | included in all copies or substantial portions of this Source Code Form. |
10 | 10 | */ |
| 11 | +const { getTokens } = require('../tokenize'); |
11 | 12 | const { registerWalker } = require('../walker'); |
12 | 13 |
|
13 | 14 | const Container = require('./Container'); |
14 | 15 |
|
| 16 | +const allFunctions = [ |
| 17 | + 'annotation', |
| 18 | + 'attr', |
| 19 | + 'blur', |
| 20 | + 'brightness', |
| 21 | + 'calc', |
| 22 | + 'character-variant', |
| 23 | + 'circle', |
| 24 | + 'contrast', |
| 25 | + 'cubic-bezier', |
| 26 | + 'dir', |
| 27 | + 'drop-shadow', |
| 28 | + 'element', |
| 29 | + 'ellipse', |
| 30 | + 'grayscale', |
| 31 | + 'hsl', |
| 32 | + 'hsla', |
| 33 | + 'hue-rotate', |
| 34 | + 'image', |
| 35 | + 'inset', |
| 36 | + 'invert', |
| 37 | + 'lang', |
| 38 | + 'linear-gradient', |
| 39 | + 'matrix', |
| 40 | + 'matrix3d', |
| 41 | + 'minmax', |
| 42 | + 'not', |
| 43 | + 'nth-child', |
| 44 | + 'nth-last-child', |
| 45 | + 'nth-last-of-type', |
| 46 | + 'nth-of-type', |
| 47 | + 'opacity', |
| 48 | + 'ornaments', |
| 49 | + 'perspective', |
| 50 | + 'polygon', |
| 51 | + 'radial-gradient', |
| 52 | + 'rect', |
| 53 | + 'repeat', |
| 54 | + 'repeating-linear-gradient', |
| 55 | + 'repeating-radial-gradient', |
| 56 | + 'rgb', |
| 57 | + 'rgba', |
| 58 | + 'rotate', |
| 59 | + 'rotatex', |
| 60 | + 'rotatey', |
| 61 | + 'rotatez', |
| 62 | + 'rotate3d', |
| 63 | + 'saturate', |
| 64 | + 'scale', |
| 65 | + 'scalex', |
| 66 | + 'scaley', |
| 67 | + 'scalez', |
| 68 | + 'scale3d', |
| 69 | + 'sepia', |
| 70 | + 'skew', |
| 71 | + 'skewx', |
| 72 | + 'skewy', |
| 73 | + 'steps', |
| 74 | + 'styleset', |
| 75 | + 'stylistic', |
| 76 | + 'swash', |
| 77 | + 'symbols', |
| 78 | + 'translate', |
| 79 | + 'translatex', |
| 80 | + 'translatey', |
| 81 | + 'translatez', |
| 82 | + 'translate3d', |
| 83 | + 'url', |
| 84 | + 'var' |
| 85 | +]; |
15 | 86 | const colorFunctions = ['hsl', 'hsla', 'rgb', 'rgba']; |
| 87 | +const vendorPrefixes = ['-webkit-', '-moz-', '-ms-', '-o-']; |
| 88 | +const reFunctions = new RegExp(`^(${vendorPrefixes.join('|')})?(${allFunctions.join('|')})`, 'i'); |
16 | 89 | const reVar = /^--[^\s]+$/; |
17 | 90 |
|
18 | 91 | class Func extends Container { |
@@ -43,6 +116,14 @@ class Func extends Container { |
43 | 116 | let expectedParens = 1; |
44 | 117 | let lastToken = brackets; |
45 | 118 |
|
| 119 | + // fixes #92 |
| 120 | + if (!reFunctions.test(node.name) && !/^[a-zA-Z]+$/.test(node.name)) { |
| 121 | + const nameTokens = getTokens(node.name); |
| 122 | + tokens.unshift(...nameTokens, brackets); |
| 123 | + parser.back(tokens); |
| 124 | + return; |
| 125 | + } |
| 126 | + |
46 | 127 | parser.init(node, startLine, startChar); |
47 | 128 | parser.current = node; // eslint-disable-line no-param-reassign |
48 | 129 |
|
@@ -85,7 +166,8 @@ class Func extends Container { |
85 | 166 | opts.parentNode = node; |
86 | 167 | // use a new parser to parse the params of the function. recursion here makes for easier maint |
87 | 168 | // we must require this here due to circular dependency resolution |
88 | | - const { parse } = require('../'); // eslint-disable-line global-require |
| 169 | + // eslint-disable-next-line global-require |
| 170 | + const { parse } = require('../'); |
89 | 171 | const root = parse(params, opts); |
90 | 172 | const { nodes: children } = root; |
91 | 173 |
|
|
0 commit comments