From 8ad8d7b7177454fb9d430d4da31b01825ca4eff8 Mon Sep 17 00:00:00 2001 From: Anthony Van de Gejuchte Date: Sun, 22 May 2016 21:49:12 +0200 Subject: [PATCH] Add Symbol to builtins --- lib/propmangle.js | 8 +++++++- test/mocha/builtins.js | 26 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 test/mocha/builtins.js diff --git a/lib/propmangle.js b/lib/propmangle.js index 050f07d7..b20a3815 100644 --- a/lib/propmangle.js +++ b/lib/propmangle.js @@ -44,10 +44,16 @@ "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, - 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); + }); +});