-
• #2
Hmm, it's a thought. I wonder whether minification could be modified to do what you want though. For instance:
var DBG = false; if (DBG) console.log("Debug"); console.log("Foo");
That actually works fine when minified - it goes down to:
var DBG=!1;console.log("Foo");
However when in a function, it doesn't work properly (because it thinks that the state of DBG might get changed).
Object.freeze
doesn't seem to work either. You could do:(function() { var DBG = false; function foo() { if (DBG) console.log("Debug"); console.log("Foo"); } setTimeout(foo,1000); })();
And that minifies down really nicely:
(function(){setTimeout(function(){console.log("Foo")},1E3)})();
-
• #3
Hello Gordon,
Adding such a feature to the minifcation would be great.
Regards
Sacha
-
• #4
There are several new syntax proposals for ES7 that would like to make use of "#", as it's one of the last ascii characters available. I strongly recommend avoiding the introduction of non-standard syntactic forms.
-
• #6
Right, that won't work—
Object.freeze
only sets the meta object descriptor properties to: [[configurable]]: false, [[writable]]: false. It won't turn a non-object into a const. What you could do is provide a "built-in" keyword whose value istrue
and is essentially a const binding. Special keywords are safe additions, as long as they're not any of the FutureReservedWords: class, enum, extends, super, const, export, import, implements, let, private, public, interface, package, protected, static or yield; additionally, there is precedent in node with bindings likeprocess
, which aren't const, but are special (if you attempt to reassign it, the process itself will crash) -
• #7
I'm not talking about extending Espruino at all here... I can want a way to tell someone else's minifier that a value isn't going to change.
I guess I could pre-parse the code, detect the pattern
var DBG = true/false;
at the beginning, and then search/replaceDBG
with the actual value before passing the code to the minifier. It's pretty ugly though. -
• #8
I see, I misunderstood.
Hi Gordon,
It would be very nice if a tiny preprocessor with #ifdef / #endif statements where included in WebIDE. I would like to strip out debug code that way.
Regards
Sacha