Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: postcss/postcss-nested
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 4.1.2
Choose a base ref
...
head repository: postcss/postcss-nested
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 4.2.0
Choose a head ref
  • 12 commits
  • 8 files changed
  • 3 contributors

Commits on Mar 25, 2019

  1. Add type definition

    RumyantsevMichael committed Mar 25, 2019
    Copy the full SHA
    ecc1a76 View commit details
  2. Merge pull request #82 from RumyantsevMichael/feature/type-definition

    Typescript type definition
    ai authored Mar 25, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    fd34625 View commit details

Commits on Nov 5, 2019

  1. feat: add at root support

    jquense committed Nov 5, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2ef0d43 View commit details
  2. docs: add at-root docs

    jquense committed Nov 5, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    bfc71d1 View commit details
  3. Merge pull request #87 from jquense/at-rule

    feat: add at root support
    ai authored Nov 5, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    fda7ce8 View commit details
  4. Update Travis CI config

    ai committed Nov 5, 2019
    Copy the full SHA
    30d6e37 View commit details
  5. Update dependencies

    ai committed Nov 5, 2019
    Copy the full SHA
    8fc5d31 View commit details
  6. Put scripts above

    ai committed Nov 5, 2019
    Copy the full SHA
    2b88f3e View commit details
  7. Simplify docs

    ai committed Nov 5, 2019
    Copy the full SHA
    7898fa0 View commit details
  8. Improve docs

    ai committed Nov 5, 2019
    Copy the full SHA
    1806956 View commit details
  9. Update postcss-selector-parser

    ai committed Nov 5, 2019
    Copy the full SHA
    99eaf88 View commit details
  10. Release 4.2 version

    ai committed Nov 5, 2019
    Copy the full SHA
    f6d9882 View commit details
Showing with 1,758 additions and 1,067 deletions.
  1. +3 −2 .travis.yml
  2. +3 −0 CHANGELOG.md
  3. +31 −11 README.md
  4. +9 −0 index.d.ts
  5. +18 −2 index.js
  6. +91 −57 index.test.js
  7. +19 −17 package.json
  8. +1,584 −978 yarn.lock
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -2,8 +2,9 @@ language: node_js
cache: yarn
node_js:
- node
- "12"
- "10"
- "8"
- "6"
git:
depth: 5
install:
- yarn install --ignore-engines
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Change Log
This project adheres to [Semantic Versioning](http://semver.org/).

## 4.2
* Add `@at-root` support (by Jason Quense).

## 4.1.2
* Improve error messsage on broken selector

42 changes: 31 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# PostCSS Nested [![Build Status][ci-img]][ci]
# PostCSS Nested

<img align="right" width="135" height="95"
title="Philosopher’s stone, logo of PostCSS"
@@ -21,6 +21,15 @@
display: block;
}
}

.title {
font-size: var(--font);

@at-root html {
--font: 16px
}
}
}
```

will be processed to:
@@ -40,27 +49,38 @@ body.is_dark .phone_title {
.phone img {
display: block;
}

.title {
font-size: var(--font);
}
html {
--font: 16px
}
```

Use [postcss-current-selector] **after** this plugin if you want to use current selector in properties or variables values.
Related plugins:

Use [postcss-nested-ancestors] **before** this plugin if you want to reference any ancestor element directly in your selectors with `^&`.
* Use [`postcss-current-selector`] **after** this plugin if you want
to use current selector in properties or variables values.
* Use [`postcss-nested-ancestors`] **before** this plugin if you want
to reference any ancestor element directly in your selectors with `^&`.

See also [postcss-nesting], which implements [Tab Atkin's proposed syntax](https://tabatkins.github.io/specs/css-nesting/) (requires the `&` and introduces `@nest`).
Alternatives:

There is also [postcss-nested-props] for nested properties like `font-size`.
* See also [`postcss-nesting`], which implements [CSSWG draft]
(requires the `&` and introduces `@nest`).
* [`postcss-nested-props`] for nested properties like `font-size`.

<a href="https://evilmartians.com/?utm_source=postcss-nested">
<img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54">
</a>

[postcss-current-selector]: https://github.com/komlev/postcss-current-selector
[postcss-nested-ancestors]: https://github.com/toomuchdesign/postcss-nested-ancestors
[postcss-nested-props]: https://github.com/jedmao/postcss-nested-props
[postcss-nesting]: https://github.com/jonathantneal/postcss-nesting
[`postcss-current-selector`]: https://github.com/komlev/postcss-current-selector
[`postcss-nested-ancestors`]: https://github.com/toomuchdesign/postcss-nested-ancestors
[`postcss-nested-props`]: https://github.com/jedmao/postcss-nested-props
[`postcss-nesting`]: https://github.com/jonathantneal/postcss-nesting
[CSSWG draft]: https://drafts.csswg.org/css-nesting-1/
[PostCSS]: https://github.com/postcss/postcss
[ci-img]: https://travis-ci.org/postcss/postcss-nested.svg
[ci]: https://travis-ci.org/postcss/postcss-nested

## Usage

9 changes: 9 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Plugin } from 'postcss';

interface Options {
bubble?: string[];
unwrap?: string[];
preserveEmpty?: boolean;
}

export default function(options?: Options): Plugin<any>;
20 changes: 18 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -70,7 +70,7 @@ function atruleChilds (rule, atrule, bubbling) {
atrule.each(function (child) {
if (child.type === 'comment') {
children.push(child)
} if (child.type === 'decl') {
} else if (child.type === 'decl') {
children.push(child)
} else if (child.type === 'rule' && bubbling) {
child.selectors = selectors(rule, child)
@@ -92,6 +92,7 @@ function atruleChilds (rule, atrule, bubbling) {
function processRule (rule, bubble, unwrap, preserveEmpty) {
var unwrapped = false
var after = rule

rule.each(function (child) {
if (child.type === 'rule') {
unwrapped = true
@@ -100,7 +101,22 @@ function processRule (rule, bubble, unwrap, preserveEmpty) {
after.after(child)
after = child
} else if (child.type === 'atrule') {
if (bubble[child.name]) {
if (child.name === 'at-root') {
unwrapped = true
atruleChilds(rule, child, false)

var nodes = child.nodes
if (child.params) {
nodes = postcss.rule({
selector: child.params,
nodes: nodes
})
}

after.after(nodes)
after = nodes
child.remove()
} else if (bubble[child.name]) {
unwrapped = true
atruleChilds(rule, child, true)
after = pickComment(child.prev(), after)
Loading