From 8678917e2a595c80267acb44b596910542c42d02 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Thu, 22 Jan 2015 18:39:31 +1100 Subject: [PATCH] add util.object that we'll use to construct objects to avoid prototype collisions --- lib/6to5/transformation/modules/_default.js | 4 ++-- lib/6to5/transformation/transformers/es6/block-scoping.js | 6 +++--- lib/6to5/util.js | 4 ++++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/6to5/transformation/modules/_default.js b/lib/6to5/transformation/modules/_default.js index 9b2ce03b9c..c944078b87 100644 --- a/lib/6to5/transformation/modules/_default.js +++ b/lib/6to5/transformation/modules/_default.js @@ -28,7 +28,7 @@ var exportsVisitor = { }; DefaultFormatter.prototype.getLocalExports = function () { - var localExports = {}; + var localExports = util.object(); traverse(this.file.ast, exportsVisitor, this.file.scope, localExports); return localExports; }; @@ -42,7 +42,7 @@ var importsVisitor = { }; DefaultFormatter.prototype.getLocalImports = function () { - var localImports = {}; + var localImports = util.object(); traverse(this.file.ast, importsVisitor, this.file.scope, localImports); return localImports; }; diff --git a/lib/6to5/transformation/transformers/es6/block-scoping.js b/lib/6to5/transformation/transformers/es6/block-scoping.js index 45656ff22f..097d821324 100644 --- a/lib/6to5/transformation/transformers/es6/block-scoping.js +++ b/lib/6to5/transformation/transformers/es6/block-scoping.js @@ -82,9 +82,9 @@ function LetScoping(loopParent, block, parent, scope, file) { this.block = block; this.file = file; - this.outsideLetReferences = {}; + this.outsideLetReferences = util.object(); this.hasLetReferences = false; - this.letReferences = block._letReferences = {}; + this.letReferences = block._letReferences = util.object(); this.body = []; } @@ -150,7 +150,7 @@ LetScoping.prototype.remap = function () { // we have to check if any of our let variables collide with // those in upper scopes and then if they do, generate a uid // for them and replace all references with it - var remaps = {}; + var remaps = util.object(); for (var key in letRefs) { // just an Identifier node we collected in `getLetReferences` diff --git a/lib/6to5/util.js b/lib/6to5/util.js index c5b33284be..3909bf9e9b 100644 --- a/lib/6to5/util.js +++ b/lib/6to5/util.js @@ -25,6 +25,10 @@ exports.isInteger = function (i) { return _.isNumber(i) && i % 1 === 0; }; +exports.object = function () { + return Object.create(null); +}; + exports.resolve = function (loc) { try { return require.resolve(loc);