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

8.0.1 #135

Merged
merged 1 commit into from
Sep 17, 2018
Merged

8.0.1 #135

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .rollup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import babel from 'rollup-plugin-babel';
export default {
input: 'index.js',
output: [
{ file: 'index.cjs.js', format: 'cjs' },
{ file: 'index.es.mjs', format: 'es' }
{ file: 'index.cjs.js', format: 'cjs', sourcemap: true },
{ file: 'index.es.mjs', format: 'es', sourcemap: true }
],
plugins: [
babel({
Expand Down
12 changes: 6 additions & 6 deletions .tape.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {
options: {
importFrom: {
customProperties: {
'--color': 'red',
'--color': 'rgb(255, 0, 0)',
'--color-2': 'yellow',
'--ref-color': 'var(--color)'
}
Expand All @@ -27,7 +27,7 @@ module.exports = {
importFrom() {
return {
customProperties: {
'--color': 'red',
'--color': 'rgb(255, 0, 0)',
'--color-2': 'yellow',
'--ref-color': 'var(--color)'
}
Expand All @@ -44,7 +44,7 @@ module.exports = {
return new Promise(resolve => {
resolve({
customProperties: {
'--color': 'red',
'--color': 'rgb(255, 0, 0)',
'--color-2': 'yellow',
'--ref-color': 'var(--color)'
}
Expand Down Expand Up @@ -105,7 +105,7 @@ module.exports = {
expect: 'basic.expect.css',
result: 'basic.result.css',
after() {
if (__exportPropertiesObject.customProperties['--color'] !== 'red') {
if (__exportPropertiesObject.customProperties['--color'] !== 'rgb(255, 0, 0)') {
throw new Error('The exportTo function failed');
}
}
Expand All @@ -114,7 +114,7 @@ module.exports = {
message: 'supports { exportTo() } usage',
options: {
exportTo(customProperties) {
if (customProperties['--color'] !== 'red') {
if (customProperties['--color'] !== 'rgb(255, 0, 0)') {
throw new Error('The exportTo function failed');
}
}
Expand All @@ -127,7 +127,7 @@ module.exports = {
options: {
exportTo(customProperties) {
return new Promise((resolve, reject) => {
if (customProperties['--color'] !== 'red') {
if (customProperties['--color'] !== 'rgb(255, 0, 0)') {
reject('The exportTo function failed');
} else {
resolve();
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changes to PostCSS Custom Properties

### 8.0.1 (September 17, 2018)

- Fixed: Workaround issue in `postcss-values-parser` incorrectly cloning nodes.

### 8.0.0 (September 16, 2018)

- Added: New `exportTo` function to specify where to export custom properties to.
Expand Down
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ will need to namespace Custom Properties using the `customProperties` or
```js
postcssCustomProperties({
importFrom: [
'path/to/file.css',
'and/then/this.js',
'and/then/that.json',
'path/to/file.css', // :root { --color: red; }
'and/then/this.js', // module.exports = { customProperties: { '--color': 'red' } }
'and/then/that.json', // { "custom-properties": { "--color": "red" } }
{
customProperties: { '--color': 'red' }
},
Expand All @@ -138,6 +138,9 @@ postcssCustomProperties({
});
```

See example imports written in [CSS](test/import-properties.css),
[JS](test/import-properties.js), and [JSON](test/import-properties.json).

### exportTo

The `exportTo` option specifies destinations where Custom Properties can be exported
Expand Down Expand Up @@ -172,6 +175,10 @@ postcssCustomProperties({
});
```

See example exports written to [CSS](test/export-properties.css),
[JS](test/export-properties.js), [MJS](test/export-properties.mjs), and
[JSON](test/export-properties.json).

[cli-img]: https://img.shields.io/travis/postcss/postcss-custom-properties.svg
[cli-url]: https://travis-ci.org/postcss/postcss-custom-properties
[css-img]: https://cssdb.org/badge/custom-properties.svg
Expand Down
21 changes: 19 additions & 2 deletions lib/transform-value-ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function transformValueAST(root, customProperties) {
if (name in customProperties) {
// conditionally replace a known custom property
child.replaceWith(
...asClonedArray(customProperties[name])
...asClonedArray(customProperties[name], null)
);

const nextCustomProperties = Object.assign({}, customProperties);
Expand Down Expand Up @@ -47,4 +47,21 @@ const varRegExp = /^var$/i;
const isVarFunction = node => node.type === 'func' && varRegExp.test(node.value) && Object(node.nodes).length > 0;

// return an array with its nodes cloned
const asClonedArray = array => array.map(node => node.clone());
const asClonedArray = (array, parent) => array.map(node => asClonedNode(node, parent));

// return a cloned node
const asClonedNode = (node, parent) => {
const cloneNode = new node.constructor(node);

for (const key in node) {
if (key === 'parent') {
cloneNode.parent = parent;
} else if (Object(node[key]).constructor === Array) {
cloneNode[key] = asClonedArray(node.nodes, cloneNode);
} else if (Object(node[key]).constructor === Object) {
cloneNode[key] = Object.assign({}, node[key]);
}
}

return cloneNode;
}
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postcss-custom-properties",
"version": "8.0.0",
"version": "8.0.1",
"description": "Use Custom Properties Queries in CSS",
"author": "Jonathan Neal <jonathantneal@hotmail.com>",
"contributors": [
Expand All @@ -14,7 +14,9 @@
"module": "index.es.mjs",
"files": [
"index.cjs.js",
"index.es.mjs"
"index.cjs.js.map",
"index.es.mjs",
"index.es.mjs.map"
],
"scripts": {
"prepublishOnly": "npm test",
Expand Down
2 changes: 1 addition & 1 deletion test/basic.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ html {
}

:root {
--color: red;
--color: rgb(255, 0, 0);
--ref-color: var(--color);
--circular: var(--circular-2);
--circular-2: var(--circular);
Expand Down
6 changes: 3 additions & 3 deletions test/basic.expect.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ html {
}

:root {
--color: red;
--color: rgb(255, 0, 0);
--ref-color: var(--color);
--circular: var(--circular-2);
--circular-2: var(--circular);
}

.test {
--skip: gray;
color: red;
color: rgb(255, 0, 0);
color: var(--color);
}

Expand All @@ -21,7 +21,7 @@ html {
}

.test--color_w_var {
color: red;
color: rgb(255, 0, 0);
color: var(--ref-color);
}

Expand Down
6 changes: 3 additions & 3 deletions test/basic.import.expect.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ html {
}

:root {
--color: red;
--color: rgb(255, 0, 0);
--ref-color: var(--color);
--circular: var(--circular-2);
--circular-2: var(--circular);
}

.test {
--skip: gray;
color: red;
color: rgb(255, 0, 0);
color: var(--color);
}

Expand All @@ -21,7 +21,7 @@ html {
}

.test--color_w_var {
color: red;
color: rgb(255, 0, 0);
color: var(--ref-color);
}

Expand Down
4 changes: 2 additions & 2 deletions test/basic.preserve.expect.css
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
.test {
--skip: gray;
color: red;
color: rgb(255, 0, 0);
}

.test--fallback {
color: blue;
}

.test--color_w_var {
color: red;
color: rgb(255, 0, 0);
}

.test--circular_var {
Expand Down
2 changes: 1 addition & 1 deletion test/export-properties.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
:root {
--ref-color: var(--color);
--color: red;
--color: rgb(255, 0, 0);
--circular: var(--circular-2);
--circular-2: var(--circular);
}
2 changes: 1 addition & 1 deletion test/export-properties.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
customProperties: {
'--ref-color': 'var(--color)',
'--color': 'red',
'--color': 'rgb(255, 0, 0)',
'--circular': 'var(--circular-2)',
'--circular-2': 'var(--circular)'
}
Expand Down
2 changes: 1 addition & 1 deletion test/export-properties.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"custom-properties": {
"--ref-color": "var(--color)",
"--color": "red",
"--color": "rgb(255, 0, 0)",
"--circular": "var(--circular-2)",
"--circular-2": "var(--circular)"
}
Expand Down
2 changes: 1 addition & 1 deletion test/export-properties.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const customProperties = {
'--ref-color': 'var(--color)',
'--color': 'red',
'--color': 'rgb(255, 0, 0)',
'--circular': 'var(--circular-2)',
'--circular-2': 'var(--circular)'
};
2 changes: 1 addition & 1 deletion test/import-properties.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
:root {
--color: red;
--color: rgb(255, 0, 0);
--color-2: yellow;
--ref-color: var(--color);
}
2 changes: 1 addition & 1 deletion test/import-properties.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
customProperties: {
'--color': 'red',
'--color': 'rgb(255, 0, 0)',
'--color-2': 'yellow',
'--ref-color': 'var(--color)'
}
Expand Down
2 changes: 1 addition & 1 deletion test/import-properties.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"custom-properties": {
"--color": "red",
"--color": "rgb(255, 0, 0)",
"--color-2": "yellow",
"--ref-color": "var(--color)"
}
Expand Down