@tbela99/css-parser 1.4.4 → 1.4.6

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,10 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.4.6
4
+
5
+ - [x] Fix if syntax expansion regression bug #134
6
+
7
+ ## v1.4.5
8
+
9
+ - [x] Temporarily disable if syntax expansion #131
10
+
3
11
  ## v1.4.4
4
12
 
5
13
  ### Validation changes
6
14
 
7
- - [x] Added the `state` and `errors` properties to nodes to expose their validation status and any associated validation errors.
15
+ - [x] Added the `state` and `errors` properties to nodes to expose their validation status and any associated validation errors. #127
8
16
  - [x] Nodes that fail validation are no longer discarded. Nodes are discarded only if they are invalid, unparsed, or malformed. Unknown nodes are discarded when lenient parsing is disabled.
9
17
 
10
18
  ### Color
@@ -12107,29 +12107,6 @@
12107
12107
  if (!doNotValidate && !result?.success && result.errors.length > 0) {
12108
12108
  errors.push(...result.errors);
12109
12109
  }
12110
- if (!doNotValidate && !(success || result.success)) {
12111
- return Object.defineProperties(Object.assign(name, {
12112
- typ: exports.EnumToken.DeclarationNodeType,
12113
- nam: name.val,
12114
- val: parseTokens(tokens),
12115
- }), {
12116
- state: {
12117
- ...definedPropertySettings,
12118
- value: exports.EnumAstNodeStatus.ValidationFailed,
12119
- },
12120
- errors: {
12121
- ...definedPropertySettings,
12122
- value: result?.errors ?? [],
12123
- },
12124
- loc: {
12125
- ...definedPropertySettings,
12126
- value: {
12127
- ...name.loc,
12128
- end: tokens[tokens.length - 1]?.loc.end ?? name.loc.end,
12129
- },
12130
- },
12131
- });
12132
- }
12133
12110
  }
12134
12111
  }
12135
12112
  for (i = 0; i < tokens.length; i++) {
@@ -21543,7 +21520,48 @@
21543
21520
  }
21544
21521
  }
21545
21522
  if (result.length > 0) {
21546
- replaceNodeOrValue(declarationNode.parent, declarationNode, result);
21523
+ let invalidTokensTypes = new Set([
21524
+ exports.EnumToken.WhitespaceTokenType,
21525
+ exports.EnumToken.SemiColonTokenType,
21526
+ exports.EnumToken.ColonTokenType
21527
+ ]);
21528
+ for (i = 0; i < result.length; i++) {
21529
+ if (result[i].typ === exports.EnumToken.DeclarationNodeType) {
21530
+ for (const { value } of walkValues(result[i].val, result[i])) {
21531
+ if (value.typ === exports.EnumToken.ImageFunctionTokenType && value.val.includes('-gradient')) {
21532
+ let valid = true;
21533
+ let j;
21534
+ for (j = 0; j < value.chi.length; j++) {
21535
+ if (value.chi[j].typ === exports.EnumToken.IdenTokenType && 'else' == value.chi[j].val) {
21536
+ valid = false;
21537
+ break;
21538
+ }
21539
+ if (invalidTokensTypes.has(value.chi[j].typ) &&
21540
+ (value.chi[j + 1]?.typ === exports.EnumToken.CommaTokenType || j == value.chi.length - 1) &&
21541
+ (j == 0 || exports.EnumToken.CommaTokenType == value.chi[j - 1]?.typ)) {
21542
+ valid = false;
21543
+ break;
21544
+ }
21545
+ }
21546
+ if (!valid) {
21547
+ result.splice(i--, 1);
21548
+ break;
21549
+ }
21550
+ // const res = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, (value as FunctionToken).val + '()'), createValidationContext((value as FunctionToken).chi), {
21551
+ // });
21552
+ // if (!res.success) {
21553
+ // result.splice(i--, 1);
21554
+ // break;
21555
+ // }
21556
+ }
21557
+ }
21558
+ }
21559
+ }
21560
+ // console.debug({result});
21561
+ // throw new Error("Not implemented");
21562
+ if (result.length > 0) {
21563
+ replaceNodeOrValue(declarationNode.parent, declarationNode, result);
21564
+ }
21547
21565
  }
21548
21566
  // else remove node?
21549
21567
  return result;
package/dist/index.cjs CHANGED
@@ -9211,29 +9211,6 @@ function parseDeclaration(tokens, parent, options, errors) {
9211
9211
  if (!doNotValidate && !result?.success && result.errors.length > 0) {
9212
9212
  errors.push(...result.errors);
9213
9213
  }
9214
- if (!doNotValidate && !(success || result.success)) {
9215
- return Object.defineProperties(Object.assign(name, {
9216
- typ: exports.EnumToken.DeclarationNodeType,
9217
- nam: name.val,
9218
- val: parseTokens(tokens),
9219
- }), {
9220
- state: {
9221
- ...definedPropertySettings,
9222
- value: exports.EnumAstNodeStatus.ValidationFailed,
9223
- },
9224
- errors: {
9225
- ...definedPropertySettings,
9226
- value: result?.errors ?? [],
9227
- },
9228
- loc: {
9229
- ...definedPropertySettings,
9230
- value: {
9231
- ...name.loc,
9232
- end: tokens[tokens.length - 1]?.loc.end ?? name.loc.end,
9233
- },
9234
- },
9235
- });
9236
- }
9237
9214
  }
9238
9215
  }
9239
9216
  for (i = 0; i < tokens.length; i++) {
@@ -22785,7 +22762,48 @@ function processNode(declarationNode, cache) {
22785
22762
  }
22786
22763
  }
22787
22764
  if (result.length > 0) {
22788
- replaceNodeOrValue(declarationNode.parent, declarationNode, result);
22765
+ let invalidTokensTypes = new Set([
22766
+ exports.EnumToken.WhitespaceTokenType,
22767
+ exports.EnumToken.SemiColonTokenType,
22768
+ exports.EnumToken.ColonTokenType
22769
+ ]);
22770
+ for (i = 0; i < result.length; i++) {
22771
+ if (result[i].typ === exports.EnumToken.DeclarationNodeType) {
22772
+ for (const { value } of walkValues(result[i].val, result[i])) {
22773
+ if (value.typ === exports.EnumToken.ImageFunctionTokenType && value.val.includes('-gradient')) {
22774
+ let valid = true;
22775
+ let j;
22776
+ for (j = 0; j < value.chi.length; j++) {
22777
+ if (value.chi[j].typ === exports.EnumToken.IdenTokenType && 'else' == value.chi[j].val) {
22778
+ valid = false;
22779
+ break;
22780
+ }
22781
+ if (invalidTokensTypes.has(value.chi[j].typ) &&
22782
+ (value.chi[j + 1]?.typ === exports.EnumToken.CommaTokenType || j == value.chi.length - 1) &&
22783
+ (j == 0 || exports.EnumToken.CommaTokenType == value.chi[j - 1]?.typ)) {
22784
+ valid = false;
22785
+ break;
22786
+ }
22787
+ }
22788
+ if (!valid) {
22789
+ result.splice(i--, 1);
22790
+ break;
22791
+ }
22792
+ // const res = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, (value as FunctionToken).val + '()'), createValidationContext((value as FunctionToken).chi), {
22793
+ // });
22794
+ // if (!res.success) {
22795
+ // result.splice(i--, 1);
22796
+ // break;
22797
+ // }
22798
+ }
22799
+ }
22800
+ }
22801
+ }
22802
+ // console.debug({result});
22803
+ // throw new Error("Not implemented");
22804
+ if (result.length > 0) {
22805
+ replaceNodeOrValue(declarationNode.parent, declarationNode, result);
22806
+ }
22789
22807
  }
22790
22808
  // else remove node?
22791
22809
  return result;
@@ -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;
@@ -8,7 +8,6 @@ import { walkValues } from '../../ast/walk.js';
8
8
  import { equalsIgnoreCase } from './text.js';
9
9
  import { buildExpression } from '../../ast/math/expression.js';
10
10
  import { splitTokenList } from '../../validation/utils/list.js';
11
- import { parseTokens } from '../parse.js';
12
11
 
13
12
  /**
14
13
  *
@@ -333,29 +332,6 @@ function parseDeclaration(tokens, parent, options, errors) {
333
332
  if (!doNotValidate && !result?.success && result.errors.length > 0) {
334
333
  errors.push(...result.errors);
335
334
  }
336
- if (!doNotValidate && !(success || result.success)) {
337
- return Object.defineProperties(Object.assign(name, {
338
- typ: EnumToken.DeclarationNodeType,
339
- nam: name.val,
340
- val: parseTokens(tokens),
341
- }), {
342
- state: {
343
- ...definedPropertySettings,
344
- value: EnumAstNodeStatus.ValidationFailed,
345
- },
346
- errors: {
347
- ...definedPropertySettings,
348
- value: result?.errors ?? [],
349
- },
350
- loc: {
351
- ...definedPropertySettings,
352
- value: {
353
- ...name.loc,
354
- end: tokens[tokens.length - 1]?.loc.end ?? name.loc.end,
355
- },
356
- },
357
- });
358
- }
359
335
  }
360
336
  }
361
337
  for (i = 0; i < tokens.length; i++) {
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.6",
5
5
  "exports": {
6
6
  ".": "./dist/node.js",
7
7
  "./node": "./dist/node.js",