diff --git a/src/babel/transformation/file.js b/src/babel/transformation/file.js index c508fe147c..cdac0e4d62 100644 --- a/src/babel/transformation/file.js +++ b/src/babel/transformation/file.js @@ -48,7 +48,7 @@ export default class File { static helpers = [ "inherits", "defaults", - "prototype-properties", + "create-class", "apply-constructor", "tagged-template-literal", "tagged-template-literal-loose", diff --git a/src/babel/transformation/helpers/define-map.js b/src/babel/transformation/helpers/define-map.js index a951974cf5..02819ae6cd 100644 --- a/src/babel/transformation/helpers/define-map.js +++ b/src/babel/transformation/helpers/define-map.js @@ -1,6 +1,5 @@ import cloneDeep from "lodash/lang/cloneDeep"; import traverse from "../../traversal"; -import clone from "lodash/lang/clone"; import each from "lodash/collection/each"; import has from "lodash/object/has"; import t from "../../types"; @@ -14,7 +13,7 @@ export function push(mutatorMap, key, kind, computed, value) { } else if (t.isLiteral(key)) { alias = String(key.value); } else { - alias = JSON.stringify(traverse.removeProperties(cloneDeep(key))); + alias = JSON.stringify(traverse.removeProperties(t.cloneDeep(key))); } var map; @@ -33,7 +32,7 @@ export function push(mutatorMap, key, kind, computed, value) { map[kind] = value; } -export function build(mutatorMap) { +export function toClassObject(mutatorMap) { var objExpr = t.objectExpression([]); each(mutatorMap, function (map) { @@ -41,22 +40,43 @@ export function build(mutatorMap) { var propNode = t.property("init", map._key, mapNode, map._computed); - if (!map.get && !map.set) { - map.writable = t.literal(true); - } - - if (map.enumerable === false) { - delete map.enumerable; - } else { - map.enumerable = t.literal(true); - } - - map.configurable = t.literal(true); - each(map, function (node, key) { if (key[0] === "_") return; - node = clone(node); + var inheritNode = node; + if (t.isMethodDefinition(node)) node = node.value; + + var prop = t.property("init", t.identifier(key), node); + t.inheritsComments(prop, inheritNode); + t.removeComments(inheritNode); + mapNode.properties.push(prop); + }); + + objExpr.properties.push(propNode); + }); + + return objExpr; +} + +export function toDefineObject(mutatorMap) { + var objExpr = t.objectExpression([]); + + each(mutatorMap, function (map) { + var mapNode = t.objectExpression([]); + + var propNode = t.property("init", map._key, mapNode, map._computed); + + if (map.value) { + map.writable = t.literal(true); + } + + map.configurable = t.literal(true); + map.enumerable = t.literal(true); + + each(map, function (node, key) { + if (key[0] === "_") return; + + node = t.clone(node); var inheritNode = node; if (t.isMethodDefinition(node)) node = node.value; diff --git a/src/babel/transformation/templates/create-class.js b/src/babel/transformation/templates/create-class.js new file mode 100644 index 0000000000..c04f76eb60 --- /dev/null +++ b/src/babel/transformation/templates/create-class.js @@ -0,0 +1,16 @@ +(function() { + function defineProperties(target, props) { + for (var key in props) { + var prop = props[key]; + prop.configurable = true; + if (prop.value) prop.writable = true; + } + Object.defineProperties(target, props); + } + + 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/prototype-properties.js b/src/babel/transformation/templates/prototype-properties.js deleted file mode 100644 index 2838803875..0000000000 --- a/src/babel/transformation/templates/prototype-properties.js +++ /dev/null @@ -1,4 +0,0 @@ -(function (child, staticProps, instanceProps) { - if (staticProps) Object.defineProperties(child, staticProps); - if (instanceProps) Object.defineProperties(child.prototype, instanceProps); -}) diff --git a/src/babel/transformation/transformers/es5/properties.mutators.js b/src/babel/transformation/transformers/es5/properties.mutators.js index 49811a3dc2..d8feebc088 100644 --- a/src/babel/transformation/transformers/es5/properties.mutators.js +++ b/src/babel/transformation/transformers/es5/properties.mutators.js @@ -23,6 +23,6 @@ export function ObjectExpression(node) { return t.callExpression( t.memberExpression(t.identifier("Object"), t.identifier("defineProperties")), - [node, defineMap.build(mutatorMap)] + [node, defineMap.toDefineObject(mutatorMap)] ); } diff --git a/src/babel/transformation/transformers/es6/classes.js b/src/babel/transformation/transformers/es6/classes.js index 3f36556a40..036c04247d 100644 --- a/src/babel/transformation/transformers/es6/classes.js +++ b/src/babel/transformation/transformers/es6/classes.js @@ -195,21 +195,21 @@ class ClassTransformer { var staticProps; if (this.hasInstanceMutators) { - instanceProps = defineMap.build(this.instanceMutatorMap); + instanceProps = defineMap.toClassObject(this.instanceMutatorMap); } if (this.hasStaticMutators) { - staticProps = defineMap.build(this.staticMutatorMap); + staticProps = defineMap.toClassObject(this.staticMutatorMap); } if (instanceProps || staticProps) { - staticProps ||= t.literal(null); + instanceProps ||= t.literal(null); - var args = [className, staticProps]; - if (instanceProps) args.push(instanceProps); + var args = [className, instanceProps]; + if (staticProps) args.push(staticProps); body.push(t.expressionStatement( - t.callExpression(this.file.addHelper("prototype-properties"), args) + t.callExpression(this.file.addHelper("create-class"), args) )); } } @@ -253,7 +253,6 @@ class ClassTransformer { } defineMap.push(mutatorMap, methodName, kind, node.computed, node); - defineMap.push(mutatorMap, methodName, "enumerable", node.computed, false); } /** diff --git a/test/_transformation-helper.js b/test/_transformation-helper.js index bd1610ef0e..7edfb09dba 100644 --- a/test/_transformation-helper.js +++ b/test/_transformation-helper.js @@ -1,17 +1,20 @@ -var genHelpers = require("./_generator-helpers"); -var transform = require("../lib/babel/transformation"); -var sourceMap = require("source-map"); -var codeFrame = require("../lib/babel/helpers/code-frame"); -var Module = require("module"); -var helper = require("./_helper"); -var assert = require("assert"); -var chai = require("chai"); -var path = require("path"); -var util = require("../lib/babel/util"); -var _ = require("lodash"); +var genHelpers = require("./_generator-helpers"); +var transform = require("../lib/babel/transformation"); +var buildExernalHelpers = require("../lib/babel/build-external-helpers"); +var sourceMap = require("source-map"); +var codeFrame = require("../lib/babel/helpers/code-frame"); +var Module = require("module"); +var helper = require("./_helper"); +var assert = require("assert"); +var chai = require("chai"); +var path = require("path"); +var util = require("../lib/babel/util"); +var _ = require("lodash"); require("../lib/babel/polyfill"); +eval(buildExernalHelpers()); + global.assertNoOwnProperties = function (obj) { assert.equal(Object.getOwnPropertyNames(obj).length, 0); }; diff --git a/test/fixtures/transformation/async-to-generator/async/expected.js b/test/fixtures/transformation/async-to-generator/async/expected.js index ff97e4796e..7ff4ac6f79 100644 --- a/test/fixtures/transformation/async-to-generator/async/expected.js +++ b/test/fixtures/transformation/async-to-generator/async/expected.js @@ -1,25 +1,16 @@ "use strict"; -var _asyncToGenerator = function (fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { var callNext = step.bind(null, "next"); var callThrow = step.bind(null, "throw"); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(callNext, callThrow); } } callNext(); }); }; }; - -var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; - -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; - var Foo = (function () { function Foo() { - _classCallCheck(this, Foo); + babelHelpers.classCallCheck(this, Foo); } - _prototypeProperties(Foo, null, { + babelHelpers.createClass(Foo, { foo: { - value: _asyncToGenerator(function* () { + value: babelHelpers.asyncToGenerator(function* () { var wat = yield bar(); - }), - writable: true, - configurable: true + }) } }); - return Foo; })(); \ No newline at end of file diff --git a/test/fixtures/transformation/async-to-generator/expression/expected.js b/test/fixtures/transformation/async-to-generator/expression/expected.js index 5d00201b64..ee1218ec25 100644 --- a/test/fixtures/transformation/async-to-generator/expression/expected.js +++ b/test/fixtures/transformation/async-to-generator/expression/expected.js @@ -1,7 +1,5 @@ "use strict"; -var _asyncToGenerator = function (fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { var callNext = step.bind(null, "next"); var callThrow = step.bind(null, "throw"); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(callNext, callThrow); } } callNext(); }); }; }; - -var foo = _asyncToGenerator(function* () { +var foo = babelHelpers.asyncToGenerator(function* () { var wat = yield bar(); -}); +}); \ No newline at end of file diff --git a/test/fixtures/transformation/async-to-generator/options.json b/test/fixtures/transformation/async-to-generator/options.json index 9dbdefeeb0..66f9b5aed0 100644 --- a/test/fixtures/transformation/async-to-generator/options.json +++ b/test/fixtures/transformation/async-to-generator/options.json @@ -1,4 +1,5 @@ { + "externalHelpers": true, "noCheckAst": true, "optional": ["asyncToGenerator"] } diff --git a/test/fixtures/transformation/async-to-generator/statement/expected.js b/test/fixtures/transformation/async-to-generator/statement/expected.js index 5d00201b64..ee1218ec25 100644 --- a/test/fixtures/transformation/async-to-generator/statement/expected.js +++ b/test/fixtures/transformation/async-to-generator/statement/expected.js @@ -1,7 +1,5 @@ "use strict"; -var _asyncToGenerator = function (fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { var callNext = step.bind(null, "next"); var callThrow = step.bind(null, "throw"); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(callNext, callThrow); } } callNext(); }); }; }; - -var foo = _asyncToGenerator(function* () { +var foo = babelHelpers.asyncToGenerator(function* () { var wat = yield bar(); -}); +}); \ No newline at end of file diff --git a/test/fixtures/transformation/bluebird-coroutines/class/expected.js b/test/fixtures/transformation/bluebird-coroutines/class/expected.js index fdb5965add..25d962f60c 100644 --- a/test/fixtures/transformation/bluebird-coroutines/class/expected.js +++ b/test/fixtures/transformation/bluebird-coroutines/class/expected.js @@ -2,7 +2,7 @@ var _bluebird = require("bluebird"); -var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; +var _createClass = (function () { function defineProperties(target, props) { for (var key in props) { var prop = props[key]; prop.configurable = true; if (prop.value) prop.writable = true; } Object.defineProperties(target, props); } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; @@ -11,13 +11,11 @@ var Foo = (function () { _classCallCheck(this, Foo); } - _prototypeProperties(Foo, null, { + _createClass(Foo, { foo: { value: _bluebird.coroutine(function* () { var wat = yield bar(); - }), - writable: true, - configurable: true + }) } }); diff --git a/test/fixtures/transformation/es5-property.mutators/getter-and-setter/expected.js b/test/fixtures/transformation/es5-property.mutators/getter-and-setter/expected.js index 036772d3c9..45c66960b2 100644 --- a/test/fixtures/transformation/es5-property.mutators/getter-and-setter/expected.js +++ b/test/fixtures/transformation/es5-property.mutators/getter-and-setter/expected.js @@ -8,7 +8,7 @@ var obj = Object.defineProperties({}, { set: function (value) { this._foo = value; }, - enumerable: true, - configurable: true + configurable: true, + enumerable: true } -}); +}); \ No newline at end of file diff --git a/test/fixtures/transformation/es5-property.mutators/getter/expected.js b/test/fixtures/transformation/es5-property.mutators/getter/expected.js index 7e898ee4a1..de11e70dc5 100644 --- a/test/fixtures/transformation/es5-property.mutators/getter/expected.js +++ b/test/fixtures/transformation/es5-property.mutators/getter/expected.js @@ -5,7 +5,7 @@ var obj = Object.defineProperties({}, { get: function () { return 5 + 5; }, - enumerable: true, - configurable: true + configurable: true, + enumerable: true } -}); +}); \ No newline at end of file diff --git a/test/fixtures/transformation/es5-property.mutators/setter/expected.js b/test/fixtures/transformation/es5-property.mutators/setter/expected.js index a04867b4aa..2e39901c7c 100644 --- a/test/fixtures/transformation/es5-property.mutators/setter/expected.js +++ b/test/fixtures/transformation/es5-property.mutators/setter/expected.js @@ -5,7 +5,7 @@ var obj = Object.defineProperties({}, { set: function (value) { this._foo = value; }, - enumerable: true, - configurable: true + configurable: true, + enumerable: true } -}); +}); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-classes-exec/declaration-no-binding.js b/test/fixtures/transformation/es6-classes-exec/declaration-no-binding.js new file mode 100644 index 0000000000..ece8429437 --- /dev/null +++ b/test/fixtures/transformation/es6-classes-exec/declaration-no-binding.js @@ -0,0 +1,9 @@ +class Foo { + bar() { + return Foo; + } +} + +var Bar = Foo; +Foo = 5; +assert.equal((new Bar).bar(), 5); diff --git a/test/fixtures/transformation/es6-classes-exec/expression-binding.js b/test/fixtures/transformation/es6-classes-exec/expression-binding.js new file mode 100644 index 0000000000..ff776071e8 --- /dev/null +++ b/test/fixtures/transformation/es6-classes-exec/expression-binding.js @@ -0,0 +1,9 @@ +var Foo = class Foo { + bar() { + return Foo; + } +} + +var Bar = Foo; +Foo = 5; +assert.equal((new Bar).bar(), Bar); diff --git a/test/fixtures/transformation/es6-classes-exec/retain-no-call-on-reassign.js b/test/fixtures/transformation/es6-classes-exec/retain-no-call-on-reassign.js new file mode 100644 index 0000000000..dbf35b7b66 --- /dev/null +++ b/test/fixtures/transformation/es6-classes-exec/retain-no-call-on-reassign.js @@ -0,0 +1,11 @@ +class Foo { + bar() { + return Foo; + } +} + +var Bar = Foo; +Foo = 5; +assert.throws(function () { + Bar.call(6); +}, /Cannot call a class as a function/); diff --git a/test/fixtures/transformation/es6-classes/super-change-proto/exec.js b/test/fixtures/transformation/es6-classes-exec/super-change-proto.js similarity index 100% rename from test/fixtures/transformation/es6-classes/super-change-proto/exec.js rename to test/fixtures/transformation/es6-classes-exec/super-change-proto.js diff --git a/test/fixtures/transformation/es6-classes-loose/accessing-super-class/expected.js b/test/fixtures/transformation/es6-classes-loose/accessing-super-class/expected.js index a02029f0be..4d2403839d 100644 --- a/test/fixtures/transformation/es6-classes-loose/accessing-super-class/expected.js +++ b/test/fixtures/transformation/es6-classes-loose/accessing-super-class/expected.js @@ -1,45 +1,39 @@ "use strict"; -var _slice = Array.prototype.slice; - -var _inherits = function (subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; - -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; - var Test = (function (Foo) { function Test() { var _Foo$prototype$test, _Foo$prototype$test2; - _classCallCheck(this, Test); + babelHelpers.classCallCheck(this, Test); woops["super"].test(); Foo.call(this); Foo.prototype.test.call(this); - Foo.call.apply(Foo, [this].concat(_slice.call(arguments))); - Foo.call.apply(Foo, [this, "test"].concat(_slice.call(arguments))); + Foo.call.apply(Foo, [this].concat(babelHelpers.slice.call(arguments))); + Foo.call.apply(Foo, [this, "test"].concat(babelHelpers.slice.call(arguments))); - (_Foo$prototype$test = Foo.prototype.test).call.apply(_Foo$prototype$test, [this].concat(_slice.call(arguments))); - (_Foo$prototype$test2 = Foo.prototype.test).call.apply(_Foo$prototype$test2, [this, "test"].concat(_slice.call(arguments))); + (_Foo$prototype$test = Foo.prototype.test).call.apply(_Foo$prototype$test, [this].concat(babelHelpers.slice.call(arguments))); + (_Foo$prototype$test2 = Foo.prototype.test).call.apply(_Foo$prototype$test2, [this, "test"].concat(babelHelpers.slice.call(arguments))); } - _inherits(Test, Foo); + babelHelpers.inherits(Test, Foo); Test.prototype.test = function test() { var _Foo$prototype$test, _Foo$prototype$test2; Foo.prototype.test.call(this); - (_Foo$prototype$test = Foo.prototype.test).call.apply(_Foo$prototype$test, [this].concat(_slice.call(arguments))); - (_Foo$prototype$test2 = Foo.prototype.test).call.apply(_Foo$prototype$test2, [this, "test"].concat(_slice.call(arguments))); + (_Foo$prototype$test = Foo.prototype.test).call.apply(_Foo$prototype$test, [this].concat(babelHelpers.slice.call(arguments))); + (_Foo$prototype$test2 = Foo.prototype.test).call.apply(_Foo$prototype$test2, [this, "test"].concat(babelHelpers.slice.call(arguments))); }; Test.foo = function foo() { var _Foo$foo, _Foo$foo2; Foo.foo.call(this); - (_Foo$foo = Foo.foo).call.apply(_Foo$foo, [this].concat(_slice.call(arguments))); - (_Foo$foo2 = Foo.foo).call.apply(_Foo$foo2, [this, "test"].concat(_slice.call(arguments))); + (_Foo$foo = Foo.foo).call.apply(_Foo$foo, [this].concat(babelHelpers.slice.call(arguments))); + (_Foo$foo2 = Foo.foo).call.apply(_Foo$foo2, [this, "test"].concat(babelHelpers.slice.call(arguments))); }; return Test; -})(Foo); +})(Foo); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-classes-loose/accessing-super-properties/expected.js b/test/fixtures/transformation/es6-classes-loose/accessing-super-properties/expected.js index 915798aa48..eceea3a990 100644 --- a/test/fixtures/transformation/es6-classes-loose/accessing-super-properties/expected.js +++ b/test/fixtures/transformation/es6-classes-loose/accessing-super-properties/expected.js @@ -1,18 +1,13 @@ "use strict"; -var _inherits = function (subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; - -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; - var Test = (function (Foo) { function Test() { - _classCallCheck(this, Test); + babelHelpers.classCallCheck(this, Test); Foo.prototype.test; Foo.prototype.test.whatever; } - _inherits(Test, Foo); - + babelHelpers.inherits(Test, Foo); return Test; })(Foo); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-classes-loose/calling-super-properties/expected.js b/test/fixtures/transformation/es6-classes-loose/calling-super-properties/expected.js index 8b66f1fafe..f4f5edd784 100644 --- a/test/fixtures/transformation/es6-classes-loose/calling-super-properties/expected.js +++ b/test/fixtures/transformation/es6-classes-loose/calling-super-properties/expected.js @@ -1,18 +1,14 @@ "use strict"; -var _inherits = function (subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; - -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; - var Test = (function (Foo) { function Test() { - _classCallCheck(this, Test); + babelHelpers.classCallCheck(this, Test); Foo.prototype.test.whatever(); Foo.prototype.test.call(this); } - _inherits(Test, Foo); + babelHelpers.inherits(Test, Foo); Test.test = function test() { return Foo.wow.call(this); diff --git a/test/fixtures/transformation/es6-classes-loose/options.json b/test/fixtures/transformation/es6-classes-loose/options.json index d9b047c54c..d2a727fcb1 100644 --- a/test/fixtures/transformation/es6-classes-loose/options.json +++ b/test/fixtures/transformation/es6-classes-loose/options.json @@ -1,4 +1,5 @@ { + "externalHelpers": true, "loose": ["es6.classes"], "blacklist": ["es6.tailCall"] } diff --git a/test/fixtures/transformation/es6-classes-loose/super-class-id-member-expression/expected.js b/test/fixtures/transformation/es6-classes-loose/super-class-id-member-expression/expected.js index e277b544fd..c71784d934 100644 --- a/test/fixtures/transformation/es6-classes-loose/super-class-id-member-expression/expected.js +++ b/test/fixtures/transformation/es6-classes-loose/super-class-id-member-expression/expected.js @@ -1,33 +1,27 @@ "use strict"; -var _inherits = function (subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; - -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; - var BaseController = (function (_Chaplin$Controller) { function BaseController() { - _classCallCheck(this, BaseController); + babelHelpers.classCallCheck(this, BaseController); if (_Chaplin$Controller != null) { _Chaplin$Controller.apply(this, arguments); } } - _inherits(BaseController, _Chaplin$Controller); - + babelHelpers.inherits(BaseController, _Chaplin$Controller); return BaseController; })(Chaplin.Controller); var BaseController2 = (function (_Chaplin$Controller$Another) { function BaseController2() { - _classCallCheck(this, BaseController2); + babelHelpers.classCallCheck(this, BaseController2); if (_Chaplin$Controller$Another != null) { _Chaplin$Controller$Another.apply(this, arguments); } } - _inherits(BaseController2, _Chaplin$Controller$Another); - + babelHelpers.inherits(BaseController2, _Chaplin$Controller$Another); return BaseController2; })(Chaplin.Controller.Another); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-classes-loose/super-class/expected.js b/test/fixtures/transformation/es6-classes-loose/super-class/expected.js index 338d66b696..ada91904e9 100644 --- a/test/fixtures/transformation/es6-classes-loose/super-class/expected.js +++ b/test/fixtures/transformation/es6-classes-loose/super-class/expected.js @@ -1,19 +1,14 @@ "use strict"; -var _inherits = function (subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; - -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; - var Test = (function (Foo) { function Test() { - _classCallCheck(this, Test); + babelHelpers.classCallCheck(this, Test); if (Foo != null) { Foo.apply(this, arguments); } } - _inherits(Test, Foo); - + babelHelpers.inherits(Test, Foo); return Test; })(Foo); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-classes-loose/super-function-fallback/expected.js b/test/fixtures/transformation/es6-classes-loose/super-function-fallback/expected.js index 8f393151d3..4366f3918d 100644 --- a/test/fixtures/transformation/es6-classes-loose/super-function-fallback/expected.js +++ b/test/fixtures/transformation/es6-classes-loose/super-function-fallback/expected.js @@ -1,9 +1,7 @@ "use strict"; -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; - var Test = function Test() { - _classCallCheck(this, Test); + babelHelpers.classCallCheck(this, Test); Function.prototype.hasOwnProperty.call(this, "test"); }; \ No newline at end of file diff --git a/test/fixtures/transformation/es6-classes/accessing-super-class/expected.js b/test/fixtures/transformation/es6-classes/accessing-super-class/expected.js index ab0c291252..f235b5aeb4 100644 --- a/test/fixtures/transformation/es6-classes/accessing-super-class/expected.js +++ b/test/fixtures/transformation/es6-classes/accessing-super-class/expected.js @@ -1,59 +1,43 @@ "use strict"; -var _slice = Array.prototype.slice; - -var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; - -var _get = function get(object, property, receiver) { var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc && desc.writable) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; - -var _inherits = function (subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; - -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; - var Test = (function (Foo) { function Test() { - var _get2, _get3; + var _babelHelpers$get, _babelHelpers$get2; - _classCallCheck(this, Test); + babelHelpers.classCallCheck(this, Test); woops["super"].test(); - _get(Object.getPrototypeOf(Test.prototype), "constructor", this).call(this); - _get(Object.getPrototypeOf(Test.prototype), "test", this).call(this); + babelHelpers.get(Object.getPrototypeOf(Test.prototype), "constructor", this).call(this); + babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", this).call(this); - _get(Object.getPrototypeOf(Test.prototype), "constructor", this).apply(this, arguments); - (_get2 = _get(Object.getPrototypeOf(Test.prototype), "constructor", this)).call.apply(_get2, [this, "test"].concat(_slice.call(arguments))); + babelHelpers.get(Object.getPrototypeOf(Test.prototype), "constructor", this).apply(this, arguments); + (_babelHelpers$get = babelHelpers.get(Object.getPrototypeOf(Test.prototype), "constructor", this)).call.apply(_babelHelpers$get, [this, "test"].concat(babelHelpers.slice.call(arguments))); - _get(Object.getPrototypeOf(Test.prototype), "test", this).apply(this, arguments); - (_get3 = _get(Object.getPrototypeOf(Test.prototype), "test", this)).call.apply(_get3, [this, "test"].concat(_slice.call(arguments))); + babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", this).apply(this, arguments); + (_babelHelpers$get2 = babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", this)).call.apply(_babelHelpers$get2, [this, "test"].concat(babelHelpers.slice.call(arguments))); } - _inherits(Test, Foo); - - _prototypeProperties(Test, { - foo: { - value: function foo() { - var _get2; - - _get(Object.getPrototypeOf(Test), "foo", this).call(this); - _get(Object.getPrototypeOf(Test), "foo", this).apply(this, arguments); - (_get2 = _get(Object.getPrototypeOf(Test), "foo", this)).call.apply(_get2, [this, "test"].concat(_slice.call(arguments))); - }, - writable: true, - configurable: true - } - }, { + babelHelpers.inherits(Test, Foo); + babelHelpers.createClass(Test, { test: { value: function test() { - var _get2; + var _babelHelpers$get; - _get(Object.getPrototypeOf(Test.prototype), "test", this).call(this); - _get(Object.getPrototypeOf(Test.prototype), "test", this).apply(this, arguments); - (_get2 = _get(Object.getPrototypeOf(Test.prototype), "test", this)).call.apply(_get2, [this, "test"].concat(_slice.call(arguments))); - }, - writable: true, - configurable: true + babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", this).call(this); + babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", this).apply(this, arguments); + (_babelHelpers$get = babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", this)).call.apply(_babelHelpers$get, [this, "test"].concat(babelHelpers.slice.call(arguments))); + } + } + }, { + foo: { + value: function foo() { + var _babelHelpers$get; + + babelHelpers.get(Object.getPrototypeOf(Test), "foo", this).call(this); + babelHelpers.get(Object.getPrototypeOf(Test), "foo", this).apply(this, arguments); + (_babelHelpers$get = babelHelpers.get(Object.getPrototypeOf(Test), "foo", this)).call.apply(_babelHelpers$get, [this, "test"].concat(babelHelpers.slice.call(arguments))); + } } }); - return Test; -})(Foo); +})(Foo); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-classes/accessing-super-properties/expected.js b/test/fixtures/transformation/es6-classes/accessing-super-properties/expected.js index 7ee14a53f1..9c167a5f9f 100644 --- a/test/fixtures/transformation/es6-classes/accessing-super-properties/expected.js +++ b/test/fixtures/transformation/es6-classes/accessing-super-properties/expected.js @@ -1,20 +1,13 @@ "use strict"; -var _get = function get(object, property, receiver) { var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc && desc.writable) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; - -var _inherits = function (subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; - -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; - var Test = (function (Foo) { function Test() { - _classCallCheck(this, Test); + babelHelpers.classCallCheck(this, Test); - _get(Object.getPrototypeOf(Test.prototype), "test", this); - _get(Object.getPrototypeOf(Test.prototype), "test", this).whatever; + babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", this); + babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", this).whatever; } - _inherits(Test, Foo); - + babelHelpers.inherits(Test, Foo); return Test; })(Foo); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-classes/calling-super-properties/expected.js b/test/fixtures/transformation/es6-classes/calling-super-properties/expected.js index 4ae369971d..a0382a0b8a 100644 --- a/test/fixtures/transformation/es6-classes/calling-super-properties/expected.js +++ b/test/fixtures/transformation/es6-classes/calling-super-properties/expected.js @@ -1,32 +1,20 @@ "use strict"; -var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; - -var _get = function get(object, property, receiver) { var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc && desc.writable) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; - -var _inherits = function (subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; - -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; - var Test = (function (Foo) { function Test() { - _classCallCheck(this, Test); + babelHelpers.classCallCheck(this, Test); - _get(Object.getPrototypeOf(Test.prototype), "test", this).whatever(); - _get(Object.getPrototypeOf(Test.prototype), "test", this).call(this); + babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", this).whatever(); + babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", this).call(this); } - _inherits(Test, Foo); - - _prototypeProperties(Test, { + babelHelpers.inherits(Test, Foo); + babelHelpers.createClass(Test, null, { test: { value: function test() { - return _get(Object.getPrototypeOf(Test), "wow", this).call(this); - }, - writable: true, - configurable: true + return babelHelpers.get(Object.getPrototypeOf(Test), "wow", this).call(this); + } } }); - return Test; })(Foo); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-classes/constructor/expected.js b/test/fixtures/transformation/es6-classes/constructor/expected.js index 69e8c55d3b..c5656eb66b 100644 --- a/test/fixtures/transformation/es6-classes/constructor/expected.js +++ b/test/fixtures/transformation/es6-classes/constructor/expected.js @@ -1,23 +1,18 @@ "use strict"; -var _inherits = function (subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; - -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; - var Test = function Test() { - _classCallCheck(this, Test); + babelHelpers.classCallCheck(this, Test); this.state = "test"; }; var Foo = (function (Bar) { function Foo() { - _classCallCheck(this, Foo); + babelHelpers.classCallCheck(this, Foo); this.state = "test"; } - _inherits(Foo, Bar); - + babelHelpers.inherits(Foo, Bar); return Foo; })(Bar); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-classes/instance-getter-and-setter/expected.js b/test/fixtures/transformation/es6-classes/instance-getter-and-setter/expected.js index f4bb836401..50667d62ca 100644 --- a/test/fixtures/transformation/es6-classes/instance-getter-and-setter/expected.js +++ b/test/fixtures/transformation/es6-classes/instance-getter-and-setter/expected.js @@ -1,25 +1,19 @@ "use strict"; -var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; - -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; - var Test = (function () { function Test() { - _classCallCheck(this, Test); + babelHelpers.classCallCheck(this, Test); } - _prototypeProperties(Test, null, { + babelHelpers.createClass(Test, { test: { get: function () { return 5 + 5; }, set: function (val) { this._test = val; - }, - configurable: true + } } }); - return Test; })(); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-classes/instance-getter/expected.js b/test/fixtures/transformation/es6-classes/instance-getter/expected.js index 17f3dc1e1a..474c1e5e86 100644 --- a/test/fixtures/transformation/es6-classes/instance-getter/expected.js +++ b/test/fixtures/transformation/es6-classes/instance-getter/expected.js @@ -1,22 +1,16 @@ "use strict"; -var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; - -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; - var Test = (function () { function Test() { - _classCallCheck(this, Test); + babelHelpers.classCallCheck(this, Test); } - _prototypeProperties(Test, null, { + babelHelpers.createClass(Test, { test: { get: function () { return 5 + 5; - }, - configurable: true + } } }); - return Test; })(); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-classes/instance-method/expected.js b/test/fixtures/transformation/es6-classes/instance-method/expected.js index ff77c0006c..a62877a971 100644 --- a/test/fixtures/transformation/es6-classes/instance-method/expected.js +++ b/test/fixtures/transformation/es6-classes/instance-method/expected.js @@ -1,23 +1,16 @@ "use strict"; -var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; - -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; - var Test = (function () { function Test() { - _classCallCheck(this, Test); + babelHelpers.classCallCheck(this, Test); } - _prototypeProperties(Test, null, { + babelHelpers.createClass(Test, { test: { value: function test() { return 5 + 5; - }, - writable: true, - configurable: true + } } }); - return Test; })(); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-classes/instance-setter/expected.js b/test/fixtures/transformation/es6-classes/instance-setter/expected.js index 6bd83dcef7..98f8bcfadb 100644 --- a/test/fixtures/transformation/es6-classes/instance-setter/expected.js +++ b/test/fixtures/transformation/es6-classes/instance-setter/expected.js @@ -1,22 +1,16 @@ "use strict"; -var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; - -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; - var Test = (function () { function Test() { - _classCallCheck(this, Test); + babelHelpers.classCallCheck(this, Test); } - _prototypeProperties(Test, null, { + babelHelpers.createClass(Test, { test: { set: function (val) { this._test = val; - }, - configurable: true + } } }); - return Test; })(); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-classes/options.json b/test/fixtures/transformation/es6-classes/options.json new file mode 100644 index 0000000000..7d6e6cda1c --- /dev/null +++ b/test/fixtures/transformation/es6-classes/options.json @@ -0,0 +1,3 @@ +{ + "externalHelpers": true +} diff --git a/test/fixtures/transformation/es6-classes/plain-class/expected.js b/test/fixtures/transformation/es6-classes/plain-class/expected.js index ab3583fca2..73c98b9f71 100644 --- a/test/fixtures/transformation/es6-classes/plain-class/expected.js +++ b/test/fixtures/transformation/es6-classes/plain-class/expected.js @@ -1,7 +1,5 @@ "use strict"; -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; - var Test = function Test() { - _classCallCheck(this, Test); + babelHelpers.classCallCheck(this, Test); }; \ No newline at end of file diff --git a/test/fixtures/transformation/es6-classes/statement/expected.js b/test/fixtures/transformation/es6-classes/statement/expected.js index fb8ea66a32..7ba0f4f940 100644 --- a/test/fixtures/transformation/es6-classes/statement/expected.js +++ b/test/fixtures/transformation/es6-classes/statement/expected.js @@ -1,35 +1,28 @@ "use strict"; -var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; - -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; - var BaseView = function BaseView() { - _classCallCheck(this, BaseView); + babelHelpers.classCallCheck(this, BaseView); this.autoRender = true; }; var BaseView = function BaseView() { - _classCallCheck(this, BaseView); + babelHelpers.classCallCheck(this, BaseView); this.autoRender = true; }; var BaseView = (function () { function BaseView() { - _classCallCheck(this, BaseView); + babelHelpers.classCallCheck(this, BaseView); } - _prototypeProperties(BaseView, null, { + babelHelpers.createClass(BaseView, { foo: { value: function foo() { this.autoRender = true; - }, - writable: true, - configurable: true + } } }); - return BaseView; })(); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-classes/static/expected.js b/test/fixtures/transformation/es6-classes/static/expected.js index 0eb86b84bf..013d6f2647 100644 --- a/test/fixtures/transformation/es6-classes/static/expected.js +++ b/test/fixtures/transformation/es6-classes/static/expected.js @@ -1,26 +1,18 @@ "use strict"; -var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; - -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; - var A = (function () { function A() { - _classCallCheck(this, A); + babelHelpers.classCallCheck(this, A); } - _prototypeProperties(A, { + babelHelpers.createClass(A, null, { a: { - value: function a() {}, - writable: true, - configurable: true + value: function a() {} }, b: { get: function () {}, - set: function (b) {}, - configurable: true + set: function (b) {} } }); - return A; -})(); \ No newline at end of file +})(); diff --git a/test/fixtures/transformation/es6-classes/super-class-anonymous/expected.js b/test/fixtures/transformation/es6-classes/super-class-anonymous/expected.js index 91faeccc4b..3d89298c5b 100644 --- a/test/fixtures/transformation/es6-classes/super-class-anonymous/expected.js +++ b/test/fixtures/transformation/es6-classes/super-class-anonymous/expected.js @@ -1,129 +1,106 @@ "use strict"; -var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; - -var _inherits = function (subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; - -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; - var TestEmpty = (function (_ref) { function TestEmpty() { - _classCallCheck(this, TestEmpty); + babelHelpers.classCallCheck(this, TestEmpty); if (_ref != null) { _ref.apply(this, arguments); } } - _inherits(TestEmpty, _ref); - + babelHelpers.inherits(TestEmpty, _ref); return TestEmpty; })(function _class() { - _classCallCheck(this, _class); + babelHelpers.classCallCheck(this, _class); }); var TestConstructorOnly = (function (_ref2) { function TestConstructorOnly() { - _classCallCheck(this, TestConstructorOnly); + babelHelpers.classCallCheck(this, TestConstructorOnly); if (_ref2 != null) { _ref2.apply(this, arguments); } } - _inherits(TestConstructorOnly, _ref2); - + babelHelpers.inherits(TestConstructorOnly, _ref2); return TestConstructorOnly; })(function _class2() { - _classCallCheck(this, _class2); + babelHelpers.classCallCheck(this, _class2); }); var TestMethodOnly = (function (_ref3) { function TestMethodOnly() { - _classCallCheck(this, TestMethodOnly); + babelHelpers.classCallCheck(this, TestMethodOnly); if (_ref3 != null) { _ref3.apply(this, arguments); } } - _inherits(TestMethodOnly, _ref3); - + babelHelpers.inherits(TestMethodOnly, _ref3); return TestMethodOnly; })((function () { var _class3 = function () { - _classCallCheck(this, _class3); + babelHelpers.classCallCheck(this, _class3); }; - _prototypeProperties(_class3, null, { + babelHelpers.createClass(_class3, { method: { - value: function method() {}, - writable: true, - configurable: true + value: function method() {} } }); - return _class3; })()); var TestConstructorAndMethod = (function (_ref4) { function TestConstructorAndMethod() { - _classCallCheck(this, TestConstructorAndMethod); + babelHelpers.classCallCheck(this, TestConstructorAndMethod); if (_ref4 != null) { _ref4.apply(this, arguments); } } - _inherits(TestConstructorAndMethod, _ref4); - + babelHelpers.inherits(TestConstructorAndMethod, _ref4); return TestConstructorAndMethod; })((function () { var _class4 = function () { - _classCallCheck(this, _class4); + babelHelpers.classCallCheck(this, _class4); }; - _prototypeProperties(_class4, null, { + babelHelpers.createClass(_class4, { method: { - value: function method() {}, - writable: true, - configurable: true + value: function method() {} } }); - return _class4; })()); var TestMultipleMethods = (function (_ref5) { function TestMultipleMethods() { - _classCallCheck(this, TestMultipleMethods); + babelHelpers.classCallCheck(this, TestMultipleMethods); if (_ref5 != null) { _ref5.apply(this, arguments); } } - _inherits(TestMultipleMethods, _ref5); - + babelHelpers.inherits(TestMultipleMethods, _ref5); return TestMultipleMethods; })((function () { var _class5 = function () { - _classCallCheck(this, _class5); + babelHelpers.classCallCheck(this, _class5); }; - _prototypeProperties(_class5, null, { + babelHelpers.createClass(_class5, { m1: { - value: function m1() {}, - writable: true, - configurable: true + value: function m1() {} }, m2: { - value: function m2() {}, - writable: true, - configurable: true + value: function m2() {} } }); - return _class5; -})()); - +})()); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-classes/super-class-id-member-expression/expected.js b/test/fixtures/transformation/es6-classes/super-class-id-member-expression/expected.js index e277b544fd..c71784d934 100644 --- a/test/fixtures/transformation/es6-classes/super-class-id-member-expression/expected.js +++ b/test/fixtures/transformation/es6-classes/super-class-id-member-expression/expected.js @@ -1,33 +1,27 @@ "use strict"; -var _inherits = function (subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; - -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; - var BaseController = (function (_Chaplin$Controller) { function BaseController() { - _classCallCheck(this, BaseController); + babelHelpers.classCallCheck(this, BaseController); if (_Chaplin$Controller != null) { _Chaplin$Controller.apply(this, arguments); } } - _inherits(BaseController, _Chaplin$Controller); - + babelHelpers.inherits(BaseController, _Chaplin$Controller); return BaseController; })(Chaplin.Controller); var BaseController2 = (function (_Chaplin$Controller$Another) { function BaseController2() { - _classCallCheck(this, BaseController2); + babelHelpers.classCallCheck(this, BaseController2); if (_Chaplin$Controller$Another != null) { _Chaplin$Controller$Another.apply(this, arguments); } } - _inherits(BaseController2, _Chaplin$Controller$Another); - + babelHelpers.inherits(BaseController2, _Chaplin$Controller$Another); return BaseController2; })(Chaplin.Controller.Another); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-classes/super-class/expected.js b/test/fixtures/transformation/es6-classes/super-class/expected.js index 338d66b696..ada91904e9 100644 --- a/test/fixtures/transformation/es6-classes/super-class/expected.js +++ b/test/fixtures/transformation/es6-classes/super-class/expected.js @@ -1,19 +1,14 @@ "use strict"; -var _inherits = function (subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; - -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; - var Test = (function (Foo) { function Test() { - _classCallCheck(this, Test); + babelHelpers.classCallCheck(this, Test); if (Foo != null) { Foo.apply(this, arguments); } } - _inherits(Test, Foo); - + babelHelpers.inherits(Test, Foo); return Test; })(Foo); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-classes/super-function-fallback/expected.js b/test/fixtures/transformation/es6-classes/super-function-fallback/expected.js index e278a09b33..9d4d8335e0 100644 --- a/test/fixtures/transformation/es6-classes/super-function-fallback/expected.js +++ b/test/fixtures/transformation/es6-classes/super-function-fallback/expected.js @@ -1,11 +1,7 @@ "use strict"; -var _get = function get(object, property, receiver) { var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc && desc.writable) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; - -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; - var Test = function Test() { - _classCallCheck(this, Test); + babelHelpers.classCallCheck(this, Test); - _get(Object.getPrototypeOf(Test.prototype), "hasOwnProperty", this).call(this, "test"); + babelHelpers.get(Object.getPrototypeOf(Test.prototype), "hasOwnProperty", this).call(this, "test"); }; \ No newline at end of file diff --git a/test/fixtures/transformation/es6-properties.shorthand/method-computed/expected.js b/test/fixtures/transformation/es6-properties.shorthand/method-computed/expected.js index 240e3e05a1..7973f269f7 100644 --- a/test/fixtures/transformation/es6-properties.shorthand/method-computed/expected.js +++ b/test/fixtures/transformation/es6-properties.shorthand/method-computed/expected.js @@ -11,8 +11,8 @@ var obj = Object.defineProperties({}, _defineProperty({}, x, { set: function (value) { valueSet = value; }, - enumerable: true, - configurable: true + configurable: true, + enumerable: true })); obj.y = "foo"; obj.y === 1 && valueSet === "foo"; \ No newline at end of file diff --git a/test/fixtures/transformation/playground/object-getter-memoization/expected.js b/test/fixtures/transformation/playground/object-getter-memoization/expected.js index 00f7966f7b..cc9dbcb09c 100644 --- a/test/fixtures/transformation/playground/object-getter-memoization/expected.js +++ b/test/fixtures/transformation/playground/object-getter-memoization/expected.js @@ -1,45 +1,36 @@ "use strict"; -var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; - -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; - -var _defineProperty = function (obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); }; - var Foo = (function () { function Foo() { - _classCallCheck(this, Foo); + babelHelpers.classCallCheck(this, Foo); } - _prototypeProperties(Foo, null, _defineProperty({ + babelHelpers.createClass(Foo, babelHelpers.defineProperty({ bar: { get: function () { - return _defineProperty(this, "bar", complex()).bar; - }, - configurable: true + return babelHelpers.defineProperty(this, "bar", complex()).bar; + } } }, bar, { get: function () { - return _defineProperty(this, bar, complex())[bar]; - }, - configurable: true + return babelHelpers.defineProperty(this, bar, complex())[bar]; + } })); - return Foo; })(); -var foo = Object.defineProperties({}, _defineProperty({ +var foo = Object.defineProperties({}, babelHelpers.defineProperty({ bar: { get: function () { - return _defineProperty(this, "bar", complex()).bar; + return babelHelpers.defineProperty(this, "bar", complex()).bar; }, - enumerable: true, - configurable: true + configurable: true, + enumerable: true } }, bar, { get: function () { - return _defineProperty(this, bar, complex())[bar]; + return babelHelpers.defineProperty(this, bar, complex())[bar]; }, - enumerable: true, - configurable: true + configurable: true, + enumerable: true })); \ No newline at end of file diff --git a/test/fixtures/transformation/playground/options.json b/test/fixtures/transformation/playground/options.json index e68df25688..05c8fd16bc 100644 --- a/test/fixtures/transformation/playground/options.json +++ b/test/fixtures/transformation/playground/options.json @@ -1,3 +1,4 @@ { + "externalHelpers": true, "playground": true } diff --git a/test/fixtures/transformation/source-maps/class/expected.js b/test/fixtures/transformation/source-maps/class/expected.js index f559425ef5..8b485be2b3 100644 --- a/test/fixtures/transformation/source-maps/class/expected.js +++ b/test/fixtures/transformation/source-maps/class/expected.js @@ -1,6 +1,6 @@ "use strict"; -var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; +var _createClass = (function () { function defineProperties(target, props) { for (var key in props) { var prop = props[key]; prop.configurable = true; if (prop.value) prop.writable = true; } Object.defineProperties(target, props); } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; @@ -9,12 +9,11 @@ var Test = (function () { _classCallCheck(this, Test); } - _prototypeProperties(Test, null, { + _createClass(Test, { bar: { get: function () { throw new Error("wow"); - }, - configurable: true + } } });