sugar-high 2.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,6 +26,47 @@ export const onLiteral = (curr, index, code) => {
26
26
  const isIgnored = (type) => type === T_SPACE || type === T_BREAK || type === T_COMMENT
27
27
  const isPropertyPart = ([type, value]) =>
28
28
  type === T_IDENTIFIER || type === T_CLASS || (type === T_SIGN && value === '-')
29
+ const isNamePart = ([type]) =>
30
+ type === T_IDENTIFIER || type === T_CLASS || type === T_PROPERTY
31
+ const isNameStart = (token) => isNamePart(token) && !/^\d/.test(token[1])
32
+ const isHyphen = ([type, value]) => type === T_SIGN && value === '-'
33
+
34
+ /**
35
+ * Rejoin CSS dashed identifiers split by the shared punctuation lexer.
36
+ * @param {Array<[number, string]>} tokens
37
+ */
38
+ const mergeDashedNames = (tokens) => {
39
+ for (let index = 0; index < tokens.length; index++) {
40
+ let firstWord = index
41
+ let end = index
42
+
43
+ if (isHyphen(tokens[end])) {
44
+ while (isHyphen(tokens[end])) end++
45
+ if (!tokens[end] || !isNameStart(tokens[end])) continue
46
+ firstWord = end++
47
+ } else if (isNameStart(tokens[end])) {
48
+ end++
49
+ } else {
50
+ continue
51
+ }
52
+
53
+ let dashed = firstWord > index
54
+ while (tokens[end] && isHyphen(tokens[end])) {
55
+ const hyphenStart = end
56
+ while (tokens[end] && isHyphen(tokens[end])) end++
57
+ if (!tokens[end] || !isNamePart(tokens[end])) {
58
+ end = hyphenStart
59
+ break
60
+ }
61
+ dashed = true
62
+ end++
63
+ }
64
+
65
+ if (!dashed) continue
66
+ const name = tokens.slice(index, end).map(([, value]) => value).join('')
67
+ tokens.splice(index, end - index, [tokens[firstWord][0], name])
68
+ }
69
+ }
29
70
 
30
71
  /** Return true when a colon belongs to a nested selector instead of a declaration. */
31
72
  const opensBlock = (tokens, start) => {
@@ -51,6 +92,7 @@ const opensBlock = (tokens, start) => {
51
92
  */
52
93
  export const tokenize = (code, options) => {
53
94
  const tokens = tokenizePlain(code, { ...options, tokenize: undefined })
95
+ mergeDashedNames(tokens)
54
96
  let blockDepth = 0
55
97
  let declarationStart = false
56
98
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sugar-high",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/huozhi/sugar-high.git",