From fd2187b37d6dffff3cc4b0e56102af55854472b1 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Thu, 9 Oct 2014 22:58:36 +1100 Subject: [PATCH] ensure BlockStatement when we're going to be pushing nodes --- lib/6to5/transformers/destructuring.js | 2 ++ lib/6to5/transformers/for-of.js | 2 ++ lib/6to5/util.js | 7 +++++++ package.json | 2 +- 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/6to5/transformers/destructuring.js b/lib/6to5/transformers/destructuring.js index 0f865fcbe6..5c250fa099 100644 --- a/lib/6to5/transformers/destructuring.js +++ b/lib/6to5/transformers/destructuring.js @@ -79,6 +79,8 @@ exports.ForOfStatement = function (node, parent, opts, generateUid) { push(declar.kind, nodes, pattern, key); + util.ensureBlock(node); + var block = node.body; block.body = nodes.concat(block.body); }; diff --git a/lib/6to5/transformers/for-of.js b/lib/6to5/transformers/for-of.js index f17a619727..cada83ad2f 100644 --- a/lib/6to5/transformers/for-of.js +++ b/lib/6to5/transformers/for-of.js @@ -20,6 +20,8 @@ exports.ForOfStatement = function (node, parent, opts, generateUid) { KEY: key }); + util.ensureBlock(node); + var block = node2.body; block.body = block.body.concat(node.body.body || []); diff --git a/lib/6to5/util.js b/lib/6to5/util.js index 7de095b1a9..7103f1c1c2 100644 --- a/lib/6to5/util.js +++ b/lib/6to5/util.js @@ -41,6 +41,13 @@ exports.parse = function (filename, code, callback, opts) { } }; +exports.ensureBlock = function (node) { + var block = node.body; + if (block.type === "BlockStatement") return; + + node.body = [node.body]; +}; + exports.isPattern = function (node) { return node.type === "ArrayPattern" || node.type === "ObjectPattern"; }; diff --git a/package.json b/package.json index ad90c4f7d2..6ec59963e3 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "6to5", "description": "Turn ES6 code into vanilla ES5 with source maps and no runtime", - "version": "1.5.4", + "version": "1.5.5", "author": "Sebastian McKenzie ", "homepage": "https://github.com/sebmck/6to5", "repository": {