From 130e0ebe6bf14fb1b7dc290ff73a43312720caa5 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Fri, 6 Mar 2015 23:08:10 +1100 Subject: [PATCH] better classes, more spec compliant and nicer output - fixes #952 --- .../transformation/helpers/name-method.js | 11 +- .../transformers/es6/classes.js | 172 ++++++++++++------ .../transformation/api/blacklist/expected.js | 12 +- .../async-to-generator/async/expected.js | 10 +- .../bluebird-coroutines/class/expected.js | 10 +- .../expression/expected.js | 2 +- .../bluebird-coroutines/statement/expected.js | 2 +- .../accessing-super-class/expected.js | 40 ++-- .../accessing-super-properties/actual.js | 1 + .../accessing-super-properties/expected.js | 17 +- .../calling-super-properties/actual.js | 1 + .../calling-super-properties/expected.js | 25 +-- .../expected.js | 20 +- .../es6-classes-loose/super-class/expected.js | 16 +- .../super-function-fallback/expected.js | 12 +- .../accessing-super-class/expected.js | 40 ++-- .../accessing-super-properties/actual.js | 1 + .../accessing-super-properties/expected.js | 17 +- .../calling-super-properties/actual.js | 1 + .../calling-super-properties/expected.js | 21 ++- .../es6-classes/constructor/actual.js | 1 + .../es6-classes/constructor/expected.js | 29 +-- .../actual.js | 5 + .../options.json | 3 + .../instance-getter-and-setter/expected.js | 10 +- .../es6-classes/instance-getter/expected.js | 10 +- .../es6-classes/instance-method/expected.js | 10 +- .../es6-classes/instance-setter/expected.js | 10 +- .../es6-classes/plain-class/expected.js | 10 +- .../es6-classes/statement/expected.js | 36 ++-- .../es6-classes/static/expected.js | 12 +- .../actual.js | 5 + .../expected.js | 11 ++ .../options.json | 3 + .../super-class-anonymous/expected.js | 70 +++---- .../expected.js | 20 +- .../es6-classes/super-class/expected.js | 16 +- .../super-function-fallback/expected.js | 12 +- .../actual.js | 6 + .../options.json | 3 + .../exports-default/expected.js | 20 +- .../exports-variable/expected.js | 10 +- .../import/expected.js | 2 +- .../exports-default/expected.js | 20 +- .../exports-variable/expected.js | 10 +- .../hoist-function-exports/expected.js | 2 +- .../imports-named/expected.js | 2 +- .../es6-modules-common/overview/expected.js | 2 +- .../exports-default/expected.js | 20 +- .../exports-variable/expected.js | 10 +- .../exports-default/expected.js | 20 +- .../exports-variable/expected.js | 10 +- .../exports-default/expected.js | 20 +- .../exports-variable/expected.js | 10 +- .../private/expected.js | 24 ++- .../object-getter-memoization/expected.js | 10 +- .../runtime/aliased-constructors/expected.js | 2 +- .../transformation/runtime/full/expected.js | 2 +- .../runtime/modules-common/expected.js | 2 +- .../runtime/regenerator-runtime/expected.js | 2 +- .../runtime/symbol-iterator-in/expected.js | 2 +- .../source-maps/class/expected.js | 10 +- .../spec-proto-to-assign/class/expected.js | 16 +- 63 files changed, 571 insertions(+), 370 deletions(-) create mode 100644 test/fixtures/transformation/es6-classes/derived-constructor-must-call-super/actual.js create mode 100644 test/fixtures/transformation/es6-classes/derived-constructor-must-call-super/options.json create mode 100644 test/fixtures/transformation/es6-classes/super-call-only-allowed-in-derived-constructor/actual.js create mode 100644 test/fixtures/transformation/es6-classes/super-call-only-allowed-in-derived-constructor/expected.js create mode 100644 test/fixtures/transformation/es6-classes/super-call-only-allowed-in-derived-constructor/options.json create mode 100644 test/fixtures/transformation/es6-classes/this-not-allowed-before-super-in-derived-classes/actual.js create mode 100644 test/fixtures/transformation/es6-classes/this-not-allowed-before-super-in-derived-classes/options.json diff --git a/src/babel/transformation/helpers/name-method.js b/src/babel/transformation/helpers/name-method.js index ff76f09102..3de58f067e 100644 --- a/src/babel/transformation/helpers/name-method.js +++ b/src/babel/transformation/helpers/name-method.js @@ -89,6 +89,11 @@ var visit = function (node, name, scope) { return state; }; +export function custom(node, id, scope) { + var state = visit(node, id.name, scope); + return wrap(state, node, id, scope); +} + export function property(node, file, scope) { var key = t.toComputedKey(node, node.key); if (!t.isLiteral(key)) return node; // we can't set a function id with this @@ -103,7 +108,7 @@ export function property(node, file, scope) { export function bare(node, parent, scope) { // has an `id` so we don't need to infer one - if (node.id) return; + if (node.id) return node; var id; if (t.isProperty(parent) && parent.kind === "init" && !parent.computed) { @@ -113,10 +118,10 @@ export function bare(node, parent, scope) { // var foo = function () {}; id = parent.id; } else { - return; + return node; } - if (!t.isIdentifier(id)) return; + if (!t.isIdentifier(id)) return node; var name = t.toIdentifier(id.name); id = t.identifier(name); diff --git a/src/babel/transformation/transformers/es6/classes.js b/src/babel/transformation/transformers/es6/classes.js index 036c04247d..2ce7ecd7c0 100644 --- a/src/babel/transformation/transformers/es6/classes.js +++ b/src/babel/transformation/transformers/es6/classes.js @@ -3,29 +3,40 @@ import * as nameMethod from "../../helpers/name-method"; import * as defineMap from "../../helpers/define-map"; import * as messages from "../../../messages"; import * as util from "../../../util"; +import traverse from "../../../traversal"; import t from "../../../types"; export var check = t.isClass; export function ClassDeclaration(node, parent, scope, file) { - return new ClassTransformer(node, file, scope, true).run(); + return new ClassTransformer(node, parent, scope, file, true).run(); } export function ClassExpression(node, parent, scope, file) { - if (!node.id) { - if (t.isProperty(parent) && parent.value === node && !parent.computed && t.isIdentifier(parent.key)) { - // var o = { foo: class {} }; - node.id = parent.key; - } + return new ClassTransformer(node, parent, scope, file, false).run(); +} - if (t.isVariableDeclarator(parent) && t.isIdentifier(parent.id)) { - // var foo = class {}; - node.id = parent.id; +var verifyConstructorVisitor = { + CallExpression: { + enter(node, parent, scope, state) { + if (t.isIdentifier(node.callee, { name: "super" })) { + state.hasBareSuper = true; + + if (!state.hasSuper) { + throw state.file.errorWithNode(node, "super call is only allowed in derived constructor"); + } + } + } + }, + + ThisExpression: { + enter(node, parent, scope, state) { + if (state.hasSuper && !state.hasBareSuper) { + throw state.file.errorWithNode(node, "'this' is not allowed before super()"); + } } } - - return new ClassTransformer(node, file, scope, false).run(); -} +}; class ClassTransformer { @@ -33,13 +44,15 @@ class ClassTransformer { * Description * * @param {Node} node - * @param {File} file + * @param {Node} parent * @param {Scope} scope + * @param {File} file * @param {Boolean} isStatement */ - constructor(node, file, scope, isStatement) { + constructor(node, parent, scope, file, isStatement) { this.isStatement = isStatement; + this.parent = parent; this.scope = scope; this.node = node; this.file = file; @@ -49,11 +62,15 @@ class ClassTransformer { this.instanceMutatorMap = {}; this.staticMutatorMap = {}; - this.hasConstructor = false; - this.className = node.id || scope.generateUidIdentifier("class"); - this.superName = node.superClass || t.identifier("Function"); - this.hasSuper = !!node.superClass; - this.isLoose = file.isLoose("es6.classes"); + + this.hasConstructor = false; + this.className = node.id; + this.classRef = scope.generateUidIdentifier(node.id ? node.id.name : "class"); + + this.superName = node.superClass || t.identifier("Function"); + this.hasSuper = !!node.superClass; + + this.isLoose = file.isLoose("es6.classes"); } /** @@ -66,39 +83,46 @@ class ClassTransformer { var superName = this.superName; var className = this.className; var classBody = this.node.body.body; + var classRef = this.classRef; var file = this.file; // var body = this.body = []; + // + + var useFunctionDeclaration = false; + + // class expressions have their class id lexically bound + + if (!this.isStatement && this.className) { + useFunctionDeclaration = true; + classRef = this.classRef = this.className || this.classRef; + } + + // + var constructorBody = t.blockStatement([ t.expressionStatement(t.callExpression(file.addHelper("class-call-check"), [ t.thisExpression(), - className + classRef ])) ]); var constructor; - if (this.node.id) { - constructor = t.functionDeclaration(className, [], constructorBody); + + if (useFunctionDeclaration) { + constructor = t.functionDeclaration(classRef, [], constructorBody); body.push(constructor); } else { - var constructorName = null; - // when a class has no parent and there is only a constructor or no body - // then the constructor is not wrapped in a closure and needs to be named - var containsOnlyConstructor = classBody.length === 1 && classBody[0].key.name === "constructor"; - if (!this.hasSuper && (classBody.length === 0 || containsOnlyConstructor)) { - constructorName = className; - } - - constructor = t.functionExpression(constructorName, [], constructorBody); - body.push(t.variableDeclaration("var", [ - t.variableDeclarator(className, constructor) - ])); + constructor = t.functionExpression(null, [], constructorBody); } + this.constructor = constructor; + // + var closureParams = []; var closureArgs = []; @@ -107,36 +131,44 @@ class ClassTransformer { if (this.hasSuper) { closureArgs.push(superName); - if (!t.isIdentifier(superName)) { - superName = this.scope.generateUidBasedOnNode(superName, this.file); - } - + superName = this.scope.generateUidBasedOnNode(superName, this.file); closureParams.push(superName); this.superName = superName; - body.push(t.expressionStatement(t.callExpression(file.addHelper("inherits"), [className, superName]))); + body.push(t.expressionStatement(t.callExpression(file.addHelper("inherits"), [classRef, superName]))); } + // + this.buildBody(); - t.inheritsComments(body[0], this.node); + if (!useFunctionDeclaration) { + if (this.isStatement) { + constructor = nameMethod.custom(constructor, this.className, this.scope); + } else if (!this.className) { + // infer class name if this is a nameless class expression + constructor = nameMethod.bare(constructor, this.parent, this.scope); + } - var init; + body.unshift(t.variableDeclaration("var", [ + t.variableDeclarator(classRef, constructor) + ])); - if (body.length === 1) { - // only a constructor so no need for a closure container - init = t.toExpression(constructor); - } else { - body.push(t.returnStatement(className)); - init = t.callExpression( - t.functionExpression(null, closureParams, t.blockStatement(body)), - closureArgs - ); + t.inheritsComments(body[0], this.node); } + // + + body.push(t.returnStatement(classRef)); + + var init = t.callExpression( + t.functionExpression(null, closureParams, t.blockStatement(body)), + closureArgs + ); + if (this.isStatement) { return t.variableDeclaration("let", [ - t.variableDeclarator(className, init) + t.variableDeclarator(this.className, init) ]); } else { return init; @@ -157,18 +189,22 @@ class ClassTransformer { for (var i = 0; i < classBody.length; i++) { var node = classBody[i]; if (t.isMethodDefinition(node)) { + var isConstructor = (!node.computed && t.isIdentifier(node.key, { name: "constructor" })) || t.isLiteral(node.key, { value: "constructor" }); + if (isConstructor) this.verifyConstructor(node); + var replaceSupers = new ReplaceSupers({ methodNode: node, - objectRef: this.className, + objectRef: this.classRef, superRef: this.superName, isStatic: node.static, isLoose: this.isLoose, scope: this.scope, file: this.file }, true); + replaceSupers.replace(); - if ((!node.computed && t.isIdentifier(node.key, { name: "constructor" })) || t.isLiteral(node.key, { value: "constructor" })) { + if (isConstructor) { this.pushConstructor(node); } else { this.pushMethod(node); @@ -205,7 +241,7 @@ class ClassTransformer { if (instanceProps || staticProps) { instanceProps ||= t.literal(null); - var args = [className, instanceProps]; + var args = [this.classRef, instanceProps]; if (staticProps) args.push(staticProps); body.push(t.expressionStatement( @@ -214,6 +250,26 @@ class ClassTransformer { } } + /** + * Description + * + * @param {Node} node + */ + + verifyConstructor(node) { + var state = { + hasBareSuper: false, + hasSuper: this.hasSuper, + file: this.file + }; + + traverse(node, verifyConstructorVisitor, this.scope, state); + + if (!state.hasBareSuper && this.hasSuper) { + throw this.file.errorWithNode(node, "Derived constructor must call super()"); + } + } + /** * Push a method to its respective mutatorMap. * @@ -231,9 +287,9 @@ class ClassTransformer { if (this.isLoose) { // use assignments instead of define properties for loose classes - var className = this.className; - if (!node.static) className = t.memberExpression(className, t.identifier("prototype")); - methodName = t.memberExpression(className, methodName, node.computed); + var classRef = this.classRef; + if (!node.static) classRef = t.memberExpression(classRef, t.identifier("prototype")); + methodName = t.memberExpression(classRef, methodName, node.computed); var expr = t.expressionStatement(t.assignmentExpression("=", methodName, node.value)); t.inheritsComments(expr, node); @@ -267,7 +323,7 @@ class ClassTransformer { var key; if (node.static) { - key = t.memberExpression(this.className, node.key); + key = t.memberExpression(this.classRef, node.key); this.body.push( t.expressionStatement(t.assignmentExpression("=", key, node.value)) ); diff --git a/test/fixtures/transformation/api/blacklist/expected.js b/test/fixtures/transformation/api/blacklist/expected.js index 934fea14ff..c520c7271e 100644 --- a/test/fixtures/transformation/api/blacklist/expected.js +++ b/test/fixtures/transformation/api/blacklist/expected.js @@ -2,8 +2,12 @@ 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); +var Test = (function () { + var _Test = function Test() { + _classCallCheck(this, _Test); - arr.map(x => x * x); -}; \ No newline at end of file + arr.map(x => x * x); + }; + + return _Test; +})(); \ No newline at end of file diff --git a/test/fixtures/transformation/async-to-generator/async/expected.js b/test/fixtures/transformation/async-to-generator/async/expected.js index 7ff4ac6f79..4f8182f980 100644 --- a/test/fixtures/transformation/async-to-generator/async/expected.js +++ b/test/fixtures/transformation/async-to-generator/async/expected.js @@ -1,16 +1,16 @@ "use strict"; var Foo = (function () { - function Foo() { - babelHelpers.classCallCheck(this, Foo); - } + var _Foo = function Foo() { + babelHelpers.classCallCheck(this, _Foo); + }; - babelHelpers.createClass(Foo, { + babelHelpers.createClass(_Foo, { foo: { value: babelHelpers.asyncToGenerator(function* () { var wat = yield bar(); }) } }); - return Foo; + return _Foo; })(); \ 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 25d962f60c..88d18fd9e3 100644 --- a/test/fixtures/transformation/bluebird-coroutines/class/expected.js +++ b/test/fixtures/transformation/bluebird-coroutines/class/expected.js @@ -7,11 +7,11 @@ var _createClass = (function () { function defineProperties(target, props) { for 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); - } + var _Foo = function Foo() { + _classCallCheck(this, _Foo); + }; - _createClass(Foo, { + _createClass(_Foo, { foo: { value: _bluebird.coroutine(function* () { var wat = yield bar(); @@ -19,5 +19,5 @@ var Foo = (function () { } }); - return Foo; + return _Foo; })(); \ No newline at end of file diff --git a/test/fixtures/transformation/bluebird-coroutines/expression/expected.js b/test/fixtures/transformation/bluebird-coroutines/expression/expected.js index ed68858b19..acac1b33b6 100644 --- a/test/fixtures/transformation/bluebird-coroutines/expression/expected.js +++ b/test/fixtures/transformation/bluebird-coroutines/expression/expected.js @@ -4,4 +4,4 @@ var _bluebird = require("bluebird"); var foo = _bluebird.coroutine(function* () { var wat = yield bar(); -}); +}); \ No newline at end of file diff --git a/test/fixtures/transformation/bluebird-coroutines/statement/expected.js b/test/fixtures/transformation/bluebird-coroutines/statement/expected.js index ed68858b19..acac1b33b6 100644 --- a/test/fixtures/transformation/bluebird-coroutines/statement/expected.js +++ b/test/fixtures/transformation/bluebird-coroutines/statement/expected.js @@ -4,4 +4,4 @@ var _bluebird = require("bluebird"); var foo = _bluebird.coroutine(function* () { var wat = yield bar(); -}); +}); \ No newline at end of file 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 4d2403839d..7fa4cc1975 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,39 +1,39 @@ "use strict"; -var Test = (function (Foo) { - function Test() { +var Test = (function (_Foo) { + var _Test = function Test() { var _Foo$prototype$test, _Foo$prototype$test2; - babelHelpers.classCallCheck(this, Test); + babelHelpers.classCallCheck(this, _Test); woops["super"].test(); - Foo.call(this); - Foo.prototype.test.call(this); + _Foo.call(this); + _Foo.prototype.test.call(this); - Foo.call.apply(Foo, [this].concat(babelHelpers.slice.call(arguments))); - Foo.call.apply(Foo, [this, "test"].concat(babelHelpers.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(babelHelpers.slice.call(arguments))); - (_Foo$prototype$test2 = Foo.prototype.test).call.apply(_Foo$prototype$test2, [this, "test"].concat(babelHelpers.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))); + }; - babelHelpers.inherits(Test, Foo); + babelHelpers.inherits(_Test, _Foo); - Test.prototype.test = function test() { + _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(babelHelpers.slice.call(arguments))); - (_Foo$prototype$test2 = Foo.prototype.test).call.apply(_Foo$prototype$test2, [this, "test"].concat(babelHelpers.slice.call(arguments))); + _Foo.prototype.test.call(this); + (_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() { + _Test.foo = function foo() { var _Foo$foo, _Foo$foo2; - Foo.foo.call(this); - (_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))); + _Foo.foo.call(this); + (_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; + return _Test; })(Foo); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-classes-loose/accessing-super-properties/actual.js b/test/fixtures/transformation/es6-classes-loose/accessing-super-properties/actual.js index 524a05eaa4..fad2b31584 100644 --- a/test/fixtures/transformation/es6-classes-loose/accessing-super-properties/actual.js +++ b/test/fixtures/transformation/es6-classes-loose/accessing-super-properties/actual.js @@ -1,5 +1,6 @@ class Test extends Foo { constructor() { + super(); super.test; super.test.whatever; } 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 eceea3a990..ecfdc1920e 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,13 +1,14 @@ "use strict"; -var Test = (function (Foo) { - function Test() { - babelHelpers.classCallCheck(this, Test); +var Test = (function (_Foo) { + var _Test = function Test() { + babelHelpers.classCallCheck(this, _Test); - Foo.prototype.test; - Foo.prototype.test.whatever; - } + _Foo.call(this); + _Foo.prototype.test; + _Foo.prototype.test.whatever; + }; - babelHelpers.inherits(Test, Foo); - return Test; + 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/actual.js b/test/fixtures/transformation/es6-classes-loose/calling-super-properties/actual.js index 993109dc24..0b392d3eb2 100644 --- a/test/fixtures/transformation/es6-classes-loose/calling-super-properties/actual.js +++ b/test/fixtures/transformation/es6-classes-loose/calling-super-properties/actual.js @@ -1,5 +1,6 @@ class Test extends Foo { constructor() { + super(); super.test.whatever(); super.test(); } 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 f4f5edd784..f99d01434e 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,19 @@ "use strict"; -var Test = (function (Foo) { - function Test() { - babelHelpers.classCallCheck(this, Test); +var Test = (function (_Foo) { + var _Test = function Test() { + babelHelpers.classCallCheck(this, _Test); - Foo.prototype.test.whatever(); - Foo.prototype.test.call(this); - } - - babelHelpers.inherits(Test, Foo); - - Test.test = function test() { - return Foo.wow.call(this); + _Foo.call(this); + _Foo.prototype.test.whatever(); + _Foo.prototype.test.call(this); }; - return Test; + babelHelpers.inherits(_Test, _Foo); + + _Test.test = function test() { + return _Foo.wow.call(this); + }; + + return _Test; })(Foo); \ No newline at end of file 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 c71784d934..93f536ee83 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,27 +1,27 @@ "use strict"; var BaseController = (function (_Chaplin$Controller) { - function BaseController() { - babelHelpers.classCallCheck(this, BaseController); + var _BaseController = function BaseController() { + babelHelpers.classCallCheck(this, _BaseController); if (_Chaplin$Controller != null) { _Chaplin$Controller.apply(this, arguments); } - } + }; - babelHelpers.inherits(BaseController, _Chaplin$Controller); - return BaseController; + babelHelpers.inherits(_BaseController, _Chaplin$Controller); + return _BaseController; })(Chaplin.Controller); var BaseController2 = (function (_Chaplin$Controller$Another) { - function BaseController2() { - babelHelpers.classCallCheck(this, BaseController2); + var _BaseController2 = function BaseController2() { + babelHelpers.classCallCheck(this, _BaseController2); if (_Chaplin$Controller$Another != null) { _Chaplin$Controller$Another.apply(this, arguments); } - } + }; - babelHelpers.inherits(BaseController2, _Chaplin$Controller$Another); - return BaseController2; + 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 ada91904e9..3521641d5c 100644 --- a/test/fixtures/transformation/es6-classes-loose/super-class/expected.js +++ b/test/fixtures/transformation/es6-classes-loose/super-class/expected.js @@ -1,14 +1,14 @@ "use strict"; -var Test = (function (Foo) { - function Test() { - babelHelpers.classCallCheck(this, Test); +var Test = (function (_Foo) { + var _Test = function Test() { + babelHelpers.classCallCheck(this, _Test); - if (Foo != null) { - Foo.apply(this, arguments); + if (_Foo != null) { + _Foo.apply(this, arguments); } - } + }; - babelHelpers.inherits(Test, Foo); - return Test; + 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 4366f3918d..8ccb1dc891 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,7 +1,11 @@ "use strict"; -var Test = function Test() { - babelHelpers.classCallCheck(this, Test); +var Test = (function () { + var _Test = function Test() { + babelHelpers.classCallCheck(this, _Test); - Function.prototype.hasOwnProperty.call(this, "test"); -}; \ No newline at end of file + Function.prototype.hasOwnProperty.call(this, "test"); + }; + + return _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 f235b5aeb4..b77ae2a31a 100644 --- a/test/fixtures/transformation/es6-classes/accessing-super-class/expected.js +++ b/test/fixtures/transformation/es6-classes/accessing-super-class/expected.js @@ -1,31 +1,31 @@ "use strict"; -var Test = (function (Foo) { - function Test() { +var Test = (function (_Foo) { + var _Test = function Test() { var _babelHelpers$get, _babelHelpers$get2; - babelHelpers.classCallCheck(this, Test); + babelHelpers.classCallCheck(this, _Test); woops["super"].test(); - babelHelpers.get(Object.getPrototypeOf(Test.prototype), "constructor", this).call(this); - babelHelpers.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); - 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))); + 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))); - 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))); - } + 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))); + }; - babelHelpers.inherits(Test, Foo); - babelHelpers.createClass(Test, { + babelHelpers.inherits(_Test, _Foo); + babelHelpers.createClass(_Test, { test: { value: function test() { var _babelHelpers$get; - 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))); + 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))); } } }, { @@ -33,11 +33,11 @@ var Test = (function (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))); + 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); \ No newline at end of file + return _Test; +})(Foo); diff --git a/test/fixtures/transformation/es6-classes/accessing-super-properties/actual.js b/test/fixtures/transformation/es6-classes/accessing-super-properties/actual.js index 524a05eaa4..fad2b31584 100644 --- a/test/fixtures/transformation/es6-classes/accessing-super-properties/actual.js +++ b/test/fixtures/transformation/es6-classes/accessing-super-properties/actual.js @@ -1,5 +1,6 @@ class Test extends Foo { constructor() { + super(); super.test; super.test.whatever; } 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 9c167a5f9f..c2933fb96e 100644 --- a/test/fixtures/transformation/es6-classes/accessing-super-properties/expected.js +++ b/test/fixtures/transformation/es6-classes/accessing-super-properties/expected.js @@ -1,13 +1,14 @@ "use strict"; -var Test = (function (Foo) { - function Test() { - babelHelpers.classCallCheck(this, Test); +var Test = (function (_Foo) { + var _Test = function Test() { + babelHelpers.classCallCheck(this, _Test); - babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", this); - babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", this).whatever; - } + babelHelpers.get(Object.getPrototypeOf(_Test.prototype), "constructor", this).call(this); + babelHelpers.get(Object.getPrototypeOf(_Test.prototype), "test", this); + babelHelpers.get(Object.getPrototypeOf(_Test.prototype), "test", this).whatever; + }; - babelHelpers.inherits(Test, Foo); - return Test; + babelHelpers.inherits(_Test, _Foo); + return _Test; })(Foo); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-classes/calling-super-properties/actual.js b/test/fixtures/transformation/es6-classes/calling-super-properties/actual.js index 993109dc24..0b392d3eb2 100644 --- a/test/fixtures/transformation/es6-classes/calling-super-properties/actual.js +++ b/test/fixtures/transformation/es6-classes/calling-super-properties/actual.js @@ -1,5 +1,6 @@ class Test extends Foo { constructor() { + super(); super.test.whatever(); super.test(); } 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 a0382a0b8a..523ceb6d49 100644 --- a/test/fixtures/transformation/es6-classes/calling-super-properties/expected.js +++ b/test/fixtures/transformation/es6-classes/calling-super-properties/expected.js @@ -1,20 +1,21 @@ "use strict"; -var Test = (function (Foo) { - function Test() { - babelHelpers.classCallCheck(this, Test); +var Test = (function (_Foo) { + var _Test = function Test() { + babelHelpers.classCallCheck(this, _Test); - babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", this).whatever(); - babelHelpers.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).whatever(); + babelHelpers.get(Object.getPrototypeOf(_Test.prototype), "test", this).call(this); + }; - babelHelpers.inherits(Test, Foo); - babelHelpers.createClass(Test, null, { + babelHelpers.inherits(_Test, _Foo); + babelHelpers.createClass(_Test, null, { test: { value: function test() { - return babelHelpers.get(Object.getPrototypeOf(Test), "wow", this).call(this); + return babelHelpers.get(Object.getPrototypeOf(_Test), "wow", this).call(this); } } }); - return Test; + return _Test; })(Foo); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-classes/constructor/actual.js b/test/fixtures/transformation/es6-classes/constructor/actual.js index 2d26f87082..c968e6c108 100644 --- a/test/fixtures/transformation/es6-classes/constructor/actual.js +++ b/test/fixtures/transformation/es6-classes/constructor/actual.js @@ -6,6 +6,7 @@ class Test { class Foo extends Bar { constructor() { + super(); this.state = "test"; } } diff --git a/test/fixtures/transformation/es6-classes/constructor/expected.js b/test/fixtures/transformation/es6-classes/constructor/expected.js index c5656eb66b..53a72ca4dc 100644 --- a/test/fixtures/transformation/es6-classes/constructor/expected.js +++ b/test/fixtures/transformation/es6-classes/constructor/expected.js @@ -1,18 +1,23 @@ "use strict"; -var Test = function Test() { - babelHelpers.classCallCheck(this, Test); - - this.state = "test"; -}; - -var Foo = (function (Bar) { - function Foo() { - babelHelpers.classCallCheck(this, Foo); +var Test = (function () { + var _Test = function Test() { + babelHelpers.classCallCheck(this, _Test); this.state = "test"; - } + }; - babelHelpers.inherits(Foo, Bar); - return Foo; + return _Test; +})(); + +var Foo = (function (_Bar) { + var _Foo = function Foo() { + babelHelpers.classCallCheck(this, _Foo); + + babelHelpers.get(Object.getPrototypeOf(_Foo.prototype), "constructor", this).call(this); + this.state = "test"; + }; + + babelHelpers.inherits(_Foo, _Bar); + return _Foo; })(Bar); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-classes/derived-constructor-must-call-super/actual.js b/test/fixtures/transformation/es6-classes/derived-constructor-must-call-super/actual.js new file mode 100644 index 0000000000..5fae7a7b14 --- /dev/null +++ b/test/fixtures/transformation/es6-classes/derived-constructor-must-call-super/actual.js @@ -0,0 +1,5 @@ +class Foo extends Bar { + constructor() { + + } +} diff --git a/test/fixtures/transformation/es6-classes/derived-constructor-must-call-super/options.json b/test/fixtures/transformation/es6-classes/derived-constructor-must-call-super/options.json new file mode 100644 index 0000000000..c262ea7e16 --- /dev/null +++ b/test/fixtures/transformation/es6-classes/derived-constructor-must-call-super/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Derived constructor must call super()" +} 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 50667d62ca..908524ec07 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,11 +1,11 @@ "use strict"; var Test = (function () { - function Test() { - babelHelpers.classCallCheck(this, Test); - } + var _Test = function Test() { + babelHelpers.classCallCheck(this, _Test); + }; - babelHelpers.createClass(Test, { + babelHelpers.createClass(_Test, { test: { get: function () { return 5 + 5; @@ -15,5 +15,5 @@ var Test = (function () { } } }); - return Test; + 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 474c1e5e86..f2bcef36be 100644 --- a/test/fixtures/transformation/es6-classes/instance-getter/expected.js +++ b/test/fixtures/transformation/es6-classes/instance-getter/expected.js @@ -1,16 +1,16 @@ "use strict"; var Test = (function () { - function Test() { - babelHelpers.classCallCheck(this, Test); - } + var _Test = function Test() { + babelHelpers.classCallCheck(this, _Test); + }; - babelHelpers.createClass(Test, { + babelHelpers.createClass(_Test, { test: { get: function () { return 5 + 5; } } }); - return Test; + 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 a62877a971..05d28a60dd 100644 --- a/test/fixtures/transformation/es6-classes/instance-method/expected.js +++ b/test/fixtures/transformation/es6-classes/instance-method/expected.js @@ -1,16 +1,16 @@ "use strict"; var Test = (function () { - function Test() { - babelHelpers.classCallCheck(this, Test); - } + var _Test = function Test() { + babelHelpers.classCallCheck(this, _Test); + }; - babelHelpers.createClass(Test, { + babelHelpers.createClass(_Test, { test: { value: function test() { return 5 + 5; } } }); - return Test; + 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 98f8bcfadb..8240c8e048 100644 --- a/test/fixtures/transformation/es6-classes/instance-setter/expected.js +++ b/test/fixtures/transformation/es6-classes/instance-setter/expected.js @@ -1,16 +1,16 @@ "use strict"; var Test = (function () { - function Test() { - babelHelpers.classCallCheck(this, Test); - } + var _Test = function Test() { + babelHelpers.classCallCheck(this, _Test); + }; - babelHelpers.createClass(Test, { + babelHelpers.createClass(_Test, { test: { set: function (val) { this._test = val; } } }); - return Test; + return _Test; })(); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-classes/plain-class/expected.js b/test/fixtures/transformation/es6-classes/plain-class/expected.js index 73c98b9f71..6f2503b4b2 100644 --- a/test/fixtures/transformation/es6-classes/plain-class/expected.js +++ b/test/fixtures/transformation/es6-classes/plain-class/expected.js @@ -1,5 +1,9 @@ "use strict"; -var Test = function Test() { - babelHelpers.classCallCheck(this, Test); -}; \ No newline at end of file +var Test = (function () { + var _Test = function Test() { + babelHelpers.classCallCheck(this, _Test); + }; + + return _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 7ba0f4f940..701427f6f2 100644 --- a/test/fixtures/transformation/es6-classes/statement/expected.js +++ b/test/fixtures/transformation/es6-classes/statement/expected.js @@ -1,28 +1,36 @@ "use strict"; -var BaseView = function BaseView() { - babelHelpers.classCallCheck(this, BaseView); - - this.autoRender = true; -}; - -var BaseView = function BaseView() { - babelHelpers.classCallCheck(this, BaseView); - - this.autoRender = true; -}; - var BaseView = (function () { function BaseView() { babelHelpers.classCallCheck(this, BaseView); + + this.autoRender = true; } - babelHelpers.createClass(BaseView, { + return BaseView; +})(); + +var BaseView = (function () { + var _class = function BaseView() { + babelHelpers.classCallCheck(this, _class); + + this.autoRender = true; + }; + + return _class; +})(); + +var BaseView = (function () { + var _class2 = function BaseView() { + babelHelpers.classCallCheck(this, _class2); + }; + + babelHelpers.createClass(_class2, { foo: { value: function foo() { this.autoRender = true; } } }); - return BaseView; + return _class2; })(); \ 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 013d6f2647..f03c057686 100644 --- a/test/fixtures/transformation/es6-classes/static/expected.js +++ b/test/fixtures/transformation/es6-classes/static/expected.js @@ -1,11 +1,11 @@ "use strict"; var A = (function () { - function A() { - babelHelpers.classCallCheck(this, A); - } + var _A = function A() { + babelHelpers.classCallCheck(this, _A); + }; - babelHelpers.createClass(A, null, { + babelHelpers.createClass(_A, null, { a: { value: function a() {} }, @@ -14,5 +14,5 @@ var A = (function () { set: function (b) {} } }); - return A; -})(); + return _A; +})(); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-classes/super-call-only-allowed-in-derived-constructor/actual.js b/test/fixtures/transformation/es6-classes/super-call-only-allowed-in-derived-constructor/actual.js new file mode 100644 index 0000000000..036ce36e39 --- /dev/null +++ b/test/fixtures/transformation/es6-classes/super-call-only-allowed-in-derived-constructor/actual.js @@ -0,0 +1,5 @@ +class Foo { + constructor() { + super(); + } +} diff --git a/test/fixtures/transformation/es6-classes/super-call-only-allowed-in-derived-constructor/expected.js b/test/fixtures/transformation/es6-classes/super-call-only-allowed-in-derived-constructor/expected.js new file mode 100644 index 0000000000..a0cc6ecf6c --- /dev/null +++ b/test/fixtures/transformation/es6-classes/super-call-only-allowed-in-derived-constructor/expected.js @@ -0,0 +1,11 @@ +"use strict"; + +var Foo = (function () { + var _Foo = function Foo() { + babelHelpers.classCallCheck(this, _Foo); + + babelHelpers.get(Object.getPrototypeOf(_Foo.prototype), "constructor", this).call(this); + }; + + return _Foo; +})(); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-classes/super-call-only-allowed-in-derived-constructor/options.json b/test/fixtures/transformation/es6-classes/super-call-only-allowed-in-derived-constructor/options.json new file mode 100644 index 0000000000..272d58ce9f --- /dev/null +++ b/test/fixtures/transformation/es6-classes/super-call-only-allowed-in-derived-constructor/options.json @@ -0,0 +1,3 @@ +{ + "throws": "super call is only allowed in derived constructor" +} 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 3d89298c5b..9baf524880 100644 --- a/test/fixtures/transformation/es6-classes/super-class-anonymous/expected.js +++ b/test/fixtures/transformation/es6-classes/super-class-anonymous/expected.js @@ -1,46 +1,54 @@ "use strict"; var TestEmpty = (function (_ref) { - function TestEmpty() { - babelHelpers.classCallCheck(this, TestEmpty); + var _TestEmpty = function TestEmpty() { + babelHelpers.classCallCheck(this, _TestEmpty); if (_ref != null) { _ref.apply(this, arguments); } - } + }; - babelHelpers.inherits(TestEmpty, _ref); - return TestEmpty; -})(function _class() { - babelHelpers.classCallCheck(this, _class); -}); + babelHelpers.inherits(_TestEmpty, _ref); + return _TestEmpty; +})((function () { + var _class = function () { + babelHelpers.classCallCheck(this, _class); + }; + + return _class; +})()); var TestConstructorOnly = (function (_ref2) { - function TestConstructorOnly() { - babelHelpers.classCallCheck(this, TestConstructorOnly); + var _TestConstructorOnly = function TestConstructorOnly() { + babelHelpers.classCallCheck(this, _TestConstructorOnly); if (_ref2 != null) { _ref2.apply(this, arguments); } - } + }; - babelHelpers.inherits(TestConstructorOnly, _ref2); - return TestConstructorOnly; -})(function _class2() { - babelHelpers.classCallCheck(this, _class2); -}); + babelHelpers.inherits(_TestConstructorOnly, _ref2); + return _TestConstructorOnly; +})((function () { + var _class2 = function () { + babelHelpers.classCallCheck(this, _class2); + }; + + return _class2; +})()); var TestMethodOnly = (function (_ref3) { - function TestMethodOnly() { - babelHelpers.classCallCheck(this, TestMethodOnly); + var _TestMethodOnly = function TestMethodOnly() { + babelHelpers.classCallCheck(this, _TestMethodOnly); if (_ref3 != null) { _ref3.apply(this, arguments); } - } + }; - babelHelpers.inherits(TestMethodOnly, _ref3); - return TestMethodOnly; + babelHelpers.inherits(_TestMethodOnly, _ref3); + return _TestMethodOnly; })((function () { var _class3 = function () { babelHelpers.classCallCheck(this, _class3); @@ -55,16 +63,16 @@ var TestMethodOnly = (function (_ref3) { })()); var TestConstructorAndMethod = (function (_ref4) { - function TestConstructorAndMethod() { - babelHelpers.classCallCheck(this, TestConstructorAndMethod); + var _TestConstructorAndMethod = function TestConstructorAndMethod() { + babelHelpers.classCallCheck(this, _TestConstructorAndMethod); if (_ref4 != null) { _ref4.apply(this, arguments); } - } + }; - babelHelpers.inherits(TestConstructorAndMethod, _ref4); - return TestConstructorAndMethod; + babelHelpers.inherits(_TestConstructorAndMethod, _ref4); + return _TestConstructorAndMethod; })((function () { var _class4 = function () { babelHelpers.classCallCheck(this, _class4); @@ -79,16 +87,16 @@ var TestConstructorAndMethod = (function (_ref4) { })()); var TestMultipleMethods = (function (_ref5) { - function TestMultipleMethods() { - babelHelpers.classCallCheck(this, TestMultipleMethods); + var _TestMultipleMethods = function TestMultipleMethods() { + babelHelpers.classCallCheck(this, _TestMultipleMethods); if (_ref5 != null) { _ref5.apply(this, arguments); } - } + }; - babelHelpers.inherits(TestMultipleMethods, _ref5); - return TestMultipleMethods; + babelHelpers.inherits(_TestMultipleMethods, _ref5); + return _TestMultipleMethods; })((function () { var _class5 = function () { babelHelpers.classCallCheck(this, _class5); 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 c71784d934..93f536ee83 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,27 +1,27 @@ "use strict"; var BaseController = (function (_Chaplin$Controller) { - function BaseController() { - babelHelpers.classCallCheck(this, BaseController); + var _BaseController = function BaseController() { + babelHelpers.classCallCheck(this, _BaseController); if (_Chaplin$Controller != null) { _Chaplin$Controller.apply(this, arguments); } - } + }; - babelHelpers.inherits(BaseController, _Chaplin$Controller); - return BaseController; + babelHelpers.inherits(_BaseController, _Chaplin$Controller); + return _BaseController; })(Chaplin.Controller); var BaseController2 = (function (_Chaplin$Controller$Another) { - function BaseController2() { - babelHelpers.classCallCheck(this, BaseController2); + var _BaseController2 = function BaseController2() { + babelHelpers.classCallCheck(this, _BaseController2); if (_Chaplin$Controller$Another != null) { _Chaplin$Controller$Another.apply(this, arguments); } - } + }; - babelHelpers.inherits(BaseController2, _Chaplin$Controller$Another); - return BaseController2; + 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 ada91904e9..3521641d5c 100644 --- a/test/fixtures/transformation/es6-classes/super-class/expected.js +++ b/test/fixtures/transformation/es6-classes/super-class/expected.js @@ -1,14 +1,14 @@ "use strict"; -var Test = (function (Foo) { - function Test() { - babelHelpers.classCallCheck(this, Test); +var Test = (function (_Foo) { + var _Test = function Test() { + babelHelpers.classCallCheck(this, _Test); - if (Foo != null) { - Foo.apply(this, arguments); + if (_Foo != null) { + _Foo.apply(this, arguments); } - } + }; - babelHelpers.inherits(Test, Foo); - return Test; + 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 9d4d8335e0..73d0f37629 100644 --- a/test/fixtures/transformation/es6-classes/super-function-fallback/expected.js +++ b/test/fixtures/transformation/es6-classes/super-function-fallback/expected.js @@ -1,7 +1,11 @@ "use strict"; -var Test = function Test() { - babelHelpers.classCallCheck(this, Test); +var Test = (function () { + var _Test = function Test() { + babelHelpers.classCallCheck(this, _Test); - babelHelpers.get(Object.getPrototypeOf(Test.prototype), "hasOwnProperty", this).call(this, "test"); -}; \ No newline at end of file + babelHelpers.get(Object.getPrototypeOf(_Test.prototype), "hasOwnProperty", this).call(this, "test"); + }; + + return _Test; +})(); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-classes/this-not-allowed-before-super-in-derived-classes/actual.js b/test/fixtures/transformation/es6-classes/this-not-allowed-before-super-in-derived-classes/actual.js new file mode 100644 index 0000000000..52461f5401 --- /dev/null +++ b/test/fixtures/transformation/es6-classes/this-not-allowed-before-super-in-derived-classes/actual.js @@ -0,0 +1,6 @@ +class Foo extends Bar { + constructor() { + this.foo = "bar"; + super(); + } +} diff --git a/test/fixtures/transformation/es6-classes/this-not-allowed-before-super-in-derived-classes/options.json b/test/fixtures/transformation/es6-classes/this-not-allowed-before-super-in-derived-classes/options.json new file mode 100644 index 0000000000..73f43b137d --- /dev/null +++ b/test/fixtures/transformation/es6-classes/this-not-allowed-before-super-in-derived-classes/options.json @@ -0,0 +1,3 @@ +{ + "throws": "'this' is not allowed before super()" +} diff --git a/test/fixtures/transformation/es6-modules-amd/exports-default/expected.js b/test/fixtures/transformation/es6-modules-amd/exports-default/expected.js index 19d2991d7d..fbfd3204d7 100644 --- a/test/fixtures/transformation/es6-modules-amd/exports-default/expected.js +++ b/test/fixtures/transformation/es6-modules-amd/exports-default/expected.js @@ -11,17 +11,25 @@ define(["exports", "module"], function (exports, module) { module.exports = function () {}; - var _default = function _default() { - _classCallCheck(this, _default); - }; + var _default = (function () { + var _class = function _default() { + _classCallCheck(this, _class); + }; + + return _class; + })(); module.exports = _default; function foo() {} - var Foo = function Foo() { - _classCallCheck(this, Foo); - }; + var Foo = (function () { + var _Foo = function Foo() { + _classCallCheck(this, _Foo); + }; + + return _Foo; + })(); module.exports = Foo; }); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-modules-amd/exports-variable/expected.js b/test/fixtures/transformation/es6-modules-amd/exports-variable/expected.js index 758bedb23a..b1496c31f3 100644 --- a/test/fixtures/transformation/es6-modules-amd/exports-variable/expected.js +++ b/test/fixtures/transformation/es6-modules-amd/exports-variable/expected.js @@ -15,9 +15,13 @@ define(["exports"], function (exports) { function foo7() {} - var foo8 = exports.foo8 = function foo8() { - _classCallCheck(this, foo8); - }; + var foo8 = exports.foo8 = (function () { + var _foo8 = function foo8() { + _classCallCheck(this, _foo8); + }; + + return _foo8; + })(); Object.defineProperty(exports, "__esModule", { value: true diff --git a/test/fixtures/transformation/es6-modules-common-strict/import/expected.js b/test/fixtures/transformation/es6-modules-common-strict/import/expected.js index 3f51bafc84..5870b36b7f 100644 --- a/test/fixtures/transformation/es6-modules-common-strict/import/expected.js +++ b/test/fixtures/transformation/es6-modules-common-strict/import/expected.js @@ -5,4 +5,4 @@ var _foo = require("foo"); var foo = _foo["default"]; var foo2 = _foo["default"]; var foo3 = _foo.foo3; -var foo4 = _foo; +var foo4 = _foo; \ No newline at end of file diff --git a/test/fixtures/transformation/es6-modules-common/exports-default/expected.js b/test/fixtures/transformation/es6-modules-common/exports-default/expected.js index e104cd3415..d9a82072e8 100644 --- a/test/fixtures/transformation/es6-modules-common/exports-default/expected.js +++ b/test/fixtures/transformation/es6-modules-common/exports-default/expected.js @@ -10,16 +10,24 @@ module.exports = foo; module.exports = function () {}; -var _default = function _default() { - _classCallCheck(this, _default); -}; +var _default = (function () { + var _class = function _default() { + _classCallCheck(this, _class); + }; + + return _class; +})(); module.exports = _default; function foo() {} -var Foo = function Foo() { - _classCallCheck(this, Foo); -}; +var Foo = (function () { + var _Foo = function Foo() { + _classCallCheck(this, _Foo); + }; + + return _Foo; +})(); module.exports = Foo; \ No newline at end of file diff --git a/test/fixtures/transformation/es6-modules-common/exports-variable/expected.js b/test/fixtures/transformation/es6-modules-common/exports-variable/expected.js index d2cb09cbef..590b7384dd 100644 --- a/test/fixtures/transformation/es6-modules-common/exports-variable/expected.js +++ b/test/fixtures/transformation/es6-modules-common/exports-variable/expected.js @@ -14,9 +14,13 @@ var foo6 = exports.foo6 = 3; function foo7() {} -var foo8 = exports.foo8 = function foo8() { - _classCallCheck(this, foo8); -}; +var foo8 = exports.foo8 = (function () { + var _foo8 = function foo8() { + _classCallCheck(this, _foo8); + }; + + return _foo8; +})(); Object.defineProperty(exports, "__esModule", { value: true diff --git a/test/fixtures/transformation/es6-modules-common/hoist-function-exports/expected.js b/test/fixtures/transformation/es6-modules-common/hoist-function-exports/expected.js index 32243d1a56..d68f62cebb 100644 --- a/test/fixtures/transformation/es6-modules-common/hoist-function-exports/expected.js +++ b/test/fixtures/transformation/es6-modules-common/hoist-function-exports/expected.js @@ -15,4 +15,4 @@ var isOdd = exports.isOdd = (function (isEven) { })(isEven); Object.defineProperty(exports, "__esModule", { value: true -}); +}); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-modules-common/imports-named/expected.js b/test/fixtures/transformation/es6-modules-common/imports-named/expected.js index 54de3191ad..5eb09626d6 100644 --- a/test/fixtures/transformation/es6-modules-common/imports-named/expected.js +++ b/test/fixtures/transformation/es6-modules-common/imports-named/expected.js @@ -7,4 +7,4 @@ var bar2 = _foo.bar2; var baz = _foo.baz; var baz2 = _foo.bar; var baz3 = _foo.bar; -var xyz = _foo.xyz; +var xyz = _foo.xyz; \ No newline at end of file diff --git a/test/fixtures/transformation/es6-modules-common/overview/expected.js b/test/fixtures/transformation/es6-modules-common/overview/expected.js index ecc04745a8..88351aa91f 100644 --- a/test/fixtures/transformation/es6-modules-common/overview/expected.js +++ b/test/fixtures/transformation/es6-modules-common/overview/expected.js @@ -22,4 +22,4 @@ exports.test = test; var test = exports.test = 5; Object.defineProperty(exports, "__esModule", { value: true -}); +}); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-modules-ignore/exports-default/expected.js b/test/fixtures/transformation/es6-modules-ignore/exports-default/expected.js index 27cd0177e0..888156f616 100644 --- a/test/fixtures/transformation/es6-modules-ignore/exports-default/expected.js +++ b/test/fixtures/transformation/es6-modules-ignore/exports-default/expected.js @@ -2,12 +2,20 @@ var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; -var _default = function _default() { - _classCallCheck(this, _default); -}; +var _default = (function () { + var _class = function _default() { + _classCallCheck(this, _class); + }; + + return _class; +})(); function foo() {} -var Foo = function Foo() { - _classCallCheck(this, Foo); -}; +var Foo = (function () { + var _Foo = function Foo() { + _classCallCheck(this, _Foo); + }; + + return _Foo; +})(); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-modules-ignore/exports-variable/expected.js b/test/fixtures/transformation/es6-modules-ignore/exports-variable/expected.js index 1a08078682..e7a29fc603 100644 --- a/test/fixtures/transformation/es6-modules-ignore/exports-variable/expected.js +++ b/test/fixtures/transformation/es6-modules-ignore/exports-variable/expected.js @@ -13,6 +13,10 @@ var foo6 = 3; function foo7() {} -var foo8 = function foo8() { - _classCallCheck(this, foo8); -}; \ No newline at end of file +var foo8 = (function () { + var _foo8 = function foo8() { + _classCallCheck(this, _foo8); + }; + + return _foo8; +})(); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-modules-system/exports-default/expected.js b/test/fixtures/transformation/es6-modules-system/exports-default/expected.js index cab98a125b..8c5ef66d20 100644 --- a/test/fixtures/transformation/es6-modules-system/exports-default/expected.js +++ b/test/fixtures/transformation/es6-modules-system/exports-default/expected.js @@ -22,15 +22,23 @@ System.register([], function (_export) { _export("default", function () {}); - _default = function _default() { - _classCallCheck(this, _default); - }; + _default = (function () { + var _class = function _default() { + _classCallCheck(this, _class); + }; + + return _class; + })(); _export("default", _default); - Foo = function Foo() { - _classCallCheck(this, Foo); - }; + Foo = (function () { + var _Foo = function Foo() { + _classCallCheck(this, _Foo); + }; + + return _Foo; + })(); _export("default", Foo); } diff --git a/test/fixtures/transformation/es6-modules-system/exports-variable/expected.js b/test/fixtures/transformation/es6-modules-system/exports-variable/expected.js index c94cf23409..6d868e8e80 100644 --- a/test/fixtures/transformation/es6-modules-system/exports-variable/expected.js +++ b/test/fixtures/transformation/es6-modules-system/exports-variable/expected.js @@ -18,9 +18,13 @@ System.register([], function (_export) { foo4 = _export("foo4", 2); foo5 = _export("foo5", undefined); foo6 = _export("foo6", 3); - foo8 = _export("foo8", function foo8() { - _classCallCheck(this, foo8); - }); + foo8 = _export("foo8", (function () { + var _foo8 = function foo8() { + _classCallCheck(this, _foo8); + }; + + return _foo8; + })()); _export("foo3", foo3 = 5); } diff --git a/test/fixtures/transformation/es6-modules-umd/exports-default/expected.js b/test/fixtures/transformation/es6-modules-umd/exports-default/expected.js index 79b102762c..4276d1e2cb 100644 --- a/test/fixtures/transformation/es6-modules-umd/exports-default/expected.js +++ b/test/fixtures/transformation/es6-modules-umd/exports-default/expected.js @@ -17,17 +17,25 @@ module.exports = function () {}; - var _default = function _default() { - _classCallCheck(this, _default); - }; + var _default = (function () { + var _class = function _default() { + _classCallCheck(this, _class); + }; + + return _class; + })(); module.exports = _default; function foo() {} - var Foo = function Foo() { - _classCallCheck(this, Foo); - }; + var Foo = (function () { + var _Foo = function Foo() { + _classCallCheck(this, _Foo); + }; + + return _Foo; + })(); module.exports = Foo; }); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-modules-umd/exports-variable/expected.js b/test/fixtures/transformation/es6-modules-umd/exports-variable/expected.js index f162e35935..11838705e6 100644 --- a/test/fixtures/transformation/es6-modules-umd/exports-variable/expected.js +++ b/test/fixtures/transformation/es6-modules-umd/exports-variable/expected.js @@ -21,9 +21,13 @@ function foo7() {} - var foo8 = exports.foo8 = function foo8() { - _classCallCheck(this, foo8); - }; + var foo8 = exports.foo8 = (function () { + var _foo8 = function foo8() { + _classCallCheck(this, _foo8); + }; + + return _foo8; + })(); Object.defineProperty(exports, "__esModule", { value: true diff --git a/test/fixtures/transformation/es7-abstract-references/private/expected.js b/test/fixtures/transformation/es7-abstract-references/private/expected.js index ad0c2b95c7..b7b9b238d3 100644 --- a/test/fixtures/transformation/es7-abstract-references/private/expected.js +++ b/test/fixtures/transformation/es7-abstract-references/private/expected.js @@ -7,25 +7,23 @@ var B = new WeakMap(), C = new WeakMap(); var D = (function () { + var _D = function D() { + _classCallCheck(this, _D); + }; + var F = new WeakMap(), G = new WeakMap(); var E = new WeakMap(); - - function D() { - _classCallCheck(this, D); - } - - return D; + return _D; })(); var H = (function () { + var _class = function H() { + _classCallCheck(this, _class); + }; + var J = new WeakMap(), K = new WeakMap(); var I = new WeakMap(); - - function H() { - _classCallCheck(this, H); - } - - return H; -})(); + return _class; +})(); \ 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 cc9dbcb09c..58a680b4c8 100644 --- a/test/fixtures/transformation/playground/object-getter-memoization/expected.js +++ b/test/fixtures/transformation/playground/object-getter-memoization/expected.js @@ -1,11 +1,11 @@ "use strict"; var Foo = (function () { - function Foo() { - babelHelpers.classCallCheck(this, Foo); - } + var _Foo = function Foo() { + babelHelpers.classCallCheck(this, _Foo); + }; - babelHelpers.createClass(Foo, babelHelpers.defineProperty({ + babelHelpers.createClass(_Foo, babelHelpers.defineProperty({ bar: { get: function () { return babelHelpers.defineProperty(this, "bar", complex()).bar; @@ -16,7 +16,7 @@ var Foo = (function () { return babelHelpers.defineProperty(this, bar, complex())[bar]; } })); - return Foo; + return _Foo; })(); var foo = Object.defineProperties({}, babelHelpers.defineProperty({ diff --git a/test/fixtures/transformation/runtime/aliased-constructors/expected.js b/test/fixtures/transformation/runtime/aliased-constructors/expected.js index 71a45ff0b9..afdbedbdd2 100644 --- a/test/fixtures/transformation/runtime/aliased-constructors/expected.js +++ b/test/fixtures/transformation/runtime/aliased-constructors/expected.js @@ -8,4 +8,4 @@ obj.constructor === _core.Promise; _core.Symbol(); _core.Symbol("test"); -new _core.Map(); +new _core.Map(); \ No newline at end of file diff --git a/test/fixtures/transformation/runtime/full/expected.js b/test/fixtures/transformation/runtime/full/expected.js index 76c62631aa..4c824766ad 100644 --- a/test/fixtures/transformation/runtime/full/expected.js +++ b/test/fixtures/transformation/runtime/full/expected.js @@ -31,4 +31,4 @@ var bar = _babelHelpers.interopRequireWildcard(_someModule); var myWord = exports.myWord = _core.Symbol("abc"); Object.defineProperty(exports, "__esModule", { value: true -}); +}); \ No newline at end of file diff --git a/test/fixtures/transformation/runtime/modules-common/expected.js b/test/fixtures/transformation/runtime/modules-common/expected.js index 3554ee2668..9f58721474 100644 --- a/test/fixtures/transformation/runtime/modules-common/expected.js +++ b/test/fixtures/transformation/runtime/modules-common/expected.js @@ -2,4 +2,4 @@ var _babelHelpers = require("babel-runtime/helpers")["default"]; -var foo = _babelHelpers.interopRequire(require("foo")); +var foo = _babelHelpers.interopRequire(require("foo")); \ No newline at end of file diff --git a/test/fixtures/transformation/runtime/regenerator-runtime/expected.js b/test/fixtures/transformation/runtime/regenerator-runtime/expected.js index e9871b174e..5890b53946 100644 --- a/test/fixtures/transformation/runtime/regenerator-runtime/expected.js +++ b/test/fixtures/transformation/runtime/regenerator-runtime/expected.js @@ -10,4 +10,4 @@ void _regeneratorRuntime.mark(function callee$0$0() { return context$1$0.stop(); } }, callee$0$0, this); -}); +}); \ No newline at end of file diff --git a/test/fixtures/transformation/runtime/symbol-iterator-in/expected.js b/test/fixtures/transformation/runtime/symbol-iterator-in/expected.js index c533610e7f..2872c66a20 100644 --- a/test/fixtures/transformation/runtime/symbol-iterator-in/expected.js +++ b/test/fixtures/transformation/runtime/symbol-iterator-in/expected.js @@ -2,4 +2,4 @@ var _core = require("babel-runtime/core-js")["default"]; -_core.$for.isIterable(Object(arr)); +_core.$for.isIterable(Object(arr)); \ No newline at end of file diff --git a/test/fixtures/transformation/source-maps/class/expected.js b/test/fixtures/transformation/source-maps/class/expected.js index 8b485be2b3..df70731a43 100644 --- a/test/fixtures/transformation/source-maps/class/expected.js +++ b/test/fixtures/transformation/source-maps/class/expected.js @@ -5,11 +5,11 @@ var _createClass = (function () { function defineProperties(target, props) { for 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); - } + var _Test = function Test() { + _classCallCheck(this, _Test); + }; - _createClass(Test, { + _createClass(_Test, { bar: { get: function () { throw new Error("wow"); @@ -17,7 +17,7 @@ var Test = (function () { } }); - return Test; + return _Test; })(); var test = new Test(); diff --git a/test/fixtures/transformation/spec-proto-to-assign/class/expected.js b/test/fixtures/transformation/spec-proto-to-assign/class/expected.js index 8043b14352..6f3fda0625 100644 --- a/test/fixtures/transformation/spec-proto-to-assign/class/expected.js +++ b/test/fixtures/transformation/spec-proto-to-assign/class/expected.js @@ -6,16 +6,16 @@ var _inherits = function (subClass, superClass) { if (typeof superClass !== "fun var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; -var Foo = (function (Bar) { - function Foo() { - _classCallCheck(this, Foo); +var Foo = (function (_Bar) { + var _Foo = function Foo() { + _classCallCheck(this, _Foo); - if (Bar != null) { - Bar.apply(this, arguments); + if (_Bar != null) { + _Bar.apply(this, arguments); } - } + }; - _inherits(Foo, Bar); + _inherits(_Foo, _Bar); - return Foo; + return _Foo; })(Bar); \ No newline at end of file