lahmatiy / postcss-csso

PostCSS plugin to minify CSS using CSSO
MIT License
119 stars 6 forks source link

Doesn't work properly with postcss-nested plugin #19

Closed dumistoklus closed 3 years ago

dumistoklus commented 3 years ago

In example below I got an error after using postcss-csso plugin:

1.scss

.c {
    .touch &:hover {
        color: red;
    }
}

csso.js

const postcss = require('postcss');
const nested = require('postcss-nested');
const csso = require('postcss-csso');
const fs = require('fs');

fs.readFile('1.scss', (err, css) => {
    postcss([
        nested(),
        csso(),
    ])
        .process(css, {from: '1.scss', to: 'result.css'})
        .then(result => {
            fs.writeFile('result.css', result.css, () => true)
        });
});

in result

SyntaxError: Unexpected input
    at Object.error (\node_modules\←[4mcss-tree←[24m\lib\parser\create.js:240:19)
    at \node_modules\←[4mcss-tree←[24m\lib\parser\create.js:299:20
    at parseToCsso (\node_modules\←[4mpostcss-csso←[24m\lib\postcssToCsso.js:16:26)
    at postcssToCsso (\node_modules\←[4mpostcss-csso←[24m\lib\postcssToCsso.js:40:26)
    at Array.map (<anonymous>)
    at appendChildren (\node_modules\←[4mpostcss-csso←[24m\lib\postcssToCsso.js:10:39)
    at postcssToCsso (\node_modules\←[4mpostcss-csso←[24m\lib\postcssToCsso.js:41:24)
    at Array.map (<anonymous>) {
  source: ←[32m'.touch &:hover'←[39m,
  offset: ←[33m7←[39m,
  line: ←[33m1←[39m,
  column: ←[33m8←[39m,
  sourceFragment: ←[36m[Function (anonymous)]←[39m,
  parseError: { offset: ←[33m7←[39m, line: ←[33m1←[39m, column: ←[33m8←[39m }
}

But without ccso in plugin list, I got correctly compliled file:

result.css

.touch .c:hover {
    color: red;
}
onigoetz commented 3 years ago

Hi, my PR (#18) fixes this issue. @lahmatiy can you have a look please ?

dumistoklus commented 3 years ago

@lahmatiy Have some news?

lahmatiy commented 3 years ago

Fix published in 5.0.1