From 322aa246b8a2f6baae3bc3138c42059734ad25d3 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sun, 28 Dec 2014 01:01:13 +1100 Subject: [PATCH] fix automatic closure on private declarations - fixes #335 --- .../transformers/es6-classes.js | 28 ++++++++++++------- .../private/expected.js | 4 +-- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/lib/6to5/transformation/transformers/es6-classes.js b/lib/6to5/transformation/transformers/es6-classes.js index 86629c0f03..75bccb3073 100644 --- a/lib/6to5/transformation/transformers/es6-classes.js +++ b/lib/6to5/transformation/transformers/es6-classes.js @@ -8,16 +8,24 @@ exports.ClassDeclaration = function (node, parent, file, scope) { closure = false; } - var newNode = new Class(node, file, scope, closure).run(); - if (closure) { - // declaration in an expression context... - // export default class Foo {} - scope.push({ - kind: "var", - key: node.id.key, - id: node.id - }); - return t.assignmentExpression("=", node.id, newNode); + var factory = new Class(node, file, scope, closure); + var newNode = factory.run(); + if (factory.closure) { + if (closure) { + // declaration in an expression context... + // export default class Foo {} + scope.push({ + kind: "var", + key: node.id.key, + id: node.id + }); + return t.assignmentExpression("=", node.id, newNode); + } else { + // likely has a PrivateDeclaration etc + return t.variableDeclaration("let", [ + t.variableDeclarator(node.id, newNode) + ]); + } } else { return newNode; } diff --git a/test/fixtures/transformation/es7-abstract-references/private/expected.js b/test/fixtures/transformation/es7-abstract-references/private/expected.js index 91d4b390d1..8fca7f836d 100644 --- a/test/fixtures/transformation/es7-abstract-references/private/expected.js +++ b/test/fixtures/transformation/es7-abstract-references/private/expected.js @@ -2,13 +2,13 @@ var A = new WeakMap(); var B = new WeakMap(), C = new WeakMap(); -(function () { +var D = (function () { var F = new WeakMap(), G = new WeakMap(); var E = new WeakMap(); var D = function D() {}; return D; -})() +})(); var H = (function () { var J = new WeakMap(), K = new WeakMap();