Skip to content

Commit

Permalink
fix: no longer crash when used with transform-es2015-classes
Browse files Browse the repository at this point in the history
  • Loading branch information
motiz88 committed Sep 21, 2016
1 parent 71c591c commit b15759d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"babel-plugin-syntax-jsx": "^6.13.0",
"babel-plugin-transform-async-to-generator": "^6.8.0",
"babel-plugin-transform-class-properties": "^6.11.5",
"babel-plugin-transform-es2015-classes": "^6.14.0",
"babel-plugin-transform-flow-strip-types": "^6.14.0",
"babel-preset-es2015-node4": "^2.1.0",
"babel-preset-react": "^6.11.1",
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export default function ({types: t, template}: {types: BabelTypes, template: Bab
}
if (path.node.id) {
const binding = path.scope.getBinding(path.node.id.name);
if (!binding) return;
const isUnsafeUse = usePath => {
if (usePath.parent.type !== 'MemberExpression') return false;
if (usePath.key !== 'object') return false;
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/regression-classes-unbound-name/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Clazz {
unbound () {}
}
26 changes: 26 additions & 0 deletions test/fixtures/regression-classes-unbound-name/expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var _createClass = function () { var defineProperties = _defineProperties; return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var _defineProperties = function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
};

let Clazz = function () {
function Clazz() {
_classCallCheck(this, Clazz);
}

_createClass(Clazz, [{
key: "unbound",
value: function unbound() {}
}]);

return Clazz;
}();
3 changes: 3 additions & 0 deletions test/fixtures/regression-classes-unbound-name/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["transform-es2015-classes"]
}

0 comments on commit b15759d

Please sign in to comment.