Move remaining things to named exports (#18165)

* Move remaining things to named exports

The interesting case here is the noop renderers. The wrappers around the
reconciler now changed to use a local export that gets mutated.

ReactNoop and ReactNoopPersistent now have to destructure the object to
list out the names it's going to export. We should probably refactor
ReactNoop away from createReactNoop. Especially since it's also not Flow
typed.

* Switch interactions to star exports

This will have esModule compatibility flag on them. They should ideally
export default instead.
This commit is contained in:
Sebastian Markbåge 2020-02-27 17:18:55 -08:00 committed by GitHub
parent 739f20beda
commit 549e418830
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
40 changed files with 113 additions and 200 deletions

View File

@ -5,6 +5,4 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
'use strict'; export * from './src/index';
module.exports = require('./src/index');

View File

@ -7,8 +7,4 @@
* @flow * @flow
*/ */
'use strict'; export {default} from './npm/Circle';
const Circle = require('./npm/Circle');
module.exports = Circle;

View File

@ -7,8 +7,4 @@
* @flow * @flow
*/ */
'use strict'; export {default} from './npm/Rectangle';
const Rectangle = require('./npm/Rectangle');
module.exports = Rectangle;

View File

@ -7,8 +7,4 @@
* @flow * @flow
*/ */
'use strict'; export {default} from './npm/Wedge';
const Wedge = require('./npm/Wedge');
module.exports = Wedge;

View File

@ -7,8 +7,4 @@
* @flow * @flow
*/ */
'use strict'; export * from './src/ReactART';
const ReactART = require('./src/ReactART');
module.exports = ReactART;

View File

@ -11,7 +11,19 @@
'use strict'; 'use strict';
const React = require('react'); import * as React from 'react';
import * as ReactART from 'react-art';
import ARTSVGMode from 'art/modes/svg';
import ARTCurrentMode from 'art/modes/current';
// Since these are default exports, we need to import them using ESM.
// Since they must be on top, we need to import this before ReactDOM.
import Circle from 'react-art/Circle';
import Rectangle from 'react-art/Rectangle';
import Wedge from 'react-art/Wedge';
// Isolate DOM renderer.
jest.resetModules();
const ReactDOM = require('react-dom'); const ReactDOM = require('react-dom');
const ReactTestUtils = require('react-dom/test-utils'); const ReactTestUtils = require('react-dom/test-utils');
@ -19,15 +31,6 @@ const ReactTestUtils = require('react-dom/test-utils');
jest.resetModules(); jest.resetModules();
const ReactTestRenderer = require('react-test-renderer'); const ReactTestRenderer = require('react-test-renderer');
// Isolate ART renderer.
jest.resetModules();
const ReactART = require('react-art');
const ARTSVGMode = require('art/modes/svg');
const ARTCurrentMode = require('art/modes/current');
const Circle = require('react-art/Circle');
const Rectangle = require('react-art/Rectangle');
const Wedge = require('react-art/Wedge');
// Isolate the noop renderer // Isolate the noop renderer
jest.resetModules(); jest.resetModules();
const ReactNoop = require('react-noop-renderer'); const ReactNoop = require('react-noop-renderer');

View File

@ -5,9 +5,4 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
'use strict'; export * from './src/ReactDebugTools';
const ReactDebugTools = require('./src/ReactDebugTools');
// This is hacky but makes it work with both Rollup and Jest.
module.exports = ReactDebugTools.default || ReactDebugTools;

View File

@ -7,10 +7,4 @@
* @flow * @flow
*/ */
'use strict'; export * from './src/ReactFlightDOMClient';
const ReactFlightDOMClient = require('./src/ReactFlightDOMClient');
// TODO: decide on the top-level export form.
// This is hacky but makes it work with both Rollup and Jest
module.exports = ReactFlightDOMClient.default || ReactFlightDOMClient;

View File

@ -7,11 +7,4 @@
* @flow * @flow
*/ */
'use strict'; export * from './src/ReactFlightDOMServerBrowser';
const ReactFlightDOMServerBrowser = require('./src/ReactFlightDOMServerBrowser');
// TODO: decide on the top-level export form.
// This is hacky but makes it work with both Rollup and Jest
module.exports =
ReactFlightDOMServerBrowser.default || ReactFlightDOMServerBrowser;

View File

@ -7,6 +7,4 @@
* @flow * @flow
*/ */
'use strict'; export * from './server.node';
module.exports = require('./server.node');

View File

@ -7,10 +7,4 @@
* @flow * @flow
*/ */
'use strict'; export * from './src/ReactFlightDOMServerNode';
const ReactFlightDOMServerNode = require('./src/ReactFlightDOMServerNode');
// TODO: decide on the top-level export form.
// This is hacky but makes it work with both Rollup and Jest
module.exports = ReactFlightDOMServerNode.default || ReactFlightDOMServerNode;

View File

@ -79,8 +79,4 @@ function readFromXHR<T>(request: XMLHttpRequest): ReactModelRoot<T> {
return getModelRoot(response); return getModelRoot(response);
} }
export default { export {readFromXHR, readFromFetch, readFromReadableStream};
readFromXHR,
readFromFetch,
readFromReadableStream,
};

View File

@ -29,6 +29,4 @@ function renderToReadableStream(model: ReactModel): ReadableStream {
}); });
} }
export default { export {renderToReadableStream};
renderToReadableStream,
};

View File

@ -26,6 +26,4 @@ function pipeToNodeWritable(model: ReactModel, destination: Writable): void {
startWork(request); startWork(request);
} }
export default { export {pipeToNodeWritable};
pipeToNodeWritable,
};

View File

@ -17,10 +17,4 @@
// `react-server/inline-typed` (which *is*) for the current renderer. // `react-server/inline-typed` (which *is*) for the current renderer.
// On CI, we run Flow checks for each renderer separately. // On CI, we run Flow checks for each renderer separately.
'use strict'; export * from './src/ReactFlightClient';
const ReactFlightClient = require('./src/ReactFlightClient');
// TODO: decide on the top-level export form.
// This is hacky but makes it work with both Rollup and Jest.
module.exports = ReactFlightClient.default || ReactFlightClient;

View File

@ -7,6 +7,4 @@
* @flow * @flow
*/ */
'use strict'; export * from './src/dom/ContextMenu';
module.exports = require('./src/dom/ContextMenu');

View File

@ -7,6 +7,4 @@
* @flow * @flow
*/ */
'use strict'; export * from './src/dom/Focus';
module.exports = require('./src/dom/Focus');

View File

@ -7,6 +7,4 @@
* @flow * @flow
*/ */
'use strict'; export * from './src/dom/Hover';
module.exports = require('./src/dom/Hover');

View File

@ -7,6 +7,4 @@
* @flow * @flow
*/ */
'use strict'; export * from './src/dom/Input';
module.exports = require('./src/dom/Input');

View File

@ -7,6 +7,4 @@
* @flow * @flow
*/ */
'use strict'; export * from './src/dom/Keyboard';
module.exports = require('./src/dom/Keyboard');

View File

@ -7,6 +7,4 @@
* @flow * @flow
*/ */
'use strict'; export * from './src/dom/PressLegacy';
module.exports = require('./src/dom/PressLegacy');

View File

@ -7,6 +7,4 @@
* @flow * @flow
*/ */
'use strict'; export * from './src/dom/Press';
module.exports = require('./src/dom/Press');

View File

@ -7,6 +7,4 @@
* @flow * @flow
*/ */
'use strict'; export * from './src/dom/Tap';
module.exports = require('./src/dom/Tap');

View File

@ -7,10 +7,4 @@
* @flow * @flow
*/ */
'use strict'; export * from './src/ReactNoopFlightClient';
const ReactNoopFlightClient = require('./src/ReactNoopFlightClient');
// TODO: decide on the top-level export form.
// This is hacky but makes it work with both Rollup and Jest.
module.exports = ReactNoopFlightClient.default || ReactNoopFlightClient;

View File

@ -7,10 +7,4 @@
* @flow * @flow
*/ */
'use strict'; export * from './src/ReactNoopFlightServer';
const ReactNoopFlightServer = require('./src/ReactNoopFlightServer');
// TODO: decide on the top-level export form.
// This is hacky but makes it work with both Rollup and Jest.
module.exports = ReactNoopFlightServer.default || ReactNoopFlightServer;

View File

@ -7,10 +7,4 @@
* @flow * @flow
*/ */
'use strict'; export * from './src/ReactNoop';
const ReactNoop = require('./src/ReactNoop');
// TODO: decide on the top-level export form.
// This is hacky but makes it work with both Rollup and Jest.
module.exports = ReactNoop.default || ReactNoop;

View File

@ -7,10 +7,4 @@
* @flow * @flow
*/ */
'use strict'; export * from './src/ReactNoopPersistent';
const ReactNoopPersistent = require('./src/ReactNoopPersistent');
// TODO: decide on the top-level export form.
// This is hacky but makes it work with both Rollup and Jest.
module.exports = ReactNoopPersistent.default || ReactNoopPersistent;

View File

@ -7,10 +7,4 @@
* @flow * @flow
*/ */
'use strict'; export * from './src/ReactNoopServer';
const ReactNoopServer = require('./src/ReactNoopServer');
// TODO: decide on the top-level export form.
// This is hacky but makes it work with both Rollup and Jest.
module.exports = ReactNoopServer.default || ReactNoopServer;

View File

@ -17,9 +17,36 @@
import ReactFiberReconciler from 'react-reconciler'; import ReactFiberReconciler from 'react-reconciler';
import createReactNoop from './createReactNoop'; import createReactNoop from './createReactNoop';
const ReactNoop = createReactNoop( export const {
_Scheduler,
getChildren,
getPendingChildren,
getOrCreateRootContainer,
createRoot,
createBlockingRoot,
getChildrenAsJSX,
getPendingChildrenAsJSX,
createPortal,
render,
renderLegacySyncRoot,
renderToRootWithID,
unmountRootWithID,
findInstance,
flushNextYield,
flushWithHostCounters,
expire,
flushExpired,
batchedUpdates,
deferredUpdates,
unbatchedUpdates,
discreteUpdates,
flushDiscreteUpdates,
flushSync,
flushPassiveEffects,
act,
dumpTree,
getRoot,
} = createReactNoop(
ReactFiberReconciler, // reconciler ReactFiberReconciler, // reconciler
true, // useMutation true, // useMutation
); );
export default ReactNoop;

View File

@ -38,6 +38,4 @@ function read<T>(source: Source): ReactModelRoot<T> {
return getModelRoot(response); return getModelRoot(response);
} }
export default { export {read};
read,
};

View File

@ -52,6 +52,4 @@ function render(model: ReactModel): Destination {
return destination; return destination;
} }
export default { export {render};
render,
};

View File

@ -17,9 +17,36 @@
import ReactFiberPersistentReconciler from 'react-reconciler/persistent'; import ReactFiberPersistentReconciler from 'react-reconciler/persistent';
import createReactNoop from './createReactNoop'; import createReactNoop from './createReactNoop';
const ReactNoopPersistent = createReactNoop( export const {
_Scheduler,
getChildren,
getPendingChildren,
getOrCreateRootContainer,
createRoot,
createBlockingRoot,
getChildrenAsJSX,
getPendingChildrenAsJSX,
createPortal,
render,
renderLegacySyncRoot,
renderToRootWithID,
unmountRootWithID,
findInstance,
flushNextYield,
flushWithHostCounters,
expire,
flushExpired,
batchedUpdates,
deferredUpdates,
unbatchedUpdates,
discreteUpdates,
flushDiscreteUpdates,
flushSync,
flushPassiveEffects,
act,
dumpTree,
getRoot,
} = createReactNoop(
ReactFiberPersistentReconciler, // reconciler ReactFiberPersistentReconciler, // reconciler
false, // useMutation false, // useMutation
); );
export default ReactNoopPersistent;

View File

@ -47,6 +47,4 @@ function render(children: React$Element<any>): Destination {
return destination; return destination;
} }
export default { export {render};
render,
};

View File

@ -17,10 +17,4 @@
// `react-reconciler/inline-typed` (which *is*) for the current renderer. // `react-reconciler/inline-typed` (which *is*) for the current renderer.
// On CI, we run Flow checks for each renderer separately. // On CI, we run Flow checks for each renderer separately.
'use strict'; export * from './src/ReactFiberReconciler';
const ReactFiberReconciler = require('./src/ReactFiberReconciler');
// TODO: decide on the top-level export form.
// This is hacky but makes it work with both Rollup and Jest.
module.exports = ReactFiberReconciler.default || ReactFiberReconciler;

View File

@ -9,8 +9,4 @@
// This is the same export as in index.js, // This is the same export as in index.js,
// with persistent reconciler flags turned on. // with persistent reconciler flags turned on.
const ReactFiberReconciler = require('./src/ReactFiberReconciler'); export * from './src/ReactFiberReconciler';
// TODO: decide on the top-level export form.
// This is hacky but makes it work with both Rollup and Jest.
module.exports = ReactFiberReconciler.default || ReactFiberReconciler;

View File

@ -5,9 +5,4 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
'use strict'; export {default} from './src/ReactFreshBabelPlugin';
const ReactFreshBabelPlugin = require('./src/ReactFreshBabelPlugin');
// This is hacky but makes it work with both Rollup and Jest.
module.exports = ReactFreshBabelPlugin.default || ReactFreshBabelPlugin;

View File

@ -5,9 +5,4 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
'use strict'; export * from './src/ReactFreshRuntime';
const ReactFreshRuntime = require('./src/ReactFreshRuntime');
// This is hacky but makes it work with both Rollup and Jest.
module.exports = ReactFreshRuntime.default || ReactFreshRuntime;

View File

@ -17,10 +17,4 @@
// `react-server/flight.inline-typed` (which *is*) for the current renderer. // `react-server/flight.inline-typed` (which *is*) for the current renderer.
// On CI, we run Flow checks for each renderer separately. // On CI, we run Flow checks for each renderer separately.
'use strict'; export * from './src/ReactFlightServer';
const ReactFlightServer = require('./src/ReactFlightServer');
// TODO: decide on the top-level export form.
// This is hacky but makes it work with both Rollup and Jest.
module.exports = ReactFlightServer.default || ReactFlightServer;

View File

@ -17,10 +17,4 @@
// `react-server/inline-typed` (which *is*) for the current renderer. // `react-server/inline-typed` (which *is*) for the current renderer.
// On CI, we run Flow checks for each renderer separately. // On CI, we run Flow checks for each renderer separately.
'use strict'; export * from './src/ReactFizzStreamer';
const ReactFizzStreamer = require('./src/ReactFizzStreamer');
// TODO: decide on the top-level export form.
// This is hacky but makes it work with both Rollup and Jest.
module.exports = ReactFizzStreamer.default || ReactFizzStreamer;

View File

@ -288,10 +288,9 @@ ${license}
if (process.env.NODE_ENV !== "production") { if (process.env.NODE_ENV !== "production") {
module.exports = function $$$reconciler($$$hostConfig) { module.exports = function $$$reconciler($$$hostConfig) {
var exports = {};
${source} ${source}
var $$$renderer = module.exports; return exports;
module.exports = $$$reconciler;
return $$$renderer;
}; };
}`; }`;
}, },
@ -304,10 +303,9 @@ ${source}
${license} ${license}
*/ */
module.exports = function $$$reconciler($$$hostConfig) { module.exports = function $$$reconciler($$$hostConfig) {
var exports = {};
${source} ${source}
var $$$renderer = module.exports; return exports;
module.exports = $$$reconciler;
return $$$renderer;
};`; };`;
}, },
}; };