Skip to content

Commit 9167071

Browse files
committed
Fixed some issues with priority of invariant props
1 parent 634bf36 commit 9167071

File tree

5 files changed

+61
-19
lines changed

5 files changed

+61
-19
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [0.4.1] - 2016-12-12
8+
- Improved list of potential-affected properties (priority troubles workaround)
9+
710
## [0.4.0] - 2016-12-03
811
- Added `addPrefixToSelector` option (thanks to [@crossjs](https://github.com/crossjs))
912

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "postcss-rtl",
3-
"version": "0.4.0",
3+
"version": "0.4.1",
44
"description": "PostCSS plugin for RTL-optimizations",
55
"keywords": [
66
"postcss",

src/affected-props.js

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// selectors have direction related properties
2+
// should add [dir] prefix to increase priority
3+
4+
module.exports = [
5+
'background',
6+
'background-attachment',
7+
'background-color',
8+
'background-clip',
9+
'background-image',
10+
'background-position',
11+
'background-position-x',
12+
'background-position-y',
13+
'background-repeat',
14+
'background-size',
15+
'border',
16+
'border-bottom',
17+
'border-bottom-color',
18+
'border-bottom-style',
19+
'border-bottom-width',
20+
'border-color',
21+
'border-style',
22+
'border-width',
23+
'border-top',
24+
'border-top-color',
25+
'border-top-style',
26+
'border-top-width',
27+
'border-radius',
28+
'box-shadow',
29+
'clear',
30+
'cursor',
31+
'float',
32+
'margin',
33+
'margin-top',
34+
'margin-bottom',
35+
'padding',
36+
'padding-top',
37+
'padding-bottom',
38+
'transform-origin',
39+
'transform',
40+
'transition-delay',
41+
'transition-duration',
42+
'transition-property',
43+
'transition-timing-function',
44+
'text-align',
45+
'text-align-last',
46+
'text-shadow',
47+
]

src/index.js

+2-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const postcss = require( 'postcss' )
22

3+
const affectedProps = require( './affected-props' )
34
const { isKeyframeRule, isKeyframeAlreadyProcessed, isKeyframeSymmetric, rtlifyKeyframe } = require( './keyframes' )
45
const { getDirRule, processSrcRule } = require( './rules' )
56
const { rtlifyDecl, ltrifyDecl } = require( './decls' )
@@ -9,23 +10,6 @@ module.exports = postcss.plugin( 'postcss-rtl', ( options = {} ) => css => {
910
// customized function for joining prefix and selector
1011
const addPrefixToSelector = options.addPrefixToSelector
1112

12-
// selectors have direction related properties
13-
// should add [dir] prefix to increase priority
14-
const dirRegExp = [
15-
/direction/im,
16-
/left/im,
17-
/right/im,
18-
/^(margin|padding|border-(color|style|width))$/ig,
19-
/border-radius/ig,
20-
/shadow/ig,
21-
/transform-origin/ig,
22-
/^(?!text\-).*?transform$/ig,
23-
/transition(-property)?$/i,
24-
/background(-position(-x)?|-image)?$/i,
25-
/float|clear|text-align/i,
26-
/cursor/i
27-
]
28-
2913
let keyframes = []
3014

3115
// collect @keyframes
@@ -56,7 +40,7 @@ module.exports = postcss.plugin( 'postcss-rtl', ( options = {} ) => css => {
5640
return
5741
}
5842

59-
if ( dirRegExp.some( re => !!decl.prop.match( re ) ) ) {
43+
if ( affectedProps.indexOf( decl.prop ) >= 0 ) {
6044
dirDecls.push( decl )
6145
decl.remove()
6246
}

test.js

+8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ test( 'Should add [dir] prefix to symmetric rules with direction related declara
4242
'[dir] a { text-align: center }'
4343
) )
4444

45+
test( 'Should add [dir] prefix to symmetric rules with direction related declarations (4)', t => run( t,
46+
'a { margin: 0 10px 0 0 } ' +
47+
'a { margin-top: 20px }',
48+
'[dir="ltr"] a { margin: 0 10px 0 0 } ' +
49+
'[dir="rtl"] a { margin: 0 0 0 10px } ' +
50+
'[dir] a { margin-top: 20px }'
51+
) )
52+
4553
test( 'Creates both LTR & RTL rules for asymmetric declarations', t => run( t,
4654
'a { text-align: left }',
4755
'[dir="ltr"] a { text-align: left } ' +

0 commit comments

Comments
 (0)