Skip to content
This repository has been archived by the owner on Feb 18, 2022. It is now read-only.

Commit

Permalink
upgrade to postcss-values-parser@3
Browse files Browse the repository at this point in the history
* upgrade to postcss-values-parser@3

* Remove guard
  • Loading branch information
remithomas authored and jonathantneal committed Apr 16, 2019
1 parent 654d59d commit 0e5a66d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"dependencies": {
"postcss": "^7.0.14",
"postcss-values-parser": "^2.0.1"
"postcss-values-parser": "^3.0.3"
},
"devDependencies": {
"@babel/core": "^7.4.0",
Expand Down
4 changes: 2 additions & 2 deletions src/lib/get-custom-properties-from-imports.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs';
import path from 'path';
import postcss from 'postcss';
import valueParser from 'postcss-values-parser';
import { parse } from 'postcss-values-parser';
import getCustomPropertiesFromRoot from './get-custom-properties-from-root';

/* Get Custom Properties from CSS File
Expand All @@ -25,7 +25,7 @@ function getCustomPropertiesFromObject(object) {
);

for (const key in customProperties) {
customProperties[key] = valueParser(String(customProperties[key])).parse().nodes;
customProperties[key] = parse(String(customProperties[key])).nodes;
}

return customProperties;
Expand Down
10 changes: 5 additions & 5 deletions src/lib/get-custom-properties-from-root.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import valueParser from 'postcss-values-parser';
import { parse } from 'postcss-values-parser';
import { isBlockIgnored } from './is-ignored';

// return custom selectors from the css root, conditionally removing them
export default function getCustomPropertiesFromRoot(root, opts) {
// initialize custom selectors
const customPropertiesFromHtmlElement = {};
const customPropertiesFromRootPsuedo = {};
const customPropertiesFromRootPseudo = {};

// for each html or :root rule
root.nodes.slice().forEach(rule => {
const customPropertiesObject = isHtmlRule(rule)
? customPropertiesFromHtmlElement
: isRootRule(rule)
? customPropertiesFromRootPsuedo
? customPropertiesFromRootPseudo
: null;

// for each custom property
Expand All @@ -22,7 +22,7 @@ export default function getCustomPropertiesFromRoot(root, opts) {
const { prop } = decl;

// write the parsed value to the custom property
customPropertiesObject[prop] = valueParser(decl.value).parse().nodes;
customPropertiesObject[prop] = parse(decl.value).nodes;

// conditionally remove the custom property declaration
if (!opts.preserve) {
Expand All @@ -39,7 +39,7 @@ export default function getCustomPropertiesFromRoot(root, opts) {
});

// return all custom properties, preferring :root properties over html properties
return { ...customPropertiesFromHtmlElement, ...customPropertiesFromRootPsuedo };
return { ...customPropertiesFromHtmlElement, ...customPropertiesFromRootPseudo };
}

// match html and :root rules
Expand Down
4 changes: 2 additions & 2 deletions src/lib/transform-properties.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import valueParser from 'postcss-values-parser';
import { parse } from 'postcss-values-parser';
import transformValueAST from './transform-value-ast';
import { isRuleIgnored } from './is-ignored';

Expand All @@ -8,7 +8,7 @@ export default (root, customProperties, opts) => {
root.walkDecls(decl => {
if (isTransformableDecl(decl) && !isRuleIgnored(decl)) {
const originalValue = decl.value;
const valueAST = valueParser(originalValue).parse();
const valueAST = parse(originalValue);
const value = String(transformValueAST(valueAST, customProperties));

// conditionally transform values that have changed
Expand Down
4 changes: 2 additions & 2 deletions src/lib/transform-value-ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export default function transformValueAST(root, customProperties) {
root.nodes.slice().forEach(child => {
if (isVarFunction(child)) {
// eslint-disable-next-line no-unused-vars
const [propertyNode, comma, ...fallbacks] = child.nodes.slice(1, -1);
const [propertyNode, comma, ...fallbacks] = child.nodes;
const { value: name } = propertyNode;

if (name in customProperties) {
Expand Down Expand Up @@ -45,7 +45,7 @@ function retransformValueAST(root, customProperties, withoutProperty) {
const varRegExp = /^var$/i;

// whether the node is a var() function
const isVarFunction = node => node.type === 'func' && varRegExp.test(node.value) && Object(node.nodes).length > 0;
const isVarFunction = node => node.type === 'func' && varRegExp.test(node.name) && Object(node.nodes).length > 0;

// return an array with its nodes cloned, preserving the raw
const asClonedArrayWithBeforeSpacing = (array, beforeSpacing) => {
Expand Down

0 comments on commit 0e5a66d

Please sign in to comment.