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: 5.0.1
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: 5.0.2
Choose a head ref
  • 5 commits
  • 7 files changed
  • 1 contributor

Commits on Dec 2, 2020

  1. Update dependencies

    ai committed Dec 2, 2020
    Copy the full SHA
    840208c View commit details
  2. Add Node.js 10 to CI

    ai committed Dec 2, 2020
    Copy the full SHA
    62a6b77 View commit details

Commits on Dec 3, 2020

  1. Update PostCSS

    ai committed Dec 3, 2020
    Copy the full SHA
    f23fb72 View commit details
  2. Move to visitor API

    ai committed Dec 3, 2020
    Copy the full SHA
    ec804d1 View commit details
  3. Release 5.0.2 version

    ai committed Dec 3, 2020
    Copy the full SHA
    4d4cbdd View commit details
Showing with 929 additions and 825 deletions.
  1. +41 −0 .github/workflows/test.yml
  2. +0 −6 .travis.yml
  3. +3 −0 CHANGELOG.md
  4. +63 −76 index.js
  5. +18 −1 index.test.js
  6. +14 −15 package.json
  7. +790 −727 yarn.lock
41 changes: 41 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Test
"on":
push: null
pull_request: null
env:
FORCE_COLOR: 2
jobs:
full:
name: Node.js 15 Full
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v2
- name: Install Node.js
uses: actions/setup-node@v2-beta
with:
node-version: 15
- name: Install dependencies
uses: bahmutov/npm-install@v1
- name: Run tests
run: yarn test
short:
runs-on: ubuntu-latest
strategy:
matrix:
node-version:
- 14
- 12
- 10
name: "Node.js ${{ matrix.node-version }} Quick"
steps:
- name: Checkout the repository
uses: actions/checkout@v2
- name: "Install Node.js ${{ matrix.node-version }}"
uses: actions/setup-node@v2-beta
with:
node-version: "${{ matrix.node-version }}"
- name: Install dependencies
uses: bahmutov/npm-install@v1
- name: Run unit tests
run: npx jest
6 changes: 0 additions & 6 deletions .travis.yml

This file was deleted.

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/).

## 5.0.2
* Fixed compatibility with `postcss-mixins` by moving to visitor API.

## 5.0.1
* Fixed PostCSS 8.1 compatibility.
* Added funding links.
139 changes: 63 additions & 76 deletions index.js
Original file line number Diff line number Diff line change
@@ -102,73 +102,6 @@ function pickDeclarations (selector, declarations, after, Rule) {
return parent
}

function processRule (rule, bubble, unwrap, preserveEmpty, Rule) {
let unwrapped = false
let after = rule
let copyDeclarations = false
let declarations = []

rule.each(child => {
if (child.type === 'rule') {
if (declarations.length) {
after = pickDeclarations(rule.selector, declarations, after, Rule)
declarations = []
}

copyDeclarations = true
unwrapped = true
child.selectors = selectors(rule, child)
after = pickComment(child.prev(), after)
after.after(child)
after = child
} else if (child.type === 'atrule') {
copyDeclarations = false

if (declarations.length) {
after = pickDeclarations(rule.selector, declarations, after, Rule)
declarations = []
}

if (child.name === 'at-root') {
unwrapped = true
atruleChilds(rule, child, false)

let nodes = child.nodes
if (child.params) {
nodes = new Rule({ selector: child.params, nodes })
}

after.after(nodes)
after = nodes
child.remove()
} else if (bubble[child.name]) {
unwrapped = true
atruleChilds(rule, child, true)
after = pickComment(child.prev(), after)
after.after(child)
after = child
} else if (unwrap[child.name]) {
unwrapped = true
atruleChilds(rule, child, false)
after = pickComment(child.prev(), after)
after.after(child)
after = child
}
} else if (child.type === 'decl' && copyDeclarations) {
declarations.push(child)
}
})

if (declarations.length) {
after = pickDeclarations(rule.selector, declarations, after, Rule)
}

if (unwrapped && preserveEmpty !== true) {
rule.raws.semicolon = true
if (rule.nodes.length === 0) rule.remove()
}
}

function atruleNames (defaults, custom) {
let list = {}
for (let i of defaults) {
@@ -190,17 +123,71 @@ module.exports = (opts = {}) => {

return {
postcssPlugin: 'postcss-nested',
Once (root, { Rule }) {
function process (node) {
node.each(child => {
if (child.type === 'rule') {
processRule(child, bubble, unwrap, preserveEmpty, Rule)
} else if (child.type === 'atrule') {
process(child)
RuleExit (rule, { Rule }) {
let unwrapped = false
let after = rule
let copyDeclarations = false
let declarations = []

rule.each(child => {
if (child.type === 'rule') {
if (declarations.length) {
after = pickDeclarations(rule.selector, declarations, after, Rule)
declarations = []
}

copyDeclarations = true
unwrapped = true
child.selectors = selectors(rule, child)
after = pickComment(child.prev(), after)
after.after(child)
after = child
} else if (child.type === 'atrule') {
copyDeclarations = false

if (declarations.length) {
after = pickDeclarations(rule.selector, declarations, after, Rule)
declarations = []
}
})

if (child.name === 'at-root') {
unwrapped = true
atruleChilds(rule, child, false)

let nodes = child.nodes
if (child.params) {
nodes = new Rule({ selector: child.params, nodes })
}

after.after(nodes)
after = nodes
child.remove()
} else if (bubble[child.name]) {
unwrapped = true
atruleChilds(rule, child, true)
after = pickComment(child.prev(), after)
after.after(child)
after = child
} else if (unwrap[child.name]) {
unwrapped = true
atruleChilds(rule, child, false)
after = pickComment(child.prev(), after)
after.after(child)
after = child
}
} else if (child.type === 'decl' && copyDeclarations) {
declarations.push(child)
}
})

if (declarations.length) {
after = pickDeclarations(rule.selector, declarations, after, Rule)
}

if (unwrapped && preserveEmpty !== true) {
rule.raws.semicolon = true
if (rule.nodes.length === 0) rule.remove()
}
process(root)
}
}
}
19 changes: 18 additions & 1 deletion index.test.js
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ it('unwrap rules inside at-rules', () => {
it('unwraps at-rule', () => {
run(
'a { b { @media screen { width: auto } } }',
'@media screen {a b { width: auto } }'
'@media screen { a b { width: auto } }'
)
})

@@ -175,6 +175,23 @@ it('handles :host selector case', () => {
run(':host { &(:focus) {} }', ':host(:focus) {}')
})

it('works with other visitors', () => {
let css = 'a{b{color:red}@mixin;}'
let mixinPlugin = () => {
return {
postcssPlugin: 'mixin',
AtRule: {
mixin (node) {
node.replaceWith('.in{.deep{color:blue}}')
}
}
}
}
mixinPlugin.postcss = true
let out = postcss([plugin, mixinPlugin]).process(css, { from: undefined }).css
expect(out).toEqual('a b{color:red}a .in .deep{color:blue}')
})

it('shows clear errors on missed semicolon', () => {
let css = 'a{\n color: black\n @mixin b { }\n}\n'
expect(() => {
29 changes: 14 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postcss-nested",
"version": "5.0.1",
"version": "5.0.2",
"description": "PostCSS plugin to unwrap nested rules like how Sass does it",
"keywords": [
"postcss",
@@ -23,33 +23,32 @@
"url": "https://opencollective.com/postcss/"
},
"peerDependencies": {
"postcss": "^8.1.0"
"postcss": "^8.1.5"
},
"dependencies": {
"postcss-selector-parser": "^6.0.4"
},
"devDependencies": {
"@logux/eslint-config": "^40.0.5",
"check-dts": "^0.3.3",
"@logux/eslint-config": "^42.3.0",
"check-dts": "^0.4.1",
"clean-publish": "^1.1.8",
"eslint": "^7.10.0",
"eslint": "^7.14.0",
"eslint-ci": "^1.0.0",
"eslint-config-standard": "^14.1.1",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jest": "^24.0.2",
"eslint-config-standard": "^16.0.2",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.1.3",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prefer-let": "^1.1.0",
"eslint-plugin-prettierx": "^0.14.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-security": "^1.4.0",
"eslint-plugin-standard": "^4.0.1",
"eslint-plugin-unicorn": "^22.0.0",
"eslint-plugin-unicorn": "^23.0.0",
"husky": "^4.3.0",
"jest": "^26.4.2",
"jest": "^26.6.3",
"jest-ci": "^0.1.1",
"lint-staged": "^10.4.0",
"postcss": "^8.1.0",
"postcss-sharec-config": "^0.1.8"
"lint-staged": "^10.5.2",
"postcss": "^8.1.13",
"postcss-sharec-config": "^0.2.1"
},
"husky": {
"hooks": {
@@ -75,6 +74,6 @@
},
"sharec": {
"config": "postcss-sharec-config",
"version": "0.1.8"
"version": "0.2.1"
}
}
1,517 changes: 790 additions & 727 deletions yarn.lock

Large diffs are not rendered by default.