postcss-apply
Advanced tools
Comparing version 0.3.0 to 0.4.0
# postcss-apply change Log | ||
All notable changes to this project will be documented in this file. | ||
This project adheres to [Semantic Versioning](http://semver.org/). | ||
The format is based on [Keep a Changelog](http://keepachangelog.com/) | ||
and this project adheres to [Semantic Versioning](http://semver.org/). | ||
## [Unreleased] | ||
## [0.4.0] - 2016-09-13 | ||
### Changed | ||
* Correctly handles property set overrides. | ||
[#10](https://github.com/pascalduez/postcss-apply/issues/10) | ||
## [0.3.0] - 2016-06-23 | ||
@@ -24,1 +33,7 @@ ### Changed | ||
* Initial release. | ||
[Unreleased]: https://github.com/pascalduez/postcss-apply/compare/0.4.0...HEAD | ||
[0.4.0]: https://github.com/pascalduez/postcss-apply/compare/0.3.0...0.4.0 | ||
[0.3.0]: https://github.com/pascalduez/postcss-apply/compare/0.2.0...0.3.0 | ||
[0.2.0]: https://github.com/pascalduez/postcss-apply/compare/0.1.0...0.2.0 | ||
[0.1.0]: https://github.com/pascalduez/postcss-apply/tags/0.1.0 |
@@ -20,11 +20,8 @@ 'use strict'; | ||
css.walk(function (node) { | ||
if (node.type === 'rule') { | ||
return visitor.collect(node); | ||
} | ||
if (node.type === 'atrule' && node.name === 'apply') { | ||
return visitor.replace(node); | ||
} | ||
}); | ||
css.walkRules(visitor.collect); | ||
visitor.resolveNested(); | ||
css.walkAtRules('apply', visitor.resolve); | ||
}; | ||
}); |
@@ -7,4 +7,2 @@ 'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _balancedMatch = require('balanced-match'); | ||
@@ -18,67 +16,93 @@ | ||
var RE_PROP_SET = /^(--)([\w-]+)(\s*)([:;]?)$/; | ||
var RE_PROP_SET = /^(--)([\w-]+)(\s*)([:]?)$/; | ||
var Visitor = function () { | ||
function Visitor() { | ||
_classCallCheck(this, Visitor); | ||
var Visitor = function Visitor() { | ||
var _this = this; | ||
this.cache = {}; | ||
this.result = {}; | ||
} | ||
_classCallCheck(this, Visitor); | ||
_createClass(Visitor, [{ | ||
key: 'collect', | ||
value: function collect(rule) { | ||
var matches = RE_PROP_SET.exec(rule.selector); | ||
var parent = rule.parent; | ||
this.cache = {}; | ||
this.result = {}; | ||
if (!matches) { | ||
return; | ||
} | ||
this.collect = function (rule) { | ||
var matches = RE_PROP_SET.exec(rule.selector); | ||
if (parent.selector !== ':root') { | ||
return rule.warn(this.result, 'Custom properties sets are only allowed on `:root` rules.'); | ||
} | ||
if (!matches) { | ||
return; | ||
} | ||
this.cache[matches[2]] = rule; | ||
rule.remove(); | ||
var setName = matches[2]; | ||
var parent = rule.parent; | ||
if (!parent.nodes.length) { | ||
parent.remove(); | ||
} | ||
if (parent.selector !== ':root') { | ||
rule.warn(_this.result, 'Custom property set ignored: not scoped to top-level `:root` ' + ('(--' + setName) + ((parent.type === 'rule' ? ' declared in ' + parent.selector : '') + ')')); | ||
return; | ||
} | ||
/** | ||
* Allow parens usage for Polymer integration. | ||
*/ | ||
// Custom property sets override each other wholly, | ||
// rather than cascading together like colliding style rules do. | ||
// @see: https://tabatkins.github.io/specs/css-apply-rule/#defining | ||
_this.cache[setName] = rule; | ||
}, { | ||
key: 'getParamValue', | ||
value: function getParamValue(param) { | ||
return (/^\(/.test(param) ? (0, _balancedMatch2.default)('(', ')', param).body : param | ||
); | ||
rule.remove(); | ||
if (!parent.nodes.length) { | ||
parent.remove(); | ||
} | ||
}, { | ||
key: 'replace', | ||
value: function replace(atRule) { | ||
var param = this.getParamValue(atRule.params); | ||
var matches = RE_PROP_SET.exec(param); | ||
}; | ||
if (!matches) { | ||
return; | ||
} | ||
this.resolveNested = function () { | ||
Object.keys(_this.cache).forEach(function (rule) { | ||
return _this.cache[rule].walkAtRules('apply', _this.resolve); | ||
}); | ||
}; | ||
var setName = matches[2]; | ||
this.resolve = function (atRule) { | ||
var param = getParamValue(atRule.params); | ||
var matches = RE_PROP_SET.exec(param); | ||
if (setName in this.cache) { | ||
atRule.replaceWith(this.cache[setName].nodes); | ||
} else { | ||
atRule.warn(this.result, 'No custom properties set declared for `' + setName + '`.'); | ||
} | ||
if (!matches) { | ||
return; | ||
} | ||
}]); | ||
return Visitor; | ||
}(); | ||
var setName = matches[2]; | ||
exports.default = Visitor; | ||
if (setName in _this.cache) { | ||
atRule.replaceWith(_this.cache[setName].nodes); | ||
} else { | ||
atRule.warn(_this.result, 'No custom property set declared for `' + setName + '`.'); | ||
} | ||
}; | ||
} | ||
/** | ||
* Collect all `:root` declared property sets and save same them. | ||
* @param {Node} rule | ||
*/ | ||
/** | ||
* Replace nested `@apply` at-rules declarations. | ||
*/ | ||
/** | ||
* Replace `@apply` at-rules declarations with provided custom property set. | ||
* @param {Node} atRule | ||
*/ | ||
; | ||
/** | ||
* Helper: allow parens usage in `@apply` rule declaration. | ||
* This is for Polymer integration. | ||
* @param {String} param | ||
* @return {String} | ||
*/ | ||
exports.default = Visitor; | ||
function getParamValue(param) { | ||
return (/^\(/.test(param) ? (0, _balancedMatch2.default)('(', ')', param).body : param | ||
); | ||
} |
{ | ||
"name": "postcss-apply", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "PostCSS plugin enabling custom properties sets references", | ||
@@ -37,21 +37,22 @@ "keywords": [ | ||
"dependencies": { | ||
"balanced-match": "^0.4.1", | ||
"postcss": "^5.0.21" | ||
"balanced-match": "^0.4.2", | ||
"postcss": "^5.2.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^0.15.2", | ||
"babel-cli": "^6.10.1", | ||
"babel-eslint": "^6.1.0", | ||
"babel-preset-es2015": "^6.9.0", | ||
"ava": "^0.16.0", | ||
"babel-cli": "^6.11.4", | ||
"babel-eslint": "^6.1.2", | ||
"babel-preset-es2015": "^6.13.2", | ||
"babel-preset-stage-0": "^6.1.18", | ||
"chai": "^3.5.0", | ||
"coveralls": "^2.11.9", | ||
"eslint": "^2.13.0", | ||
"eslint-config-standard": "^5.3.1", | ||
"eslint-plugin-promise": "^1.3.2", | ||
"eslint-plugin-standard": "^1.3.2", | ||
"nyc": "^6.6.1", | ||
"coveralls": "^2.11.12", | ||
"eslint": "^3.3.1", | ||
"eslint-config-airbnb-base": "^7.0.0", | ||
"eslint-plugin-ava": "^3.0.0", | ||
"eslint-plugin-import": "^1.13.0", | ||
"nyc": "^8.1.0", | ||
"opn-cli": "^3.0.1", | ||
"postcss-custom-properties": "^5.0.1" | ||
"postcss-custom-properties": "^5.0.1", | ||
"postcss-reporter": "^1.4.1" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
9317
7
93
0
102
15
Updatedbalanced-match@^0.4.2
Updatedpostcss@^5.2.0