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

Commit 83292da

Browse files
committed
5.1.1
1 parent 6380b00 commit 83292da

8 files changed

+76
-307
lines changed

.rollup.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import babel from 'rollup-plugin-babel';
33
export default {
44
input: 'index.js',
55
output: [
6-
{ file: 'index.cjs.js', format: 'cjs' },
7-
{ file: 'index.es.mjs', format: 'es' }
6+
{ file: 'index.cjs.js', format: 'cjs', sourcemap: true },
7+
{ file: 'index.es.mjs', format: 'es', sourcemap: true }
88
],
99
plugins: [
1010
babel({

.tape.js

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ module.exports = {
99
preserve: true
1010
}
1111
},
12+
'safety': {
13+
message: 'supports safe tag ordering (.foo:--h1 becomes h1.foo instead of .fooh1)'
14+
},
1215
'basic:import': {
1316
message: 'supports { importFrom: { customSelectors: { ... } } } usage',
1417
options: {

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changes to PostCSS Custom Selectors
22

3+
### 5.1.1 (September 18, 2018)
4+
5+
- Fixed: Selectors like `.foo:--h1` become `h1.foo` instead of `.fooh1`
6+
37
### 5.1.0 (September 12, 2018)
48

59
- Added: New `exportTo` function to specify where to export custom selectors

lib/transform-selectors-by-custom-selectors.js

+35
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ function transformSelector(selector, customSelectors) {
3535

3636
const retranspiledSelectors = transformSelector(selectorClone, customSelectors);
3737

38+
adjustNodesBySelectorEnds(selectorClone.nodes, Number(index));
39+
3840
if (retranspiledSelectors.length) {
3941
transpiledSelectors.push(...retranspiledSelectors);
4042
} else {
@@ -50,3 +52,36 @@ function transformSelector(selector, customSelectors) {
5052

5153
return transpiledSelectors;
5254
}
55+
56+
// match selectors by difficult-to-separate ends
57+
const withoutSelectorStartMatch = /^(tag|universal)$/;
58+
const withoutSelectorEndMatch = /^(class|id|pseudo|tag|universal)$/;
59+
60+
const isWithoutSelectorStart = node => withoutSelectorStartMatch.test(Object(node).type);
61+
const isWithoutSelectorEnd = node => withoutSelectorEndMatch.test(Object(node).type);
62+
63+
// adjust nodes by selector ends (so that .class:--h1 becomes h1.class rather than .classh1)
64+
const adjustNodesBySelectorEnds = (nodes, index) => {
65+
if (index && isWithoutSelectorStart(nodes[index]) && isWithoutSelectorEnd(nodes[index - 1])) {
66+
let safeIndex = index - 1;
67+
68+
while (safeIndex && isWithoutSelectorEnd(nodes[safeIndex])) {
69+
--safeIndex;
70+
}
71+
72+
if (safeIndex < index) {
73+
const node = nodes.splice(index, 1)[0];
74+
75+
nodes.splice(safeIndex, 0, node);
76+
77+
nodes[safeIndex].spaces.before = nodes[safeIndex + 1].spaces.before;
78+
nodes[safeIndex + 1].spaces.before = '';
79+
80+
if (nodes[index]) {
81+
nodes[index].spaces.after = nodes[safeIndex].spaces.after;
82+
nodes[safeIndex].spaces.after = '';
83+
}
84+
}
85+
}
86+
};
87+

package.json

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "postcss-custom-selectors",
3-
"version": "5.1.0",
3+
"version": "5.1.1",
44
"description": "Use Custom Selectors in CSS",
55
"author": "Jonathan Neal <jonathantneal@hotmail.com>",
66
"contributors": [
@@ -15,7 +15,9 @@
1515
"module": "index.es.mjs",
1616
"files": [
1717
"index.cjs.js",
18-
"index.es.mjs"
18+
"index.cjs.js.map",
19+
"index.es.mjs",
20+
"index.es.mjs.map"
1921
],
2022
"scripts": {
2123
"prepublishOnly": "npm test",
@@ -32,15 +34,15 @@
3234
"postcss-selector-parser": "^5.0.0-rc.3"
3335
},
3436
"devDependencies": {
35-
"@babel/core": "^7.0.1",
37+
"@babel/core": "^7.1.0",
3638
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
37-
"@babel/preset-env": "^7.0.0",
39+
"@babel/preset-env": "^7.1.0",
3840
"babel-eslint": "^9.0.0",
39-
"eslint": "^5.5.0",
41+
"eslint": "^5.6.0",
4042
"eslint-config-dev": "^2.0.0",
4143
"postcss-tape": "^2.2.0",
4244
"pre-commit": "^1.2.2",
43-
"rollup": "^0.65.2",
45+
"rollup": "^0.66.0",
4446
"rollup-plugin-babel": "^4.0.3"
4547
},
4648
"eslintConfig": {

0 commit comments

Comments
 (0)