Skip to content

Commit

Permalink
Pass the correct this to JSX's __self with the old plugin (#11290)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Mar 19, 2020
1 parent 11292a3 commit 2e6f958
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 45 deletions.
6 changes: 5 additions & 1 deletion packages/babel-plugin-transform-react-jsx-self/src/index.js
Expand Up @@ -30,6 +30,10 @@ export default declare(api => {

return {
name: "transform-react-jsx-self",
visitor,
visitor: {
Program(path) {
path.traverse(visitor);
},
},
};
});
@@ -0,0 +1,7 @@
<div />;
() => <div />;

function fn() {
<div />;
() => <div />;
}
@@ -0,0 +1,3 @@
{
"plugins": ["syntax-jsx", "transform-react-jsx-self", "transform-arrow-functions"]
}
@@ -0,0 +1,17 @@
var _this = this;

<div __self={this} />;

(function () {
return <div __self={_this} />;
});

function fn() {
var _this2 = this;

<div __self={this} />;

(function () {
return <div __self={_this2} />;
});
}

This file was deleted.

@@ -0,0 +1 @@
<Foo bar="baz" />;
@@ -0,0 +1,12 @@
var _jsxFileName = "C:\\Users\\travis\\build\\babel\\babel\\packages\\babel-preset-react\\test\\fixtures\\preset-options\\development-windows\\input.js";

/*#__PURE__*/
React.createElement(Foo, {
bar: "baz",
__self: this,
__source: {
fileName: _jsxFileName,
lineNumber: 1,
columnNumber: 1
}
});

This file was deleted.

@@ -0,0 +1 @@
<Foo bar="baz" />;
@@ -0,0 +1,12 @@
var _jsxFileName = "<CWD>/packages/babel-preset-react/test/fixtures/preset-options/development/input.js";

/*#__PURE__*/
React.createElement(Foo, {
bar: "baz",
__self: this,
__source: {
fileName: _jsxFileName,
lineNumber: 1,
columnNumber: 1
}
});

0 comments on commit 2e6f958

Please sign in to comment.