mirror of
https://github.com/status-im/metro.git
synced 2025-01-13 12:35:57 +00:00
Workaround for babel7
Reviewed By: arcanis Differential Revision: D7337431 fbshipit-source-id: f25a576b1ead75cba32cdffd3341a89380665d7a
This commit is contained in:
parent
9b90096a2a
commit
b3619fc838
@ -0,0 +1,9 @@
|
|||||||
|
class Foo {
|
||||||
|
f() {
|
||||||
|
class Bar extends React.Component {
|
||||||
|
render() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
foo(Bar);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"transforms": [{
|
||||||
|
"transform": "react-transform-hmr/lib/index.js",
|
||||||
|
"imports": ["react"],
|
||||||
|
"locals": ["module"]
|
||||||
|
}]
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
var _transformLib = _interopRequireDefault(require(\\"transform-lib\\")).default;
|
||||||
|
|
||||||
|
const _components = {
|
||||||
|
Bar: {
|
||||||
|
displayName: \\"Bar\\",
|
||||||
|
isInFunction: true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const _transformLib2 = _transformLib({
|
||||||
|
filename: \\"unknown\\",
|
||||||
|
components: _components,
|
||||||
|
locals: [],
|
||||||
|
imports: []
|
||||||
|
});
|
||||||
|
|
||||||
|
function _wrapComponent(id) {
|
||||||
|
return function (Component) {
|
||||||
|
return _transformLib2(Component, id);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||||
|
|
||||||
|
class Foo {
|
||||||
|
f() {
|
||||||
|
const Bar = _wrapComponent(\\"Bar\\")(function () {
|
||||||
|
return class Bar extends React.Component {
|
||||||
|
render() {}
|
||||||
|
|
||||||
|
};
|
||||||
|
}());
|
||||||
|
|
||||||
|
foo(Bar);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,5 +1,40 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`finds React components should babel7 regression 1`] = `
|
||||||
|
"import _react from \\"react\\";
|
||||||
|
import _reactTransformHmrLibIndexJs from \\"react-transform-hmr/lib/index.js\\";
|
||||||
|
const _components = {
|
||||||
|
Bar: {
|
||||||
|
displayName: \\"Bar\\",
|
||||||
|
isInFunction: true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const _reactTransformHmrLibIndexJs2 = _reactTransformHmrLibIndexJs({
|
||||||
|
filename: \\"unknown\\",
|
||||||
|
components: _components,
|
||||||
|
locals: [module],
|
||||||
|
imports: [_react]
|
||||||
|
});
|
||||||
|
|
||||||
|
function _wrapComponent(id) {
|
||||||
|
return function (Component) {
|
||||||
|
return _reactTransformHmrLibIndexJs2(Component, id);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
class Foo {
|
||||||
|
f() {
|
||||||
|
class Bar extends React.Component {
|
||||||
|
render() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
Bar = _wrapComponent(\\"Bar\\")(Bar);
|
||||||
|
foo(Bar);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`finds React components should code call expression with render method 1`] = `
|
exports[`finds React components should code call expression with render method 1`] = `
|
||||||
"factory({
|
"factory({
|
||||||
render() {}
|
render() {}
|
||||||
@ -71,10 +106,10 @@ function _wrapComponent(id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
|
class Foo extends Component {
|
||||||
const Foo = _wrapComponent('Foo')(class Foo extends Component {
|
|
||||||
render() {}
|
render() {}
|
||||||
});"
|
}
|
||||||
|
Foo = _wrapComponent('Foo')(Foo);"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`finds React components should code class extends purecomponent with render method 1`] = `
|
exports[`finds React components should code class extends purecomponent with render method 1`] = `
|
||||||
@ -99,10 +134,10 @@ function _wrapComponent(id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
import React, { PureComponent } from 'react';
|
import React, { PureComponent } from 'react';
|
||||||
|
class Foo extends PureComponent {
|
||||||
const Foo = _wrapComponent('Foo')(class Foo extends PureComponent {
|
|
||||||
render() {}
|
render() {}
|
||||||
});"
|
}
|
||||||
|
Foo = _wrapComponent('Foo')(Foo);"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`finds React components should code class extends react component 1`] = `"class Foo extends React.Component {}"`;
|
exports[`finds React components should code class extends react component 1`] = `"class Foo extends React.Component {}"`;
|
||||||
@ -128,9 +163,10 @@ function _wrapComponent(id) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const Foo = _wrapComponent(\\"Foo\\")(class Foo extends React.Component {
|
class Foo extends React.Component {
|
||||||
render() {}
|
render() {}
|
||||||
});"
|
}
|
||||||
|
Foo = _wrapComponent(\\"Foo\\")(Foo);"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`finds React components should code class with render method 1`] = `
|
exports[`finds React components should code class with render method 1`] = `
|
||||||
@ -393,13 +429,14 @@ function _wrapComponent(id) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const Foo = _wrapComponent(\\"Foo\\")(class Foo extends BooComponent {
|
class Foo extends BooComponent {
|
||||||
render() {}
|
render() {}
|
||||||
});
|
}
|
||||||
|
Foo = _wrapComponent(\\"Foo\\")(Foo);
|
||||||
const Bar = _wrapComponent(\\"Bar\\")(class Bar extends CustomComponent {
|
class Bar extends CustomComponent {
|
||||||
render() {}
|
render() {}
|
||||||
});"
|
}
|
||||||
|
Bar = _wrapComponent(\\"Bar\\")(Bar);"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`finds React components should options multiple transforms 1`] = `"class Foo extends React.Component {}"`;
|
exports[`finds React components should options multiple transforms 1`] = `"class Foo extends React.Component {}"`;
|
||||||
@ -433,9 +470,10 @@ function _wrapComponent(id) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const Foo = _wrapComponent(\\"Foo\\")(class Foo extends React.Component {
|
class Foo extends React.Component {
|
||||||
render() {}
|
render() {}
|
||||||
});"
|
}
|
||||||
|
Foo = _wrapComponent(\\"Foo\\")(Foo);"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`finds React components should options with imports 1`] = `"class Foo extends React.Component {}"`;
|
exports[`finds React components should options with imports 1`] = `"class Foo extends React.Component {}"`;
|
||||||
@ -463,9 +501,10 @@ function _wrapComponent(id) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const Foo = _wrapComponent(\\"Foo\\")(class Foo extends React.Component {
|
class Foo extends React.Component {
|
||||||
render() {}
|
render() {}
|
||||||
});"
|
}
|
||||||
|
Foo = _wrapComponent(\\"Foo\\")(Foo);"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`finds React components should options with locals 1`] = `"class Foo extends React.Component {}"`;
|
exports[`finds React components should options with locals 1`] = `"class Foo extends React.Component {}"`;
|
||||||
@ -491,7 +530,8 @@ function _wrapComponent(id) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const Foo = _wrapComponent(\\"Foo\\")(class Foo extends React.Component {
|
class Foo extends React.Component {
|
||||||
render() {}
|
render() {}
|
||||||
});"
|
}
|
||||||
|
Foo = _wrapComponent(\\"Foo\\")(Foo);"
|
||||||
`;
|
`;
|
||||||
|
@ -125,6 +125,29 @@ module.exports = {
|
|||||||
|
|
||||||
// Can't wrap ClassDeclarations
|
// Can't wrap ClassDeclarations
|
||||||
const isStatement = t.isStatement(path.node);
|
const isStatement = t.isStatement(path.node);
|
||||||
|
const isExport = t.isExportDefaultDeclaration(path.parent);
|
||||||
|
|
||||||
|
if (isStatement && !isExport) {
|
||||||
|
// class decl
|
||||||
|
// need to work around Babel 7 detecting duplicate decls here
|
||||||
|
|
||||||
|
path.insertAfter(
|
||||||
|
t.expressionStatement(
|
||||||
|
t.assignmentExpression(
|
||||||
|
'=',
|
||||||
|
t.identifier(componentId),
|
||||||
|
wrapComponent(
|
||||||
|
t.identifier(componentId),
|
||||||
|
componentId,
|
||||||
|
this.wrapperFunctionId,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const expression = t.toExpression(path.node);
|
const expression = t.toExpression(path.node);
|
||||||
|
|
||||||
// wrapperFunction("componentId")(node)
|
// wrapperFunction("componentId")(node)
|
||||||
@ -143,7 +166,7 @@ module.exports = {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t.isExportDefaultDeclaration(path.parent)) {
|
if (isExport) {
|
||||||
path.parentPath.insertBefore(wrapped);
|
path.parentPath.insertBefore(wrapped);
|
||||||
path.parent.declaration = constId;
|
path.parent.declaration = constId;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user