postcss-nesting
Advanced tools
Comparing version 2.3.1 to 3.0.0
@@ -1,3 +0,12 @@ | ||
## 2.3.1 (2016-03-16) | ||
# Changes to PostCSS Nesting | ||
### 3.0.0 (May 8, 2017) | ||
- Added: Node 4.x support | ||
- Added: PostCSS 6 support | ||
- Added: Preserved ordering | ||
- Removed: Node 0.12 support | ||
### 2.3.1 (March 16, 2016) | ||
- Updated: Allow any direct nesting that follows the syntactic constraints | ||
@@ -9,3 +18,3 @@ - Updated: PostCSS 5.0.6 | ||
## 2.3.0 (2016-02-20) | ||
### 2.3.0 (February 20, 2016) | ||
@@ -16,3 +25,3 @@ - Updated: JavaScript formatting, linting, tests, and documentation | ||
## 2.2.0 (2016-01-30) | ||
### 2.2.0 (January 30, 2016) | ||
@@ -23,15 +32,15 @@ - Added: Nesting of all at-rules | ||
## 2.1.1 (2016-01-03) | ||
### 2.1.1 (January 3, 2016) | ||
- Updated: Project conventions | ||
## 2.1.0 (2016-01-03) | ||
### 2.1.0 (January 3, 2016) | ||
- Added: Support for valid direct nesting | ||
## 2.0.6 (2015-10-15) | ||
### 2.0.6 (October 15, 2015) | ||
- Fixed: Issue with new PostCSS rules | ||
## 2.0.5 (2015-10-12) | ||
### 2.0.5 (October 12, 2015) | ||
@@ -43,7 +52,7 @@ - Updated: Nested rules source map to the parent rule | ||
## 2.0.4 (2015-09-23) | ||
### 2.0.4 (September 23, 2015) | ||
- Updated: Map source raws | ||
## 2.0.3 (2015-09-22) | ||
### 2.0.3 (September 22, 2015) | ||
@@ -54,7 +63,7 @@ - Updated: Refactored plugin | ||
## 2.0.2 (2015-09-16) | ||
### 2.0.2 (September 16, 2015) | ||
- Fixed: Issue where the new rule’s children were not mapped to the parent internally | ||
## 2.0.1 (2015-09-16) | ||
### 2.0.1 (September 16, 2015) | ||
@@ -64,3 +73,3 @@ - Fixed: Issue where a `@nest` rule followed by another bubbling at-rule would not bubble | ||
## 2.0.0 (2015-09-16) | ||
### 2.0.0 (September 16, 2015) | ||
@@ -72,3 +81,3 @@ - Added: Requirement of `&` per the specification | ||
## 1.0.0 (2015-09-15) | ||
### 1.0.0 (September 15, 2015) | ||
@@ -79,4 +88,4 @@ - Added: New `@nest` at-rule syntax | ||
## 0.1.0 (2015-06-17) | ||
### 0.1.0 (June 17, 2015) | ||
- Added: Initial release |
120
index.js
@@ -1,98 +0,38 @@ | ||
var postcss = require('postcss'); | ||
var comma = postcss.list.comma; | ||
'use strict'; | ||
module.exports = postcss.plugin('postcss-nesting', function (opts) { | ||
var bubble = ['document', 'media', 'supports']; | ||
var name = 'nest'; | ||
// tooling | ||
const postcss = require('postcss'); | ||
const transformBubblingAtrule = require('./lib/transform-bubbling-atrule'); | ||
const transformNestingAtRule = require('./lib/transform-nesting-atrule'); | ||
const transformNestingRule = require('./lib/transform-nesting-rule'); | ||
if (opts && opts.bubble) { | ||
bubble = bubble.concat(opts.bubble); | ||
} | ||
// plugin | ||
module.exports = postcss.plugin('postcss-nesting', () => { | ||
return walk; | ||
}); | ||
if (opts && opts.prefix) { | ||
name = '-' + opts.prefix + '-' + name; | ||
function walk(node) { | ||
// console.log('walk', [node.type], [node.name || node.selector || node.prop || 'root'], node.nodes ? `length: ${node.nodes.length}` : `value: "${node.value}"`); | ||
if (transformBubblingAtrule.test(node)) { | ||
// conditionally transform a bubbling atrule | ||
transformBubblingAtrule(node); | ||
} else if (transformNestingAtRule.test(node)) { | ||
// conditionally transform a nesting atrule | ||
node = transformNestingAtRule(node); // eslint-disable-line no-param-reassign | ||
} else if (transformNestingRule.test(node)) { | ||
// conditionally transform a nesting rule | ||
transformNestingRule(node); | ||
} | ||
return function (css) { | ||
css.walk(function (target) { | ||
var rule = target.parent; | ||
var root = rule && rule.parent; | ||
if (node.nodes) { | ||
// conditionally walk the children of the node | ||
let childNode = node.nodes[0]; | ||
var isAtRule = target.type === 'atrule'; | ||
var isRule = target.type === 'rule'; | ||
while (childNode) { | ||
walk(childNode); | ||
if (root && rule.type === 'rule') { | ||
var newrule = postcss.rule({ | ||
source: target.source | ||
}); | ||
if (isRule && target.selectors.every(function (selector) { | ||
return selector.indexOf('&') === 0; | ||
})) { | ||
target.remove(); | ||
newrule.selector = target.selector; | ||
newrule.append(target.nodes); | ||
transpileSelectors(rule, newrule); | ||
root.insertAfter(rule.insertAfterNode || rule, newrule); | ||
rule.insertAfterNode = newrule; | ||
} else if (isAtRule && target.name === name && target.params.indexOf('&') !== -1) { | ||
target.remove(); | ||
newrule.selector = target.params; | ||
newrule.append(target.nodes); | ||
transpileSelectors(rule, newrule); | ||
root.insertAfter(rule.insertAfterNode || rule, newrule); | ||
rule.insertAfterNode = newrule; | ||
} else if (isAtRule && bubble.indexOf(target.name) !== -1) { | ||
var selector = rule.selector; | ||
if (root.type === 'atrule' && root.name === target.name && root.parent) { | ||
target.params = comma(root.params).map(function (params1) { | ||
return comma(target.params).map(function (params2) { | ||
return params1 + ' and ' + params2; | ||
}).join(', '); | ||
}).join(', '); | ||
rule = root; | ||
root = root.parent; | ||
} | ||
target.remove(); | ||
newrule.selector = selector; | ||
newrule.append(target.nodes); | ||
target.removeAll(); | ||
target.append(newrule); | ||
root.insertAfter(rule.insertAfterNode || rule, target); | ||
rule.insertAfterNode = target; | ||
} | ||
} | ||
}); | ||
}; | ||
}); | ||
function transpileSelectors(fromRule, toRule) { | ||
var selectors = []; | ||
fromRule.selectors.forEach(function (fromSelector) { | ||
toRule.selectors.forEach(function (toSelector) { | ||
selectors.push(toSelector.replace(/&/g, fromSelector)); | ||
}); | ||
}); | ||
toRule.selectors = selectors; | ||
childNode = childNode.parent && childNode.parent.nodes[childNode.parent.nodes.indexOf(childNode) + 1]; | ||
} | ||
} | ||
} |
107
LICENSE.md
@@ -1,15 +0,106 @@ | ||
# CC0 1.0 Universal License | ||
# CC0 1.0 Universal | ||
Public Domain Dedication | ||
## Statement of Purpose | ||
The person(s) who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. | ||
The laws of most jurisdictions throughout the world automatically confer | ||
exclusive Copyright and Related Rights (defined below) upon the creator and | ||
subsequent owner(s) (each and all, an “owner”) of an original work of | ||
authorship and/or a database (each, a “Work”). | ||
You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission. | ||
Certain owners wish to permanently relinquish those rights to a Work for the | ||
purpose of contributing to a commons of creative, cultural and scientific works | ||
(“Commons”) that the public can reliably and without fear of later claims of | ||
infringement build upon, modify, incorporate in other works, reuse and | ||
redistribute as freely as possible in any form whatsoever and for any purposes, | ||
including without limitation commercial purposes. These owners may contribute | ||
to the Commons to promote the ideal of a free culture and the further | ||
production of creative, cultural and scientific works, or to gain reputation or | ||
greater distribution for their Work in part through the use and efforts of | ||
others. | ||
In no way are the patent or trademark rights of any person affected by CC0, nor are the rights that other persons may have in the work or in how the work is used, such as publicity or privacy rights. | ||
For these and/or other purposes and motivations, and without any expectation of | ||
additional consideration or compensation, the person associating CC0 with a | ||
Work (the “Affirmer”), to the extent that he or she is an owner of Copyright | ||
and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and | ||
publicly distribute the Work under its terms, with knowledge of his or her | ||
Copyright and Related Rights in the Work and the meaning and intended legal | ||
effect of CC0 on those rights. | ||
Unless expressly stated otherwise, the person(s) who associated a work with this deed makes no warranties about the work, and disclaims liability for all uses of the work, to the fullest extent permitted by applicable law. | ||
1. Copyright and Related Rights. A Work made available under CC0 may be | ||
protected by copyright and related or neighboring rights (“Copyright and | ||
Related Rights”). Copyright and Related Rights include, but are not limited | ||
to, the following: | ||
1. the right to reproduce, adapt, distribute, perform, display, | ||
communicate, and translate a Work; | ||
2. moral rights retained by the original author(s) and/or performer(s); | ||
3. publicity and privacy rights pertaining to a person’s image or likeness | ||
depicted in a Work; | ||
4. rights protecting against unfair competition in regards to a Work, | ||
subject to the limitations in paragraph 4(i), below; | ||
5. rights protecting the extraction, dissemination, use and reuse of data | ||
in a Work; | ||
6. database rights (such as those arising under Directive 96/9/EC of the | ||
European Parliament and of the Council of 11 March 1996 on the legal | ||
protection of databases, and under any national implementation thereof, | ||
including any amended or successor version of such directive); and | ||
7. other similar, equivalent or corresponding rights throughout the world | ||
based on applicable law or treaty, and any national implementations | ||
thereof. | ||
When using or citing the work, you should not imply endorsement by the author or the affirmer. | ||
2. Waiver. To the greatest extent permitted by, but not in contravention of, | ||
applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and | ||
unconditionally waives, abandons, and surrenders all of Affirmer’s Copyright | ||
and Related Rights and associated claims and causes of action, whether now | ||
known or unknown (including existing as well as future claims and causes of | ||
action), in the Work (i) in all territories worldwide, (ii) for the maximum | ||
duration provided by applicable law or treaty (including future time | ||
extensions), (iii) in any current or future medium and for any number of | ||
copies, and (iv) for any purpose whatsoever, including without limitation | ||
commercial, advertising or promotional purposes (the “Waiver”). Affirmer makes | ||
the Waiver for the benefit of each member of the public at large and to the | ||
detriment of Affirmer’s heirs and successors, fully intending that such Waiver | ||
shall not be subject to revocation, rescission, cancellation, termination, or | ||
any other legal or equitable action to disrupt the quiet enjoyment of the Work | ||
by the public as contemplated by Affirmer’s express Statement of Purpose. | ||
This is a [human-readable summary of the Legal Code](https://creativecommons.org/publicdomain/zero/1.0/) ([read the full text](https://creativecommons.org/publicdomain/zero/1.0/legalcode)). | ||
3. Public License Fallback. Should any part of the Waiver for any reason be | ||
judged legally invalid or ineffective under applicable law, then the Waiver | ||
shall be preserved to the maximum extent permitted taking into account | ||
Affirmer’s express Statement of Purpose. In addition, to the extent the Waiver | ||
is so judged Affirmer hereby grants to each affected person a royalty-free, non | ||
transferable, non sublicensable, non exclusive, irrevocable and unconditional | ||
license to exercise Affirmer’s Copyright and Related Rights in the Work (i) in | ||
all territories worldwide, (ii) for the maximum duration provided by applicable | ||
law or treaty (including future time extensions), (iii) in any current or | ||
future medium and for any number of copies, and (iv) for any purpose | ||
whatsoever, including without limitation commercial, advertising or promotional | ||
purposes (the “License”). The License shall be deemed effective as of the date | ||
CC0 was applied by Affirmer to the Work. Should any part of the License for any | ||
reason be judged legally invalid or ineffective under applicable law, such | ||
partial invalidity or ineffectiveness shall not invalidate the remainder of the | ||
License, and in such case Affirmer hereby affirms that he or she will not (i) | ||
exercise any of his or her remaining Copyright and Related Rights in the Work | ||
or (ii) assert any associated claims and causes of action with respect to the | ||
Work, in either case contrary to Affirmer’s express Statement of Purpose. | ||
4. Limitations and Disclaimers. | ||
1. No trademark or patent rights held by Affirmer are waived, abandoned, | ||
surrendered, licensed or otherwise affected by this document. | ||
2. Affirmer offers the Work as-is and makes no representations or | ||
warranties of any kind concerning the Work, express, implied, statutory | ||
or otherwise, including without limitation warranties of title, | ||
merchantability, fitness for a particular purpose, non infringement, or | ||
the absence of latent or other defects, accuracy, or the present or | ||
absence of errors, whether or not discoverable, all to the greatest | ||
extent permissible under applicable law. | ||
3. Affirmer disclaims responsibility for clearing rights of other persons | ||
that may apply to the Work or any use thereof, including without | ||
limitation any person’s Copyright and Related Rights in the Work. | ||
Further, Affirmer disclaims responsibility for obtaining any necessary | ||
consents, permissions or other rights required for any use of the Work. | ||
4. Affirmer understands and acknowledges that Creative Commons is not a | ||
party to this document and has no duty or obligation with respect to | ||
this CC0 or use of the Work. | ||
For more information, please see | ||
http://creativecommons.org/publicdomain/zero/1.0/. |
{ | ||
"name": "postcss-nesting", | ||
"version": "2.3.1", | ||
"description": "Transpiles nested rules according to CSS Nesting Module Level 3", | ||
"version": "3.0.0", | ||
"description": "Nest style and media rules inside each another, following the CSS Nesting Module Level 3 specification", | ||
"author": "Jonathan Neal <jonathantneal@hotmail.com>", | ||
"license": "CC0-1.0", | ||
"repository": "jonathantneal/postcss-nesting", | ||
"homepage": "https://github.com/jonathantneal/postcss-nesting#readme", | ||
"bugs": "https://github.com/jonathantneal/postcss-nesting/issues", | ||
"main": "index.js", | ||
"files": [ | ||
"index.js", | ||
"lib" | ||
], | ||
"scripts": { | ||
"clean": "git clean -X -d -f", | ||
"prepublish": "npm test", | ||
"test": "echo 'Running tests...'; npm run test:js && npm run test:tape", | ||
"test:js": "eslint *.js --cache --ignore-pattern .gitignore", | ||
"test:tape": "postcss-tape" | ||
}, | ||
"engines": { | ||
"node": ">=4.0.0" | ||
}, | ||
"dependencies": { | ||
"postcss": "^6.0.1" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^3.19.0", | ||
"eslint-config-dev": "^2.0.0", | ||
"postcss-tape": "^2.0.1", | ||
"pre-commit": "^1.2.2" | ||
}, | ||
"eslintConfig": { | ||
"extends": "dev" | ||
}, | ||
"keywords": [ | ||
@@ -17,29 +49,8 @@ "postcss", | ||
"selectors", | ||
"syntax", | ||
"specifications", | ||
"specs", | ||
"w3c" | ||
], | ||
"author": "Jonathan Neal <jonathantneal@hotmail.com>", | ||
"license": "CC0-1.0", | ||
"repository": "jonathantneal/postcss-nesting", | ||
"bugs": "https://github.com/jonathantneal/postcss-nesting/issues", | ||
"homepage": "https://github.com/jonathantneal/postcss-nesting", | ||
"dependencies": { | ||
"postcss": "^5.0.19" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^2.4.0", | ||
"jscs": "^2.11.0", | ||
"tap-spec": "^4.1.1", | ||
"tape": "^4.5.1" | ||
}, | ||
"scripts": { | ||
"lint": "eslint *.js --ignore-path .gitignore && jscs *.js", | ||
"tape": "tape test.js | tap-spec", | ||
"test": "npm run lint && npm run tape" | ||
}, | ||
"engines": { | ||
"iojs": ">=2.0.0", | ||
"node": ">=0.12.0" | ||
} | ||
"w3c", | ||
"csswg" | ||
] | ||
} |
130
README.md
@@ -1,85 +0,30 @@ | ||
# CSS Nesting | ||
# PostCSS Nesting [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS Logo" width="90" height="90" align="right">][postcss] | ||
<a href="https://github.com/postcss/postcss"><img src="http://postcss.github.io/postcss/logo.svg" alt="PostCSS Logo" width="80" height="80" align="right"></a> | ||
[![NPM Version][npm-img]][npm-url] | ||
[![Build Status][cli-img]][cli-url] | ||
[![Licensing][lic-img]][lic-url] | ||
[![Changelog][log-img]][log-url] | ||
[![Gitter Chat][git-img]][git-url] | ||
[![NPM Version][npm-img]][npm] [![Build Status][ci-img]][ci] | ||
[PostCSS Nesting] lets you nest style rules inside each other, following the | ||
[CSS Nesting Module Level 3] specification. | ||
[CSS Nesting] allows you to nest one style rule inside another, following the [CSS Nesting Module Level 3] specification. | ||
```css | ||
/* direct nesting */ | ||
a, b { | ||
color: red; | ||
color: red; | ||
& c, & d { | ||
color: white; | ||
} | ||
& & { | ||
color: blue; | ||
} | ||
&:hover { | ||
color: black; | ||
} | ||
@media (min-width: 30em) { | ||
color: yellow; | ||
@media (min-device-pixel-ratio: 1.5) { | ||
color: green; | ||
} | ||
} | ||
& c, & d { | ||
color: white; | ||
} | ||
} | ||
/* or at-rule nesting */ | ||
/* after postcss-nesting */ | ||
a, b { | ||
color: red; | ||
@nest & c, & d { | ||
color: white; | ||
} | ||
@nest & & { | ||
color: blue; | ||
} | ||
@nest &:hover { | ||
color: black; | ||
} | ||
@media (min-width: 30em) { | ||
color: yellow; | ||
} | ||
color: red; | ||
} | ||
/* after */ | ||
a, b { | ||
color: red; | ||
} | ||
a c, a d, b c, b d { | ||
color: white; | ||
color: white; | ||
} | ||
a a, b b { | ||
color: blue; | ||
} | ||
a:hover, b:hover { | ||
color: black; | ||
} | ||
@media (min-width: 30em) { | ||
a, b { | ||
color: yellow; | ||
} | ||
} | ||
@media (min-width: 30em) and (min-device-pixel-ratio: 1.5) { | ||
color: green; | ||
} | ||
``` | ||
@@ -89,3 +34,3 @@ | ||
Add [CSS Nesting] to your build tool: | ||
Add [PostCSS Nesting] to your build tool: | ||
@@ -98,2 +43,4 @@ ```bash | ||
Use [PostCSS Nesting] to process your CSS: | ||
```js | ||
@@ -111,3 +58,3 @@ require('postcss-nesting').process(YOUR_CSS, { /* options */ }); | ||
Load [CSS Nesting] as a PostCSS plugin: | ||
Use [PostCSS Nesting] as a plugin: | ||
@@ -128,3 +75,3 @@ ```js | ||
Enable [CSS Nesting] within your Gulpfile: | ||
Use [PostCSS Nesting] in your Gulpfile: | ||
@@ -153,3 +100,3 @@ ```js | ||
Enable [CSS Nesting] within your Gruntfile: | ||
Use [PostCSS Nesting] in your Gruntfile: | ||
@@ -173,29 +120,18 @@ ```js | ||
## Options | ||
#### `bubble` | ||
Type: `Array` | ||
Default: `['document', 'media', 'supports']` | ||
Specifies additional at-rules whose contents should be transpiled so that the at-rule comes first. By default, `@media`, `@supports` and `@document` will do this. | ||
#### `prefix` | ||
Type: `String` | ||
Default: `null` | ||
Specifies a prefix to be surrounded by dashes before the `@nest` at-rule (e.g. `@-x-nest`). | ||
[ci]: https://travis-ci.org/jonathantneal/postcss-nesting | ||
[ci-img]: https://img.shields.io/travis/jonathantneal/postcss-nesting.svg | ||
[npm]: https://www.npmjs.com/package/postcss-nesting | ||
[npm-url]: https://www.npmjs.com/package/postcss-nesting | ||
[npm-img]: https://img.shields.io/npm/v/postcss-nesting.svg | ||
[cli-url]: https://travis-ci.org/jonathantneal/postcss-nesting | ||
[cli-img]: https://img.shields.io/travis/jonathantneal/postcss-nesting.svg | ||
[lic-url]: LICENSE.md | ||
[lic-img]: https://img.shields.io/npm/l/postcss-nesting.svg | ||
[log-url]: CHANGELOG.md | ||
[log-img]: https://img.shields.io/badge/changelog-md-blue.svg | ||
[git-url]: https://gitter.im/postcss/postcss | ||
[git-img]: https://img.shields.io/badge/chat-gitter-blue.svg | ||
[Gulp PostCSS]: https://github.com/postcss/gulp-postcss | ||
[PostCSS Nesting]: https://github.com/jonathantneal/postcss-nesting | ||
[PostCSS]: https://github.com/postcss/postcss | ||
[Gulp PostCSS]: https://github.com/postcss/gulp-postcss | ||
[Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss | ||
[PostCSS]: https://github.com/postcss/postcss | ||
[CSS Nesting Module Level 3]: http://tabatkins.github.io/specs/css-nesting/ | ||
[CSS Nesting]: https://github.com/jonathantneal/postcss-nesting |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
0
100
1
19055
12
165
132
1
+ Addedansi-styles@3.2.1(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedpostcss@6.0.23(transitive)
+ Addedsource-map@0.6.1(transitive)
+ Addedsupports-color@5.5.0(transitive)
- Removedansi-regex@2.1.1(transitive)
- Removedansi-styles@2.2.1(transitive)
- Removedchalk@1.1.3(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedhas-flag@1.0.0(transitive)
- Removedjs-base64@2.6.4(transitive)
- Removedpostcss@5.2.18(transitive)
- Removedsource-map@0.5.7(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedsupports-color@2.0.03.2.3(transitive)
Updatedpostcss@^6.0.1