CSharp-Minifier icon indicating copy to clipboard operation
CSharp-Minifier copied to clipboard

Preprocessor

Open lcnvdl opened this issue 9 years ago • 1 comments

Hi, I'm having problems with "preprocessor" conditions:

if I have the next code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CSharpMinifier.GUI
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
#if DEBUG
            string text  = "";
#else
            string myOtherTestText = "hi";
#endif
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new frmMain());
        }
    }
}

The code is not minified correctly:

using System;using System.Collections.Generic;using System.Linq;using System.
Threading.Tasks;using System.Windows.Forms;static class b{[STAThread]static void
Main(){
#if DEBUG
                                            string text  = "";
#else
var a="hi";
#endif
Application.EnableVisualStyles();Application.
SetCompatibleTextRenderingDefault(false);Application.Run(new frmMain());}}

As you see, the first variable's name "text" stills unminified.

Can you add "preprocessor" support?

Thank you very much!

Best regards, Luciano Rasente

lcnvdl avatar Sep 30 '15 11:09 lcnvdl

Such behaviour appears due to NRefactory treats first statement as comment (because of DEBUG symbol is not defined). You can explore parsed nodes in NRefactory.Demo project.

It's possible to define DEBUG symbol and minify first statement instead of second. But in general unfortunately I dont know how to fix this issue without NRefactory modifing.

KvanTTT avatar Sep 30 '15 20:09 KvanTTT