Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix PathHoister hoisting JSX member expressions on "this".
The PathHoister ignored member references on "this", causing it to potentially hoist an expression above its function scope. This patch tells the hoister to watch for "this", and if seen, mark the nearest non-arrow function scope as the upper limit for hoistng. This fixes #4397 and is an alternative to #4787.
- Loading branch information
Showing
9 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
...ct-constant-elements/test/fixtures/constant-elements/member-expression-constant/actual.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
function render() { | ||
this.component = "div"; | ||
return () => <this.component />; | ||
} |
7 changes: 7 additions & 0 deletions
7
...-constant-elements/test/fixtures/constant-elements/member-expression-constant/expected.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
function render() { | ||
this.component = "div"; | ||
|
||
var _ref = <this.component />; | ||
|
||
return () => _ref; | ||
} |
5 changes: 5 additions & 0 deletions
5
...-react-constant-elements/test/fixtures/constant-elements/member-expression-this/actual.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Component extends React.Component { | ||
subComponent = () => <span>Sub Component</span> | ||
|
||
render = () => <this.subComponent /> | ||
} |
12 changes: 12 additions & 0 deletions
12
...eact-constant-elements/test/fixtures/constant-elements/member-expression-this/expected.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
var _ref = <span>Sub Component</span>; | ||
|
||
class Component extends React.Component { | ||
constructor(...args) { | ||
var _temp; | ||
|
||
var _ref2 = <this.subComponent />; | ||
|
||
return _temp = super(...args), this.subComponent = () => _ref, this.render = () => _ref2, _temp; | ||
} | ||
|
||
} |
3 changes: 3 additions & 0 deletions
3
...act-constant-elements/test/fixtures/constant-elements/member-expression-this/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"plugins": ["syntax-jsx", "transform-react-constant-elements", "transform-class-properties"] | ||
} |
6 changes: 6 additions & 0 deletions
6
...sform-react-constant-elements/test/fixtures/constant-elements/member-expression/actual.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const els = { | ||
subComponent: () => <span>Sub Component</span> | ||
}; | ||
class Component extends React.Component { | ||
render = () => <els.subComponent /> | ||
} |
16 changes: 16 additions & 0 deletions
16
...orm-react-constant-elements/test/fixtures/constant-elements/member-expression/expected.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
var _ref = <span>Sub Component</span>; | ||
|
||
const els = { | ||
subComponent: () => _ref | ||
}; | ||
|
||
var _ref2 = <els.subComponent />; | ||
|
||
class Component extends React.Component { | ||
constructor(...args) { | ||
var _temp; | ||
|
||
return _temp = super(...args), this.render = () => _ref2, _temp; | ||
} | ||
|
||
} |
3 changes: 3 additions & 0 deletions
3
...rm-react-constant-elements/test/fixtures/constant-elements/member-expression/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"plugins": ["syntax-jsx", "transform-react-constant-elements", "transform-class-properties"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters