SassNinja / media-query-plugin

Webpack plugin for media query extraction.
MIT License
205 stars 27 forks source link

Using Regular Expression for group matching throws ERROR #20

Closed dNitro closed 4 years ago

dNitro commented 5 years ago

When using with the following config:

new MediaQueryPlugin({
  include: true,
  queries: {
    'screen and (min-width: 1000px)': 'desktop'
  },
  groups: {
    app: /^example/
  }
});

modules that doesn't get matched with group RegExp throws TypeError:

(node:31262) UnhandledPromiseRejectionWarning: TypeError: group.indexOf is not a function
    at /Users/david/Projects/new/app:1:48
    at getGroupName (/Users/david/Projects/new/node_modules/media-query-plugin/src/postcss.js:29:52)
    at callback (/Users/david/Projects/new/node_modules/media-query-plugin/src/postcss.js:42:35)
    ...

Seems typeof group === 'object' guard on line 29 of src/postcss.js should be more stricter and check if group is array. Regexps are object and when their names does not get match on previous line, pass this guard and get to group.indexOf which obviously does not exist on regular expressions.

SassNinja commented 4 years ago

Good catch!

Seems I totally lost track of this. It's going to be fixed in release 1.3.2