Skip to content

Commit c076560

Browse files
committed
add jsx-runtime and jsx-dev-runtime
1 parent 0705b72 commit c076560

19 files changed

+918
-228
lines changed

packages/react/index.classic.fb.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,5 @@ export {
5050
DEPRECATED_createResponder,
5151
// enableScopeAPI
5252
unstable_createScope,
53-
// enableJSXTransformAPI
54-
jsx,
55-
jsxs,
56-
jsxDEV,
5753
} from './src/React';
54+
export {jsx, jsxs, jsxDEV} from './src/jsx/ReactJSX';

packages/react/index.experimental.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,5 @@ export {
4545
unstable_withSuspenseConfig,
4646
// enableBlocksAPI
4747
block,
48-
// enableJSXTransformAPI
49-
jsx,
50-
jsxs,
51-
jsxDEV,
5248
} from './src/React';
49+
export {jsx, jsxs, jsxDEV} from './src/jsx/ReactJSX';

packages/react/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,5 @@ export {
7676
DEPRECATED_createResponder,
7777
unstable_createFundamental,
7878
unstable_createScope,
79-
jsx,
80-
jsxs,
81-
jsxDEV,
8279
} from './src/React';
80+
export {jsx, jsxs, jsxDEV} from './src/jsx/ReactJSX';

packages/react/index.modern.fb.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,5 @@ export {
4949
DEPRECATED_createResponder,
5050
// enableScopeAPI
5151
unstable_createScope,
52-
// enableJSXTransformAPI
53-
jsx,
54-
jsxs,
55-
jsxDEV,
5652
} from './src/React';
53+
export {jsx, jsxs, jsxDEV} from './src/jsx/ReactJSX';

packages/react/jsx-dev-runtime.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
export {Fragment, jsxDEV} from './src/jsx/ReactJSX';

packages/react/jsx-runtime.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
export {Fragment, jsx, jsxs} from './src/jsx/ReactJSX';

packages/react/npm/jsx-dev-runtime.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
if (process.env.NODE_ENV === 'production') {
4+
module.exports = require('./cjs/react-jsx-dev-runtime.production.min.js');
5+
} else {
6+
module.exports = require('./cjs/react-jsx-dev-runtime.development.js');
7+
}

packages/react/npm/jsx-runtime.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
if (process.env.NODE_ENV === 'production') {
4+
module.exports = require('./cjs/react-jsx-runtime.production.min.js');
5+
} else {
6+
module.exports = require('./cjs/react-jsx-runtime.development.js');
7+
}

packages/react/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
"build-info.json",
1515
"index.js",
1616
"cjs/",
17-
"umd/"
17+
"umd/",
18+
"jsx-runtime.js",
19+
"jsx-dev-runtime.js"
1820
],
1921
"main": "index.js",
2022
"repository": {

packages/react/src/React.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import {
2424
createFactory as createFactoryProd,
2525
cloneElement as cloneElementProd,
2626
isValidElement,
27-
jsx as jsxProd,
2827
} from './ReactElement';
2928
import {createContext} from './ReactContext';
3029
import {lazy} from './ReactLazy';
@@ -52,9 +51,6 @@ import {
5251
createElementWithValidation,
5352
createFactoryWithValidation,
5453
cloneElementWithValidation,
55-
jsxWithValidation,
56-
jsxWithValidationStatic,
57-
jsxWithValidationDynamic,
5854
} from './ReactElementValidator';
5955
import createMutableSource from './createMutableSource';
6056
import ReactSharedInternals from './ReactSharedInternals';
@@ -67,12 +63,6 @@ const createElement = __DEV__ ? createElementWithValidation : createElementProd;
6763
const cloneElement = __DEV__ ? cloneElementWithValidation : cloneElementProd;
6864
const createFactory = __DEV__ ? createFactoryWithValidation : createFactoryProd;
6965

70-
const jsxDEV = __DEV__ ? jsxWithValidation : undefined;
71-
const jsx = __DEV__ ? jsxWithValidationDynamic : jsxProd;
72-
// we may want to special case jsxs internally to take advantage of static children.
73-
// for now we can ship identical prod functions
74-
const jsxs = __DEV__ ? jsxWithValidationStatic : jsxProd;
75-
7666
const Children = {
7767
map,
7868
forEach,
@@ -127,9 +117,4 @@ export {
127117
createFundamental as unstable_createFundamental,
128118
// enableScopeAPI
129119
createScope as unstable_createScope,
130-
// enableJSXTransformAPI
131-
jsx,
132-
jsxs,
133-
// TODO: jsxDEV should not be exposed as a name. We might want to move it to a different entry point.
134-
jsxDEV,
135120
};

packages/react/src/ReactDebugCurrentFrame.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ export function setCurrentlyValidatingElement(element: null | ReactElement) {
2323
}
2424

2525
if (__DEV__) {
26+
ReactDebugCurrentFrame.setCurrentlyValidatingElement = function(
27+
element: null | ReactElement,
28+
) {
29+
if (__DEV__) {
30+
currentlyValidatingElement = element;
31+
}
32+
};
2633
// Stack implementation injected by the current renderer.
2734
ReactDebugCurrentFrame.getCurrentStack = (null: null | (() => string));
2835

packages/react/src/ReactElementValidator.js

Lines changed: 1 addition & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,10 @@ import {
2121
REACT_FRAGMENT_TYPE,
2222
REACT_ELEMENT_TYPE,
2323
} from 'shared/ReactSymbols';
24-
import {warnAboutSpreadingKeyToJSX} from 'shared/ReactFeatureFlags';
2524
import checkPropTypes from 'shared/checkPropTypes';
2625

2726
import ReactCurrentOwner from './ReactCurrentOwner';
28-
import {
29-
isValidElement,
30-
createElement,
31-
cloneElement,
32-
jsxDEV,
33-
} from './ReactElement';
27+
import {isValidElement, createElement, cloneElement} from './ReactElement';
3428
import {setCurrentlyValidatingElement} from './ReactDebugCurrentFrame';
3529

3630
let propTypesMisspellWarningShown;
@@ -39,8 +33,6 @@ if (__DEV__) {
3933
propTypesMisspellWarningShown = false;
4034
}
4135

42-
const hasOwnProperty = Object.prototype.hasOwnProperty;
43-
4436
function getDeclarationErrorAddendum() {
4537
if (ReactCurrentOwner.current) {
4638
const name = getComponentName(ReactCurrentOwner.current.type);
@@ -261,137 +253,6 @@ function validateFragmentProps(fragment) {
261253
}
262254
}
263255

264-
export function jsxWithValidation(
265-
type,
266-
props,
267-
key,
268-
isStaticChildren,
269-
source,
270-
self,
271-
) {
272-
const validType = isValidElementType(type);
273-
274-
// We warn in this case but don't throw. We expect the element creation to
275-
// succeed and there will likely be errors in render.
276-
if (!validType) {
277-
let info = '';
278-
if (
279-
type === undefined ||
280-
(typeof type === 'object' &&
281-
type !== null &&
282-
Object.keys(type).length === 0)
283-
) {
284-
info +=
285-
' You likely forgot to export your component from the file ' +
286-
"it's defined in, or you might have mixed up default and named imports.";
287-
}
288-
289-
const sourceInfo = getSourceInfoErrorAddendum(source);
290-
if (sourceInfo) {
291-
info += sourceInfo;
292-
} else {
293-
info += getDeclarationErrorAddendum();
294-
}
295-
296-
let typeString;
297-
if (type === null) {
298-
typeString = 'null';
299-
} else if (Array.isArray(type)) {
300-
typeString = 'array';
301-
} else if (type !== undefined && type.$$typeof === REACT_ELEMENT_TYPE) {
302-
typeString = `<${getComponentName(type.type) || 'Unknown'} />`;
303-
info =
304-
' Did you accidentally export a JSX literal instead of a component?';
305-
} else {
306-
typeString = typeof type;
307-
}
308-
309-
if (__DEV__) {
310-
console.error(
311-
'React.jsx: type is invalid -- expected a string (for ' +
312-
'built-in components) or a class/function (for composite ' +
313-
'components) but got: %s.%s',
314-
typeString,
315-
info,
316-
);
317-
}
318-
}
319-
320-
const element = jsxDEV(type, props, key, source, self);
321-
322-
// The result can be nullish if a mock or a custom function is used.
323-
// TODO: Drop this when these are no longer allowed as the type argument.
324-
if (element == null) {
325-
return element;
326-
}
327-
328-
// Skip key warning if the type isn't valid since our key validation logic
329-
// doesn't expect a non-string/function type and can throw confusing errors.
330-
// We don't want exception behavior to differ between dev and prod.
331-
// (Rendering will throw with a helpful message and as soon as the type is
332-
// fixed, the key warnings will appear.)
333-
334-
if (validType) {
335-
const children = props.children;
336-
if (children !== undefined) {
337-
if (isStaticChildren) {
338-
if (Array.isArray(children)) {
339-
for (let i = 0; i < children.length; i++) {
340-
validateChildKeys(children[i], type);
341-
}
342-
343-
if (Object.freeze) {
344-
Object.freeze(children);
345-
}
346-
} else {
347-
if (__DEV__) {
348-
console.error(
349-
'React.jsx: Static children should always be an array. ' +
350-
'You are likely explicitly calling React.jsxs or React.jsxDEV. ' +
351-
'Use the Babel transform instead.',
352-
);
353-
}
354-
}
355-
} else {
356-
validateChildKeys(children, type);
357-
}
358-
}
359-
}
360-
361-
if (__DEV__) {
362-
if (warnAboutSpreadingKeyToJSX) {
363-
if (hasOwnProperty.call(props, 'key')) {
364-
console.error(
365-
'React.jsx: Spreading a key to JSX is a deprecated pattern. ' +
366-
'Explicitly pass a key after spreading props in your JSX call. ' +
367-
'E.g. <%s {...props} key={key} />',
368-
getComponentName(type) || 'ComponentName',
369-
);
370-
}
371-
}
372-
}
373-
374-
if (type === REACT_FRAGMENT_TYPE) {
375-
validateFragmentProps(element);
376-
} else {
377-
validatePropTypes(element);
378-
}
379-
380-
return element;
381-
}
382-
383-
// These two functions exist to still get child warnings in dev
384-
// even with the prod transform. This means that jsxDEV is purely
385-
// opt-in behavior for better messages but that we won't stop
386-
// giving you warnings if you use production apis.
387-
export function jsxWithValidationStatic(type, props, key) {
388-
return jsxWithValidation(type, props, key, true);
389-
}
390-
391-
export function jsxWithValidationDynamic(type, props, key) {
392-
return jsxWithValidation(type, props, key, false);
393-
}
394-
395256
export function createElementWithValidation(type, props, children) {
396257
const validType = isValidElementType(type);
397258

0 commit comments

Comments
 (0)