diff --git a/src/babel/transformation/file/index.js b/src/babel/transformation/file/index.js index cd4417b4df..accbe5f09a 100644 --- a/src/babel/transformation/file/index.js +++ b/src/babel/transformation/file/index.js @@ -58,7 +58,6 @@ export default class File { "defaults", "create-class", "create-decorated-class", - "apply-constructor", "tagged-template-literal", "tagged-template-literal-loose", "interop-require", @@ -324,7 +323,7 @@ export default class File { var id = t.identifier(t.toIdentifier(name)); return t.memberExpression(runtime, id); } else { - var ref = util.template(name); + var ref = util.template("helper-" + name); ref._compact = true; var uid = this.scope.generateUidIdentifier(name); this.scope.push({ diff --git a/src/babel/transformation/templates/apply-constructor.js b/src/babel/transformation/templates/apply-constructor.js deleted file mode 100644 index db337be303..0000000000 --- a/src/babel/transformation/templates/apply-constructor.js +++ /dev/null @@ -1,5 +0,0 @@ -(function (Constructor, args) { - var instance = Object.create(Constructor.prototype); - var result = Constructor.apply(instance, args); - return result != null && (typeof result == "object" || typeof result == "function") ? result : instance; -}); diff --git a/src/babel/transformation/templates/create-decorated-class.js b/src/babel/transformation/templates/create-decorated-class.js deleted file mode 100644 index 2a16ebf5b9..0000000000 --- a/src/babel/transformation/templates/create-decorated-class.js +++ /dev/null @@ -1,30 +0,0 @@ -(function() { - function defineProperties(target, props) { - for (var i = 0; i < props.length; i ++) { - var descriptor = props[i]; - - descriptor.enumerable = false; - descriptor.configurable = true; - if (descriptor.value) descriptor.writable = true; - - if (descriptor.decorators) { - for (var i = 0; i < descriptor.decorators.length; i++) { - var decorator = descriptor.decorators[i]; - if (typeof decorator === "function") { - descriptor = decorator(target, descriptor.key, descriptor) || descriptor; - } else { - throw new TypeError("The decorator for method " + descriptor.key + " is of the invalid type " + typeof decorator); - } - } - } - - Object.defineProperty(target, descriptor.key, descriptor); - } - } - - return function (Constructor, protoProps, staticProps) { - if (protoProps) defineProperties(Constructor.prototype, protoProps); - if (staticProps) defineProperties(Constructor, staticProps); - return Constructor; - }; -})() diff --git a/src/babel/transformation/templates/async-to-generator.js b/src/babel/transformation/templates/helper-async-to-generator.js similarity index 100% rename from src/babel/transformation/templates/async-to-generator.js rename to src/babel/transformation/templates/helper-async-to-generator.js diff --git a/src/babel/transformation/templates/bind.js b/src/babel/transformation/templates/helper-bind.js similarity index 100% rename from src/babel/transformation/templates/bind.js rename to src/babel/transformation/templates/helper-bind.js diff --git a/src/babel/transformation/templates/class-call-check.js b/src/babel/transformation/templates/helper-class-call-check.js similarity index 100% rename from src/babel/transformation/templates/class-call-check.js rename to src/babel/transformation/templates/helper-class-call-check.js diff --git a/src/babel/transformation/templates/create-class.js b/src/babel/transformation/templates/helper-create-class.js similarity index 57% rename from src/babel/transformation/templates/create-class.js rename to src/babel/transformation/templates/helper-create-class.js index 4ebbc7e61e..09df13e546 100644 --- a/src/babel/transformation/templates/create-class.js +++ b/src/babel/transformation/templates/helper-create-class.js @@ -1,10 +1,11 @@ (function() { function defineProperties(target, props) { for (var i = 0; i < props.length; i ++) { - var prop = props[i]; - prop.configurable = true; - if (prop.value) prop.writable = true; - Object.defineProperty(target, prop.key, prop); + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if (descriptor.value) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); } } diff --git a/src/babel/transformation/templates/helper-create-decorated-class.js b/src/babel/transformation/templates/helper-create-decorated-class.js new file mode 100644 index 0000000000..af5b6ae992 --- /dev/null +++ b/src/babel/transformation/templates/helper-create-decorated-class.js @@ -0,0 +1,37 @@ +(function() { + function defineProperties(target, descriptors) { + for (var i = 0; i < descriptors.length; i ++) { + var descriptor = descriptors[i]; + var decorators = descriptor.decorators; + var key = descriptor.key; + + // don't want to expose these to userland since i know people will rely on them + // and think it's spec behaviour + delete descriptor.key; + delete descriptor.decorators; + + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor || descriptor.initializer) descriptor.writable = true; + + if (decorators) { + for (var f = 0; f < decorators.length; f++) { + var decorator = decorators[f]; + if (typeof decorator === "function") { + descriptor = decorator(target, key, descriptor) || descriptor; + } else { + throw new TypeError("The decorator for method " + descriptor.key + " is of the invalid type " + typeof decorator); + } + } + } + + Object.defineProperty(target, key, descriptor); + } + } + + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; +})() diff --git a/src/babel/transformation/templates/defaults.js b/src/babel/transformation/templates/helper-defaults.js similarity index 100% rename from src/babel/transformation/templates/defaults.js rename to src/babel/transformation/templates/helper-defaults.js diff --git a/src/babel/transformation/templates/define-property.js b/src/babel/transformation/templates/helper-define-property.js similarity index 100% rename from src/babel/transformation/templates/define-property.js rename to src/babel/transformation/templates/helper-define-property.js diff --git a/src/babel/transformation/templates/extends.js b/src/babel/transformation/templates/helper-extends.js similarity index 100% rename from src/babel/transformation/templates/extends.js rename to src/babel/transformation/templates/helper-extends.js diff --git a/src/babel/transformation/templates/get.js b/src/babel/transformation/templates/helper-get.js similarity index 100% rename from src/babel/transformation/templates/get.js rename to src/babel/transformation/templates/helper-get.js diff --git a/src/babel/transformation/templates/has-own.js b/src/babel/transformation/templates/helper-has-own.js similarity index 100% rename from src/babel/transformation/templates/has-own.js rename to src/babel/transformation/templates/helper-has-own.js diff --git a/src/babel/transformation/templates/inherits.js b/src/babel/transformation/templates/helper-inherits.js similarity index 100% rename from src/babel/transformation/templates/inherits.js rename to src/babel/transformation/templates/helper-inherits.js diff --git a/src/babel/transformation/templates/interop-require-wildcard.js b/src/babel/transformation/templates/helper-interop-require-wildcard.js similarity index 100% rename from src/babel/transformation/templates/interop-require-wildcard.js rename to src/babel/transformation/templates/helper-interop-require-wildcard.js diff --git a/src/babel/transformation/templates/interop-require.js b/src/babel/transformation/templates/helper-interop-require.js similarity index 100% rename from src/babel/transformation/templates/interop-require.js rename to src/babel/transformation/templates/helper-interop-require.js diff --git a/src/babel/transformation/templates/object-destructuring-empty.js b/src/babel/transformation/templates/helper-object-destructuring-empty.js similarity index 100% rename from src/babel/transformation/templates/object-destructuring-empty.js rename to src/babel/transformation/templates/helper-object-destructuring-empty.js diff --git a/src/babel/transformation/templates/object-without-properties.js b/src/babel/transformation/templates/helper-object-without-properties.js similarity index 100% rename from src/babel/transformation/templates/object-without-properties.js rename to src/babel/transformation/templates/helper-object-without-properties.js diff --git a/src/babel/transformation/templates/self-global.js b/src/babel/transformation/templates/helper-self-global.js similarity index 100% rename from src/babel/transformation/templates/self-global.js rename to src/babel/transformation/templates/helper-self-global.js diff --git a/src/babel/transformation/templates/set.js b/src/babel/transformation/templates/helper-set.js similarity index 100% rename from src/babel/transformation/templates/set.js rename to src/babel/transformation/templates/helper-set.js diff --git a/src/babel/transformation/templates/sliced-to-array-loose.js b/src/babel/transformation/templates/helper-sliced-to-array-loose.js similarity index 100% rename from src/babel/transformation/templates/sliced-to-array-loose.js rename to src/babel/transformation/templates/helper-sliced-to-array-loose.js diff --git a/src/babel/transformation/templates/sliced-to-array.js b/src/babel/transformation/templates/helper-sliced-to-array.js similarity index 100% rename from src/babel/transformation/templates/sliced-to-array.js rename to src/babel/transformation/templates/helper-sliced-to-array.js diff --git a/src/babel/transformation/templates/tagged-template-literal-loose.js b/src/babel/transformation/templates/helper-tagged-template-literal-loose.js similarity index 100% rename from src/babel/transformation/templates/tagged-template-literal-loose.js rename to src/babel/transformation/templates/helper-tagged-template-literal-loose.js diff --git a/src/babel/transformation/templates/tagged-template-literal.js b/src/babel/transformation/templates/helper-tagged-template-literal.js similarity index 100% rename from src/babel/transformation/templates/tagged-template-literal.js rename to src/babel/transformation/templates/helper-tagged-template-literal.js diff --git a/src/babel/transformation/templates/temporal-assert-defined.js b/src/babel/transformation/templates/helper-temporal-assert-defined.js similarity index 100% rename from src/babel/transformation/templates/temporal-assert-defined.js rename to src/babel/transformation/templates/helper-temporal-assert-defined.js diff --git a/src/babel/transformation/templates/temporal-undefined.js b/src/babel/transformation/templates/helper-temporal-undefined.js similarity index 100% rename from src/babel/transformation/templates/temporal-undefined.js rename to src/babel/transformation/templates/helper-temporal-undefined.js diff --git a/src/babel/transformation/templates/to-array.js b/src/babel/transformation/templates/helper-to-array.js similarity index 100% rename from src/babel/transformation/templates/to-array.js rename to src/babel/transformation/templates/helper-to-array.js diff --git a/src/babel/transformation/templates/to-consumable-array.js b/src/babel/transformation/templates/helper-to-consumable-array.js similarity index 100% rename from src/babel/transformation/templates/to-consumable-array.js rename to src/babel/transformation/templates/helper-to-consumable-array.js diff --git a/src/babel/transformation/templates/typeof.js b/src/babel/transformation/templates/helper-typeof.js similarity index 100% rename from src/babel/transformation/templates/typeof.js rename to src/babel/transformation/templates/helper-typeof.js