$ echo 'console.log(CONFIG.foo, true);' | bin/uglifyjs -c passes=3 -d CONFIG.foo=true
console.log(true,!0);
Was expecting !0 instead of true. The passes compress option does not help.
@alexlamsl Related feature request: Would it be much work to support the following?
$ echo 'console.log(process.env.BAR);' | bin/uglifyjs -c -d process.env.BAR=true
console.log(process.env.BAR);
They are both bugs actually:
diff --git a/lib/compress.js b/lib/compress.js
index de0ff38..dee1990 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1346,7 +1346,7 @@ merge(Compressor.prototype, {
}
def(AST_Node, noop);
def(AST_Dot, function(compressor, suffix){
- return this.expression._find_defs(compressor, suffix + "." + this.property);
+ return this.expression._find_defs(compressor, "." + this.property + suffix);
});
def(AST_SymbolRef, function(compressor, suffix){
if (!this.global()) return;
@@ -3582,7 +3582,7 @@ merge(Compressor.prototype, {
OPT(AST_SymbolRef, function(self, compressor){
var def = self.resolve_defines(compressor);
if (def) {
- return def;
+ return def.optimize(compressor);
}
// testing against !self.scope.uses_with first is an optimization
if (compressor.option("screw_ie8")
@@ -3932,7 +3932,7 @@ merge(Compressor.prototype, {
OPT(AST_Dot, function(self, compressor){
var def = self.resolve_defines(compressor);
if (def) {
- return def;
+ return def.optimize(compressor);
}
var prop = self.property;
if (RESERVED_WORDS(prop) && !compressor.option("screw_ie8")) {
Thanks!
Just curious - do you use a debugger of some sort or do you just inspect the code? I do the latter and add console.error()s as needed.
I never use debuggers or profilers unless there's a gun on my head.
I start with code inspection, then console.error() if head starts to hurt. Failing that, start removing sections of code and see the difference in failure modes...
I never use debuggers or profilers unless there's a gun on my head.
Amen to not using debuggers.
I've never used a JS profiler, although for C/C++ valgrind is indispensable.
For C/C++ I actually like the assembly view of various debuggers, and got used to backtracking from/around the area of trouble.
Way before valgrind I used to use purify - a tool designed by someone who went onto bigger and better things. Maybe there's hope for us yet. :-)
This human-machine interface problem is difficult even in the case of humans being programmers and the problem domain being restricted to computer code.
But then of course, all of this will be solved by the upcoming AI revolution.
I do think there will be an AI inflection point that will render the craft of programming obsolete. The question is when.