Skip to content
This repository was archived by the owner on Dec 28, 2021. It is now read-only.

remove allowDeclarationsAfterNestedRules #96

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
27 changes: 20 additions & 7 deletions .bin/test-tape.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ export default async function tape() {
failures += await test('ignores invalid entries', { basename: 'ignore' })
failures += await test('supports complex entries', { basename: 'complex' })
failures += await test('supports all spec examples', { basename: 'spec-examples' })
failures += await test('supports spec compliant mixing of nested rules and declarations', { basename: 'mixing-nested-rules-and-declarations-spec' })
failures += await test('supports legacy mixing of nested rules and declarations', { basename: 'mixing-nested-rules-and-declarations-legacy', pluginOptions: { allowDeclarationsAfterNestedRules: true } })

let mixinPlugin = () => {
let mixinPluginRule = () => {
return {
postcssPlugin: 'mixin',
AtRule: {
Expand All @@ -34,20 +32,35 @@ export default async function tape() {
},
}
}
mixinPlugin.postcss = true
failures += await test('supports other visitors', { basename: 'mixin' }, mixinPlugin)

mixinPluginRule.postcss = true
failures += await test('supports other visitors (mixin rule)', { basename: 'mixin-rule' }, mixinPluginRule)

let mixinPluginDeclaration = () => {
return {
postcssPlugin: 'mixin',
AtRule: {
mixin(node) {
node.replaceWith('color: blue;')
},
},
}
}

mixinPluginDeclaration.postcss = true
failures += await test('supports other visitors (mixin declaration)', { basename: 'mixin-declaration' }, mixinPluginDeclaration)

return failures === 0
}

async function test(name, init, ...plugins) {
const { basename, pluginOptions } = Object(init)
const { basename } = Object(init)

let sourceUrl = new URL(`test/${basename}.css`, workingUrl)
let expectUrl = new URL(`test/${basename}.expect.css`, workingUrl)
let resultUrl = new URL(`test/${basename}.result.css`, workingUrl)

plugins.unshift(plugin(pluginOptions))
plugins.unshift(plugin())

let sourceCss = await fs.readFile(sourceUrl, 'utf8')
let expectCss = await fs.readFile(expectUrl, 'utf8')
Expand Down
59 changes: 0 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,65 +71,6 @@ import postcssNesting from "https://deno.land/x/postcss_nesting/mod.js";
await postcss([postcssNesting]).process(YOUR_CSS /*, processOptions */);
```

## Options

### allowDeclarationsAfterNestedRules

The [specification](https://www.w3.org/TR/css-nesting-1/#mixing) does not allow declarations after nested rules.
This was previously supported by this plugin and can be re-enabled with `allowDeclarationsAfterNestedRules`.

Before :

```css
a {
color: red;

& b {
color: white;
}

padding: 20px;
}
```

After **without** the option :

```js
postcssNesting()
```

```css
a {
color: red;
}

a b {
color: white;
}
```

After **with** the option :

```js
postcssNesting({
allowDeclarationsAfterNestedRules: true
})
```

```css
a {
color: red;
}

a b {
color: white;
}

a {
padding: 20px;
}
```

[cli-img]: https://img.shields.io/travis/csstools/postcss-nesting.svg
[cli-url]: https://travis-ci.org/csstools/postcss-nesting
[css-img]: https://cssdb.org/badge/nesting-rules.svg
Expand Down
9 changes: 1 addition & 8 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
import ensureCorrectMixingOfNestingRulesAndDeclarations from './lib/mixing-nesting-rules-and-declarations.js'
import walk from './lib/walk.js'

/**
* @param {{allowDeclarationsAfterNestedRules?: boolean}} opts
* @returns {import('postcss').Plugin}
*/
export default function postcssNesting(opts) {
const allowDeclarationsAfterNestedRules = Object(opts).allowDeclarationsAfterNestedRules || false

export default function postcssNesting() {
return {
postcssPlugin: 'postcss-nesting',
Rule(rule) {
if (!allowDeclarationsAfterNestedRules) {
ensureCorrectMixingOfNestingRulesAndDeclarations(rule)
}
walk(rule)
},
}
Expand Down
41 changes: 0 additions & 41 deletions src/lib/mixing-nesting-rules-and-declarations.js

This file was deleted.

16 changes: 16 additions & 0 deletions test/basic.expect.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ a {
}
}

a {

order: 5;
order: 6
}

a b {
order: 7;
}
Expand All @@ -37,6 +43,11 @@ a b {
order: 9;
}

a {

order: 10
}

body a {
order: 11
}
Expand All @@ -50,6 +61,11 @@ body a {
order: 13
}

a {

order: 14
}

@media screen {

a {
Expand Down
6 changes: 6 additions & 0 deletions test/direct.expect.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ a, b {
:is(a,b) c, :is(a,b) d {
order: 4;
}
a, b {
order: 5;
}
a, b {
order: 1;
}
Expand All @@ -22,3 +25,6 @@ a, b {
:is(a,b) c, :is(a,b) d {
order: 4;
}
a, b {
order: 5;
}
6 changes: 6 additions & 0 deletions test/empty.expect.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ d e {
f g {
order: 4;
}
f {
order: 5;
}
a b c {
order: 1
}
Expand All @@ -23,3 +26,6 @@ d e {
f g {
order: 4;
}
f {
order: 5;
}
8 changes: 2 additions & 6 deletions test/ignore.expect.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
a, b {
order: 1
}
a, b {
order: 1;
c, d {
order: 2;
}
Expand All @@ -13,9 +11,7 @@ f:is(g) {
order: 5;
}
a, b {
order: 1
}
a, b {
order: 1;
@nest c, d {
order: 2;
}
Expand Down
13 changes: 13 additions & 0 deletions test/mixin-declaration.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* prevent regressions : https://github.com/csstools/postcss-nesting/issues/95 */
body {
@mixin;

background: red;
font-size: 1rem;

@media (min-width: 64em) {
background: green;
}

margin: 0;
}
15 changes: 15 additions & 0 deletions test/mixin-declaration.expect.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* prevent regressions : https://github.com/csstools/postcss-nesting/issues/95 */
body {color: blue;

background: red;
font-size: 1rem;
}
@media (min-width: 64em) {
body {
background: green;
}
}
body {

margin: 0;
}
File renamed without changes.
File renamed without changes.
19 changes: 0 additions & 19 deletions test/mixing-nested-rules-and-declarations-legacy.css

This file was deleted.

25 changes: 0 additions & 25 deletions test/mixing-nested-rules-and-declarations-legacy.expect.css

This file was deleted.

19 changes: 0 additions & 19 deletions test/mixing-nested-rules-and-declarations-spec.css

This file was deleted.

15 changes: 0 additions & 15 deletions test/mixing-nested-rules-and-declarations-spec.expect.css

This file was deleted.

Loading