mirror of https://github.com/status-im/metro.git
Revert D7305051: Work around babel7 issue with duplicate declarations
Differential Revision: D7305051 Original commit changeset: ac9a0130dc61 fbshipit-source-id: 6489a2385477be5c37e63387bf6367dd3ae97be1
This commit is contained in:
parent
94c03a6cd3
commit
045cf843d1
|
@ -1,9 +0,0 @@
|
||||||
class Foo {
|
|
||||||
f() {
|
|
||||||
class Bar extends React.Component {
|
|
||||||
render() {}
|
|
||||||
}
|
|
||||||
|
|
||||||
foo(Bar);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
{
|
|
||||||
"transforms": [{
|
|
||||||
"transform": "react-transform-hmr/lib/index.js",
|
|
||||||
"imports": ["react"],
|
|
||||||
"locals": ["module"]
|
|
||||||
}]
|
|
||||||
}
|
|
|
@ -1,37 +0,0 @@
|
||||||
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,40 +1,5 @@
|
||||||
// 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() {}
|
||||||
|
@ -106,10 +71,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`] = `
|
||||||
|
@ -134,10 +99,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 {}"`;
|
||||||
|
@ -163,10 +128,9 @@ function _wrapComponent(id) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
class Foo extends React.Component {
|
const Foo = _wrapComponent(\\"Foo\\")(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`] = `
|
||||||
|
@ -429,14 +393,13 @@ function _wrapComponent(id) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
class Foo extends BooComponent {
|
const Foo = _wrapComponent(\\"Foo\\")(class Foo extends BooComponent {
|
||||||
render() {}
|
render() {}
|
||||||
}
|
});
|
||||||
Foo = _wrapComponent(\\"Foo\\")(Foo);
|
|
||||||
class Bar extends CustomComponent {
|
const Bar = _wrapComponent(\\"Bar\\")(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 {}"`;
|
||||||
|
@ -470,10 +433,9 @@ function _wrapComponent(id) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
class Foo extends React.Component {
|
const Foo = _wrapComponent(\\"Foo\\")(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 {}"`;
|
||||||
|
@ -501,10 +463,9 @@ function _wrapComponent(id) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
class Foo extends React.Component {
|
const Foo = _wrapComponent(\\"Foo\\")(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 {}"`;
|
||||||
|
@ -530,8 +491,7 @@ function _wrapComponent(id) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
class Foo extends React.Component {
|
const Foo = _wrapComponent(\\"Foo\\")(class Foo extends React.Component {
|
||||||
render() {}
|
render() {}
|
||||||
}
|
});"
|
||||||
Foo = _wrapComponent(\\"Foo\\")(Foo);"
|
|
||||||
`;
|
`;
|
||||||
|
|
|
@ -125,29 +125,6 @@ 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)
|
||||||
|
@ -166,7 +143,7 @@ module.exports = {
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isExport) {
|
if (t.isExportDefaultDeclaration(path.parent)) {
|
||||||
path.parentPath.insertBefore(wrapped);
|
path.parentPath.insertBefore(wrapped);
|
||||||
path.parent.declaration = constId;
|
path.parent.declaration = constId;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue