diff --git a/README.md b/README.md index 8717bf4c41..f2017d87a5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@

- babel + babel

diff --git a/packages/babel-cli/src/_babel-node b/packages/babel-cli/src/_babel-node index c7e9596416..07d935d88f 100644 --- a/packages/babel-cli/src/_babel-node +++ b/packages/babel-cli/src/_babel-node @@ -18,9 +18,9 @@ program.option("-p, --print [code]", "Evaluate script and print result"); program.option("-i, --ignore [regex]", "Ignore all files that match this regex when using the require hook"); program.option("-x, --extensions [extensions]", "List of extensions to hook into [.es6,.js,.es,.jsx]"); program.option("-r, --stage [stage]", "Enable support for specific ECMAScript stages"); -program.option("-w, --whitelist [whitelist]", "Whitelist of transformers to ONLY use", util.list); -program.option("-b, --blacklist [blacklist]", "Blacklist of transformers to NOT use", util.list); -program.option("-o, --optional [optional]", "List of optional transformers to enable", util.list); +program.option("-w, --whitelist [whitelist]", "Whitelist of transformers separated by comma to ONLY use", util.list); +program.option("-b, --blacklist [blacklist]", "Blacklist of transformers separated by comma to NOT use", util.list); +program.option("-o, --optional [optional]", "List of optional transformers separated by comma to enable", util.list); var pkg = require("../package.json"); program.version(pkg.version); diff --git a/packages/babel/src/generation/generators/modules.js b/packages/babel/src/generation/generators/modules.js index 27578e9dd3..998eaa0c8d 100644 --- a/packages/babel/src/generation/generators/modules.js +++ b/packages/babel/src/generation/generators/modules.js @@ -90,8 +90,8 @@ function ExportDeclaration(node, print) { export function ImportDeclaration(node, print) { this.push("import "); - if (node.isType) { - this.push("type "); + if (node.importKind === "type" || node.importKind === "typeof") { + this.push(node.importKind + " "); } var specfiers = node.specifiers; diff --git a/packages/babel/src/transformation/transformers/es6/classes/vanilla.js b/packages/babel/src/transformation/transformers/es6/classes/vanilla.js index db0845a05f..b4fe2675ed 100644 --- a/packages/babel/src/transformation/transformers/es6/classes/vanilla.js +++ b/packages/babel/src/transformation/transformers/es6/classes/vanilla.js @@ -592,8 +592,10 @@ export default class ClassTransformer { pushInherits() { if (!this.isDerived || this.pushedInherits) return; + // Unshift to ensure that the constructor inheritance is set up before + // any properties can be assigned to the prototype. this.pushedInherits = true; - this.body.push(t.expressionStatement(t.callExpression( + this.body.unshift(t.expressionStatement(t.callExpression( this.file.addHelper("inherits"), [this.classRef, this.superName] ))); diff --git a/packages/babel/src/transformation/transformers/es6/modules.js b/packages/babel/src/transformation/transformers/es6/modules.js index ba653750fb..5959ef1b81 100644 --- a/packages/babel/src/transformation/transformers/es6/modules.js +++ b/packages/babel/src/transformation/transformers/es6/modules.js @@ -15,7 +15,7 @@ export var metadata = { export var visitor = { ImportDeclaration(node, parent, scope, file) { // flow type - if (node.isType) return; + if (node.importKind === "type" || node.importKind === "typeof") return; var nodes = []; diff --git a/packages/babel/src/transformation/transformers/other/flow.js b/packages/babel/src/transformation/transformers/other/flow.js index bb7184576f..d8806dfecf 100644 --- a/packages/babel/src/transformation/transformers/other/flow.js +++ b/packages/babel/src/transformation/transformers/other/flow.js @@ -41,7 +41,7 @@ export var visitor = { }, ImportDeclaration(node) { - if (node.isType) this.dangerouslyRemove(); + if (node.importKind === "type" || node.importKind === "typeof") this.dangerouslyRemove(); }, ExportDeclaration() { diff --git a/packages/babel/test/fixtures/transformation/es6.classes-loose/accessing-super-class/expected.js b/packages/babel/test/fixtures/transformation/es6.classes-loose/accessing-super-class/expected.js index 0001aaf002..f46e74a4b1 100644 --- a/packages/babel/test/fixtures/transformation/es6.classes-loose/accessing-super-class/expected.js +++ b/packages/babel/test/fixtures/transformation/es6.classes-loose/accessing-super-class/expected.js @@ -1,6 +1,8 @@ "use strict"; var Test = (function (_Foo) { + babelHelpers.inherits(Test, _Foo); + function Test() { var _Foo$prototype$test, _Foo$prototype$test2; @@ -17,8 +19,6 @@ var Test = (function (_Foo) { (_Foo$prototype$test2 = _Foo.prototype.test).call.apply(_Foo$prototype$test2, [this, "test"].concat(babelHelpers.slice.call(arguments))); } - babelHelpers.inherits(Test, _Foo); - Test.prototype.test = function test() { var _Foo$prototype$test3, _Foo$prototype$test4; diff --git a/packages/babel/test/fixtures/transformation/es6.classes-loose/accessing-super-properties/expected.js b/packages/babel/test/fixtures/transformation/es6.classes-loose/accessing-super-properties/expected.js index 009804c65e..d35e8b20ae 100644 --- a/packages/babel/test/fixtures/transformation/es6.classes-loose/accessing-super-properties/expected.js +++ b/packages/babel/test/fixtures/transformation/es6.classes-loose/accessing-super-properties/expected.js @@ -1,6 +1,8 @@ "use strict"; var Test = (function (_Foo) { + babelHelpers.inherits(Test, _Foo); + function Test() { babelHelpers.classCallCheck(this, Test); @@ -9,6 +11,5 @@ var Test = (function (_Foo) { _Foo.prototype.test.whatever; } - babelHelpers.inherits(Test, _Foo); return Test; -})(Foo); \ No newline at end of file +})(Foo); diff --git a/packages/babel/test/fixtures/transformation/es6.classes-loose/calling-super-properties/expected.js b/packages/babel/test/fixtures/transformation/es6.classes-loose/calling-super-properties/expected.js index ad9b87b712..522bd45ff1 100644 --- a/packages/babel/test/fixtures/transformation/es6.classes-loose/calling-super-properties/expected.js +++ b/packages/babel/test/fixtures/transformation/es6.classes-loose/calling-super-properties/expected.js @@ -1,6 +1,8 @@ "use strict"; var Test = (function (_Foo) { + babelHelpers.inherits(Test, _Foo); + function Test() { babelHelpers.classCallCheck(this, Test); @@ -9,11 +11,9 @@ var Test = (function (_Foo) { _Foo.prototype.test.call(this); } - babelHelpers.inherits(Test, _Foo); - Test.test = function test() { return _Foo.wow.call(this); }; return Test; -})(Foo); \ No newline at end of file +})(Foo); diff --git a/packages/babel/test/fixtures/transformation/es6.classes-loose/super-class-id-member-expression/expected.js b/packages/babel/test/fixtures/transformation/es6.classes-loose/super-class-id-member-expression/expected.js index 14f00f622a..ab9eedf6df 100644 --- a/packages/babel/test/fixtures/transformation/es6.classes-loose/super-class-id-member-expression/expected.js +++ b/packages/babel/test/fixtures/transformation/es6.classes-loose/super-class-id-member-expression/expected.js @@ -1,23 +1,25 @@ "use strict"; var BaseController = (function (_Chaplin$Controller) { + babelHelpers.inherits(BaseController, _Chaplin$Controller); + function BaseController() { babelHelpers.classCallCheck(this, BaseController); _Chaplin$Controller.apply(this, arguments); } - babelHelpers.inherits(BaseController, _Chaplin$Controller); return BaseController; })(Chaplin.Controller); var BaseController2 = (function (_Chaplin$Controller$Another) { + babelHelpers.inherits(BaseController2, _Chaplin$Controller$Another); + function BaseController2() { babelHelpers.classCallCheck(this, BaseController2); _Chaplin$Controller$Another.apply(this, arguments); } - babelHelpers.inherits(BaseController2, _Chaplin$Controller$Another); return BaseController2; })(Chaplin.Controller.Another); diff --git a/packages/babel/test/fixtures/transformation/es6.classes-loose/super-class/expected.js b/packages/babel/test/fixtures/transformation/es6.classes-loose/super-class/expected.js index 161d930afe..a1b0761440 100644 --- a/packages/babel/test/fixtures/transformation/es6.classes-loose/super-class/expected.js +++ b/packages/babel/test/fixtures/transformation/es6.classes-loose/super-class/expected.js @@ -1,12 +1,13 @@ "use strict"; var Test = (function (_Foo) { + babelHelpers.inherits(Test, _Foo); + function Test() { babelHelpers.classCallCheck(this, Test); _Foo.apply(this, arguments); } - babelHelpers.inherits(Test, _Foo); return Test; })(Foo); diff --git a/packages/babel/test/fixtures/transformation/es6.classes/accessing-super-class/expected.js b/packages/babel/test/fixtures/transformation/es6.classes/accessing-super-class/expected.js index 42672ea451..80e467ff26 100644 --- a/packages/babel/test/fixtures/transformation/es6.classes/accessing-super-class/expected.js +++ b/packages/babel/test/fixtures/transformation/es6.classes/accessing-super-class/expected.js @@ -1,6 +1,8 @@ "use strict"; var Test = (function (_Foo) { + babelHelpers.inherits(Test, _Foo); + function Test() { var _babelHelpers$get, _babelHelpers$get2; @@ -17,7 +19,6 @@ var Test = (function (_Foo) { (_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, [{ key: "test", value: function test() { @@ -38,4 +39,4 @@ var Test = (function (_Foo) { } }]); return Test; -})(Foo); \ No newline at end of file +})(Foo); diff --git a/packages/babel/test/fixtures/transformation/es6.classes/accessing-super-properties/expected.js b/packages/babel/test/fixtures/transformation/es6.classes/accessing-super-properties/expected.js index 9ab2af0f38..5eb06810f8 100644 --- a/packages/babel/test/fixtures/transformation/es6.classes/accessing-super-properties/expected.js +++ b/packages/babel/test/fixtures/transformation/es6.classes/accessing-super-properties/expected.js @@ -1,6 +1,8 @@ "use strict"; var Test = (function (_Foo) { + babelHelpers.inherits(Test, _Foo); + function Test() { babelHelpers.classCallCheck(this, Test); @@ -9,6 +11,5 @@ var Test = (function (_Foo) { babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", this).whatever; } - babelHelpers.inherits(Test, _Foo); return Test; -})(Foo); \ No newline at end of file +})(Foo); diff --git a/packages/babel/test/fixtures/transformation/es6.classes/calling-super-properties/expected.js b/packages/babel/test/fixtures/transformation/es6.classes/calling-super-properties/expected.js index bd6aedcc2a..2171f302f5 100644 --- a/packages/babel/test/fixtures/transformation/es6.classes/calling-super-properties/expected.js +++ b/packages/babel/test/fixtures/transformation/es6.classes/calling-super-properties/expected.js @@ -1,6 +1,8 @@ "use strict"; var Test = (function (_Foo) { + babelHelpers.inherits(Test, _Foo); + function Test() { babelHelpers.classCallCheck(this, Test); @@ -9,7 +11,6 @@ var Test = (function (_Foo) { babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", this).call(this); } - babelHelpers.inherits(Test, _Foo); babelHelpers.createClass(Test, null, [{ key: "test", value: function test() { diff --git a/packages/babel/test/fixtures/transformation/es6.classes/constructor/expected.js b/packages/babel/test/fixtures/transformation/es6.classes/constructor/expected.js index 9aefa96a1c..5fa33a7d94 100644 --- a/packages/babel/test/fixtures/transformation/es6.classes/constructor/expected.js +++ b/packages/babel/test/fixtures/transformation/es6.classes/constructor/expected.js @@ -7,6 +7,8 @@ var Test = function Test() { }; var Foo = (function (_Bar) { + babelHelpers.inherits(Foo, _Bar); + function Foo() { babelHelpers.classCallCheck(this, Foo); @@ -14,7 +16,6 @@ var Foo = (function (_Bar) { this.state = "test"; } - babelHelpers.inherits(Foo, _Bar); return Foo; })(Bar); diff --git a/packages/babel/test/fixtures/transformation/es6.classes/delay-arrow-function-for-bare-super-derived/expected.js b/packages/babel/test/fixtures/transformation/es6.classes/delay-arrow-function-for-bare-super-derived/expected.js index 4140da0602..93be66feef 100644 --- a/packages/babel/test/fixtures/transformation/es6.classes/delay-arrow-function-for-bare-super-derived/expected.js +++ b/packages/babel/test/fixtures/transformation/es6.classes/delay-arrow-function-for-bare-super-derived/expected.js @@ -1,6 +1,8 @@ "use strict"; var Foo = (function (_Bar) { + babelHelpers.inherits(Foo, _Bar); + function Foo() { babelHelpers.classCallCheck(this, Foo); @@ -11,6 +13,5 @@ var Foo = (function (_Bar) { var _this = this; } - babelHelpers.inherits(Foo, _Bar); return Foo; })(Bar); diff --git a/packages/babel/test/fixtures/transformation/es6.classes/derived-constructor-must-call-super/expected.js b/packages/babel/test/fixtures/transformation/es6.classes/derived-constructor-must-call-super/expected.js index af80e3bb86..b62f83e720 100644 --- a/packages/babel/test/fixtures/transformation/es6.classes/derived-constructor-must-call-super/expected.js +++ b/packages/babel/test/fixtures/transformation/es6.classes/derived-constructor-must-call-super/expected.js @@ -1,10 +1,11 @@ "use strict"; var Foo = (function (_Bar) { + babelHelpers.inherits(Foo, _Bar); + function Foo() { babelHelpers.classCallCheck(this, Foo); } - babelHelpers.inherits(Foo, _Bar); return Foo; -})(Bar); \ No newline at end of file +})(Bar); diff --git a/packages/babel/test/fixtures/transformation/es6.classes/super-class-anonymous/expected.js b/packages/babel/test/fixtures/transformation/es6.classes/super-class-anonymous/expected.js index cc74cfb896..7942481077 100644 --- a/packages/babel/test/fixtures/transformation/es6.classes/super-class-anonymous/expected.js +++ b/packages/babel/test/fixtures/transformation/es6.classes/super-class-anonymous/expected.js @@ -1,12 +1,13 @@ "use strict"; var TestEmpty = (function (_ref) { + babelHelpers.inherits(TestEmpty, _ref); + function TestEmpty() { babelHelpers.classCallCheck(this, TestEmpty); babelHelpers.get(Object.getPrototypeOf(TestEmpty.prototype), "constructor", this).apply(this, arguments); } - babelHelpers.inherits(TestEmpty, _ref); return TestEmpty; })((function () { function _class() { @@ -17,12 +18,13 @@ var TestEmpty = (function (_ref) { })()); var TestConstructorOnly = (function (_ref2) { + babelHelpers.inherits(TestConstructorOnly, _ref2); + function TestConstructorOnly() { babelHelpers.classCallCheck(this, TestConstructorOnly); babelHelpers.get(Object.getPrototypeOf(TestConstructorOnly.prototype), "constructor", this).apply(this, arguments); } - babelHelpers.inherits(TestConstructorOnly, _ref2); return TestConstructorOnly; })((function () { function _class2() { @@ -33,12 +35,13 @@ var TestConstructorOnly = (function (_ref2) { })()); var TestMethodOnly = (function (_ref3) { + babelHelpers.inherits(TestMethodOnly, _ref3); + function TestMethodOnly() { babelHelpers.classCallCheck(this, TestMethodOnly); babelHelpers.get(Object.getPrototypeOf(TestMethodOnly.prototype), "constructor", this).apply(this, arguments); } - babelHelpers.inherits(TestMethodOnly, _ref3); return TestMethodOnly; })((function () { function _class3() { @@ -53,12 +56,13 @@ var TestMethodOnly = (function (_ref3) { })()); var TestConstructorAndMethod = (function (_ref4) { + babelHelpers.inherits(TestConstructorAndMethod, _ref4); + function TestConstructorAndMethod() { babelHelpers.classCallCheck(this, TestConstructorAndMethod); babelHelpers.get(Object.getPrototypeOf(TestConstructorAndMethod.prototype), "constructor", this).apply(this, arguments); } - babelHelpers.inherits(TestConstructorAndMethod, _ref4); return TestConstructorAndMethod; })((function () { function _class4() { @@ -73,12 +77,13 @@ var TestConstructorAndMethod = (function (_ref4) { })()); var TestMultipleMethods = (function (_ref5) { + babelHelpers.inherits(TestMultipleMethods, _ref5); + function TestMultipleMethods() { babelHelpers.classCallCheck(this, TestMultipleMethods); babelHelpers.get(Object.getPrototypeOf(TestMultipleMethods.prototype), "constructor", this).apply(this, arguments); } - babelHelpers.inherits(TestMultipleMethods, _ref5); return TestMultipleMethods; })((function () { function _class5() { @@ -93,4 +98,4 @@ var TestMultipleMethods = (function (_ref5) { value: function m2() {} }]); return _class5; -})()); \ No newline at end of file +})()); diff --git a/packages/babel/test/fixtures/transformation/es6.classes/super-class-id-member-expression/expected.js b/packages/babel/test/fixtures/transformation/es6.classes/super-class-id-member-expression/expected.js index 3aadfc32b9..6394f2df5f 100644 --- a/packages/babel/test/fixtures/transformation/es6.classes/super-class-id-member-expression/expected.js +++ b/packages/babel/test/fixtures/transformation/es6.classes/super-class-id-member-expression/expected.js @@ -1,21 +1,23 @@ "use strict"; var BaseController = (function (_Chaplin$Controller) { + babelHelpers.inherits(BaseController, _Chaplin$Controller); + function BaseController() { babelHelpers.classCallCheck(this, BaseController); babelHelpers.get(Object.getPrototypeOf(BaseController.prototype), "constructor", this).apply(this, arguments); } - babelHelpers.inherits(BaseController, _Chaplin$Controller); return BaseController; })(Chaplin.Controller); var BaseController2 = (function (_Chaplin$Controller$Another) { + babelHelpers.inherits(BaseController2, _Chaplin$Controller$Another); + function BaseController2() { babelHelpers.classCallCheck(this, BaseController2); babelHelpers.get(Object.getPrototypeOf(BaseController2.prototype), "constructor", this).apply(this, arguments); } - babelHelpers.inherits(BaseController2, _Chaplin$Controller$Another); return BaseController2; -})(Chaplin.Controller.Another); \ No newline at end of file +})(Chaplin.Controller.Another); diff --git a/packages/babel/test/fixtures/transformation/es6.classes/super-class/expected.js b/packages/babel/test/fixtures/transformation/es6.classes/super-class/expected.js index 9f13499a4a..3ffa78e87c 100644 --- a/packages/babel/test/fixtures/transformation/es6.classes/super-class/expected.js +++ b/packages/babel/test/fixtures/transformation/es6.classes/super-class/expected.js @@ -1,11 +1,12 @@ "use strict"; var Test = (function (_Foo) { + babelHelpers.inherits(Test, _Foo); + function Test() { babelHelpers.classCallCheck(this, Test); babelHelpers.get(Object.getPrototypeOf(Test.prototype), "constructor", this).apply(this, arguments); } - babelHelpers.inherits(Test, _Foo); return Test; -})(Foo); \ No newline at end of file +})(Foo); diff --git a/packages/babel/test/fixtures/transformation/es6.parameters/rest-nested-iife/expected.js b/packages/babel/test/fixtures/transformation/es6.parameters/rest-nested-iife/expected.js index 509591d150..438a6ffbeb 100644 --- a/packages/babel/test/fixtures/transformation/es6.parameters/rest-nested-iife/expected.js +++ b/packages/babel/test/fixtures/transformation/es6.parameters/rest-nested-iife/expected.js @@ -14,14 +14,14 @@ function broken(x) { if (true) { var _ret = (function () { var Foo = (function (_Bar) { + _inherits(Foo, _Bar); + function Foo() { _classCallCheck(this, Foo); _get(Object.getPrototypeOf(Foo.prototype), "constructor", this).apply(this, arguments); } - _inherits(Foo, _Bar); - return Foo; })(Bar); diff --git a/packages/babel/test/fixtures/transformation/es7.class-properties/derived/expected.js b/packages/babel/test/fixtures/transformation/es7.class-properties/derived/expected.js index 0362065035..221a69fd86 100644 --- a/packages/babel/test/fixtures/transformation/es7.class-properties/derived/expected.js +++ b/packages/babel/test/fixtures/transformation/es7.class-properties/derived/expected.js @@ -1,12 +1,13 @@ "use strict"; var Foo = (function (_Bar) { + babelHelpers.inherits(Foo, _Bar); + function Foo() { babelHelpers.classCallCheck(this, Foo); babelHelpers.get(Object.getPrototypeOf(Foo.prototype), "constructor", this).apply(this, arguments); this.bar = "foo"; } - babelHelpers.inherits(Foo, _Bar); return Foo; -})(Bar); \ No newline at end of file +})(Bar); diff --git a/packages/babel/test/fixtures/transformation/es7.class-properties/super-expression/expected.js b/packages/babel/test/fixtures/transformation/es7.class-properties/super-expression/expected.js index 0dc028074d..d7eb6e3d51 100644 --- a/packages/babel/test/fixtures/transformation/es7.class-properties/super-expression/expected.js +++ b/packages/babel/test/fixtures/transformation/es7.class-properties/super-expression/expected.js @@ -1,6 +1,8 @@ "use strict"; var Foo = (function (_Bar) { + babelHelpers.inherits(Foo, _Bar); + function Foo() { var _temp; @@ -9,6 +11,5 @@ var Foo = (function (_Bar) { foo((_temp = babelHelpers.get(Object.getPrototypeOf(Foo.prototype), "constructor", this).call(this), this.bar = "foo", _temp)); } - babelHelpers.inherits(Foo, _Bar); return Foo; -})(Bar); \ No newline at end of file +})(Bar); diff --git a/packages/babel/test/fixtures/transformation/es7.class-properties/super-statement/expected.js b/packages/babel/test/fixtures/transformation/es7.class-properties/super-statement/expected.js index 17c7c8dfb8..37cf39e659 100644 --- a/packages/babel/test/fixtures/transformation/es7.class-properties/super-statement/expected.js +++ b/packages/babel/test/fixtures/transformation/es7.class-properties/super-statement/expected.js @@ -1,6 +1,8 @@ "use strict"; var Foo = (function (_Bar) { + babelHelpers.inherits(Foo, _Bar); + function Foo() { babelHelpers.classCallCheck(this, Foo); @@ -8,6 +10,5 @@ var Foo = (function (_Bar) { this.bar = "foo"; } - babelHelpers.inherits(Foo, _Bar); return Foo; -})(Bar); \ No newline at end of file +})(Bar); diff --git a/packages/babel/test/fixtures/transformation/es7.decorators/class-super/expected.js b/packages/babel/test/fixtures/transformation/es7.decorators/class-super/expected.js index 4150b8a957..00c54848e8 100644 --- a/packages/babel/test/fixtures/transformation/es7.decorators/class-super/expected.js +++ b/packages/babel/test/fixtures/transformation/es7.decorators/class-super/expected.js @@ -1,27 +1,29 @@ "use strict"; var Foo = (function (_Bar) { + babelHelpers.inherits(Foo, _Bar); + function Foo() { babelHelpers.classCallCheck(this, _Foo); babelHelpers.get(Object.getPrototypeOf(_Foo.prototype), "constructor", this).call(this); } - babelHelpers.inherits(Foo, _Bar); var _Foo = Foo; Foo = bar(Foo) || Foo; return Foo; })(Bar); var Foo2 = (function (_Bar2) { + babelHelpers.inherits(Foo2, _Bar2); + function Foo2() { babelHelpers.classCallCheck(this, _Foo2); babelHelpers.get(Object.getPrototypeOf(_Foo2.prototype), "constructor", this).call(this); } - babelHelpers.inherits(Foo2, _Bar2); var _Foo2 = Foo2; Foo2 = bar(Foo2) || Foo2; return Foo2; -})(Bar); \ No newline at end of file +})(Bar); diff --git a/packages/babel/test/fixtures/transformation/misc/regression-1155/expected.js b/packages/babel/test/fixtures/transformation/misc/regression-1155/expected.js index 9acd4f71a6..6559a17448 100644 --- a/packages/babel/test/fixtures/transformation/misc/regression-1155/expected.js +++ b/packages/babel/test/fixtures/transformation/misc/regression-1155/expected.js @@ -1,6 +1,8 @@ "use strict"; var Foo = (function (_Bar) { + babelHelpers.inherits(Foo, _Bar); + function Foo(options) { babelHelpers.classCallCheck(this, Foo); @@ -11,6 +13,5 @@ var Foo = (function (_Bar) { babelHelpers.get(Object.getPrototypeOf(Foo.prototype), "constructor", this).call(this, parentOptions); } - babelHelpers.inherits(Foo, _Bar); return Foo; })(Bar); diff --git a/packages/babel/test/fixtures/transformation/react/optimisation.react.constant-elements/expected.js b/packages/babel/test/fixtures/transformation/react/optimisation.react.constant-elements/expected.js index 66274bd2b5..32b1dc88bc 100644 --- a/packages/babel/test/fixtures/transformation/react/optimisation.react.constant-elements/expected.js +++ b/packages/babel/test/fixtures/transformation/react/optimisation.react.constant-elements/expected.js @@ -9,12 +9,13 @@ var _ref = React.createElement( ); var App = (function (_React$Component) { + babelHelpers.inherits(App, _React$Component); + function App() { babelHelpers.classCallCheck(this, App); babelHelpers.get(Object.getPrototypeOf(App.prototype), "constructor", this).apply(this, arguments); } - babelHelpers.inherits(App, _React$Component); babelHelpers.createClass(App, [{ key: "render", value: function render() { @@ -36,4 +37,4 @@ var App = (function (_React$Component) { } }]); return App; -})(React.Component); \ No newline at end of file +})(React.Component); diff --git a/packages/babel/test/fixtures/transformation/spec.function-name/modules-3/expected.js b/packages/babel/test/fixtures/transformation/spec.function-name/modules-3/expected.js index 7cd9ac5a1a..9dbe20a4d6 100644 --- a/packages/babel/test/fixtures/transformation/spec.function-name/modules-3/expected.js +++ b/packages/babel/test/fixtures/transformation/spec.function-name/modules-3/expected.js @@ -7,12 +7,13 @@ Object.defineProperty(exports, "__esModule", { var _store = require("./store"); var Login = (function (_React$Component) { + babelHelpers.inherits(Login, _React$Component); + function Login() { babelHelpers.classCallCheck(this, Login); babelHelpers.get(Object.getPrototypeOf(Login.prototype), "constructor", this).apply(this, arguments); } - babelHelpers.inherits(Login, _React$Component); babelHelpers.createClass(Login, [{ key: "getForm", value: function getForm() { @@ -23,4 +24,4 @@ var Login = (function (_React$Component) { })(React.Component); exports["default"] = Login; -module.exports = exports["default"]; \ No newline at end of file +module.exports = exports["default"]; diff --git a/packages/babel/test/fixtures/transformation/spec.proto-to-assign/class/expected.js b/packages/babel/test/fixtures/transformation/spec.proto-to-assign/class/expected.js index 9e179061d5..4e1f073366 100644 --- a/packages/babel/test/fixtures/transformation/spec.proto-to-assign/class/expected.js +++ b/packages/babel/test/fixtures/transformation/spec.proto-to-assign/class/expected.js @@ -1,11 +1,12 @@ "use strict"; var Foo = (function (_Bar) { + babelHelpers.inherits(Foo, _Bar); + function Foo() { babelHelpers.classCallCheck(this, Foo); babelHelpers.get(Object.getPrototypeOf(Foo.prototype), "constructor", this).apply(this, arguments); } - babelHelpers.inherits(Foo, _Bar); return Foo; -})(Bar); \ No newline at end of file +})(Bar); diff --git a/packages/babylon/src/options.js b/packages/babylon/src/options.js index bdbab22040..15460fd28e 100755 --- a/packages/babylon/src/options.js +++ b/packages/babylon/src/options.js @@ -95,11 +95,12 @@ export function getOptions(opts) { options[opt] = opts && has(opts, opt) ? opts[opt] : defaultOptions[opt]; if (Array.isArray(options.onToken)) { - let tokens = options.onToken; - options.onToken = (token) => tokens.push(token); + let tokens = options.onToken + options.onToken = (token) => tokens.push(token) + } + if (Array.isArray(options.onComment)) { + options.onComment = pushComment(options, options.onComment) } - if (Array.isArray(options.onComment)) - options.onComment = pushComment(options, options.onComment); return options; } diff --git a/packages/babylon/src/plugins/flow.js b/packages/babylon/src/plugins/flow.js index 6efb79b961..fdd6713e3c 100644 --- a/packages/babylon/src/plugins/flow.js +++ b/packages/babylon/src/plugins/flow.js @@ -784,19 +784,19 @@ export default function (instance) { instance.extend("parseImportSpecifiers", function (inner) { return function (node) { - node.isType = false; - if (this.isContextual("type")) { - var startPos = this.start, startLoc = this.startLoc; - var typeId = this.parseIdent(); - if ((this.type === tt.name && this.value !== "from") || this.type === tt.braceL || this.type === tt.star) { - node.isType = true; - } else { - node.specifiers.push(this.parseImportSpecifierDefault(typeId, startPos, startLoc)); - if (this.isContextual("from")) return; - this.eat(tt.comma); + node.importKind = "value" + var kind = + (this.type === tt._typeof ? "typeof" : + (this.isContextual("type") ? "type" : null)) + if (kind) { + var lh = this.lookahead() + if ((lh.type === tt.name && lh.value !== "from") || lh.type === tt.braceL || lh.type === tt.star) { + this.next() + node.importKind = kind } } - inner.call(this, node); + + inner.call(this, node) }; }); diff --git a/packages/babylon/test/tests-flow.js b/packages/babylon/test/tests-flow.js index ac0ea347d5..f630e8955e 100644 --- a/packages/babylon/test/tests-flow.js +++ b/packages/babylon/test/tests-flow.js @@ -6728,13 +6728,49 @@ var fbTestFixture = { end: { line: 1, column: 26 } } }, - isType: true, + importKind: 'type', range: [0, 27], loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 27 } } }, + 'import typeof foo from "bar";': { + type: 'ImportDeclaration', + specifiers: [{ + type: 'ImportDefaultSpecifier', + local: { + type: 'Identifier', + name: 'foo', + range: [14, 17], + loc: { + start: { line: 1, column: 14 }, + end: { line: 1, column: 17 } + } + }, + range: [14, 17], + loc: { + start: { line: 1, column: 14 }, + end: { line: 1, column: 17 } + } + }], + source: { + type: 'Literal', + value: 'bar', + raw: '"bar"', + range: [23, 28], + loc: { + start: { line: 1, column: 23 }, + end: { line: 1, column: 28 } + } + }, + importKind: 'typeof', + range: [0, 29], + loc: { + start: { line: 1, column: 0 }, + end: { line: 1, column: 29 } + } + }, 'import type {foo, bar} from "baz";': { type: 'ImportDeclaration', specifiers: [{ @@ -6798,17 +6834,26 @@ var fbTestFixture = { end: { line: 1, column: 33 } } }, - isType: true, + importKind: 'type', range: [0, 34], loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 34 } } }, - 'import type {foo as bar} from "baz";': { + 'import type {foo, bar} from "baz";': { type: 'ImportDeclaration', specifiers: [{ type: 'ImportSpecifier', + local: { + type: 'Identifier', + name: 'foo', + range: [13, 16], + loc: { + start: { line: 1, column: 13 }, + end: { line: 1, column: 16 } + } + }, imported: { type: 'Identifier', name: 'foo', @@ -6818,36 +6863,97 @@ var fbTestFixture = { end: { line: 1, column: 16 } } }, + range: [13, 16], + loc: { + start: { line: 1, column: 13 }, + end: { line: 1, column: 16 } + } + }, { + type: 'ImportSpecifier', local: { type: 'Identifier', name: 'bar', - range: [20, 23], + range: [18, 21], loc: { - start: { line: 1, column: 20 }, - end: { line: 1, column: 23 } + start: { line: 1, column: 18 }, + end: { line: 1, column: 21 } } }, - range: [13, 23], + imported: { + type: 'Identifier', + name: 'bar', + range: [18, 21], + loc: { + start: { line: 1, column: 18 }, + end: { line: 1, column: 21 } + } + }, + range: [18, 21], loc: { - start: { line: 1, column: 13 }, - end: { line: 1, column: 23 } + start: { line: 1, column: 18 }, + end: { line: 1, column: 21 } } }], source: { type: 'Literal', value: 'baz', raw: '"baz"', - range: [30, 35], + range: [28, 33], loc: { - start: { line: 1, column: 30 }, - end: { line: 1, column: 35 } + start: { line: 1, column: 28 }, + end: { line: 1, column: 33 } } }, - isType: true, - range: [0, 36], + importKind: 'type', + range: [0, 34], loc: { start: { line: 1, column: 0 }, - end: { line: 1, column: 36 } + end: { line: 1, column: 34 } + } + }, + 'import typeof {foo as bar} from "baz";': { + type: 'ImportDeclaration', + specifiers: [{ + type: 'ImportSpecifier', + imported: { + type: 'Identifier', + name: 'foo', + range: [15, 18], + loc: { + start: { line: 1, column: 15 }, + end: { line: 1, column: 18 } + } + }, + local: { + type: 'Identifier', + name: 'bar', + range: [22, 25], + loc: { + start: { line: 1, column: 22 }, + end: { line: 1, column: 25 } + } + }, + range: [15, 25], + loc: { + start: { line: 1, column: 15 }, + end: { line: 1, column: 25 } + } + }], + source: { + type: 'Literal', + value: 'baz', + raw: '"baz"', + range: [32, 37], + loc: { + start: { line: 1, column: 32 }, + end: { line: 1, column: 37 } + } + }, + importKind: 'typeof', + range: [0, 38], + loc: { + start: { line: 1, column: 0 }, + end: { line: 1, column: 38 } } }, 'import type from "foo";': { @@ -6879,7 +6985,7 @@ var fbTestFixture = { end: { line: 1, column: 22 } } }, - isType: false, + importKind: 'value', range: [0, 23], loc: { start: { line: 1, column: 0 }, @@ -6940,7 +7046,7 @@ var fbTestFixture = { end: { line: 1, column: 29 } } }, - isType: false, + importKind: 'value', range: [0, 30], loc: { start: { line: 1, column: 0 }, @@ -6976,13 +7082,49 @@ var fbTestFixture = { end: { line: 1, column: 37 } } }, - isType: true, + importKind: 'type', range: [0, 38], loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 38 } } }, + 'import typeof * as namespace from "bar";': { + type: 'ImportDeclaration', + specifiers: [{ + type: 'ImportNamespaceSpecifier', + local: { + type: 'Identifier', + name: 'namespace', + range: [19, 28], + loc: { + start: { line: 1, column: 19 }, + end: { line: 1, column: 28 } + } + }, + range: [14, 28], + loc: { + start: { line: 1, column: 14 }, + end: { line: 1, column: 28 } + } + }], + source: { + type: 'Literal', + value: 'bar', + raw: '"bar"', + range: [34, 39], + loc: { + start: { line: 1, column: 34 }, + end: { line: 1, column: 39 } + } + }, + importKind: 'typeof', + range: [0, 40], + loc: { + start: { line: 1, column: 0 }, + end: { line: 1, column: 40 } + } + }, }, 'Array Types': { 'var a: number[]': { diff --git a/test/core/fixtures/transformation/es6.classes-loose/method-order/actual.js b/test/core/fixtures/transformation/es6.classes-loose/method-order/actual.js new file mode 100644 index 0000000000..1cbc01438c --- /dev/null +++ b/test/core/fixtures/transformation/es6.classes-loose/method-order/actual.js @@ -0,0 +1,11 @@ +class Foo {} + +class Bar extends Foo { + methodA(){} + + constructor(){ + super(); + } + + methodB(){} +} diff --git a/test/core/fixtures/transformation/es6.classes-loose/method-order/expected.js b/test/core/fixtures/transformation/es6.classes-loose/method-order/expected.js new file mode 100644 index 0000000000..f7cd7a462c --- /dev/null +++ b/test/core/fixtures/transformation/es6.classes-loose/method-order/expected.js @@ -0,0 +1,21 @@ +"use strict"; + +var Foo = function Foo() { + babelHelpers.classCallCheck(this, Foo); +}; + +var Bar = (function (_Foo) { + babelHelpers.inherits(Bar, _Foo); + + Bar.prototype.methodA = function methodA() {}; + + function Bar() { + babelHelpers.classCallCheck(this, Bar); + + _Foo.call(this); + } + + Bar.prototype.methodB = function methodB() {}; + + return Bar; +})(Foo);