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

Commit

Permalink
9.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathantneal committed Jul 15, 2019
1 parent 3e72084 commit 1e1ef6b
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 10 deletions.
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

### 9.1.0 (July 15, 2019)

- Added: Support for preserving trailing comments within a declaration.

### 9.0.2 (July 15, 2019)

- Updated: `postcss-values-parser` to 3.0.5 (patch)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postcss-custom-properties",
"version": "9.0.2",
"version": "9.1.0",
"description": "Use Custom Properties Queries in CSS",
"author": "Jonathan Neal <[email protected]>",
"contributors": [
Expand Down
16 changes: 15 additions & 1 deletion src/lib/transform-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,19 @@ export default (root, customProperties, opts) => {
// conditionally transform values that have changed
if (value !== originalValue) {
if (opts.preserve) {
decl.cloneBefore({ value });
const beforeDecl = decl.cloneBefore({ value });

if (hasTrailingComment(beforeDecl)) {
beforeDecl.raws.value.value = beforeDecl.value.replace(trailingCommentRegExp, '$1');
beforeDecl.raws.value.raw = beforeDecl.raws.value.value + beforeDecl.raws.value.raw.replace(trailingCommentRegExp, '$2');
}
} else {
decl.value = value;

if (hasTrailingComment(decl)) {
decl.raws.value.value = decl.value.replace(trailingCommentRegExp, '$1');
decl.raws.value.raw = decl.raws.value.value + decl.raws.value.raw.replace(trailingCommentRegExp, '$2');
}
}
}
}
Expand All @@ -31,3 +41,7 @@ const customPropertiesRegExp = /(^|[^\w-])var\([\W\w]+\)/;

// whether the declaration should be potentially transformed
const isTransformableDecl = decl => !customPropertyRegExp.test(decl.prop) && customPropertiesRegExp.test(decl.value);

// whether the declaration has a trailing comment
const hasTrailingComment = decl => 'value' in Object(Object(decl.raws).value) && 'raw' in decl.raws.value && trailingCommentRegExp.test(decl.raws.value.raw);
const trailingCommentRegExp = /^([\W\w]+)(\s*\/\*[\W\w]+?\*\/)$/;
2 changes: 1 addition & 1 deletion test/basic.css
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ html {
color: var(
--color,
blue
);
)/*rtl:red*/;
}
4 changes: 2 additions & 2 deletions test/basic.expect.css
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ html {
}

.test--loose-formatting {
color: rgb(255, 0, 0);
color: rgb(255, 0, 0)/*rtl:red*/;
color: var(
--color,
blue
);
)/*rtl:red*/;
}
4 changes: 2 additions & 2 deletions test/basic.import-is-empty.expect.css
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ html {
}

.test--loose-formatting {
color: rgb(255, 0, 0);
color: rgb(255, 0, 0)/*rtl:red*/;
color: var(
--color,
blue
);
)/*rtl:red*/;
}
4 changes: 2 additions & 2 deletions test/basic.import.expect.css
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ html {
}

.test--loose-formatting {
color: rgb(255, 0, 0);
color: rgb(255, 0, 0)/*rtl:red*/;
color: var(
--color,
blue
);
)/*rtl:red*/;
}
2 changes: 1 addition & 1 deletion test/basic.preserve.expect.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@
}

.test--loose-formatting {
color: rgb(255, 0, 0);
color: rgb(255, 0, 0)/*rtl:red*/;
}

0 comments on commit 1e1ef6b

Please sign in to comment.