Class properties: Add path.ensureBlock for ArrowFunctionExpression (#3486)

* Class properties: Add path.ensureBlock for ArrowFunctionExpression

* Class properties: Add test case for non-block arrow function
This commit is contained in:
Jhen-Jie Hong 2016-05-14 05:45:15 +08:00 committed by Henry Zhu
parent 109d99bb5e
commit 2d7fb9af41
3 changed files with 41 additions and 0 deletions

View File

@ -145,6 +145,16 @@ export default function ({ types: t }) {
}
path.insertAfter(nodes);
},
ArrowFunctionExpression(path) {
let classExp = path.get("body");
if (!classExp.isClassExpression()) return;
let body = classExp.get("body");
let members = body.get("body");
if (members.some((member) => member.isClassProperty())) {
path.ensureBlock();
}
}
}
};

View File

@ -0,0 +1,11 @@
export default param =>
class App {
static props = {
prop1: 'prop1',
prop2: 'prop2'
}
getParam() {
return param;
}
}

View File

@ -0,0 +1,20 @@
export default (param => {
var _class, _temp;
return _temp = _class = function () {
function App() {
babelHelpers.classCallCheck(this, App);
}
babelHelpers.createClass(App, [{
key: 'getParam',
value: function getParam() {
return param;
}
}]);
return App;
}(), _class.props = {
prop1: 'prop1',
prop2: 'prop2'
}, _temp;
})