sindresorhus / strip-debug

Strip console, alert, and debugger statements from JavaScript code
MIT License
84 stars 15 forks source link

New edge case found #2

Closed Antonio-Laguna closed 10 years ago

Antonio-Laguna commented 10 years ago

Hi there!

I was trying to give a go today to the grunt version of this script and I ran across an edge case. Which I really don't know why it's happening:

This is a test:

var test = {
    getReadSections: function(){
        var readSections = window.localStorage.getItem('storyReadSections') || '[]';
        return JSON.parse(readSections);
    }
};

Is stripped to:

var test = {getReadSections: function(){var readSections = ;return JSON.parse(readSections);}};

Giving you a bad code result and will fail upon execution.

I don't see any potential debugging sentence there. Here is the full code anyway I used to test this failure:

var stripDebug = require('strip-debug');

console.log(stripDebug(
        "var test = {" +
        "getReadSections: function(){" +
            "var readSections = window.localStorage.getItem('storyReadSections') || '[]';" +
            "return JSON.parse(readSections);"+
        "}};").toString());
sindresorhus commented 10 years ago

Sorry about that and the delay...

I rewrote the whole thing have much more strict validation and in addition it will replace console with void 0 instead of removing to prevent side-effects. Should be much safer to use now.