GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [RFC] Codemod invariant -> throw new Error (#22435) · react/react@a724a3b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .eslintrc.js
  • packages
    • create-subscription/src
      • createSubscription.js
    • jest-react/src
      • JestReact.js
    • react-art/src
      • ReactARTHostConfig.js
    • react-cache/src
      • ReactCacheOld.js
    • react-client/src
      • ReactFlightClient.js
      • ReactFlightClientHostConfig.js
      • ReactFlightClientHostConfigNoStream.js
    • react-debug-tools/src
      • ReactDebugHooks.js
    • react-dom/src
      • client
        • ReactDOM.js
        • ReactDOMComponentTree.js
        • ReactDOMEventHandle.js
        • ReactDOMInput.js
        • ReactDOMLegacy.js
        • ReactDOMRoot.js
        • ReactDOMTextarea.js
      • events
        • ReactDOMControlledComponent.js
        • getListener.js
      • server
        • ReactDOMLegacyServerBrowser.js
        • ReactDOMServerFormatConfig.js
        • ReactDOMServerLegacyPartialRendererBrowser.js
        • ReactPartialRenderer.js
        • ReactPartialRendererHooks.js
        • ReactThreadIDAllocator.js
      • shared
        • assertValidProps.js
        • sanitizeURL.js
      • test-utils
        • ReactTestUtils.js
    • react-fetch/src
      • ReactFetchBrowser.js
      • ReactFetchNode.js
    • react-native-renderer/src
      • ReactFabricComponentTree.js
      • ReactNativeBridgeEventPlugin.js
      • ReactNativeComponentTree.js
      • ReactNativeFiberInspector.js
      • ReactNativeGetListener.js
      • ReactNativeHostConfig.js
      • __mocks__/react-native/Libraries/ReactPrivate
        • InitializeNativeFabricUIManager.js
        • ReactNativeViewConfigRegistry.js
        • UIManager.js
      • legacy-events
        • EventBatching.js
        • EventPluginRegistry.js
        • EventPluginUtils.js
        • ResponderEventPlugin.js
        • ResponderTouchHistoryStore.js
        • SyntheticEvent.js
        • accumulate.js
        • accumulateInto.js
      • server
        • ReactNativeServerFormatConfig.js
    • react-pg/src
      • ReactPostgres.js
    • react-reconciler/src
      • ReactChildFiber.new.js
      • ReactChildFiber.old.js
      • ReactFiber.new.js
      • ReactFiber.old.js
      • ReactFiberBeginWork.new.js
      • ReactFiberBeginWork.old.js
      • ReactFiberClassComponent.new.js
      • ReactFiberClassComponent.old.js
      • ReactFiberCommitWork.new.js
      • ReactFiberCommitWork.old.js
      • ReactFiberCompleteWork.new.js
      • ReactFiberCompleteWork.old.js
      • ReactFiberContext.new.js
      • ReactFiberContext.old.js
      • ReactFiberHooks.new.js
      • ReactFiberHooks.old.js
      • ReactFiberHostConfig.js
      • ReactFiberHostConfigWithNoHydration.js
      • ReactFiberHostConfigWithNoMicrotasks.js
      • ReactFiberHostConfigWithNoMutation.js
      • ReactFiberHostConfigWithNoPersistence.js
      • ReactFiberHostConfigWithNoScopes.js
      • ReactFiberHostConfigWithNoTestSelectors.js
      • ReactFiberHostContext.new.js
      • ReactFiberHostContext.old.js
      • ReactFiberHotReloading.new.js
      • ReactFiberHotReloading.old.js
      • ReactFiberHydrationContext.new.js
      • ReactFiberHydrationContext.old.js
      • ReactFiberNewContext.new.js
      • ReactFiberNewContext.old.js
      • ReactFiberReconciler.new.js
      • ReactFiberReconciler.old.js
      • ReactFiberThrow.new.js
      • ReactFiberThrow.old.js
      • ReactFiberTreeReflection.js
      • ReactFiberUnwindWork.new.js
      • ReactFiberUnwindWork.old.js
      • ReactFiberWorkLoop.new.js
      • ReactFiberWorkLoop.old.js
      • ReactTestSelectors.js
      • ReactUpdateQueue.new.js
      • ReactUpdateQueue.old.js
      • forks
        • ReactFiberErrorDialog.native.js
        • ReactFiberErrorDialog.www.js
    • react-server/src
      • ReactFizzContext.js
      • ReactFizzHooks.js
      • ReactFizzNewContext.js
      • ReactFizzServer.js
      • ReactFlightServer.js
      • ReactFlightServerConfig.js
      • ReactServerFormatConfig.js
      • ReactServerStreamConfig.js
    • react-suspense-test-utils/src
      • ReactSuspenseTestUtils.js
    • react-test-renderer/src
      • ReactTestRenderer.js
    • react
      • src
        • ReactAct.js
        • ReactBaseClasses.js
        • ReactChildren.js
        • ReactElement.js
      • unstable-shared-subset.js
    • scheduler/src/forks
      • SchedulerMock.js
    • shared
      • ReactErrorUtils.js
      • checkPropTypes.js
      • forks
        • invokeGuardedCallbackImpl.www.js
      • invariant.js
      • invokeGuardedCallbackImpl.js
  • scripts
    • error-codes
      • __tests__
        • __snapshots__
          • transform-error-messages.js.snap
        • transform-error-messages.js
      • codes.json
      • extract-errors.js
      • transform-error-messages.js
    • eslint-rules
      • __tests__
        • prod-error-codes-test.internal.js
      • index.js
      • prod-error-codes.js
    • print-warnings
      • print-warnings.js
    • rollup
      • build.js
      • bundles.js
    • shared
      • __tests__
        • evalToString-test.js
      • evalToString.js
  • yarn.lock

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.eslintrc.js‎

Copy file name to clipboardExpand all lines: .eslintrc.js
+35Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,41 @@ module.exports = {
127127
},
128128

129129
overrides: [
130+
{
131+
// By default, anything error message that appears the packages directory
132+
// must have a corresponding error code. The exceptions are defined
133+
// in the next override entry.
134+
files: ['packages/**/*.js'],
135+
rules: {
136+
'react-internal/prod-error-codes': ERROR,
137+
},
138+
},
139+
{
140+
// These are files where it's OK to have unminified error messages. These
141+
// are environments where bundle size isn't a concern, like tests
142+
// or Node.
143+
files: [
144+
'packages/react-dom/src/test-utils/**/*.js',
145+
'packages/react-devtools-shared/**/*.js',
146+
'packages/react-noop-renderer/**/*.js',
147+
'packages/react-pg/**/*.js',
148+
'packages/react-fs/**/*.js',
149+
'packages/react-refresh/**/*.js',
150+
'packages/react-server-dom-webpack/**/*.js',
151+
'packages/react-test-renderer/**/*.js',
152+
'packages/react-debug-tools/**/*.js',
153+
'packages/react-devtools-extensions/**/*.js',
154+
'packages/react-devtools-scheduling-profiler/**/*.js',
155+
'packages/react-native-renderer/**/*.js',
156+
'packages/eslint-plugin-react-hooks/**/*.js',
157+
'packages/jest-react/**/*.js',
158+
'packages/**/__tests__/*.js',
159+
'packages/**/npm/*.js',
160+
],
161+
rules: {
162+
'react-internal/prod-error-codes': OFF,
163+
},
164+
},
130165
{
131166
// We apply these settings to files that we ship through npm.
132167
// They must be ES5.
Collapse file

‎packages/create-subscription/src/createSubscription.js‎

Copy file name to clipboardExpand all lines: packages/create-subscription/src/createSubscription.js
+6-5Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
*/
99

1010
import * as React from 'react';
11-
import invariant from 'shared/invariant';
1211

1312
type Unsubscribe = () => void;
1413

@@ -128,10 +127,12 @@ export function createSubscription<Property, Value>(
128127

129128
// Store the unsubscribe method for later (in case the subscribable prop changes).
130129
const unsubscribe = subscribe(source, callback);
131-
invariant(
132-
typeof unsubscribe === 'function',
133-
'A subscription must return an unsubscribe function.',
134-
);
130+
131+
if (typeof unsubscribe !== 'function') {
132+
throw new Error(
133+
'A subscription must return an unsubscribe function.',
134+
);
135+
}
135136

136137
// It's safe to store unsubscribe on the instance because
137138
// We only read or write that property during the "commit" phase.
Collapse file

‎packages/jest-react/src/JestReact.js‎

Copy file name to clipboardExpand all lines: packages/jest-react/src/JestReact.js
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import {REACT_ELEMENT_TYPE, REACT_FRAGMENT_TYPE} from 'shared/ReactSymbols';
99

10-
import invariant from 'shared/invariant';
1110
import isArray from 'shared/isArray';
1211

1312
export {act} from './internalAct';
@@ -31,11 +30,12 @@ function captureAssertion(fn) {
3130
function assertYieldsWereCleared(root) {
3231
const Scheduler = root._Scheduler;
3332
const actualYields = Scheduler.unstable_clearYields();
34-
invariant(
35-
actualYields.length === 0,
36-
'Log of yielded values is not empty. ' +
37-
'Call expect(ReactTestRenderer).unstable_toHaveYielded(...) first.',
38-
);
33+
if (actualYields.length !== 0) {
34+
throw new Error(
35+
'Log of yielded values is not empty. ' +
36+
'Call expect(ReactTestRenderer).unstable_toHaveYielded(...) first.',
37+
);
38+
}
3939
}
4040

4141
export function unstable_toMatchRenderedOutput(root, expectedJSX) {
Collapse file

‎packages/react-art/src/ReactARTHostConfig.js‎

Copy file name to clipboardExpand all lines: packages/react-art/src/ReactARTHostConfig.js
+17-17Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import Transform from 'art/core/transform';
99
import Mode from 'art/modes/current';
10-
import invariant from 'shared/invariant';
1110

1211
import {TYPES, EVENT_TYPES, childrenAsString} from './ReactARTInternals';
1312

@@ -248,8 +247,7 @@ export * from 'react-reconciler/src/ReactFiberHostConfigWithNoMicrotasks';
248247
export function appendInitialChild(parentInstance, child) {
249248
if (typeof child === 'string') {
250249
// Noop for string children of Text (eg <Text>{'foo'}{'bar'}</Text>)
251-
invariant(false, 'Text children should already be flattened.');
252-
return;
250+
throw new Error('Text children should already be flattened.');
253251
}
254252

255253
child.inject(parentInstance);
@@ -282,7 +280,9 @@ export function createInstance(type, props, internalInstanceHandle) {
282280
break;
283281
}
284282

285-
invariant(instance, 'ReactART does not support the type "%s"', type);
283+
if (!instance) {
284+
throw new Error(`ReactART does not support the type "${type}"`);
285+
}
286286

287287
instance._applyProps(instance, props);
288288

@@ -367,18 +367,18 @@ export function appendChildToContainer(parentInstance, child) {
367367
}
368368

369369
export function insertBefore(parentInstance, child, beforeChild) {
370-
invariant(
371-
child !== beforeChild,
372-
'ReactART: Can not insert node before itself',
373-
);
370+
if (child === beforeChild) {
371+
throw new Error('ReactART: Can not insert node before itself');
372+
}
373+
374374
child.injectBefore(beforeChild);
375375
}
376376

377377
export function insertInContainerBefore(parentInstance, child, beforeChild) {
378-
invariant(
379-
child !== beforeChild,
380-
'ReactART: Can not insert node before itself',
381-
);
378+
if (child === beforeChild) {
379+
throw new Error('ReactART: Can not insert node before itself');
380+
}
381+
382382
child.injectBefore(beforeChild);
383383
}
384384

@@ -433,25 +433,25 @@ export function clearContainer(container) {
433433
}
434434

435435
export function getInstanceFromNode(node) {
436-
throw new Error('Not yet implemented.');
436+
throw new Error('Not implemented.');
437437
}
438438

439439
export function isOpaqueHydratingObject(value: mixed): boolean {
440-
throw new Error('Not yet implemented');
440+
throw new Error('Not implemented.');
441441
}
442442

443443
export function makeOpaqueHydratingObject(
444444
attemptToReadValue: () => void,
445445
): OpaqueIDType {
446-
throw new Error('Not yet implemented.');
446+
throw new Error('Not implemented.');
447447
}
448448

449449
export function makeClientId(): OpaqueIDType {
450-
throw new Error('Not yet implemented');
450+
throw new Error('Not implemented.');
451451
}
452452

453453
export function makeClientIdInDEV(warnOnAccessInDEV: () => void): OpaqueIDType {
454-
throw new Error('Not yet implemented');
454+
throw new Error('Not implemented.');
455455
}
456456

457457
export function beforeActiveInstanceBlur(internalInstanceHandle: Object) {
Collapse file

‎packages/react-cache/src/ReactCacheOld.js‎

Copy file name to clipboardExpand all lines: packages/react-cache/src/ReactCacheOld.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ const ReactCurrentDispatcher =
4949
function readContext(Context) {
5050
const dispatcher = ReactCurrentDispatcher.current;
5151
if (dispatcher === null) {
52+
// This wasn't being minified but we're going to retire this package anyway.
53+
// eslint-disable-next-line react-internal/prod-error-codes
5254
throw new Error(
5355
'react-cache: read and preload may only be called from within a ' +
5456
"component's render. They are not supported in event handlers or " +
Collapse file

‎packages/react-client/src/ReactFlightClient.js‎

Copy file name to clipboardExpand all lines: packages/react-client/src/ReactFlightClient.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ export function resolveError(
397397
message: string,
398398
stack: string,
399399
): void {
400+
// eslint-disable-next-line react-internal/prod-error-codes
400401
const error = new Error(message);
401402
error.stack = stack;
402403
const chunks = response._chunks;
Collapse file

‎packages/react-client/src/ReactFlightClientHostConfig.js‎

Copy file name to clipboardExpand all lines: packages/react-client/src/ReactFlightClientHostConfig.js
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
* @flow
88
*/
99

10-
/* eslint-disable react-internal/invariant-args */
11-
12-
import invariant from 'shared/invariant';
10+
/* eslint-disable react-internal/prod-error-codes */
1311

1412
// We expect that our Rollup, Jest, and Flow configurations
1513
// always shim this module with the corresponding host config
@@ -19,4 +17,4 @@ import invariant from 'shared/invariant';
1917
// sure that if we *do* accidentally break the configuration,
2018
// the failure isn't silent.
2119

22-
invariant(false, 'This module must be shimmed by a specific renderer.');
20+
throw new Error('This module must be shimmed by a specific renderer.');
Collapse file

‎packages/react-client/src/ReactFlightClientHostConfigNoStream.js‎

Copy file name to clipboardExpand all lines: packages/react-client/src/ReactFlightClientHostConfigNoStream.js
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,22 @@ export type StringDecoder = void;
1212
export const supportsBinaryStreams = false;
1313

1414
export function createStringDecoder(): void {
15+
// eslint-disable-next-line react-internal/prod-error-codes
1516
throw new Error('Should never be called');
1617
}
1718

1819
export function readPartialStringChunk(
1920
decoder: StringDecoder,
2021
buffer: Uint8Array,
2122
): string {
23+
// eslint-disable-next-line react-internal/prod-error-codes
2224
throw new Error('Should never be called');
2325
}
2426

2527
export function readFinalStringChunk(
2628
decoder: StringDecoder,
2729
buffer: Uint8Array,
2830
): string {
31+
// eslint-disable-next-line react-internal/prod-error-codes
2932
throw new Error('Should never be called');
3033
}
Collapse file

‎packages/react-debug-tools/src/ReactDebugHooks.js‎

Copy file name to clipboardExpand all lines: packages/react-debug-tools/src/ReactDebugHooks.js
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import type {OpaqueIDType} from 'react-reconciler/src/ReactFiberHostConfig';
2323
import {NoMode} from 'react-reconciler/src/ReactTypeOfMode';
2424

2525
import ErrorStackParser from 'error-stack-parser';
26-
import invariant from 'shared/invariant';
2726
import ReactSharedInternals from 'shared/ReactSharedInternals';
2827
import {REACT_OPAQUE_ID_TYPE} from 'shared/ReactSymbols';
2928
import {
@@ -107,7 +106,7 @@ function nextHook(): null | Hook {
107106
}
108107

109108
function getCacheForType<T>(resourceType: () => T): T {
110-
invariant(false, 'Not implemented.');
109+
throw new Error('Not implemented.');
111110
}
112111

113112
function readContext<T>(context: ReactContext<T>): T {
Collapse file

‎packages/react-dom/src/client/ReactDOM.js‎

Copy file name to clipboardExpand all lines: packages/react-dom/src/client/ReactDOM.js
+4-5Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import {
3939
import {createPortal as createPortalImpl} from 'react-reconciler/src/ReactPortal';
4040
import {canUseDOM} from 'shared/ExecutionEnvironment';
4141
import ReactVersion from 'shared/ReactVersion';
42-
import invariant from 'shared/invariant';
4342
import {
4443
warnUnstableRenderSubtreeIntoContainer,
4544
enableNewReconciler,
@@ -108,10 +107,10 @@ function createPortal(
108107
container: Container,
109108
key: ?string = null,
110109
): React$Portal {
111-
invariant(
112-
isValidContainer(container),
113-
'Target container is not a DOM element.',
114-
);
110+
if (!isValidContainer(container)) {
111+
throw new Error('Target container is not a DOM element.');
112+
}
113+
115114
// TODO: pass ReactDOM portal implementation as third argument
116115
// $FlowFixMe The Flow type is opaque but there's no way to actually create it.
117116
return createPortalImpl(children, container, null, key);

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.