postcss / postcss-dark-theme-class

PostCSS plugin to make dark/light theme switcher by copying styles from media query to special class
MIT License
160 stars 16 forks source link

fix: handle comments #13

Closed nobuhikosawai closed 3 years ago

nobuhikosawai commented 3 years ago

This PR is to fix errors when comments exist in media queries.

For example, if you have a CSS like this,

@media (prefers-color-scheme: dark) {
   /* comments about the style */
  a {
    color: white;
  }
}

it will raise error TypeError: Cannot read property 'type' of undefined.

A full backtrace example is

failed Building production JavaScript and CSS bundles - 11.242s

 ERROR #98123  WEBPACK

Generating JavaScript bundles failed

Module build failed (from ./node_modules/postcss-loader/dist/cjs.js):
TypeError: Cannot read property 'type' of undefined
    at /Users/nobuhikosawai/.ghq/github.com/nobuhikosawai/blog/src/styles/global.css:31:1
    at Root.normalize (/Users/nobuhikosawai/.ghq/github.com/nobuhikosawai/blog/node_modules/postcss/lib/container.js:313:22)
    at Root.normalize (/Users/nobuhikosawai/.ghq/github.com/nobuhikosawai/blog/node_modules/postcss/lib/root.js:25:23)
    at Root.insertAfter (/Users/nobuhikosawai/.ghq/github.com/nobuhikosawai/blog/node_modules/postcss/lib/container.js:220:22)
    at Rule.after (/Users/nobuhikosawai/.ghq/github.com/nobuhikosawai/blog/node_modules/postcss/lib/node.js:148:17)
    at /Users/nobuhikosawai/.ghq/github.com/nobuhikosawai/blog/node_modules/postcss-dark-theme-class/index.js:50:18
    at /Users/nobuhikosawai/.ghq/github.com/nobuhikosawai/blog/node_modules/postcss/lib/container.js:379:44
    at AtRule.each (/Users/nobuhikosawai/.ghq/github.com/nobuhikosawai/blog/node_modules/postcss/lib/container.js:60:16)
    at Proxy.<anonymous> (/Users/nobuhikosawai/.ghq/github.com/nobuhikosawai/blog/node_modules/postcss/lib/container.js:376:30)
    at media (/Users/nobuhikosawai/.ghq/github.com/nobuhikosawai/blog/node_modules/postcss-dark-theme-class/index.js:38:18)
    at LazyResult.visitTick (/Users/nobuhikosawai/.ghq/github.com/nobuhikosawai/blog/node_modules/postcss/lib/lazy-result.js:456:16)
    at LazyResult.runAsync (/Users/nobuhikosawai/.ghq/github.com/nobuhikosawai/blog/node_modules/postcss/lib/lazy-result.js:372:30)
    at LazyResult.async (/Users/nobuhikosawai/.ghq/github.com/nobuhikosawai/blog/node_modules/postcss/lib/lazy-result.js:205:30)
    at LazyResult.then (/Users/nobuhikosawai/.ghq/github.com/nobuhikosawai/blog/node_modules/postcss/lib/lazy-result.js:190:17)
ai commented 3 years ago

Thinks. I will release it in Monday.

ai commented 3 years ago

Released in 0.5.2