@tbela99/css-parser 0.0.1 → 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.
@@ -1,5 +1,10 @@
1
1
  import { eq } from '../utils/eq.js';
2
2
  import { isLength } from '../utils/syntax.js';
3
+ import { EnumToken } from '../../ast/types.js';
4
+ import '../../ast/minify.js';
5
+ import '../parse.js';
6
+ import '../../renderer/utils/color.js';
7
+ import '../../renderer/sourcemap/lib/encode.js';
3
8
 
4
9
  class PropertySet {
5
10
  config;
@@ -20,7 +25,8 @@ class PropertySet {
20
25
  const tokens = [];
21
26
  // @ts-ignore
22
27
  for (let token of this.declarations.get(this.config.shorthand).val) {
23
- if (this.config.types.includes(token.typ) || (token.typ == 'Number' && token.val == '0' &&
28
+ // @ts-ignore
29
+ if (this.config.types.some(t => token.typ == EnumToken[t]) || (token.typ == EnumToken.NumberTokenType && token.val == '0' &&
24
30
  (this.config.types.includes('Length') ||
25
31
  this.config.types.includes('Angle') ||
26
32
  this.config.types.includes('Dimension')))) {
@@ -31,15 +37,15 @@ class PropertySet {
31
37
  tokens[current].push(token);
32
38
  continue;
33
39
  }
34
- if (token.typ != 'Whitespace' && token.typ != 'Comment') {
35
- if (token.typ == 'Iden' && this.config.keywords.includes(token.val)) {
40
+ if (token.typ != EnumToken.WhitespaceTokenType && token.typ != EnumToken.CommentTokenType) {
41
+ if (token.typ == EnumToken.IdenTokenType && this.config.keywords.includes(token.val)) {
36
42
  if (tokens.length == 0) {
37
43
  tokens.push([]);
38
44
  current++;
39
45
  }
40
46
  tokens[current].push(token);
41
47
  }
42
- if (token.typ == 'Literal' && token.val == this.config.separator) {
48
+ if (token.typ == EnumToken.LiteralTokenType && token.val == this.config.separator) {
43
49
  tokens.push([]);
44
50
  current++;
45
51
  continue;
@@ -54,7 +60,7 @@ class PropertySet {
54
60
  this.config.properties.forEach((property, index) => {
55
61
  if (!this.declarations.has(property)) {
56
62
  this.declarations.set(property, {
57
- typ: 'Declaration',
63
+ typ: EnumToken.DeclarationNodeType,
58
64
  nam: property,
59
65
  val: []
60
66
  });
@@ -71,7 +77,7 @@ class PropertySet {
71
77
  // @ts-ignore
72
78
  const val = this.declarations.get(property).val;
73
79
  if (val.length > 0) {
74
- val.push({ typ: 'Whitespace' });
80
+ val.push({ typ: EnumToken.WhitespaceTokenType });
75
81
  }
76
82
  val.push({ ...values[index] });
77
83
  });
@@ -102,7 +108,7 @@ class PropertySet {
102
108
  let index = 0;
103
109
  // @ts-ignore
104
110
  for (const token of this.declarations.get(property).val) {
105
- if (token.typ == 'Whitespace') {
111
+ if (token.typ == EnumToken.WhitespaceTokenType) {
106
112
  continue;
107
113
  }
108
114
  if (values.length == index) {
@@ -118,8 +124,8 @@ class PropertySet {
118
124
  const t = value[i];
119
125
  const k = value[i == 1 ? 0 : i % 2];
120
126
  if (t.val == k.val && t.val == '0') {
121
- if ((t.typ == 'Number' && isLength(k)) ||
122
- (k.typ == 'Number' && isLength(t)) ||
127
+ if ((t.typ == EnumToken.NumberTokenType && isLength(k)) ||
128
+ (k.typ == EnumToken.NumberTokenType && isLength(t)) ||
123
129
  (isLength(k) || isLength(t))) {
124
130
  value.splice(i, 1);
125
131
  continue;
@@ -133,19 +139,19 @@ class PropertySet {
133
139
  }
134
140
  }
135
141
  iterator = [{
136
- typ: 'Declaration',
142
+ typ: EnumToken.DeclarationNodeType,
137
143
  nam: this.config.shorthand,
138
144
  val: values.reduce((acc, curr) => {
139
145
  if (curr.length > 1) {
140
146
  const k = curr.length * 2 - 1;
141
147
  let i = 1;
142
148
  while (i < k) {
143
- curr.splice(i, 0, { typ: 'Whitespace' });
149
+ curr.splice(i, 0, { typ: EnumToken.WhitespaceTokenType });
144
150
  i += 2;
145
151
  }
146
152
  }
147
153
  if (acc.length > 0) {
148
- acc.push({ typ: 'Literal', val: this.config.separator });
154
+ acc.push({ typ: EnumToken.LiteralTokenType, val: this.config.separator });
149
155
  }
150
156
  acc.push(...curr);
151
157
  return acc;