Skip to content
Merged
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
44 changes: 28 additions & 16 deletions lib/options/vendor-prefix-align.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,37 @@ module.exports = {
/**
* Internal
*
* Selector for property name.
* @param {node} item
* @returns {String|false|undefined}
* Return property name.
* e.g.
* for: 'color: #fff'
* returns string: 'color'
* @param {node} node
* @returns {String|undefined}
*/
_declName: function(item) {
return item[0] === 'declaration' && item[1][1][1];
_getDeclName: function(node) {
if (node[0] !== 'declaration') return;
return node[1][1][1];
},

/**
* Internal
*
* Selector for value name.
* @param {node} item
* @returns {String|false|undefined}
* Return property value name.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

На мой взгляд тут важно что это именно property value name. очень условно но например для правила
margin: 2px; функция не вернет '2px' потому что это не имя значения а само значение, а имени тут нет.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@L0stSoul, ок, просто в терминах css нет property value name: есть property name и property value.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В терминах нашего парсера просто есть. и это довольно важно в этом случае.

* e.g.
* for: '-webkit-transition: -webkit-transform 150ms linear'
* returns string: '-webkit-transform', and
* for: 'background: -webkit-linear-gradient(...)'
* returns string: '-webkit-linear-gradient'
* @param {node} node
* @returns {String|undefined}
*/
_valName: function(item) {
return item[0] === 'declaration' && item[2] && item[2][2] &&
item[2][2][0] === 'funktion' && item[2][2][1][0] === 'ident' &&
item[2][2][1][1];
_getValName: function(node) {
if (node[0] !== 'declaration' || !node[2] || !node[2][2])
return;
if (node[2][2][0] === 'ident')
return node[2][2][1];
if (node[2][2][0] === 'funktion')
return node[2][2][1][1];
},

/**
Expand Down Expand Up @@ -140,18 +152,18 @@ module.exports = {
var _this = this;

// Gathering Info
this._walk(node, this._declName, function(info, i) {
this._walk(node, this._getDeclName, function(info, i) {
_this._updateDict(info, dict, node[i - 1][1]);
});
this._walk(node, this._valName, function(info, i) {
this._walk(node, this._getValName, function(info, i) {
_this._updateDict(info, dict, node[i][2][1][1]);
});

// Update nodes
this._walk(node, this._declName, function(info, i) {
this._walk(node, this._getDeclName, function(info, i) {
node[i - 1][1] = _this._updateIndent(info, dict, node[i - 1][1]);
});
this._walk(node, this._valName, function(info, i) {
this._walk(node, this._getValName, function(info, i) {
node[i][2][1][1] = _this._updateIndent(info, dict, node[i][2][1][1]);
});
}
Expand Down
8 changes: 7 additions & 1 deletion test/vendor-prefix-align.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,17 @@ describe('options/vendor-prefix-align', function() {
assert.equal(comb.processString(input), expected);
});

it('Should correct align prefixes in preoperties and values at the same time', function() {
var input = fs.readFileSync('./test/vendor-prefix-align/both.css', 'utf8');
var expected = fs.readFileSync('./test/vendor-prefix-align/both.expected.css', 'utf8');

assert.equal(comb.processString(input), expected);
});

it('Should always correctly align prefixes', function() {
var input = fs.readFileSync('./test/vendor-prefix-align/complex.css', 'utf8');
var expected = fs.readFileSync('./test/vendor-prefix-align/complex.expected.css', 'utf8');

assert.equal(comb.processString(input), expected);
});

});
5 changes: 5 additions & 0 deletions test/vendor-prefix-align/both.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.serp-block__head_animation_yes
{
-webkit-transition: -webkit-transform 150ms linear;
transition: transform 150ms linear;
}
5 changes: 5 additions & 0 deletions test/vendor-prefix-align/both.expected.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.serp-block__head_animation_yes
{
-webkit-transition: -webkit-transform 150ms linear;
transition: transform 150ms linear;
}