valeriansaliou / gulp-remove-logging

:shower: Removes console logging statements.
http://npmjs.com/package/gulp-remove-logging
MIT License
8 stars 2 forks source link

it's work error when I lose semicolon at the end of console.log('####') #3

Open warmilk opened 6 years ago

warmilk commented 6 years ago

It not work correct 😢

The blow is my code that want to delete the console.log()

$('#share-btn').click(function () {
                $('.mask').show();
        $('body,mask').css('touch-action', 'none')
        try {
            dataSDK.btnClick('share-btn', 'share to friend')
            console.log('click')
        } catch (e) {

        }
})

this is my glup task code

gulp.task('script', function () {
    return gulp.src('src/js/*.js')
        .pipe(plumber({
            errorHandler: notify.onError('js error: <%= error.message %>'),
        }))
        .pipe(
            removeConsolelog({
                // Options (optional) 
                // eg: 
                // namespace: ['console', 'window.console'] 
            })
        )
        .pipe(babel())
        .pipe(webpack({
            entry: './src/js/main.js',
            output: {
                filename: 'main.js',
            },
            module: {
                loaders: [{
                    test: /\.js$/,
                    loader: 'babel-loader',
                }],
            },
            plugins: [],
        }))     
        .pipe(uglify())
        .pipe(gulp.dest('dest/js'));
});

I miss a semicolon at the console.log,then run this gulp test, the result is it delete the part of the try catch......... it delete the

catch(e){ 
}

which block after the console.log( )

tremby commented 6 years ago

@carolozar and I just came across this issue. We narrowed down the issue to a particular library, Scrollreveal, and then eventually found that that running this plugin over that code resulted in output JS which contains a syntax error.

I was going to attempt to write a patch to fix this, but then decided the regex in the sourcecode was too impenetrable to grok in the time I'm willing to spend. I then thought I'd give a PR which adds a failing test, but I can't even get your tests to run (".checkbuild is not present inside project root nor inside default folder."), so I'll just give you a minimal test case.

console.log('foo')
bar()

When the above is run through this plugin, the output is the empty string.