Skip to content

Commit

Permalink
retain method return types on transform-es2015-classes (closes babel#…
Browse files Browse the repository at this point in the history
  • Loading branch information
danharper committed Oct 4, 2016
1 parent fc54264 commit d1f93fc
Show file tree
Hide file tree
Showing 20 changed files with 144 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/babel-helper-define-map/src/index.js
Expand Up @@ -55,6 +55,7 @@ export function push(mutatorMap: Object, node: Object, kind: string, file, scope
value = node.value;
} else if (t.isObjectMethod(node) || t.isClassMethod(node)) {
value = t.functionExpression(null, node.params, node.body, node.generator, node.async);
value.returnType = node.returnType;
}

let inheritedKind = toKind(node);
Expand Down
Expand Up @@ -17,6 +17,7 @@ export default class LooseClassTransformer extends VanillaTransformer {
let methodName = t.memberExpression(classRef, node.key, node.computed || t.isLiteral(node.key));

let func = t.functionExpression(null, node.params, node.body, node.generator, node.async);
func.returnType = node.returnType;
let key = t.toComputedKey(node, node.key);
if (t.isStringLiteral(key)) {
func = nameFunction({
Expand Down
@@ -0,0 +1,6 @@
// @flow
class C {
m(x: number): string {
return 'a';
}
}
@@ -0,0 +1,12 @@
// @flow
var C = function () {
function C() {
babelHelpers.classCallCheck(this, C);
}

C.prototype.m = function m(x: number): string {
return 'a';
};

return C;
}();
@@ -0,0 +1,3 @@
{
"plugins": ["external-helpers", "transform-es2015-function-name", ["transform-es2015-classes", { "loose": true }], "transform-es2015-spread", "transform-es2015-block-scoping", "syntax-flow"]
}
@@ -0,0 +1,6 @@
// @flow
class C {
m(x: number): string {
return 'a';
}
}
@@ -0,0 +1,14 @@
// @flow
var C = function () {
function C() {
babelHelpers.classCallCheck(this, C);
}

babelHelpers.createClass(C, [{
key: 'm',
value: function m(x: number): string {
return 'a';
}
}]);
return C;
}();
@@ -0,0 +1,3 @@
{
"plugins": ["external-helpers", "transform-es2015-function-name", "transform-es2015-classes", "transform-es2015-spread", "transform-es2015-block-scoping", "syntax-flow"]
}
@@ -0,0 +1,6 @@
// @flow
class C {
m(x: number): string {
return 'a';
}
}
@@ -0,0 +1,14 @@
'use strict';

// @flow
var C = function () {
function C() {
babelHelpers.classCallCheck(this, C);
}

C.prototype.m = function m(x /*: number*/) /*: string*/ {
return 'a';
};

return C;
}();
@@ -0,0 +1,4 @@
{
"presets": [["es2015", { "loose": true }]],
"plugins": ["transform-flow-comments", "external-helpers"]
}
@@ -0,0 +1,6 @@
// @flow
class C {
m(x: number): string {
return 'a';
}
}
@@ -0,0 +1,16 @@
'use strict';

// @flow
var C = function () {
function C() {
babelHelpers.classCallCheck(this, C);
}

babelHelpers.createClass(C, [{
key: 'm',
value: function m(x /*: number*/) /*: string*/ {
return 'a';
}
}]);
return C;
}();
@@ -0,0 +1,4 @@
{
"presets": ["es2015"],
"plugins": ["transform-flow-comments", "external-helpers"]
}
@@ -0,0 +1,6 @@
// @flow
class C {
m(x: number): string {
return 'a';
}
}
@@ -0,0 +1,13 @@
'use strict';

var C = function () {
function C() {
babelHelpers.classCallCheck(this, C);
}

C.prototype.m = function m(x) {
return 'a';
};

return C;
}();
@@ -0,0 +1,4 @@
{
"presets": [["es2015", { "loose": true }]],
"plugins": ["transform-flow-strip-types", "external-helpers"]
}
@@ -0,0 +1,6 @@
// @flow
class C {
m(x: number): string {
return 'a';
}
}
@@ -0,0 +1,15 @@
'use strict';

var C = function () {
function C() {
babelHelpers.classCallCheck(this, C);
}

babelHelpers.createClass(C, [{
key: 'm',
value: function m(x) {
return 'a';
}
}]);
return C;
}();
@@ -0,0 +1,4 @@
{
"presets": ["es2015"],
"plugins": ["transform-flow-strip-types", "external-helpers"]
}

0 comments on commit d1f93fc

Please sign in to comment.