anandthakker / doiuse

:bomb: Lint CSS for browser support against caniuse database.
MIT License
1.25k stars 51 forks source link

ignoreFiles crashes on atRule #36

Closed cwygoda closed 8 years ago

cwygoda commented 8 years ago

Using ignoreFiles i get a crash with an atRule. Here's the usage object at https://github.com/anandthakker/doiuse/blob/v2.2.1/src/doiuse.js#L29 just before the crash:

{ usage: 
   AtRule {
     raws: { before: '\n\n' },
     name: 'font-face',
     type: 'atrule',
     nodes: [ [Object], [Object], [Object], [Object] ],
     parent: 
      Root {
        raws: [Object],
        type: 'root',
        nodes: [Object],
        source: [Object],
        lastEach: 35,
        indexes: [Object],
        rawCache: [Object],
        _autoprefixerDisabled: false,
        _autoprefixerPrefix: false },
     lastEach: 25,
     indexes: {},
     _autoprefixerDisabled: false },
  feature: 'font-unicode-range' }

and here's the shortened traceback:

events.js:141
      throw er; // Unhandled 'error' event
      ^
TypeError: Cannot read property 'input' of undefined
    at /home/cwygoda/Workspace/wygoda.net/node_modules/doiuse/lib/doiuse.js:46:51
    at Detector.atrule (/home/cwygoda/Workspace/wygoda.net/node_modules/doiuse/lib/detect-feature-use.js:86:13)
    at /home/cwygoda/Workspace/wygoda.net/node_modules/doiuse/lib/detect-feature-use.js:106:18
    at Root.each (/home/cwygoda/Workspace/sixbrick/node_modules/postcss/lib/container.js:60:22)
    at Detector.process (/home/cwygoda/Workspace/wygoda.net/node_modules/doiuse/lib/detect-feature-use.js:97:12)
    at postcss (/home/cwygoda/Workspace/wygoda.net/node_modules/doiuse/lib/doiuse.js:34:23)
    at LazyResult.run (/home/cwygoda/Workspace/sixbrick/node_modules/postcss/lib/lazy-result.js:206:20)

Here's my doiuse config:

{
    browsers: [
        'ie >= 10',
        '> 10%'
    ],
    ignore: [
        'rem'
    ],
    ignoreFiles: [
        '**/normalize.css'
    ]
}

I am not sure if this is an bug with the atRule object or the ignoreFiles code.

SevereOverfl0w commented 8 years ago

Definitely in the ignoreFiles code. I didn't realise it was possible for a file to not have a source. Maybe that's the bug, it could be either...

SevereOverfl0w commented 8 years ago

All nodes should have an input (except where they're being created manually).

How are you running doiuse?

cwygoda commented 8 years ago

This is definitely all file based sources. My processors definitions is

var processors = [
    at_import,
    suit,
    precss({
        import: { disable: true },
        mixins: {
            mixins: {
                'font-face': font_face
            }
        }
    }),
    autoprefixer,
    doiuse({
        browsers: [
            'ie >= 10',
            '> 10%'
        ],
        ignore: [
            'rem'
        ],
        ignoreFiles: [
            '**/normalize.css'
        ]
    })
];

The actual code is though gulp-postcss:

    return gulp.src(src, {
        base: base
    })
        .pipe(sourcemaps.init())
        .pipe(postcss(processors))
        .pipe(sourcemaps.write('.'))
        .pipe(gulp.dest(dest));
SevereOverfl0w commented 8 years ago

It's possible that one of the plugins are being naughty when creating their atRule command. Could you try disabling plugins one at a time, and see if doiuse still gets upset?

If the issue is one of your plugins, I'm torn on the solution. On one hand, maybe we should expect broken input from other plugins, or maybe we should stand ground and force them to fix themselves.

cwygoda commented 8 years ago

Oh, I have a bad feeling this might my diy font-face mixin. I'll check and hope it's only me to blame. I'll let you know if I wasted your time.

SevereOverfl0w commented 8 years ago

https://github.com/postcss/postcss/blob/master/docs/api.md#nodesource

For any use it may be <3

cwygoda commented 8 years ago

Oh my, what can I say? My fault. Didn't copy the source from the mixin to it's result. Best thing is I learned something, worst thing is I wasted your time.

SevereOverfl0w commented 8 years ago

I'm glad you figured it out. I don't mind at all, it's interesting to see what can break things!