Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - convert public React core properties to strings so uglify/gcc can mangle #9293

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions src/isomorphic/React.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,35 +55,35 @@ if (__DEV__) {
var React = {
// Modern

Children: {
map: ReactChildren.map,
forEach: ReactChildren.forEach,
count: ReactChildren.count,
toArray: ReactChildren.toArray,
only: onlyChild,
'Children': {
'map': ReactChildren.map,
'forEach': ReactChildren.forEach,
'count': ReactChildren.count,
'toArray': ReactChildren.toArray,
'only': onlyChild,
},

Component: ReactBaseClasses.Component,
PureComponent: ReactBaseClasses.PureComponent,
'Component': ReactBaseClasses.Component,
'PureComponent': ReactBaseClasses.PureComponent,

createElement: createElement,
cloneElement: cloneElement,
isValidElement: ReactElement.isValidElement,
'createElement': createElement,
'cloneElement': cloneElement,
'isValidElement': ReactElement.isValidElement,

checkPropTypes: checkPropTypes,
'checkPropTypes': checkPropTypes,

// Classic

PropTypes: ReactPropTypes,
createClass: ReactClass.createClass,
createFactory: createFactory,
createMixin: createMixin,
'PropTypes': ReactPropTypes,
'createClass': ReactClass.createClass,
'createFactory': createFactory,
'createMixin': createMixin,

// This looks DOM specific but these are actually isomorphic helpers
// since they are just generating DOM strings.
DOM: ReactDOMFactories,
'DOM': ReactDOMFactories,

version: ReactVersion,
'version': ReactVersion,
};

module.exports = React;
12 changes: 6 additions & 6 deletions src/isomorphic/classic/element/ReactElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,16 @@ function defineRefPropWarningGetter(props, displayName) {
var ReactElement = function(type, key, ref, self, source, owner, props) {
var element = {
// This tag allow us to uniquely identify this as a React Element
$$typeof: REACT_ELEMENT_TYPE,
'$$typeof': REACT_ELEMENT_TYPE,

// Built-in properties that belong on the element
type: type,
key: key,
ref: ref,
props: props,
'type': type,
'key': key,
'ref': ref,
'props': props,

// Record the component responsible for creating this element.
_owner: owner,
'_owner': owner,
};

if (__DEV__) {
Expand Down
20 changes: 10 additions & 10 deletions src/isomorphic/modern/class/ReactBaseClasses.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ var warning = require('fbjs/lib/warning');
* Base class helpers for the updating state of a component.
*/
function ReactComponent(props, context, updater) {
this.props = props;
this.context = context;
this.refs = emptyObject;
this['props'] = props;
this['context'] = context;
this['refs'] = emptyObject;
// We initialize the default updater but the real one gets injected by the
// renderer.
this.updater = updater || ReactNoopUpdateQueue;
this['updater'] = updater || ReactNoopUpdateQueue;
}

ReactComponent.prototype.isReactComponent = {};
Expand Down Expand Up @@ -65,7 +65,7 @@ ReactComponent.prototype.setState = function(partialState, callback) {
'setState(...): takes an object of state variables to update or a ' +
'function which returns an object of state variables.',
);
this.updater.enqueueSetState(this, partialState, callback, 'setState');
this['updater'].enqueueSetState(this, partialState, callback, 'setState');
};

/**
Expand All @@ -83,7 +83,7 @@ ReactComponent.prototype.setState = function(partialState, callback) {
* @protected
*/
ReactComponent.prototype.forceUpdate = function(callback) {
this.updater.enqueueForceUpdate(this, callback, 'forceUpdate');
this['updater'].enqueueForceUpdate(this, callback, 'forceUpdate');
};

/**
Expand Down Expand Up @@ -131,12 +131,12 @@ if (__DEV__) {
*/
function ReactPureComponent(props, context, updater) {
// Duplicated from ReactComponent.
this.props = props;
this.context = context;
this.refs = emptyObject;
this['props'] = props;
this['context'] = context;
this['refs'] = emptyObject;
// We initialize the default updater but the real one gets injected by the
// renderer.
this.updater = updater || ReactNoopUpdateQueue;
this['updater'] = updater || ReactNoopUpdateQueue;
}

function ComponentDummy() {}
Expand Down
12 changes: 6 additions & 6 deletions src/isomorphic/modern/class/ReactNoopUpdateQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ var warning = require('fbjs/lib/warning');

function warnNoop(publicInstance, callerName) {
if (__DEV__) {
var constructor = publicInstance.constructor;
var constructor = publicInstance['constructor'];
warning(
false,
'%s(...): Can only update a mounted or mounting component. ' +
'This usually means you called %s() on an unmounted component. ' +
'This is a no-op.\n\nPlease check the code for the %s component.',
callerName,
callerName,
(constructor && (constructor.displayName || constructor.name)) ||
(constructor && (constructor['displayName'] || constructor['name'])) ||
'ReactClass',
);
}
Expand All @@ -40,7 +40,7 @@ var ReactNoopUpdateQueue = {
* @protected
* @final
*/
isMounted: function(publicInstance) {
'isMounted': function(publicInstance) {
return false;
},

Expand All @@ -59,7 +59,7 @@ var ReactNoopUpdateQueue = {
* @param {?string} Name of the calling function in the public API.
* @internal
*/
enqueueForceUpdate: function(publicInstance, callback, callerName) {
'enqueueForceUpdate': function(publicInstance, callback, callerName) {
warnNoop(publicInstance, 'forceUpdate');
},

Expand All @@ -76,7 +76,7 @@ var ReactNoopUpdateQueue = {
* @param {?string} Name of the calling function in the public API.
* @internal
*/
enqueueReplaceState: function(
'enqueueReplaceState': function(
publicInstance,
completeState,
callback,
Expand All @@ -97,7 +97,7 @@ var ReactNoopUpdateQueue = {
* @param {?string} Name of the calling function in the public API.
* @internal
*/
enqueueSetState: function(
'enqueueSetState': function(
publicInstance,
partialState,
callback,
Expand Down
10 changes: 5 additions & 5 deletions src/shared/utils/PooledClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ var addPoolingTo = function<T>(
};

var PooledClass = {
addPoolingTo: addPoolingTo,
oneArgumentPooler: (oneArgumentPooler: Pooler),
twoArgumentPooler: (twoArgumentPooler: Pooler),
threeArgumentPooler: (threeArgumentPooler: Pooler),
fourArgumentPooler: (fourArgumentPooler: Pooler),
'addPoolingTo': addPoolingTo,
'oneArgumentPooler': (oneArgumentPooler: Pooler),
'twoArgumentPooler': (twoArgumentPooler: Pooler),
'threeArgumentPooler': (threeArgumentPooler: Pooler),
'fourArgumentPooler': (fourArgumentPooler: Pooler),
};

module.exports = PooledClass;
6 changes: 3 additions & 3 deletions src/shared/utils/ReactElementSymbol.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

// The Symbol used to tag the ReactElement type. If there is no native Symbol
// nor polyfill, then a plain number is used for performance.
var REACT_ELEMENT_TYPE = (typeof Symbol === 'function' &&
Symbol.for &&
Symbol.for('react.element')) ||
const SymbolFor = Symbol.for;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will throw in environments without Symbol

var REACT_ELEMENT_TYPE = (typeof Symbol === 'function'
&& SymbolFor && SymbolFor('react.element')) ||
0xeac7;

module.exports = REACT_ELEMENT_TYPE;
4 changes: 2 additions & 2 deletions src/umd/ReactUMDEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ var React = require('React');
// `version` will be added here by the React module.
var ReactUMDEntry = Object.assign(
{
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: {
ReactCurrentOwner: require('react/lib/ReactCurrentOwner'),
'__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED': {
'ReactCurrentOwner': require('react/lib/ReactCurrentOwner'),
},
},
React,
Expand Down