From df00507fb37bc04b165d7795620d0af6dde8b298 Mon Sep 17 00:00:00 2001 From: Anthony Van de Gejuchte Date: Sun, 22 May 2016 21:49:12 +0200 Subject: [PATCH 1/2] Add Symbol to builtins --- lib/propmangle.js | 2 +- test/mocha/builtins.js | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 test/mocha/builtins.js diff --git a/lib/propmangle.js b/lib/propmangle.js index 050f07d7..ae2a3f44 100644 --- a/lib/propmangle.js +++ b/lib/propmangle.js @@ -47,7 +47,7 @@ function find_builtins() { var a = []; [ Object, Array, Function, Number, String, Boolean, Error, Math, - Date, RegExp + Date, RegExp, Symbol ].forEach(function(ctor){ Object.getOwnPropertyNames(ctor).map(add); if (ctor.prototype) { diff --git a/test/mocha/builtins.js b/test/mocha/builtins.js new file mode 100644 index 00000000..2782830a --- /dev/null +++ b/test/mocha/builtins.js @@ -0,0 +1,26 @@ +var UglifyJS = require("../../"); +var assert = require("assert"); + +describe("builtins", function() { + it ("Should not mangle builtins", function() { + var test = "function foo(something){\n" + + " return [Object,Array,Function,Number,String,Boolean,Error,Math,Date,RegExp,Symbol,something];\n" + + "};"; + + var result = UglifyJS.minify(test, {fromString: true, parse: {bare_returns: true}}).code; + + assert.strictEqual(result.indexOf("something"), -1); + + assert.notEqual(result.indexOf("Object"), -1); + assert.notEqual(result.indexOf("Array"), -1); + assert.notEqual(result.indexOf("Function"), -1); + assert.notEqual(result.indexOf("Number"), -1); + assert.notEqual(result.indexOf("String"), -1); + assert.notEqual(result.indexOf("Boolean"), -1); + assert.notEqual(result.indexOf("Error"), -1); + assert.notEqual(result.indexOf("Math"), -1); + assert.notEqual(result.indexOf("Date"), -1); + assert.notEqual(result.indexOf("RegExp"), -1); + assert.notEqual(result.indexOf("Symbol"), -1); + }); +}); From 5cfefd0c41ffba3df0a29d0913b7c6abf3b110ac Mon Sep 17 00:00:00 2001 From: Anthony Van de Gejuchte Date: Sun, 22 May 2016 22:08:18 +0200 Subject: [PATCH 2/2] Make sure Symbol is defined on older js engines --- lib/propmangle.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/propmangle.js b/lib/propmangle.js index ae2a3f44..b20a3815 100644 --- a/lib/propmangle.js +++ b/lib/propmangle.js @@ -44,6 +44,12 @@ "use strict"; function find_builtins() { + + // Compatibility fix for es5.1 and earlier where Symbol isn't defined + if (!global.Symbol) { + global.Symbol = new Function(); + } + var a = []; [ Object, Array, Function, Number, String, Boolean, Error, Math,