From e4a3d222d6c360903fd46023761ae08b608f60c2 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sun, 23 Nov 2014 01:16:09 +1100 Subject: [PATCH] fix constructor spread optimisation - thanks @zloirock --- CHANGELOG.md | 6 +++++- lib/6to5/templates/apply-constructor.js | 4 ++-- .../transformation/spread/new-expression/expected.js | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fab33841a..809232fde8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,11 @@ +# 1.13.1 + + * Fix constructor spread optimisation. Thanks [@zloirock](https://github.com/zloirock). + # 1.13.0 * Put experimental ES7 features behind a flag `--experimental` and `experimental` option. - * Constructor speed performance increase. Thanks [@RReverser](https://github.com/RReverser). + * Constructor spread performance increase. Thanks [@RReverser](https://github.com/RReverser). * Use `self` instead of `window` in the optional 6to5 runtime. Thanks [@RReverser](https://github.com/RReverser). # 1.12.26 diff --git a/lib/6to5/templates/apply-constructor.js b/lib/6to5/templates/apply-constructor.js index 0c61411455..db337be303 100644 --- a/lib/6to5/templates/apply-constructor.js +++ b/lib/6to5/templates/apply-constructor.js @@ -1,5 +1,5 @@ (function (Constructor, args) { var instance = Object.create(Constructor.prototype); - Constructor.apply(instance, args); - return instance; + var result = Constructor.apply(instance, args); + return result != null && (typeof result == "object" || typeof result == "function") ? result : instance; }); diff --git a/test/fixtures/transformation/spread/new-expression/expected.js b/test/fixtures/transformation/spread/new-expression/expected.js index 112c05e007..ae08cf0b9d 100644 --- a/test/fixtures/transformation/spread/new-expression/expected.js +++ b/test/fixtures/transformation/spread/new-expression/expected.js @@ -3,9 +3,9 @@ var _applyConstructor = function (Constructor, args) { var instance = Object.create(Constructor.prototype); - Constructor.apply(instance, args); + var result = Constructor.apply(instance, args); - return instance; + return result != null && (typeof result == "object" || typeof result == "function") ? result : instance; }; _applyConstructor(Numbers, Array.from(nums));