Pass the correct this to JSX's __self with the old plugin (#11290)
This commit is contained in:
parent
11292a3c74
commit
2e6f9583ca
@ -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} />;
|
||||
});
|
||||
}
|
||||
@ -1,22 +0,0 @@
|
||||
const actual = transform(
|
||||
'<Foo bar="baz" />',
|
||||
Object.assign({}, opts, { filename: 'C:\\fake\\path\\mock.js' })
|
||||
).code;
|
||||
|
||||
const expected = multiline([
|
||||
'var _jsxFileName = "C:\\\\fake\\\\path\\\\mock.js";',
|
||||
'',
|
||||
'/*#__PURE__*/',
|
||||
'React.createElement(Foo, {',
|
||||
' bar: "baz",',
|
||||
' __source: {',
|
||||
' fileName: _jsxFileName,',
|
||||
' lineNumber: 1,',
|
||||
' columnNumber: 1',
|
||||
' },',
|
||||
' __self: this',
|
||||
'});',
|
||||
]);
|
||||
|
||||
|
||||
expect(actual).toBe(expected);
|
||||
1
packages/babel-preset-react/test/fixtures/preset-options/development-windows/input.js
vendored
Normal file
1
packages/babel-preset-react/test/fixtures/preset-options/development-windows/input.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
<Foo bar="baz" />;
|
||||
12
packages/babel-preset-react/test/fixtures/preset-options/development-windows/output.js
vendored
Normal file
12
packages/babel-preset-react/test/fixtures/preset-options/development-windows/output.js
vendored
Normal file
@ -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
|
||||
}
|
||||
});
|
||||
@ -1,22 +0,0 @@
|
||||
const actual = transform(
|
||||
'<Foo bar="baz" />',
|
||||
Object.assign({}, opts, { filename: '/fake/path/mock.js' })
|
||||
).code;
|
||||
|
||||
const expected = multiline([
|
||||
'var _jsxFileName = "/fake/path/mock.js";',
|
||||
'',
|
||||
'/*#__PURE__*/',
|
||||
'React.createElement(Foo, {',
|
||||
' bar: "baz",',
|
||||
' __source: {',
|
||||
' fileName: _jsxFileName,',
|
||||
' lineNumber: 1,',
|
||||
' columnNumber: 1',
|
||||
' },',
|
||||
' __self: this',
|
||||
'});',
|
||||
]);
|
||||
|
||||
|
||||
expect(actual).toBe(expected);
|
||||
1
packages/babel-preset-react/test/fixtures/preset-options/development/input.js
vendored
Normal file
1
packages/babel-preset-react/test/fixtures/preset-options/development/input.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
<Foo bar="baz" />;
|
||||
12
packages/babel-preset-react/test/fixtures/preset-options/development/output.js
vendored
Normal file
12
packages/babel-preset-react/test/fixtures/preset-options/development/output.js
vendored
Normal file
@ -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
|
||||
}
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user