Fix PathHoister error attaching after export declarations.

Fixes #5369.

See also 4ee385e96c/packages/babel-plugin-transform-class-properties/src/index.js (L167)
This commit is contained in:
Samuel Reed 2017-03-03 16:56:42 -06:00 committed by Logan Smyth
parent 60adcd68a0
commit 3570ba7c28
7 changed files with 50 additions and 0 deletions

View File

@ -0,0 +1,7 @@
class A {
render() {
return <B />
}
}
export default class B {}

View File

@ -0,0 +1,9 @@
class A {
render() {
return _ref;
}
}
export default class B {}
var _ref = React.createElement(B, null);

View File

@ -0,0 +1,6 @@
{
"plugins": [
"transform-react-jsx",
"transform-react-constant-elements"
]
}

View File

@ -0,0 +1,7 @@
class A {
render() {
return <B />
}
}
export class B {}

View File

@ -0,0 +1,9 @@
class A {
render() {
return _ref;
}
}
export class B {}
var _ref = React.createElement(B, null);

View File

@ -0,0 +1,6 @@
{
"plugins": [
"transform-react-jsx",
"transform-react-constant-elements"
]
}

View File

@ -117,6 +117,12 @@ export default class PathHoister {
}
}
// We can't insert before/after a child of an export declaration, so move up
// to the declaration itself.
if (path.parentPath.isExportDeclaration()) {
path = path.parentPath;
}
return path;
}