Skip to content

Commit 21d0c11

Browse files
authored
Convert the Source to ES Modules (#11389)
* Update transforms to handle ES modules * Update Jest to handle ES modules * Convert react package to ES modules * Convert react-art package to ES Modules * Convert react-call-return package to ES Modules * Convert react-test-renderer package to ES Modules * Convert react-cs-renderer package to ES Modules * Convert react-rt-renderer package to ES Modules * Convert react-noop-renderer package to ES Modules * Convert react-dom/server to ES modules * Convert react-dom/{client,events,test-utils} to ES modules * Convert react-dom/shared to ES modules * Convert react-native-renderer to ES modules * Convert react-reconciler to ES modules * Convert events to ES modules * Convert shared to ES modules * Remove CommonJS support from transforms * Move ReactDOMFB entry point code into react-dom/src This is clearer because we can use ES imports in it. * Fix Rollup shim configuration to work with ESM * Fix incorrect comment * Exclude external imports without side effects * Fix ReactDOM FB build * Remove TODOs I don’t intend to fix yet
1 parent fbf617a commit 21d0c11

File tree

234 files changed

+3236
-3439
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

234 files changed

+3236
-3439
lines changed

packages/events/EventPluginHub.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
'use strict';
99

10-
var ReactErrorUtils = require('shared/ReactErrorUtils');
11-
var invariant = require('fbjs/lib/invariant');
10+
import ReactErrorUtils from 'shared/ReactErrorUtils';
11+
import invariant from 'fbjs/lib/invariant';
1212

13-
var EventPluginRegistry = require('./EventPluginRegistry');
14-
var EventPluginUtils = require('./EventPluginUtils');
15-
var accumulateInto = require('./accumulateInto');
16-
var forEachAccumulated = require('./forEachAccumulated');
13+
import EventPluginRegistry from './EventPluginRegistry';
14+
import EventPluginUtils from './EventPluginUtils';
15+
import accumulateInto from './accumulateInto';
16+
import forEachAccumulated from './forEachAccumulated';
1717

1818
/**
1919
* Internal queue of events that have accumulated their dispatches and are
@@ -220,4 +220,4 @@ var EventPluginHub = {
220220
},
221221
};
222222

223-
module.exports = EventPluginHub;
223+
export default EventPluginHub;

packages/events/EventPluginRegistry.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import type {
1616
PluginModule,
1717
} from './PluginModuleType';
1818

19-
var invariant = require('fbjs/lib/invariant');
19+
import invariant from 'fbjs/lib/invariant';
2020

2121
type NamesToPlugins = {[key: PluginName]: PluginModule<AnyNativeEvent>};
2222
type EventPluginOrder = null | Array<PluginName>;
@@ -251,4 +251,4 @@ var EventPluginRegistry = {
251251
},
252252
};
253253

254-
module.exports = EventPluginRegistry;
254+
export default EventPluginRegistry;

packages/events/EventPluginUtils.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,9 @@
77

88
'use strict';
99

10-
var ReactErrorUtils = require('shared/ReactErrorUtils');
11-
var invariant = require('fbjs/lib/invariant');
12-
13-
if (__DEV__) {
14-
var warning = require('fbjs/lib/warning');
15-
}
10+
import ReactErrorUtils from 'shared/ReactErrorUtils';
11+
import invariant from 'fbjs/lib/invariant';
12+
import warning from 'fbjs/lib/warning';
1613

1714
/**
1815
* Injected dependencies:
@@ -228,4 +225,4 @@ var EventPluginUtils = {
228225
injection: injection,
229226
};
230227

231-
module.exports = EventPluginUtils;
228+
export default EventPluginUtils;

packages/events/EventPropagators.js

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,21 @@
77

88
'use strict';
99

10-
var ReactTreeTraversal = require('shared/ReactTreeTraversal');
10+
import {
11+
getParentInstance,
12+
traverseTwoPhase,
13+
traverseEnterLeave,
14+
} from 'shared/ReactTreeTraversal';
15+
import warning from 'fbjs/lib/warning';
1116

12-
var EventPluginHub = require('./EventPluginHub');
13-
var accumulateInto = require('./accumulateInto');
14-
var forEachAccumulated = require('./forEachAccumulated');
17+
import EventPluginHub from './EventPluginHub';
18+
import accumulateInto from './accumulateInto';
19+
import forEachAccumulated from './forEachAccumulated';
1520

1621
type PropagationPhases = 'bubbled' | 'captured';
1722

1823
var getListener = EventPluginHub.getListener;
1924

20-
if (__DEV__) {
21-
var warning = require('fbjs/lib/warning');
22-
}
23-
2425
/**
2526
* Some event types have a notion of different registration names for different
2627
* "phases" of propagation. This finds listeners by a given phase.
@@ -60,11 +61,7 @@ function accumulateDirectionalDispatches(inst, phase, event) {
6061
*/
6162
function accumulateTwoPhaseDispatchesSingle(event) {
6263
if (event && event.dispatchConfig.phasedRegistrationNames) {
63-
ReactTreeTraversal.traverseTwoPhase(
64-
event._targetInst,
65-
accumulateDirectionalDispatches,
66-
event,
67-
);
64+
traverseTwoPhase(event._targetInst, accumulateDirectionalDispatches, event);
6865
}
6966
}
7067

@@ -74,14 +71,8 @@ function accumulateTwoPhaseDispatchesSingle(event) {
7471
function accumulateTwoPhaseDispatchesSingleSkipTarget(event) {
7572
if (event && event.dispatchConfig.phasedRegistrationNames) {
7673
var targetInst = event._targetInst;
77-
var parentInst = targetInst
78-
? ReactTreeTraversal.getParentInstance(targetInst)
79-
: null;
80-
ReactTreeTraversal.traverseTwoPhase(
81-
parentInst,
82-
accumulateDirectionalDispatches,
83-
event,
84-
);
74+
var parentInst = targetInst ? getParentInstance(targetInst) : null;
75+
traverseTwoPhase(parentInst, accumulateDirectionalDispatches, event);
8576
}
8677
}
8778

@@ -124,13 +115,7 @@ function accumulateTwoPhaseDispatchesSkipTarget(events) {
124115
}
125116

126117
function accumulateEnterLeaveDispatches(leave, enter, from, to) {
127-
ReactTreeTraversal.traverseEnterLeave(
128-
from,
129-
to,
130-
accumulateDispatches,
131-
leave,
132-
enter,
133-
);
118+
traverseEnterLeave(from, to, accumulateDispatches, leave, enter);
134119
}
135120

136121
function accumulateDirectDispatches(events) {
@@ -155,4 +140,4 @@ var EventPropagators = {
155140
accumulateEnterLeaveDispatches: accumulateEnterLeaveDispatches,
156141
};
157142

158-
module.exports = EventPropagators;
143+
export default EventPropagators;

packages/events/ReactControlledComponent.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
'use strict';
99

10-
var invariant = require('fbjs/lib/invariant');
10+
import invariant from 'fbjs/lib/invariant';
1111

12-
var EventPluginUtils = require('./EventPluginUtils');
12+
import EventPluginUtils from './EventPluginUtils';
1313

1414
// Use to restore controlled state after a change event has fired.
1515

@@ -83,4 +83,4 @@ var ReactControlledComponent = {
8383
},
8484
};
8585

86-
module.exports = ReactControlledComponent;
86+
export default ReactControlledComponent;

packages/events/ReactEventEmitterMixin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
'use strict';
99

10-
var EventPluginHub = require('./EventPluginHub');
10+
import EventPluginHub from './EventPluginHub';
1111

1212
function runEventQueueInBatch(events) {
1313
EventPluginHub.enqueueEvents(events);
@@ -35,4 +35,4 @@ var ReactEventEmitterMixin = {
3535
},
3636
};
3737

38-
module.exports = ReactEventEmitterMixin;
38+
export default ReactEventEmitterMixin;

packages/events/ReactGenericBatching.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
'use strict';
99

10-
var ReactControlledComponent = require('./ReactControlledComponent');
10+
import ReactControlledComponent from './ReactControlledComponent';
1111

1212
// Used as a way to call batchedUpdates when we don't have a reference to
1313
// the renderer. Such as when we're dispatching events or if third party
@@ -58,4 +58,4 @@ var ReactGenericBatching = {
5858
injection: ReactGenericBatchingInjection,
5959
};
6060

61-
module.exports = ReactGenericBatching;
61+
export default ReactGenericBatching;

packages/events/ResponderEventPlugin.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
'use strict';
99

10-
var ReactTreeTraversal = require('shared/ReactTreeTraversal');
10+
import {getLowestCommonAncestor, isAncestor} from 'shared/ReactTreeTraversal';
1111

12-
var EventPluginUtils = require('./EventPluginUtils');
13-
var EventPropagators = require('./EventPropagators');
14-
var ResponderSyntheticEvent = require('./ResponderSyntheticEvent');
15-
var ResponderTouchHistoryStore = require('./ResponderTouchHistoryStore');
16-
var accumulate = require('./accumulate');
12+
import EventPluginUtils from './EventPluginUtils';
13+
import EventPropagators from './EventPropagators';
14+
import ResponderSyntheticEvent from './ResponderSyntheticEvent';
15+
import ResponderTouchHistoryStore from './ResponderTouchHistoryStore';
16+
import accumulate from './accumulate';
1717

1818
var isStartish = EventPluginUtils.isStartish;
1919
var isMoveish = EventPluginUtils.isMoveish;
@@ -327,7 +327,7 @@ function setResponderAndExtractTransfer(
327327
// TODO: stop one short of the current responder.
328328
var bubbleShouldSetFrom = !responderInst
329329
? targetInst
330-
: ReactTreeTraversal.getLowestCommonAncestor(responderInst, targetInst);
330+
: getLowestCommonAncestor(responderInst, targetInst);
331331

332332
// When capturing/bubbling the "shouldSet" event, we want to skip the target
333333
// (deepest ID) if it happens to be the current responder. The reasoning:
@@ -450,7 +450,7 @@ function noResponderTouches(nativeEvent) {
450450
if (target !== null && target !== undefined && target !== 0) {
451451
// Is the original touch location inside of the current responder?
452452
var targetInst = EventPluginUtils.getInstanceFromNode(target);
453-
if (ReactTreeTraversal.isAncestor(responderInst, targetInst)) {
453+
if (isAncestor(responderInst, targetInst)) {
454454
return false;
455455
}
456456
}
@@ -592,4 +592,4 @@ var ResponderEventPlugin = {
592592
},
593593
};
594594

595-
module.exports = ResponderEventPlugin;
595+
export default ResponderEventPlugin;

packages/events/ResponderSyntheticEvent.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
'use strict';
99

10-
var SyntheticEvent = require('./SyntheticEvent');
10+
import SyntheticEvent from './SyntheticEvent';
1111

1212
/**
1313
* `touchHistory` isn't actually on the native event, but putting it in the
@@ -43,4 +43,4 @@ function ResponderSyntheticEvent(
4343

4444
SyntheticEvent.augmentClass(ResponderSyntheticEvent, ResponderEventInterface);
4545

46-
module.exports = ResponderSyntheticEvent;
46+
export default ResponderSyntheticEvent;

packages/events/ResponderTouchHistoryStore.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@
99

1010
'use strict';
1111

12-
const invariant = require('fbjs/lib/invariant');
12+
import invariant from 'fbjs/lib/invariant';
13+
import warning from 'fbjs/lib/warning';
1314

14-
const EventPluginUtils = require('./EventPluginUtils');
15-
const {isEndish, isMoveish, isStartish} = EventPluginUtils;
15+
import EventPluginUtils from './EventPluginUtils';
1616

17-
if (__DEV__) {
18-
var warning = require('fbjs/lib/warning');
19-
}
17+
const {isEndish, isMoveish, isStartish} = EventPluginUtils;
2018

2119
/**
2220
* Tracks the position and time of each active touch by `touch.identifier`. We
@@ -218,4 +216,4 @@ const ResponderTouchHistoryStore = {
218216
touchHistory,
219217
};
220218

221-
module.exports = ResponderTouchHistoryStore;
219+
export default ResponderTouchHistoryStore;

0 commit comments

Comments
 (0)