properly transform XJSIdentifier nodes referencing this into a ThisExpression - facebook/react#2927

This commit is contained in:
Sebastian McKenzie 2015-01-30 11:00:37 +11:00
parent bbbc9c0c5e
commit bf393c025f
3 changed files with 13 additions and 2 deletions

View File

@ -8,8 +8,10 @@
var esutils = require("esutils");
var t = require("../../../types");
exports.JSXIdentifier = function (node) {
if (esutils.keyword.isIdentifierName(node.name)) {
exports.JSXIdentifier = function (node, parent) {
if (node.name === "this" && t.isReferenced(node, parent)) {
return t.thisExpression();
} else if (esutils.keyword.isIdentifierName(node.name)) {
node.type = "Identifier";
} else {
return t.literal(node.name);

View File

@ -0,0 +1,3 @@
var foo = function () {
return () => <this />;
};

View File

@ -0,0 +1,6 @@
var foo = function () {
var _this = this;
return function () {
return React.createElement(_this, null);
};
};