@tbela99/css-parser 0.1.0 → 0.2.0

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.
@@ -7,12 +7,12 @@ import { walkValues } from './walk.js';
7
7
 
8
8
  function expand(ast) {
9
9
  //
10
- if (![4 /* NodeType.RuleNodeType */, 2 /* NodeType.StyleSheetNodeType */, 3 /* NodeType.AtRuleNodeType */].includes(ast.typ)) {
10
+ if (![EnumToken.RuleNodeType, EnumToken.StyleSheetNodeType, EnumToken.AtRuleNodeType].includes(ast.typ)) {
11
11
  return ast;
12
12
  }
13
- if (4 /* NodeType.RuleNodeType */ == ast.typ) {
13
+ if (EnumToken.RuleNodeType == ast.typ) {
14
14
  return {
15
- typ: 2 /* NodeType.StyleSheetNodeType */,
15
+ typ: EnumToken.StyleSheetNodeType,
16
16
  chi: expandRule(ast)
17
17
  };
18
18
  }
@@ -24,16 +24,16 @@ function expand(ast) {
24
24
  for (let i = 0; i < ast.chi.length; i++) {
25
25
  // @ts-ignore
26
26
  const node = ast.chi[i];
27
- if (node.typ == 4 /* NodeType.RuleNodeType */) {
27
+ if (node.typ == EnumToken.RuleNodeType) {
28
28
  // @ts-ignore
29
29
  result.chi.push(...expandRule(node));
30
30
  // i += expanded.length - 1;
31
31
  }
32
- else if (node.typ == 3 /* NodeType.AtRuleNodeType */ && 'chi' in node) {
32
+ else if (node.typ == EnumToken.AtRuleNodeType && 'chi' in node) {
33
33
  let hasRule = false;
34
34
  let j = node.chi.length;
35
35
  while (j--) {
36
- if (node.chi[j].typ == 4 /* NodeType.RuleNodeType */ || node.chi[j].typ == 3 /* NodeType.AtRuleNodeType */) {
36
+ if (node.chi[j].typ == EnumToken.RuleNodeType || node.chi[j].typ == EnumToken.AtRuleNodeType) {
37
37
  hasRule = true;
38
38
  break;
39
39
  }
@@ -51,10 +51,10 @@ function expand(ast) {
51
51
  function expandRule(node) {
52
52
  const ast = { ...node, chi: node.chi.slice() };
53
53
  const result = [];
54
- if (ast.typ == 4 /* NodeType.RuleNodeType */) {
54
+ if (ast.typ == EnumToken.RuleNodeType) {
55
55
  let i = 0;
56
56
  for (; i < ast.chi.length; i++) {
57
- if (ast.chi[i].typ == 4 /* NodeType.RuleNodeType */) {
57
+ if (ast.chi[i].typ == EnumToken.RuleNodeType) {
58
58
  const rule = ast.chi[i];
59
59
  if (!rule.sel.includes('&')) {
60
60
  const selRule = splitRule(rule.sel);
@@ -70,7 +70,7 @@ function expandRule(node) {
70
70
  ast.chi.splice(i--, 1);
71
71
  result.push(...expandRule(rule));
72
72
  }
73
- else if (ast.chi[i].typ == 3 /* NodeType.AtRuleNodeType */) {
73
+ else if (ast.chi[i].typ == EnumToken.AtRuleNodeType) {
74
74
  let astAtRule = ast.chi[i];
75
75
  const values = [];
76
76
  if (astAtRule.nam == 'scope') {
@@ -85,7 +85,7 @@ function expandRule(node) {
85
85
  // @ts-ignore
86
86
  astAtRule.chi.length = 0;
87
87
  for (const r of expandRule(clone)) {
88
- if (r.typ == 3 /* NodeType.AtRuleNodeType */ && 'chi' in r) {
88
+ if (r.typ == EnumToken.AtRuleNodeType && 'chi' in r) {
89
89
  if (astAtRule.val !== '' && r.val !== '') {
90
90
  if (astAtRule.nam == 'media' && r.nam == 'media') {
91
91
  r.val = astAtRule.val + ' and ' + r.val;
@@ -97,7 +97,7 @@ function expandRule(node) {
97
97
  // @ts-ignore
98
98
  values.push(r);
99
99
  }
100
- else if (r.typ == 4 /* NodeType.RuleNodeType */) {
100
+ else if (r.typ == EnumToken.RuleNodeType) {
101
101
  // @ts-ignore
102
102
  astAtRule.chi.push(...expandRule(r));
103
103
  }
@@ -1,7 +1,9 @@
1
1
  import { EnumToken } from '../types.js';
2
- import { reduceNumber, renderToken } from '../../renderer/render.js';
2
+ import { reduceNumber } from '../../renderer/render.js';
3
3
  import { walkValues } from '../walk.js';
4
- import { MinifyFeature } from '../utiles/minifyfeature.js';
4
+ import { MinifyFeature } from '../utils/minifyfeature.js';
5
+ import { compute } from './utils/math.js';
6
+ import { IterableWeakSet } from '../../iterable/set.js';
5
7
 
6
8
  class ComputeCalcExpression extends MinifyFeature {
7
9
  static get ordering() {
@@ -24,10 +26,10 @@ class ComputeCalcExpression extends MinifyFeature {
24
26
  }
25
27
  // @ts-ignore
26
28
  for (const node of ast.chi) {
27
- if (node.typ != 5 /* NodeType.DeclarationNodeType */) {
29
+ if (node.typ != EnumToken.DeclarationNodeType) {
28
30
  continue;
29
31
  }
30
- const set = new Set;
32
+ const set = new IterableWeakSet;
31
33
  for (const { parent } of walkValues(node.val)) {
32
34
  if (parent != null && parent.typ == EnumToken.FunctionTokenType && parent.val == 'calc') {
33
35
  if (!set.has(parent)) {
@@ -58,39 +60,14 @@ function doEvaluate(l, r, op) {
58
60
  }
59
61
  if ((op == EnumToken.Add || op == EnumToken.Sub)) {
60
62
  // @ts-ignore
61
- if (l.typ != r.typ || Number.isNaN(+l.val) || Number.isNaN(r.val)) {
63
+ if (l.typ != r.typ) {
62
64
  return defaultReturn;
63
65
  }
64
- // @ts-ignore
65
- return { ...l, val: reduceNumber(+l.val + (op == EnumToken.Add ? +r.val : -1 * r.val)) };
66
- }
67
- else {
68
- // @ts-ignore
69
- let val;
70
- if (op == EnumToken.Div) {
71
- if (r.typ != EnumToken.NumberTokenType || r.val == '0') {
72
- return defaultReturn;
73
- }
74
- // @ts-ignore
75
- val = reduceNumber(l.val / r.val);
76
- }
77
- else {
78
- // @ts-ignore
79
- val = reduceNumber(r.val * l.val);
80
- }
81
- let result;
82
- if (r.typ == EnumToken.NumberTokenType || op == EnumToken.Div) {
83
- result = { ...l, val };
84
- }
85
- else {
86
- // @ts-ignore
87
- result = { ...r, val };
88
- }
89
- if (renderToken(result).length <= renderToken(defaultReturn).length) {
90
- return result;
91
- }
92
66
  }
93
- return defaultReturn;
67
+ const typ = l.typ == EnumToken.NumberTokenType ? r.typ : l.typ;
68
+ // @ts-ignore
69
+ const val = compute(typeof l.val == 'string' ? +l.val : l.val, typeof r.val == 'string' ? +r.val : r.val, op);
70
+ return { ...(l.typ == EnumToken.NumberTokenType ? r : l), typ, val: typeof val == 'number' ? reduceNumber(val) : val };
94
71
  }
95
72
  /**
96
73
  * evaluate an array of tokens
@@ -146,7 +123,10 @@ function evaluate(tokens) {
146
123
  */
147
124
  function inlineExpression(token) {
148
125
  const result = [];
149
- if (token.typ == EnumToken.BinaryExpressionTokenType) {
126
+ if (token.typ == EnumToken.ParensTokenType && token.chi.length == 1) {
127
+ result.push(token.chi[0]);
128
+ }
129
+ else if (token.typ == EnumToken.BinaryExpressionTokenType) {
150
130
  if ([EnumToken.Mul, EnumToken.Div].includes(token.op)) {
151
131
  result.push(token);
152
132
  }
@@ -173,18 +153,7 @@ function evaluateExpression(token) {
173
153
  if (token.l.typ == EnumToken.BinaryExpressionTokenType) {
174
154
  token.l = evaluateExpression(token.l);
175
155
  }
176
- const result = doEvaluate(token.l, token.r, token.op);
177
- if (result.typ == EnumToken.BinaryExpressionTokenType &&
178
- [EnumToken.Mul, EnumToken.Div].includes(result.op)) {
179
- // wrap expression
180
- if (result.l.typ == EnumToken.BinaryExpressionTokenType && [EnumToken.Sub, EnumToken.Add].includes(result.l.op)) {
181
- result.l = { typ: EnumToken.ParensTokenType, chi: [result.l] };
182
- }
183
- else if (result.r.typ == EnumToken.BinaryExpressionTokenType && [EnumToken.Sub, EnumToken.Add].includes(result.r.op)) {
184
- result.r = { typ: EnumToken.ParensTokenType, chi: [result.r] };
185
- }
186
- }
187
- return result;
156
+ return doEvaluate(token.l, token.r, token.op);
188
157
  }
189
158
  function isScalarToken(token) {
190
159
  return token.typ != EnumToken.BinaryExpressionTokenType && token.typ != EnumToken.ParensTokenType && token.typ != EnumToken.FunctionTokenType;
@@ -232,7 +201,7 @@ function factorToken(token) {
232
201
  */
233
202
  function factor(tokens, ops) {
234
203
  let isOp;
235
- const opList = [EnumToken.Add, EnumToken.Sub, EnumToken.Div, EnumToken.Mul];
204
+ const opList = ops.map(x => getArithmeticOperation(x));
236
205
  if (tokens.length == 1) {
237
206
  return [factorToken(tokens[0])];
238
207
  }
@@ -1,7 +1,31 @@
1
1
  import { EnumToken } from '../types.js';
2
2
  import { walkValues } from '../walk.js';
3
- import { MinifyFeature } from '../utiles/minifyfeature.js';
3
+ import { MinifyFeature } from '../utils/minifyfeature.js';
4
+ import { IterableWeakSet } from '../../iterable/set.js';
4
5
 
6
+ function replace(node, variableScope) {
7
+ for (const { value, parent: parentValue } of walkValues(node.val)) {
8
+ if (value?.typ == EnumToken.FunctionTokenType && value.val == 'var') {
9
+ if (value.chi.length == 1 && value.chi[0].typ == EnumToken.DashedIdenTokenType) {
10
+ const info = variableScope.get(value.chi[0].val);
11
+ if (info?.replaceable) {
12
+ if (parentValue != null) {
13
+ let i = 0;
14
+ for (; i < parentValue.chi.length; i++) {
15
+ if (parentValue.chi[i] == value) {
16
+ parentValue.chi.splice(i, 1, ...info.node.val);
17
+ break;
18
+ }
19
+ }
20
+ }
21
+ else {
22
+ node.val = info.node.val.slice();
23
+ }
24
+ }
25
+ }
26
+ }
27
+ }
28
+ }
5
29
  class InlineCssVariables extends MinifyFeature {
6
30
  static get ordering() {
7
31
  return 0;
@@ -21,14 +45,14 @@ class InlineCssVariables extends MinifyFeature {
21
45
  if (!('variableScope' in context)) {
22
46
  context.variableScope = new Map;
23
47
  }
24
- const isRoot = parent.typ == 2 /* NodeType.StyleSheetNodeType */ && ast.typ == 4 /* NodeType.RuleNodeType */ && ast.sel == ':root';
48
+ const isRoot = parent.typ == EnumToken.StyleSheetNodeType && ast.typ == EnumToken.RuleNodeType && ast.sel == ':root';
25
49
  const variableScope = context.variableScope;
26
50
  // @ts-ignore
27
51
  for (const node of ast.chi) {
28
- if (node.typ == 1 /* NodeType.CDOCOMMNodeType */ || node.typ == 0 /* NodeType.CommentNodeType */) {
52
+ if (node.typ == EnumToken.CDOCOMMNodeType || node.typ == EnumToken.CommentNodeType) {
29
53
  continue;
30
54
  }
31
- if (node.typ != 5 /* NodeType.DeclarationNodeType */) {
55
+ if (node.typ != EnumToken.DeclarationNodeType) {
32
56
  break;
33
57
  }
34
58
  // css variable
@@ -37,13 +61,23 @@ class InlineCssVariables extends MinifyFeature {
37
61
  const info = {
38
62
  globalScope: isRoot,
39
63
  // @ts-ignore
40
- parent: new Set(),
64
+ parent: new IterableWeakSet(),
41
65
  declarationCount: 1,
42
66
  replaceable: isRoot,
43
67
  node: node
44
68
  };
45
69
  info.parent.add(ast);
46
70
  variableScope.set(node.nam, info);
71
+ let recursive = false;
72
+ for (const { value, parent: parentValue } of walkValues(node.val)) {
73
+ if (value?.typ == EnumToken.FunctionTokenType && value.val == 'var') {
74
+ recursive = true;
75
+ break;
76
+ }
77
+ }
78
+ if (recursive) {
79
+ replace(node, variableScope);
80
+ }
47
81
  }
48
82
  else {
49
83
  const info = variableScope.get(node.nam);
@@ -59,27 +93,7 @@ class InlineCssVariables extends MinifyFeature {
59
93
  }
60
94
  }
61
95
  else {
62
- for (const { value, parent: parentValue } of walkValues(node.val)) {
63
- if (value?.typ == EnumToken.FunctionTokenType && value.val == 'var') {
64
- if (value.chi.length == 1 && value.chi[0].typ == EnumToken.IdenTokenType) {
65
- const info = variableScope.get(value.chi[0].val);
66
- if (info?.replaceable) {
67
- if (parentValue != null) {
68
- let i = 0;
69
- for (; i < parentValue.chi.length; i++) {
70
- if (parentValue.chi[i] == value) {
71
- parentValue.chi.splice(i, 1, ...info.node.val);
72
- break;
73
- }
74
- }
75
- }
76
- else {
77
- node.val = info.node.val.slice();
78
- }
79
- }
80
- }
81
- }
82
- }
96
+ replace(node, variableScope);
83
97
  }
84
98
  }
85
99
  }
@@ -88,10 +102,11 @@ class InlineCssVariables extends MinifyFeature {
88
102
  for (const info of variableScope.values()) {
89
103
  if (info.replaceable) {
90
104
  let i;
105
+ // drop declarations from :root{}
91
106
  for (const parent of info.parent) {
92
107
  i = parent.chi?.length ?? 0;
93
108
  while (i--) {
94
- if (parent.chi[i].typ == 5 /* NodeType.DeclarationNodeType */ && parent.chi[i].nam == info.node.nam) {
109
+ if (parent.chi[i].typ == EnumToken.DeclarationNodeType && parent.chi[i].nam == info.node.nam) {
95
110
  parent.chi.splice(i, 1);
96
111
  }
97
112
  }
@@ -1,10 +1,11 @@
1
1
  import { PropertyList } from '../../parser/declaration/list.js';
2
2
  import '../../renderer/utils/color.js';
3
- import '../types.js';
3
+ import { EnumToken } from '../types.js';
4
4
  import '../minify.js';
5
5
  import '../../parser/parse.js';
6
6
  import '../../renderer/sourcemap/lib/encode.js';
7
- import { MinifyFeature } from '../utiles/minifyfeature.js';
7
+ import '../../parser/declaration/map.js';
8
+ import { MinifyFeature } from '../utils/minifyfeature.js';
8
9
 
9
10
  class ComputeShorthand extends MinifyFeature {
10
11
  static get ordering() {
@@ -30,7 +31,7 @@ class ComputeShorthand extends MinifyFeature {
30
31
  for (; k < j; k++) {
31
32
  // @ts-ignore
32
33
  const node = ast.chi[k];
33
- if (node.typ == 0 /* NodeType.CommentNodeType */ || node.typ == 5 /* NodeType.DeclarationNodeType */) {
34
+ if (node.typ == EnumToken.CommentNodeType || node.typ == EnumToken.DeclarationNodeType) {
34
35
  properties.add(node);
35
36
  continue;
36
37
  }
@@ -0,0 +1,95 @@
1
+ import { EnumToken } from '../../types.js';
2
+ import { reduceNumber } from '../../../renderer/render.js';
3
+
4
+ const gcd = (x, y) => {
5
+ x = Math.abs(x);
6
+ y = Math.abs(y);
7
+ let t;
8
+ if (x == 0 || y == 0) {
9
+ return 1;
10
+ }
11
+ while (y) {
12
+ t = y;
13
+ y = x % y;
14
+ x = t;
15
+ }
16
+ return x;
17
+ };
18
+ function compute(a, b, op) {
19
+ if (typeof a == 'number' && typeof b == 'number') {
20
+ switch (op) {
21
+ case EnumToken.Add:
22
+ return a + b;
23
+ case EnumToken.Sub:
24
+ return a - b;
25
+ case EnumToken.Mul:
26
+ return a * b;
27
+ case EnumToken.Div:
28
+ const r = simplify(a, b);
29
+ if (r[1] == 1) {
30
+ return r[0];
31
+ }
32
+ const result = a / b;
33
+ const r2 = reduceNumber(r[0]) + '/' + reduceNumber(r[1]);
34
+ return reduceNumber(result).length <= r2.length ? result : {
35
+ typ: EnumToken.FractionTokenType,
36
+ l: { typ: EnumToken.NumberTokenType, val: reduceNumber(r[0]) },
37
+ r: { typ: EnumToken.NumberTokenType, val: reduceNumber(r[1]) }
38
+ };
39
+ }
40
+ }
41
+ let l1 = typeof a == 'number' ? {
42
+ typ: EnumToken.FractionTokenType,
43
+ l: { typ: EnumToken.NumberTokenType, val: reduceNumber(a) },
44
+ r: { typ: EnumToken.NumberTokenType, val: '1' }
45
+ } : a;
46
+ let r1 = typeof b == 'number' ? {
47
+ typ: EnumToken.FractionTokenType,
48
+ l: { typ: EnumToken.NumberTokenType, val: reduceNumber(b) },
49
+ r: { typ: EnumToken.NumberTokenType, val: '1' }
50
+ } : b;
51
+ let l2;
52
+ let r2;
53
+ switch (op) {
54
+ case EnumToken.Add:
55
+ // @ts-ignore
56
+ l2 = l1.l.val * r1.r.val + l1.r.val * r1.l.val;
57
+ // @ts-ignore
58
+ r2 = l1.r.val * r1.r.val;
59
+ break;
60
+ case EnumToken.Sub:
61
+ // @ts-ignore
62
+ l2 = l1.l.val * r1.r.val - l1.r.val * r1.l.val;
63
+ // @ts-ignore
64
+ r2 = l1.r.val * r1.r.val;
65
+ break;
66
+ case EnumToken.Mul:
67
+ // @ts-ignore
68
+ l2 = l1.l.val * r1.l.val;
69
+ // @ts-ignore
70
+ r2 = l1.r.val * r1.r.val;
71
+ break;
72
+ case EnumToken.Div:
73
+ // @ts-ignore
74
+ l2 = l1.l.val * r1.r.val;
75
+ // @ts-ignore
76
+ r2 = l1.r.val * r1.l.val;
77
+ break;
78
+ }
79
+ const a2 = simplify(l2, r2);
80
+ if (a2[1] == 1) {
81
+ return a2[0];
82
+ }
83
+ const result = a2[0] / a2[1];
84
+ return reduceNumber(result).length <= reduceNumber(a2[0]).length + 1 + reduceNumber(a2[1]).length ? result : {
85
+ typ: EnumToken.FractionTokenType,
86
+ l: { typ: EnumToken.NumberTokenType, val: reduceNumber(a2[0]) },
87
+ r: { typ: EnumToken.NumberTokenType, val: reduceNumber(a2[1]) }
88
+ };
89
+ }
90
+ function simplify(a, b) {
91
+ const g = gcd(a, b);
92
+ return g > 1 ? [a / g, b / g] : [a, b];
93
+ }
94
+
95
+ export { compute, gcd, simplify };
@@ -1,5 +1,5 @@
1
1
  import { parseString } from '../parser/parse.js';
2
- import { isIdentStart, isWhiteSpace, isIdent, isFunction } from '../parser/utils/syntax.js';
2
+ import { isWhiteSpace, isIdent, isFunction, isIdentStart } from '../parser/utils/syntax.js';
3
3
  import { EnumToken } from './types.js';
4
4
  import { walkValues } from './walk.js';
5
5
  import { replaceCompound } from './expand.js';
@@ -7,7 +7,7 @@ import { eq } from '../parser/utils/eq.js';
7
7
  import { renderToken, doRender } from '../renderer/render.js';
8
8
  import * as index from './features/index.js';
9
9
 
10
- const combinators = ['+', '>', '~'];
10
+ const combinators = ['+', '>', '~', '||'];
11
11
  const notEndingWith = ['(', '['].concat(combinators);
12
12
  const definedPropertySettings = { configurable: true, enumerable: false, writable: true };
13
13
  // @ts-ignore
@@ -23,7 +23,12 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
23
23
  context.nodes.add(ast);
24
24
  if (!('features' in options)) {
25
25
  // @ts-ignore
26
- options = { removeDuplicateDeclarations: true, computeShorthand: true, computeCalcExpression: true, features: [], ...options };
26
+ options = {
27
+ removeDuplicateDeclarations: true,
28
+ computeShorthand: true,
29
+ computeCalcExpression: true,
30
+ features: [], ...options
31
+ };
27
32
  // @ts-ignore
28
33
  for (const feature of features) {
29
34
  feature.register(options);
@@ -42,7 +47,7 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
42
47
  curr.splice(0, 1);
43
48
  }
44
49
  }
45
- else if (ast.typ == 4 /* NodeType.RuleNodeType */ && (isIdent(curr[0]) || isFunction(curr[0]))) {
50
+ else if (ast.typ == EnumToken.RuleNodeType && (isIdent(curr[0]) || isFunction(curr[0]))) {
46
51
  curr.unshift('&', ' ');
47
52
  }
48
53
  acc.push(curr.join(''));
@@ -51,7 +56,7 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
51
56
  // @ts-ignore
52
57
  if ('chi' in ast && ast.chi.length > 0) {
53
58
  if (!nestingContent) {
54
- nestingContent = options.nestingRules && ast.typ == 4 /* NodeType.RuleNodeType */;
59
+ nestingContent = options.nestingRules && ast.typ == EnumToken.RuleNodeType;
55
60
  }
56
61
  let i = 0;
57
62
  let previous;
@@ -60,7 +65,7 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
60
65
  // @ts-ignore
61
66
  for (; i < ast.chi.length; i++) {
62
67
  // @ts-ignore
63
- if (ast.chi[i].typ == 0 /* NodeType.CommentNodeType */) {
68
+ if (ast.chi[i].typ == EnumToken.CommentNodeType) {
64
69
  continue;
65
70
  }
66
71
  // @ts-ignore
@@ -72,10 +77,10 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
72
77
  i--;
73
78
  continue;
74
79
  }
75
- if (node.typ == 3 /* NodeType.AtRuleNodeType */ && node.nam == 'font-face') {
80
+ if (node.typ == EnumToken.AtRuleNodeType && node.nam == 'font-face') {
76
81
  continue;
77
82
  }
78
- if (node.typ == 3 /* NodeType.AtRuleNodeType */) {
83
+ if (node.typ == EnumToken.AtRuleNodeType) {
79
84
  if (node.nam == 'media' && node.val == 'all') {
80
85
  // @ts-ignore
81
86
  ast.chi?.splice(i, 1, ...node.chi);
@@ -83,7 +88,7 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
83
88
  continue;
84
89
  }
85
90
  // @ts-ignore
86
- if (previous?.typ == 3 /* NodeType.AtRuleNodeType */ &&
91
+ if (previous?.typ == EnumToken.AtRuleNodeType &&
87
92
  previous.nam == node.nam &&
88
93
  previous.val == node.val) {
89
94
  if ('chi' in node) {
@@ -102,14 +107,14 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
102
107
  continue;
103
108
  }
104
109
  // @ts-ignore
105
- if (node.typ == 4 /* NodeType.RuleNodeType */) {
110
+ if (node.typ == EnumToken.RuleNodeType) {
106
111
  reduceRuleSelector(node);
107
112
  let wrapper;
108
113
  let match;
109
114
  // @ts-ignore
110
115
  if (options.nestingRules) {
111
116
  // @ts-ignore
112
- if (previous?.typ == 4 /* NodeType.RuleNodeType */) {
117
+ if (previous?.typ == EnumToken.RuleNodeType) {
113
118
  // @ts-ignore
114
119
  reduceRuleSelector(previous);
115
120
  // @ts-ignore
@@ -130,7 +135,7 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
130
135
  // @ts-ignore
131
136
  const nextNode = ast.chi[i];
132
137
  // @ts-ignore
133
- if (nextNode.typ != 4 /* NodeType.RuleNodeType */) {
138
+ if (nextNode.typ != EnumToken.RuleNodeType) {
134
139
  break;
135
140
  }
136
141
  reduceRuleSelector(nextNode);
@@ -184,7 +189,7 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
184
189
  curr.splice(0, 2);
185
190
  }
186
191
  else {
187
- if (ast.typ != 4 /* NodeType.RuleNodeType */ && combinators.includes(curr[1])) {
192
+ if (ast.typ != EnumToken.RuleNodeType && combinators.includes(curr[1])) {
188
193
  wrap = false;
189
194
  }
190
195
  else {
@@ -232,18 +237,18 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
232
237
  let k = previous.chi.length;
233
238
  while (k-- > 0) {
234
239
  // @ts-ignore
235
- if (previous.chi[k].typ == 0 /* NodeType.CommentNodeType */) {
240
+ if (previous.chi[k].typ == EnumToken.CommentNodeType) {
236
241
  continue;
237
242
  }
238
243
  // @ts-ignore
239
- shouldMerge = previous.chi[k].typ == 5 /* NodeType.DeclarationNodeType */;
244
+ shouldMerge = previous.chi[k].typ == EnumToken.DeclarationNodeType;
240
245
  break;
241
246
  }
242
247
  if (shouldMerge) {
243
248
  // @ts-ignore
244
- if ((node.typ == 4 /* NodeType.RuleNodeType */ && node.sel == previous.sel) ||
249
+ if ((node.typ == EnumToken.RuleNodeType && node.sel == previous.sel) ||
245
250
  // @ts-ignore
246
- (node.typ == 3 /* NodeType.AtRuleNodeType */) && node.val != 'font-face' && node.val == previous.val) {
251
+ (node.typ == EnumToken.AtRuleNodeType) && node.val != 'font-face' && node.val == previous.val) {
247
252
  // @ts-ignore
248
253
  node.chi.unshift(...previous.chi);
249
254
  // @ts-ignore
@@ -260,7 +265,7 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
260
265
  nodeIndex = i;
261
266
  continue;
262
267
  }
263
- else if (node.typ == 4 /* NodeType.RuleNodeType */ && previous?.typ == 4 /* NodeType.RuleNodeType */) {
268
+ else if (node.typ == EnumToken.RuleNodeType && previous?.typ == EnumToken.RuleNodeType) {
264
269
  const intersect = diff(previous, node, reducer, options);
265
270
  if (intersect != null) {
266
271
  if (intersect.node1.chi.length == 0) {
@@ -317,7 +322,7 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
317
322
  // @ts-ignore
318
323
  previous != null &&
319
324
  // previous.optimized != null &&
320
- previous.typ == 4 /* NodeType.RuleNodeType */ &&
325
+ previous.typ == EnumToken.RuleNodeType &&
321
326
  previous.sel.includes('&')) {
322
327
  fixSelector(previous);
323
328
  }
@@ -327,9 +332,9 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
327
332
  // @ts-ignore
328
333
  if (recursive && node != null && ('chi' in node)) {
329
334
  // @ts-ignore
330
- if (!node.chi.some(n => n.typ == 5 /* NodeType.DeclarationNodeType */)) {
335
+ if (!node.chi.some(n => n.typ == EnumToken.DeclarationNodeType)) {
331
336
  // @ts-ignore
332
- if (!(node.typ == 3 /* NodeType.AtRuleNodeType */ && node.nam != 'font-face')) {
337
+ if (!(node.typ == EnumToken.AtRuleNodeType && node.nam != 'font-face')) {
333
338
  minify(node, options, recursive, errors, nestingContent, context);
334
339
  }
335
340
  }
@@ -338,12 +343,12 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
338
343
  // @ts-ignore
339
344
  node != null &&
340
345
  // previous.optimized != null &&
341
- node.typ == 4 /* NodeType.RuleNodeType */ &&
346
+ node.typ == EnumToken.RuleNodeType &&
342
347
  node.sel.includes('&')) {
343
348
  fixSelector(node);
344
349
  }
345
350
  }
346
- if (ast.typ == 2 /* NodeType.StyleSheetNodeType */) {
351
+ if (ast.typ == EnumToken.StyleSheetNodeType) {
347
352
  let parent;
348
353
  let parents = [ast];
349
354
  while (parents.length > 0) {
@@ -352,7 +357,7 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
352
357
  for (let k = 0; k < parent.chi.length; k++) {
353
358
  // @ts-ignore
354
359
  const node = parent.chi[k];
355
- if (!('chi' in node) || node.typ == 2 /* NodeType.StyleSheetNodeType */ || (node.typ == 3 /* NodeType.AtRuleNodeType */ && node.nam == 'font-face')) {
360
+ if (!('chi' in node) || node.typ == EnumToken.StyleSheetNodeType || (node.typ == EnumToken.AtRuleNodeType && node.nam == 'font-face')) {
356
361
  continue;
357
362
  }
358
363
  // @ts-ignore
@@ -463,11 +468,11 @@ function hasDeclaration(node) {
463
468
  // @ts-ignore
464
469
  for (let i = 0; i < node.chi?.length; i++) {
465
470
  // @ts-ignore
466
- if (node.chi[i].typ == 0 /* NodeType.CommentNodeType */) {
471
+ if (node.chi[i].typ == EnumToken.CommentNodeType) {
467
472
  continue;
468
473
  }
469
474
  // @ts-ignore
470
- return node.chi[i].typ == 5 /* NodeType.DeclarationNodeType */;
475
+ return node.chi[i].typ == EnumToken.DeclarationNodeType;
471
476
  }
472
477
  return true;
473
478
  }
@@ -613,7 +618,7 @@ function matchSelectors(selector1, selector2, parentType, errors) {
613
618
  if (matchFunction != 0 || inAttr != 0) {
614
619
  return null;
615
620
  }
616
- if (parentType != 4 /* NodeType.RuleNodeType */) {
621
+ if (parentType != EnumToken.RuleNodeType) {
617
622
  for (const part of match) {
618
623
  if (part.length > 0 && combinators.includes(part[0].charAt(0))) {
619
624
  return null;
@@ -819,7 +824,7 @@ function diff(n1, n2, reducer, options = {}) {
819
824
  }
820
825
  const intersect = [];
821
826
  while (i--) {
822
- if (node1.chi[i].typ == 0 /* NodeType.CommentNodeType */) {
827
+ if (node1.chi[i].typ == EnumToken.CommentNodeType) {
823
828
  continue;
824
829
  }
825
830
  j = node2.chi.length;
@@ -827,7 +832,7 @@ function diff(n1, n2, reducer, options = {}) {
827
832
  break;
828
833
  }
829
834
  while (j--) {
830
- if (node2.chi[j].typ == 0 /* NodeType.CommentNodeType */) {
835
+ if (node2.chi[j].typ == EnumToken.CommentNodeType) {
831
836
  continue;
832
837
  }
833
838
  if (node1.chi[i].nam == node2.chi[j].nam) {