@tbela99/css-parser 1.4.4 → 1.4.5

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.4.5
4
+
5
+ - [x] Temporarily disable if syntax expansion
6
+
3
7
  ## v1.4.4
4
8
 
5
9
  ### Validation changes
package/README.md CHANGED
@@ -44,7 +44,6 @@ $ deno add @tbela99/css-parser
44
44
  ## Syntax lowering
45
45
  CSS-Parser can transform these modern CSS features into lower-level CSS syntax:
46
46
  * **Nested CSS transpilation** to legacy-compatible syntax.
47
- * **`if()` function transpilation** for broader browser compatibility.
48
47
  * **`color-mix()` function conversion** convert new color-mix() syntax to any of the supported colors.
49
48
 
50
49
  ## Benchmark
@@ -21543,7 +21543,48 @@
21543
21543
  }
21544
21544
  }
21545
21545
  if (result.length > 0) {
21546
- replaceNodeOrValue(declarationNode.parent, declarationNode, result);
21546
+ let invalidTokensTypes = new Set([
21547
+ exports.EnumToken.WhitespaceTokenType,
21548
+ exports.EnumToken.SemiColonTokenType,
21549
+ exports.EnumToken.ColonTokenType
21550
+ ]);
21551
+ for (i = 0; i < result.length; i++) {
21552
+ if (result[i].typ === exports.EnumToken.DeclarationNodeType) {
21553
+ for (const { value } of walkValues(result[i].val, result[i])) {
21554
+ if (value.typ === exports.EnumToken.ImageFunctionTokenType && value.val.includes('-gradient')) {
21555
+ let valid = true;
21556
+ let j;
21557
+ for (j = 0; j < value.chi.length; j++) {
21558
+ if (value.chi[j].typ === exports.EnumToken.IdenTokenType && 'else' == value.chi[j].val) {
21559
+ valid = false;
21560
+ break;
21561
+ }
21562
+ if (invalidTokensTypes.has(value.chi[j].typ) &&
21563
+ (value.chi[j + 1]?.typ === exports.EnumToken.CommaTokenType || j == value.chi.length - 1) &&
21564
+ (j == 0 || exports.EnumToken.CommaTokenType == value.chi[j - 1]?.typ)) {
21565
+ valid = false;
21566
+ break;
21567
+ }
21568
+ }
21569
+ if (!valid) {
21570
+ result.splice(i--, 1);
21571
+ break;
21572
+ }
21573
+ // const res = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, (value as FunctionToken).val + '()'), createValidationContext((value as FunctionToken).chi), {
21574
+ // });
21575
+ // if (!res.success) {
21576
+ // result.splice(i--, 1);
21577
+ // break;
21578
+ // }
21579
+ }
21580
+ }
21581
+ }
21582
+ }
21583
+ // console.debug({result});
21584
+ // throw new Error("Not implemented");
21585
+ if (result.length > 0) {
21586
+ replaceNodeOrValue(declarationNode.parent, declarationNode, result);
21587
+ }
21547
21588
  }
21548
21589
  // else remove node?
21549
21590
  return result;
@@ -30090,6 +30131,8 @@
30090
30131
  if (options.resolveImport) {
30091
30132
  options.resolveUrls = true;
30092
30133
  }
30134
+ // turn off expandIfSyntax for now
30135
+ options.expandIfSyntax = false;
30093
30136
  const startTime = performance.now();
30094
30137
  const errors = [];
30095
30138
  const src = options.src;
package/dist/index.cjs CHANGED
@@ -22785,7 +22785,48 @@ function processNode(declarationNode, cache) {
22785
22785
  }
22786
22786
  }
22787
22787
  if (result.length > 0) {
22788
- replaceNodeOrValue(declarationNode.parent, declarationNode, result);
22788
+ let invalidTokensTypes = new Set([
22789
+ exports.EnumToken.WhitespaceTokenType,
22790
+ exports.EnumToken.SemiColonTokenType,
22791
+ exports.EnumToken.ColonTokenType
22792
+ ]);
22793
+ for (i = 0; i < result.length; i++) {
22794
+ if (result[i].typ === exports.EnumToken.DeclarationNodeType) {
22795
+ for (const { value } of walkValues(result[i].val, result[i])) {
22796
+ if (value.typ === exports.EnumToken.ImageFunctionTokenType && value.val.includes('-gradient')) {
22797
+ let valid = true;
22798
+ let j;
22799
+ for (j = 0; j < value.chi.length; j++) {
22800
+ if (value.chi[j].typ === exports.EnumToken.IdenTokenType && 'else' == value.chi[j].val) {
22801
+ valid = false;
22802
+ break;
22803
+ }
22804
+ if (invalidTokensTypes.has(value.chi[j].typ) &&
22805
+ (value.chi[j + 1]?.typ === exports.EnumToken.CommaTokenType || j == value.chi.length - 1) &&
22806
+ (j == 0 || exports.EnumToken.CommaTokenType == value.chi[j - 1]?.typ)) {
22807
+ valid = false;
22808
+ break;
22809
+ }
22810
+ }
22811
+ if (!valid) {
22812
+ result.splice(i--, 1);
22813
+ break;
22814
+ }
22815
+ // const res = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, (value as FunctionToken).val + '()'), createValidationContext((value as FunctionToken).chi), {
22816
+ // });
22817
+ // if (!res.success) {
22818
+ // result.splice(i--, 1);
22819
+ // break;
22820
+ // }
22821
+ }
22822
+ }
22823
+ }
22824
+ }
22825
+ // console.debug({result});
22826
+ // throw new Error("Not implemented");
22827
+ if (result.length > 0) {
22828
+ replaceNodeOrValue(declarationNode.parent, declarationNode, result);
22829
+ }
22789
22830
  }
22790
22831
  // else remove node?
22791
22832
  return result;
@@ -29855,6 +29896,8 @@ async function doParse(iter, options = {}) {
29855
29896
  if (options.resolveImport) {
29856
29897
  options.resolveUrls = true;
29857
29898
  }
29899
+ // turn off expandIfSyntax for now
29900
+ options.expandIfSyntax = false;
29858
29901
  const startTime = performance.now();
29859
29902
  const errors = [];
29860
29903
  const src = options.src;
@@ -7,7 +7,7 @@ import { replaceNodeOrValue } from '../../parser/utils/token.js';
7
7
  import { cloneNode } from '../clone.js';
8
8
  import { trimArray } from '../../validation/match.js';
9
9
  import { findByValue } from '../find.js';
10
- import { walk } from '../walk.js';
10
+ import { walk, walkValues } from '../walk.js';
11
11
  import { eq } from '../../parser/utils/eq.js';
12
12
 
13
13
  const nodeMatcher = (value) => value.typ === EnumToken.IfConditionTokenType ||
@@ -169,7 +169,48 @@ function processNode(declarationNode, cache) {
169
169
  }
170
170
  }
171
171
  if (result.length > 0) {
172
- replaceNodeOrValue(declarationNode.parent, declarationNode, result);
172
+ let invalidTokensTypes = new Set([
173
+ EnumToken.WhitespaceTokenType,
174
+ EnumToken.SemiColonTokenType,
175
+ EnumToken.ColonTokenType
176
+ ]);
177
+ for (i = 0; i < result.length; i++) {
178
+ if (result[i].typ === EnumToken.DeclarationNodeType) {
179
+ for (const { value } of walkValues(result[i].val, result[i])) {
180
+ if (value.typ === EnumToken.ImageFunctionTokenType && value.val.includes('-gradient')) {
181
+ let valid = true;
182
+ let j;
183
+ for (j = 0; j < value.chi.length; j++) {
184
+ if (value.chi[j].typ === EnumToken.IdenTokenType && 'else' == value.chi[j].val) {
185
+ valid = false;
186
+ break;
187
+ }
188
+ if (invalidTokensTypes.has(value.chi[j].typ) &&
189
+ (value.chi[j + 1]?.typ === EnumToken.CommaTokenType || j == value.chi.length - 1) &&
190
+ (j == 0 || EnumToken.CommaTokenType == value.chi[j - 1]?.typ)) {
191
+ valid = false;
192
+ break;
193
+ }
194
+ }
195
+ if (!valid) {
196
+ result.splice(i--, 1);
197
+ break;
198
+ }
199
+ // const res = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, (value as FunctionToken).val + '()'), createValidationContext((value as FunctionToken).chi), {
200
+ // });
201
+ // if (!res.success) {
202
+ // result.splice(i--, 1);
203
+ // break;
204
+ // }
205
+ }
206
+ }
207
+ }
208
+ }
209
+ // console.debug({result});
210
+ // throw new Error("Not implemented");
211
+ if (result.length > 0) {
212
+ replaceNodeOrValue(declarationNode.parent, declarationNode, result);
213
+ }
173
214
  }
174
215
  // else remove node?
175
216
  return result;
@@ -244,6 +244,8 @@ async function doParse(iter, options = {}) {
244
244
  if (options.resolveImport) {
245
245
  options.resolveUrls = true;
246
246
  }
247
+ // turn off expandIfSyntax for now
248
+ options.expandIfSyntax = false;
247
249
  const startTime = performance.now();
248
250
  const errors = [];
249
251
  const src = options.src;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tbela99/css-parser",
3
3
  "description": "CSS parser, minifier and validator for node and the browser",
4
- "version": "1.4.4",
4
+ "version": "1.4.5",
5
5
  "exports": {
6
6
  ".": "./dist/node.js",
7
7
  "./node": "./dist/node.js",