Add Symbol to builtins

This commit is contained in:
Anthony Van de Gejuchte
2016-05-22 21:49:12 +02:00
committed by Richard van Velzen
parent 0357e5923f
commit 8ad8d7b717
2 changed files with 33 additions and 1 deletions

View File

@@ -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) {

26
test/mocha/builtins.js Normal file
View File

@@ -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);
});
});