postcss-double-position-gradients 3.0.0 → 3.0.1

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 @@ jobs:
7
7
  runs-on: ubuntu-latest
8
8
  strategy:
9
9
  matrix:
10
- node: [12, 16]
10
+ node: [12, 14, 16]
11
11
  steps:
12
12
  - uses: actions/checkout@v2
13
13
  - uses: actions/setup-node@v2
14
14
  with:
15
15
  node-version: ${{ matrix.node }}
16
16
 
17
- - run: yarn install --ignore-scripts
18
- - run: yarn run test
17
+ - run: npm install --ignore-scripts
18
+ - run: npm run test
package/.gitignore CHANGED
@@ -1,6 +1,6 @@
1
1
  node_modules
2
2
  package-lock.json
3
- yarn.lock
3
+ yarn-lock.json
4
4
  *.log*
5
5
  *.result.css
6
6
  .*
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changes to PostCSS Double Position Gradients
2
2
 
3
+ ### 3.0.1 (November 18, 2021)
4
+
5
+ - Added: Safeguards against postcss-values-parser potentially throwing an error.
6
+
7
+ - Fixed: Issue with some gradients creating an infinite loop.
8
+
9
+ - Updated: `postcss-value-parser` to 6.0.1 (patch)
10
+ - Updated: `eslint` to 8.2.0 (major)
11
+ - Updated: `postcss` to 8.3.11 (patch)
12
+
13
+ - Removed: yarn.lock is no longer version controlled
14
+
3
15
  ### 3.0.0 (September 17, 2021)
4
16
 
5
17
  - Updated: Support for PostCS 8+ (major).
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [<img alt="NPM Version" src="https://img.shields.io/npm/v/postcss-double-position-gradients.svg" height="20">][npm-url]
4
4
  [<img alt="CSS Standard Status" src="https://cssdb.org/badge/double-position-gradients.svg" height="20">][css-url]
5
- [<img alt="Build Status" src="https://github.com/csstools/postcss-double-position-gradients/workflows/test/badge.svg" height="20">][cli-url]
5
+ [<img alt="Build Status" src="https://img.shields.io/travis/csstools/postcss-double-position-gradients/master.svg" height="20">][cli-url]
6
6
  [<img alt="Support Chat" src="https://img.shields.io/badge/support-chat-blue.svg" height="20">][git-url]
7
7
 
8
8
  [PostCSS Double Position Gradients] lets you use double-position gradients in
@@ -94,7 +94,7 @@ postcssDoublePositionGradients({ preserve: false })
94
94
  ```
95
95
 
96
96
  [css-url]: https://cssdb.org/#double-position-gradients
97
- [cli-url]: https://github.com/csstools/postcss-double-position-gradients/actions/workflows/test.yml?query=workflow/test
97
+ [cli-url]: https://travis-ci.org/csstools/postcss-double-position-gradients
98
98
  [git-url]: https://gitter.im/postcss/postcss
99
99
  [npm-url]: https://www.npmjs.com/package/postcss-double-position-gradients
100
100
 
package/index.js CHANGED
@@ -1,10 +1,12 @@
1
- const {parse} = require("postcss-values-parser");
2
- const Punctuation = require("postcss-values-parser/lib/nodes/Punctuation");
1
+ const { parse } = require('postcss-values-parser');
2
+ const Punctuation = require('postcss-values-parser/lib/nodes/Punctuation');
3
3
 
4
4
  // whether the value has a lab() or lch() matcher
5
5
  const gradientRegExp = /(repeating-)?(conic|linear|radial)-gradient\([\W\w]*\)/i;
6
6
  const gradientPartsRegExp = /^(repeating-)?(conic|linear|radial)-gradient$/i;
7
7
 
8
+ const isPunctuationCommaNode = node => node.type === 'punctuation' && node.value === ','
9
+
8
10
  /**
9
11
  * Transform double-position gradients in CSS.
10
12
  * @param {{preserve?: boolean}} opts
@@ -15,33 +17,48 @@ module.exports = function creator(opts) {
15
17
 
16
18
  return {
17
19
  postcssPlugin: 'postcss-double-position-gradients',
18
- Declaration(decl) {
20
+ Declaration(decl, { result }) {
19
21
  if (!gradientRegExp.test(decl.value)) {
20
22
  return;
21
23
  }
22
24
 
23
- const valueAST = parse(decl.value, { ignoreUnknownWords: true });
25
+ let valueAST;
26
+
27
+ try {
28
+ valueAST = parse(decl.value, { ignoreUnknownWords: true });
29
+ } catch (error) {
30
+ decl.warn(
31
+ result,
32
+ `Failed to parse value '${decl.value}' as a CSS gradient. Leaving the original value intact.`
33
+ );
34
+ }
35
+
36
+ if (typeof valueAST === 'undefined') {
37
+ // Bail if there's an error
38
+ return;
39
+ }
24
40
 
25
41
  valueAST.walkFuncs((func) => {
26
42
  if (!gradientPartsRegExp.test(func.name)) {
27
43
  return;
28
44
  }
29
45
 
30
- func.walkNumerics((node, index) => {
31
- /** @type {import('postcss-values-parser').ChildNode} */
32
- const node1back = Object(func.nodes[index - 1]);
33
- /** @type {import('postcss-values-parser').ChildNode} */
34
- const node2back = Object(func.nodes[index - 2]);
35
- /** @type {import('postcss-values-parser').ChildNode} */
36
- const node1next = Object(func.nodes[index + 1]);
46
+ const nodes = func.nodes;
47
+
48
+ nodes.slice(0).forEach((node, index, nodes) => {
49
+ const node1back = Object(nodes[index - 1]);
50
+ const node2back = Object(nodes[index - 2]);
51
+ const node1next = Object(nodes[index + 1]);
52
+
53
+ const isDoublePositionLength = node2back.type && node1back.type === 'numeric' && node.type === 'numeric';
37
54
 
38
55
  // if the argument concludes a double-position gradient
39
- if (node2back.type && node1back.type === 'numeric') {
56
+ if (isDoublePositionLength) {
40
57
  // insert the fallback colors
41
58
  const color = node2back.clone();
42
59
  const comma = new Punctuation({
43
60
  value: ',',
44
- raws: node1next.type === 'punctuation' && node1next.value === ','
61
+ raws: isPunctuationCommaNode(node1next)
45
62
  ? Object.assign({}, node1next.clone().raws)
46
63
  : { before: '', after: '' }
47
64
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss-double-position-gradients",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "Use double-position gradients in CSS",
5
5
  "author": "Jonathan Neal <jonathantneal@hotmail.com>",
6
6
  "license": "CC0-1.0",
@@ -19,14 +19,14 @@
19
19
  "node": ">=12"
20
20
  },
21
21
  "dependencies": {
22
- "postcss-values-parser": "6.0.0"
22
+ "postcss-values-parser": "6.0.1"
23
23
  },
24
24
  "peerDependencies": {
25
25
  "postcss": "^8.3"
26
26
  },
27
27
  "devDependencies": {
28
- "eslint": "7.32.0",
29
- "postcss": "8.3.6",
28
+ "eslint": "8.2.0",
29
+ "postcss": "8.3.11",
30
30
  "postcss-tape": "6.0.1"
31
31
  },
32
32
  "eslintConfig": {
package/test/basic.css CHANGED
@@ -17,3 +17,7 @@
17
17
  .test-conic-gradient-ignored {
18
18
  background-image: conic-gradient(yellowgreen 40%, gold 0deg , gold 75% , #f06 0deg);
19
19
  }
20
+
21
+ .test-linear-gradient-loop {
22
+ background-image: linear-gradient(135deg, rgba(255, 255, 255, 0.25) 25%, transparent);
23
+ }
@@ -19,3 +19,7 @@
19
19
  .test-conic-gradient-ignored {
20
20
  background-image: conic-gradient(yellowgreen 40%, gold 0deg , gold 75% , #f06 0deg);
21
21
  }
22
+
23
+ .test-linear-gradient-loop {
24
+ background-image: linear-gradient(135deg, rgba(255, 255, 255, 0.25) 25%, transparent);
25
+ }
@@ -17,3 +17,7 @@
17
17
  .test-conic-gradient-ignored {
18
18
  background-image: conic-gradient(yellowgreen 40%, gold 0deg , gold 75% , #f06 0deg);
19
19
  }
20
+
21
+ .test-linear-gradient-loop {
22
+ background-image: linear-gradient(135deg, rgba(255, 255, 255, 0.25) 25%, transparent);
23
+ }