From 7a261a1db16adf2104cacb4e16f81a0e2133e65c Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sat, 15 Nov 2014 09:47:48 +1100 Subject: [PATCH] fix duplicate let scoping in functions - fixes #166 --- CHANGELOG.md | 4 ++++ lib/6to5/transformation/transformers/let-scoping.js | 5 +++-- .../let-scoping/exec-duplicate-function-scope/exec.js | 10 ++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/transformation/let-scoping/exec-duplicate-function-scope/exec.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 23975edb7a4a..1ebc01b6104a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.12.4 + + * Fix duplicate let scoping in functions. + # 1.12.13 * Support duplicate constants within different block scopes. diff --git a/lib/6to5/transformation/transformers/let-scoping.js b/lib/6to5/transformation/transformers/let-scoping.js index d31cbd7b8476..9ccd879620ef 100644 --- a/lib/6to5/transformation/transformers/let-scoping.js +++ b/lib/6to5/transformation/transformers/let-scoping.js @@ -74,7 +74,6 @@ function LetScoping(forParent, block, parent, file, scope) { this.letReferences = {}; this.body = []; - this.info = this.getInfo(); } /** @@ -87,8 +86,10 @@ LetScoping.prototype.run = function () { if (block._letDone) return; block._letDone = true; + this.info = this.getInfo(); + // this is a block within a `Function` so we can safely leave it be - if (t.isFunction(this.parent)) return; + if (t.isFunction(this.parent)) return this.noClosure(); // this block has no let references so let's clean up if (!this.info.keys.length) return this.noClosure(); diff --git a/test/fixtures/transformation/let-scoping/exec-duplicate-function-scope/exec.js b/test/fixtures/transformation/let-scoping/exec-duplicate-function-scope/exec.js new file mode 100644 index 000000000000..68cb396aebf6 --- /dev/null +++ b/test/fixtures/transformation/let-scoping/exec-duplicate-function-scope/exec.js @@ -0,0 +1,10 @@ +function test () { + let value = "outer"; + + return (function () { + let value = "inner"; + return value; + })(); +} + +assert(test(), "inner");