first commit

This commit is contained in:
s.golasch
2023-08-01 13:49:46 +02:00
commit 1fc239fd54
20238 changed files with 3112246 additions and 0 deletions

238
build/node_modules/prepack/lib/react/ReactElementSet.js generated vendored Normal file
View File

@@ -0,0 +1,238 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
var _realm = require("../realm.js");
var _index = require("../values/index.js");
var _invariant = require("../invariant.js");
var _invariant2 = _interopRequireDefault(_invariant);
var _utils = require("./utils");
var _index2 = require("../methods/index.js");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
// ReactElementSet keeps records around of the values
// of ReactElement/JSX nodes so we can return the same immutable values
// where possible, i.e. <div /> === <div />
//
// Rather than uses hashes, this class uses linked Maps to track equality of objects.
// It does this by recursively iterating through objects, by their properties/symbols and using
// each property key as a map, and then from that map, each value as a map. The value
// then links to the subsequent property/symbol in the object. This approach ensures insertion
// is maintained through all objects.
var ReactElementSet = function () {
function ReactElementSet(realm, equivalenceSet) {
_classCallCheck(this, ReactElementSet);
this.realm = realm;
this.equivalenceSet = equivalenceSet;
this.reactElementRoot = new Map();
this.objectRoot = new Map();
this.arrayRoot = new Map();
this.emptyArray = new _index.ArrayValue(realm);
this.emptyObject = new _index.ObjectValue(realm, realm.intrinsics.ObjectPrototype);
}
_createClass(ReactElementSet, [{
key: "_createNode",
value: function _createNode() {
return {
map: new Map(),
value: null
};
}
}, {
key: "_getKey",
value: function _getKey(key, map) {
if (!map.has(key)) {
map.set(key, new Map());
}
return map.get(key);
}
}, {
key: "_getValue",
value: function _getValue(val, map) {
if (val instanceof _index.StringValue || val instanceof _index.NumberValue) {
val = val.value;
} else if (val instanceof _index.AbstractValue) {
val = this.equivalenceSet.add(val);
} else if (val instanceof _index.ArrayValue) {
val = this._getArrayValue(val);
} else if (val instanceof _index.ObjectValue && !(val instanceof _index.FunctionValue)) {
val = this._getObjectValue(val);
}
if (!map.has(val)) {
map.set(val, this._createNode());
}
return map.get(val);
}
// for objects: [key/symbol] -> [key/symbol]... as nodes
}, {
key: "_getObjectValue",
value: function _getObjectValue(object) {
if ((0, _utils.isReactElement)(object)) {
return this.add(object);
}
var currentMap = this.objectRoot;
var result = void 0;
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = object.properties[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _ref = _step.value;
var _ref2 = _slicedToArray(_ref, 1);
var propName = _ref2[0];
currentMap = this._getKey(propName, currentMap);
var prop = (0, _index2.Get)(this.realm, object, propName);
result = this._getValue(prop, currentMap);
currentMap = result.map;
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = object.symbols[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var _ref3 = _step2.value;
var _ref4 = _slicedToArray(_ref3, 1);
var symbol = _ref4[0];
currentMap = this._getKey(symbol, currentMap);
var prop = (0, _index2.Get)(this.realm, object, symbol);
result = this._getValue(prop, currentMap);
currentMap = result.map;
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
if (result === undefined) {
return this.emptyObject;
}
if (result.value === null) {
result.value = object;
}
return result.value;
}
// for arrays: [0] -> [1] -> [2]... as nodes
}, {
key: "_getArrayValue",
value: function _getArrayValue(array) {
var lengthValue = (0, _index2.Get)(this.realm, array, "length");
(0, _invariant2.default)(lengthValue instanceof _index.NumberValue);
var length = lengthValue.value;
var currentMap = this.arrayRoot;
var result = void 0;
for (var i = 0; i < length; i++) {
currentMap = this._getKey(i, currentMap);
var element = (0, _index2.Get)(this.realm, array, "" + i);
result = this._getValue(element, currentMap);
currentMap = result.map;
}
if (result === undefined) {
return this.emptyArray;
}
if (result.value === null) {
result.value = array;
}
return result.value;
}
}, {
key: "add",
value: function add(reactElement) {
var currentMap = this.reactElementRoot;
// type
currentMap = this._getKey("type", currentMap);
var type = (0, _index2.Get)(this.realm, reactElement, "type");
var result = this._getValue(type, currentMap);
currentMap = result.map;
// key
currentMap = this._getKey("key", currentMap);
var key = (0, _index2.Get)(this.realm, reactElement, "key");
result = this._getValue(key, currentMap);
currentMap = result.map;
// ref
currentMap = this._getKey("ref", currentMap);
var ref = (0, _index2.Get)(this.realm, reactElement, "ref");
result = this._getValue(ref, currentMap);
currentMap = result.map;
// props
currentMap = this._getKey("props", currentMap);
var props = (0, _index2.Get)(this.realm, reactElement, "props");
result = this._getValue(props, currentMap);
currentMap = result.map;
if (result.value === null) {
result.value = reactElement;
}
(0, _invariant2.default)(result.value instanceof _index.ObjectValue);
return result.value;
}
}]);
return ReactElementSet;
}();
exports.default = ReactElementSet;
//# sourceMappingURL=ReactElementSet.js.map

File diff suppressed because one or more lines are too long

107
build/node_modules/prepack/lib/react/branching.js generated vendored Normal file
View File

@@ -0,0 +1,107 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.BranchState = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
var _realm = require("../realm.js");
var _index = require("../values/index.js");
require("../serializer/types.js");
var _utils = require("./utils");
var _errors = require("./errors.js");
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
// Branch state is used to capture branched ReactElements so they can be analyzed and compared
// once all branches have been processed. This allows us to add keys to the respective ReactElement
// objects depending on various heuristics (if they have the same "type" for example)
// A new branch state is created on a branch status of "NEW_BRANCH" and is reset to null once the branch is no
// longer new
// Branch status is used for when Prepack returns an abstract value from a render
// that results in a conditional path occuring. This can be problematic for reconcilation
// as the reconciler then needs to understand if this is the start of a new branch, or if
// it's actually deep into an existing branch. If it's a new branch, we need to apply
// keys to the root JSX element so that it keeps it identity (because we're folding trees).
// Furthermore, we also need to bail-out of folding class components where they have lifecycle
// events, as we can't merge lifecycles of mutliple trees when branched reliably
var BranchState = exports.BranchState = function () {
function BranchState() {
_classCallCheck(this, BranchState);
this._branchesToValidate = [];
}
_createClass(BranchState, [{
key: "_applyBranchedLogicValue",
value: function _applyBranchedLogicValue(realm, reactSerializerState, value) {
var _this = this;
if (value instanceof _index.StringValue || value instanceof _index.NumberValue || value instanceof _index.BooleanValue || value instanceof _index.NullValue || value instanceof _index.UndefinedValue) {
// terminal values
} else if (value instanceof _index.ObjectValue && (0, _utils.isReactElement)(value)) {
(0, _utils.addKeyToReactElement)(realm, reactSerializerState, value);
} else if (value instanceof _index.ArrayValue) {
(0, _utils.mapOverArrayValue)(realm, value, function (elementValue) {
_this._applyBranchedLogicValue(realm, reactSerializerState, elementValue);
});
} else if (value instanceof _index.AbstractValue) {
var length = value.args.length;
if (length > 0) {
for (var i = 0; i < length; i++) {
this._applyBranchedLogicValue(realm, reactSerializerState, value.args[i]);
}
}
} else {
throw new _errors.ExpectedBailOut("Unsupported value encountered when applying branched logic to values");
}
}
}, {
key: "applyBranchedLogic",
value: function applyBranchedLogic(realm, reactSerializerState) {
var reactElementType = void 0;
var applyBranchedLogic = false;
for (var i = 0; i < this._branchesToValidate.length; i++) {
var _type = this._branchesToValidate[i].type;
if (reactElementType === undefined) {
reactElementType = _type;
} else if (_type !== reactElementType) {
// the types of the ReactElements do not match, so apply branch logic
applyBranchedLogic = true;
break;
}
}
if (applyBranchedLogic) {
for (var _i = 0; _i < this._branchesToValidate.length; _i++) {
this._applyBranchedLogicValue(realm, reactSerializerState, this._branchesToValidate[_i].value);
}
}
}
}, {
key: "captureBranchedValue",
value: function captureBranchedValue(type, value) {
this._branchesToValidate.push({ type: type, value: value });
return value;
}
}]);
return BranchState;
}();
//# sourceMappingURL=branching.js.map

File diff suppressed because one or more lines are too long

224
build/node_modules/prepack/lib/react/components.js generated vendored Normal file
View File

@@ -0,0 +1,224 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); /**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
exports.getInitialProps = getInitialProps;
exports.getInitialContext = getInitialContext;
exports.createSimpleClassInstance = createSimpleClassInstance;
exports.createClassInstance = createClassInstance;
var _realm = require("../realm.js");
var _index = require("../values/index.js");
var _utils = require("../flow/utils.js");
var _babelTypes = require("babel-types");
var t = _interopRequireWildcard(_babelTypes);
var _abstractObjectFactories = require("../flow/abstractObjectFactories.js");
var _utils2 = require("./utils");
var _errors = require("./errors.js");
var _index2 = require("../methods/index.js");
var _singletons = require("../singletons.js");
var _invariant = require("../invariant.js");
var _invariant2 = _interopRequireDefault(_invariant);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
var lifecycleMethods = new Set(["componentWillUnmount", "componentDidMount", "componentWillMount", "componentDidUpdate", "componentWillUpdate", "componentDidCatch", "componentWillReceiveProps"]);
function getInitialProps(realm, componentType) {
var propsName = null;
var propTypes = null;
if ((0, _utils2.valueIsClassComponent)(realm, componentType)) {
propsName = "this.props";
// if flow is not required, do not try to construct the object from Flow types
if (realm.react.flowRequired) {
// it's a class component, so we need to check the type on for props of the component prototype
var superTypeParameters = componentType.$SuperTypeParameters;
if (superTypeParameters !== undefined) {
throw new _errors.ExpectedBailOut("props on class components not yet supported");
}
}
} else {
// otherwise it's a functional component, where the first paramater of the function is "props" (if it exists)
if (componentType.$FormalParameters.length > 0) {
var firstParam = componentType.$FormalParameters[0];
if (t.isIdentifier(firstParam)) {
propsName = firstParam.name;
}
// if flow is not required, do not try to construct the object from Flow types
if (realm.react.flowRequired) {
var propsTypeAnnotation = firstParam.typeAnnotation !== undefined && firstParam.typeAnnotation;
// we expect that if there's a props paramater, it should always have Flow annotations
if (!propsTypeAnnotation) {
throw new _errors.ExpectedBailOut("root component missing Flow type annotations for the \"props\" paramater");
}
propTypes = (0, _utils.flowAnnotationToObjectTypeTemplate)(propsTypeAnnotation);
}
}
}
return (0, _abstractObjectFactories.createAbstractObjectFromFlowTypes)(realm, propsName, propTypes);
}
function getInitialContext(realm, componentType) {
var contextName = null;
var contextTypes = null;
if ((0, _utils2.valueIsClassComponent)(realm, componentType)) {
// it's a class component, so we need to check the type on for context of the component prototype
var superTypeParameters = componentType.$SuperTypeParameters;
contextName = "this.context";
if (superTypeParameters !== undefined) {
throw new _errors.ExpectedBailOut("context on class components not yet supported");
}
} else {
// otherwise it's a functional component, where the second paramater of the function is "context" (if it exists)
if (componentType.$FormalParameters.length > 1) {
var secondParam = componentType.$FormalParameters[1];
if (t.isIdentifier(secondParam)) {
contextName = secondParam.name;
}
var contextTypeAnnotation = secondParam.typeAnnotation !== undefined && secondParam.typeAnnotation;
// we expect that if there's a context param, it should always have Flow annotations
if (!contextTypeAnnotation) {
throw new _errors.ExpectedBailOut("root component missing Flow type annotations for the \"context\" paramater");
}
contextTypes = (0, _utils.flowAnnotationToObjectTypeTemplate)(contextTypeAnnotation);
}
}
return (0, _abstractObjectFactories.createAbstractObjectFromFlowTypes)(realm, contextName, contextTypes);
}
function createSimpleClassInstance(realm, componentType, props, context) {
var componentPrototype = (0, _index2.Get)(realm, componentType, "prototype");
(0, _invariant2.default)(componentPrototype instanceof _index.ObjectValue);
// create an instance object and disable serialization as we don't want to output the internals we set below
var instance = new _index.ObjectValue(realm, componentPrototype, "this", true);
var allowedPropertyAccess = new Set(["props", "context"]);
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = componentPrototype.properties[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _ref = _step.value;
var _ref2 = _slicedToArray(_ref, 1);
var name = _ref2[0];
if (lifecycleMethods.has(name)) {
// this error will result in the simple class falling back to a complex class
throw new _errors.SimpleClassBailOut("lifecycle methods are not supported on simple classes");
} else if (name !== "constructor") {
allowedPropertyAccess.add(name);
_singletons.Properties.Set(realm, instance, name, (0, _index2.Get)(realm, componentPrototype, name), true);
}
}
// assign props
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
_singletons.Properties.Set(realm, instance, "props", props, true);
// assign context
_singletons.Properties.Set(realm, instance, "context", context, true);
// as this object is simple, we want to check if any access to anything other than
// "this.props" or "this.context" or methods on the class occur
var $GetOwnProperty = instance.$GetOwnProperty;
instance.$GetOwnProperty = function (P) {
if (!allowedPropertyAccess.has(P)) {
// this error will result in the simple class falling back to a complex class
throw new _errors.SimpleClassBailOut("access to basic class instance properties is not supported on simple classes");
}
return $GetOwnProperty.call(instance, P);
};
// enable serialization to support simple instance variables properties
instance.refuseSerialization = false;
// return the instance
return instance;
}
function createClassInstance(realm, componentType, props, context) {
var componentPrototype = (0, _index2.Get)(realm, componentType, "prototype");
(0, _invariant2.default)(componentPrototype instanceof _index.ObjectValue);
// create an instance object and disable serialization as we don't want to output the internals we set below
var instance = new _index.ObjectValue(realm, componentPrototype, "this", true);
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = componentPrototype.properties[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var _ref3 = _step2.value;
var _ref4 = _slicedToArray(_ref3, 1);
var name = _ref4[0];
if (name !== "constructor") {
_singletons.Properties.Set(realm, instance, name, (0, _index2.Get)(realm, componentPrototype, name), true);
}
}
// assign state
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
_singletons.Properties.Set(realm, instance, "state", (0, _abstractObjectFactories.createAbstractObject)(realm, "this.state", null), true);
// assign refs
_singletons.Properties.Set(realm, instance, "refs", (0, _abstractObjectFactories.createAbstractObject)(realm, "this.refs", null), true);
// assign props
_singletons.Properties.Set(realm, instance, "props", props, true);
// assign context
_singletons.Properties.Set(realm, instance, "context", context, true);
// enable serialization to support simple instance variables properties
instance.refuseSerialization = false;
// return the instance in an abstract object
return (0, _abstractObjectFactories.createAbstractObject)(realm, "this", null, instance);
}
//# sourceMappingURL=components.js.map

File diff suppressed because one or more lines are too long

49
build/node_modules/prepack/lib/react/errors.js generated vendored Normal file
View File

@@ -0,0 +1,49 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// ExpectedBailOut is like an error, that gets thrown during the reconcilation phase
// allowing the reconcilation to continue on other branches of the tree, the message
// given to ExpectedBailOut will be assigned to the value.$BailOutReason property and serialized
// as a comment in the output source to give the user hints as to what they need to do
// to fix the bail-out case
var ExpectedBailOut = exports.ExpectedBailOut = function ExpectedBailOut(message) {
_classCallCheck(this, ExpectedBailOut);
this.message = message;
var self = new Error(message);
Object.setPrototypeOf(self, ExpectedBailOut.prototype);
return self;
};
Object.setPrototypeOf(ExpectedBailOut, Error);
Object.setPrototypeOf(ExpectedBailOut.prototype, Error.prototype);
// SimpleClassBailOuts only occur when a simple class instance is created and used
// bailing out here will result in a complex class instance being created after
// and an alternative complex class component route being used
var SimpleClassBailOut = exports.SimpleClassBailOut = function SimpleClassBailOut(message) {
_classCallCheck(this, SimpleClassBailOut);
var self = new Error(message);
Object.setPrototypeOf(self, SimpleClassBailOut.prototype);
return self;
};
Object.setPrototypeOf(SimpleClassBailOut, Error);
Object.setPrototypeOf(SimpleClassBailOut.prototype, Error.prototype);
//# sourceMappingURL=errors.js.map

1
build/node_modules/prepack/lib/react/errors.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../src/react/errors.js"],"names":["ExpectedBailOut","message","self","Error","Object","setPrototypeOf","prototype","SimpleClassBailOut"],"mappings":";;;;;;;;AAAA;;;;;;;;;AAWA;AACA;AACA;AACA;AACA;IACaA,e,WAAAA,e,GAEX,yBAAYC,OAAZ,EAA6B;AAAA;;AAC3B,OAAKA,OAAL,GAAeA,OAAf;AACA,MAAIC,OAAO,IAAIC,KAAJ,CAAUF,OAAV,CAAX;AACAG,SAAOC,cAAP,CAAsBH,IAAtB,EAA4BF,gBAAgBM,SAA5C;AACA,SAAOJ,IAAP;AACD,C;;AAEHE,OAAOC,cAAP,CAAsBL,eAAtB,EAAuCG,KAAvC;AACAC,OAAOC,cAAP,CAAsBL,gBAAgBM,SAAtC,EAAiDH,MAAMG,SAAvD;;AAEA;AACA;AACA;;IACaC,kB,WAAAA,kB,GAEX,4BAAYN,OAAZ,EAA6B;AAAA;;AAC3B,MAAIC,OAAO,IAAIC,KAAJ,CAAUF,OAAV,CAAX;AACAG,SAAOC,cAAP,CAAsBH,IAAtB,EAA4BK,mBAAmBD,SAA/C;AACA,SAAOJ,IAAP;AACD,C;;AAEHE,OAAOC,cAAP,CAAsBE,kBAAtB,EAA0CJ,KAA1C;AACAC,OAAOC,cAAP,CAAsBE,mBAAmBD,SAAzC,EAAoDH,MAAMG,SAA1D","file":"errors.js","sourcesContent":["/**\n * Copyright (c) 2017-present, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\n/* @flow */\n\n// ExpectedBailOut is like an error, that gets thrown during the reconcilation phase\n// allowing the reconcilation to continue on other branches of the tree, the message\n// given to ExpectedBailOut will be assigned to the value.$BailOutReason property and serialized\n// as a comment in the output source to give the user hints as to what they need to do\n// to fix the bail-out case\nexport class ExpectedBailOut {\n message: string;\n constructor(message: string) {\n this.message = message;\n let self = new Error(message);\n Object.setPrototypeOf(self, ExpectedBailOut.prototype);\n return self;\n }\n}\nObject.setPrototypeOf(ExpectedBailOut, Error);\nObject.setPrototypeOf(ExpectedBailOut.prototype, Error.prototype);\n\n// SimpleClassBailOuts only occur when a simple class instance is created and used\n// bailing out here will result in a complex class instance being created after\n// and an alternative complex class component route being used\nexport class SimpleClassBailOut {\n message: string;\n constructor(message: string) {\n let self = new Error(message);\n Object.setPrototypeOf(self, SimpleClassBailOut.prototype);\n return self;\n }\n}\nObject.setPrototypeOf(SimpleClassBailOut, Error);\nObject.setPrototypeOf(SimpleClassBailOut.prototype, Error.prototype);\n"]}

251
build/node_modules/prepack/lib/react/hoisting.js generated vendored Normal file
View File

@@ -0,0 +1,251 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); /**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
exports.canHoistFunction = canHoistFunction;
exports.canHoistReactElement = canHoistReactElement;
var _realm = require("../realm.js");
var _index = require("../values/index.js");
var _index2 = require("../methods/index.js");
var _invariant = require("../invariant.js");
var _invariant2 = _interopRequireDefault(_invariant);
var _utils = require("./utils.js");
var _ResidualHeapVisitor = require("../serializer/ResidualHeapVisitor.js");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// a nested object of a React Element should be hoisted where all its properties are known
// at evaluation time to be safe to hoist (because of the heuristics of a React render)
function canHoistObject(realm, object, residualHeapVisitor) {
if ((0, _utils.isReactElement)(object)) {
return canHoistReactElement(realm, object, residualHeapVisitor);
}
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = object.properties[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _ref = _step.value;
var _ref2 = _slicedToArray(_ref, 1);
var propName = _ref2[0];
var prop = (0, _index2.Get)(realm, object, propName);
if (!canHoistValue(realm, prop, residualHeapVisitor)) {
return false;
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = object.symbols[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var _ref3 = _step2.value;
var _ref4 = _slicedToArray(_ref3, 1);
var symbol = _ref4[0];
var prop = (0, _index2.Get)(realm, object, symbol);
if (!canHoistValue(realm, prop, residualHeapVisitor)) {
return false;
}
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
return true;
}
function canHoistArray(realm, array, residualHeapVisitor) {
var lengthValue = (0, _index2.Get)(realm, array, "length");
(0, _invariant2.default)(lengthValue instanceof _index.NumberValue);
var length = lengthValue.value;
for (var i = 0; i < length; i++) {
var element = (0, _index2.Get)(realm, array, "" + i);
if (!canHoistValue(realm, element, residualHeapVisitor)) {
return false;
}
}
return true;
}
function canHoistFunction(realm, func, residualHeapVisitor) {
if (realm.react.hoistableFunctions.has(func)) {
// cast because Flow thinks that we may have set a value to be something other than a boolean?
return realm.react.hoistableFunctions.get(func);
}
if (residualHeapVisitor === undefined) {
return false;
}
// get the function instance
var functionInstance = residualHeapVisitor.functionInstances.get(func);
// we can safely hoist the function if the residual bindings hoistable too
if (functionInstance !== undefined) {
(0, _invariant2.default)(functionInstance.residualFunctionBindings instanceof Map);
var residualBindings = functionInstance.residualFunctionBindings;
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = undefined;
try {
for (var _iterator3 = residualBindings[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var _ref5 = _step3.value;
var _ref6 = _slicedToArray(_ref5, 2);
var _ref6$ = _ref6[1];
var declarativeEnvironmentRecord = _ref6$.declarativeEnvironmentRecord;
var value = _ref6$.value;
// if declarativeEnvironmentRecord is null, it's likely a global binding
// so we can assume that we can still hoist this function
if (declarativeEnvironmentRecord !== null) {
(0, _invariant2.default)(value instanceof _index.Value);
if (!canHoistValue(realm, value, residualHeapVisitor)) {
return false;
}
}
}
} catch (err) {
_didIteratorError3 = true;
_iteratorError3 = err;
} finally {
try {
if (!_iteratorNormalCompletion3 && _iterator3.return) {
_iterator3.return();
}
} finally {
if (_didIteratorError3) {
throw _iteratorError3;
}
}
}
realm.react.hoistableFunctions.set(func, true);
return true;
}
realm.react.hoistableFunctions.set(func, false);
return false;
}
function canHoistAbstract(realm, abstract, residualHeapVisitor) {
// get the scopes for this abstract value
var scopes = residualHeapVisitor.values.get(abstract);
// we can safely hoist abstracts that are created in the common scope
if (scopes !== undefined) {
var _iteratorNormalCompletion4 = true;
var _didIteratorError4 = false;
var _iteratorError4 = undefined;
try {
for (var _iterator4 = scopes[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
var scope = _step4.value;
var currentAdditionalFunction = residualHeapVisitor.commonScope;
(0, _invariant2.default)(currentAdditionalFunction instanceof _index.FunctionValue);
if (scope === currentAdditionalFunction.parent) {
return true;
}
}
} catch (err) {
_didIteratorError4 = true;
_iteratorError4 = err;
} finally {
try {
if (!_iteratorNormalCompletion4 && _iterator4.return) {
_iterator4.return();
}
} finally {
if (_didIteratorError4) {
throw _iteratorError4;
}
}
}
}
return false;
}
function isPrimitive(realm, value) {
return value instanceof _index.StringValue || value instanceof _index.NumberValue || value instanceof _index.SymbolValue || value instanceof _index.BooleanValue || value === realm.intrinsics.null || value === realm.intrinsics.undefined;
}
function canHoistValue(realm, value, residualHeapVisitor) {
if (value instanceof _index.ArrayValue && canHoistArray(realm, value, residualHeapVisitor) || value instanceof _index.FunctionValue && canHoistFunction(realm, value, residualHeapVisitor) || value instanceof _index.ObjectValue && canHoistObject(realm, value, residualHeapVisitor) || value instanceof _index.AbstractValue && canHoistAbstract(realm, value, residualHeapVisitor) || isPrimitive(realm, value)) {
return true;
}
return false;
}
function canHoistReactElement(realm, reactElement, residualHeapVisitor) {
if (realm.react.hoistableReactElements.has(reactElement)) {
// cast because Flow thinks that we may have set a value to be something other than a boolean?
return realm.react.hoistableReactElements.get(reactElement);
}
if (residualHeapVisitor === undefined) {
return false;
}
var type = (0, _index2.Get)(realm, reactElement, "type");
var ref = (0, _index2.Get)(realm, reactElement, "ref");
var key = (0, _index2.Get)(realm, reactElement, "key");
var props = (0, _index2.Get)(realm, reactElement, "props");
if (canHoistValue(realm, type, residualHeapVisitor) &&
// we can't hoist string "refs" or if they're abstract, as they might be abstract strings
!(ref instanceof String || ref instanceof _index.AbstractValue) && canHoistValue(realm, ref, residualHeapVisitor) && canHoistValue(realm, key, residualHeapVisitor) && canHoistValue(realm, props, residualHeapVisitor)) {
realm.react.hoistableReactElements.set(reactElement, true);
return true;
}
realm.react.hoistableReactElements.set(reactElement, false);
return false;
}
//# sourceMappingURL=hoisting.js.map

1
build/node_modules/prepack/lib/react/hoisting.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

72
build/node_modules/prepack/lib/react/jsx.js generated vendored Normal file
View File

@@ -0,0 +1,72 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.convertExpressionToJSXIdentifier = convertExpressionToJSXIdentifier;
exports.convertJSXExpressionToIdentifier = convertJSXExpressionToIdentifier;
exports.convertKeyValueToJSXAttribute = convertKeyValueToJSXAttribute;
var _babelTypes = require("babel-types");
var t = _interopRequireWildcard(_babelTypes);
var _invariant = require("../invariant.js");
var _invariant2 = _interopRequireDefault(_invariant);
var _utils = require("./utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function convertExpressionToJSXIdentifier(expr, isRoot) {
switch (expr.type) {
case "ThisExpression":
(0, _invariant2.default)(isRoot === false, "invalid conversion of root expression to JSXIdentifier for ThisExpression");
return t.jSXIdentifier("this");
case "Identifier":
var name = expr.name;
(0, _invariant2.default)(
// ensure the 1st character of the string is uppercase
// for a component unless it is not the root
isRoot === false || (0, _utils.isReactComponent)(name), "invalid JSXIdentifer from Identifier, Identifier name must be uppercase");
return t.jSXIdentifier(name);
case "StringLiteral":
var value = expr.value;
(0, _invariant2.default)(
// ensure the 1st character of the string is lowercase
// otherwise it will appear as a component
value.length > 0 && value[0] === value[0].toLowerCase(), "invalid JSXIdentifer from string, strings must be lowercase");
return t.jSXIdentifier(value);
case "MemberExpression":
(0, _invariant2.default)(expr.computed === false, "Cannot inline computed expressions in JSX type.");
return t.jSXMemberExpression(convertExpressionToJSXIdentifier(expr.object, false), convertExpressionToJSXIdentifier(expr.property, false));
default:
(0, _invariant2.default)(false, "Invalid JSX type");
}
} /**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
function convertJSXExpressionToIdentifier(expr) {
switch (expr.type) {
case "JSXIdentifier":
return t.identifier(expr.name);
case "JSXMemberExpression":
return t.memberExpression(convertJSXExpressionToIdentifier(expr.object), convertJSXExpressionToIdentifier(expr.property));
default:
(0, _invariant2.default)(false, "Invalid JSX type");
}
}
function convertKeyValueToJSXAttribute(key, expr) {
return t.jSXAttribute(t.jSXIdentifier(key), expr.type === "StringLiteral" ? expr : t.jSXExpressionContainer(expr));
}
//# sourceMappingURL=jsx.js.map

1
build/node_modules/prepack/lib/react/jsx.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../src/react/jsx.js"],"names":["convertExpressionToJSXIdentifier","convertJSXExpressionToIdentifier","convertKeyValueToJSXAttribute","t","expr","isRoot","type","jSXIdentifier","name","value","length","toLowerCase","computed","jSXMemberExpression","object","property","identifier","memberExpression","key","jSXAttribute","jSXExpressionContainer"],"mappings":";;;;;QAsBgBA,gC,GAAAA,gC;QAqCAC,gC,GAAAA,gC;QAgBAC,6B,GAAAA,6B;;AAhEhB;;IAAYC,C;;AAQZ;;;;AACA;;;;;;AAEO,SAASH,gCAAT,CACLI,IADK,EAELC,MAFK,EAGkD;AACvD,UAAQD,KAAKE,IAAb;AACE,SAAK,gBAAL;AACE,+BAAUD,WAAW,KAArB;AACA,aAAOF,EAAEI,aAAF,CAAgB,MAAhB,CAAP;AACF,SAAK,YAAL;AACE,UAAIC,OAAOJ,KAAKI,IAAhB;AACA;AACE;AACA;AACAH,iBAAW,KAAX,IAAoB,6BAAiBG,IAAjB,CAHtB,EAIE,yEAJF;AAMA,aAAOL,EAAEI,aAAF,CAAgBC,IAAhB,CAAP;AACF,SAAK,eAAL;AACE,UAAIC,QAAQL,KAAKK,KAAjB;AACA;AACE;AACA;AACAA,YAAMC,MAAN,GAAe,CAAf,IAAoBD,MAAM,CAAN,MAAaA,MAAM,CAAN,EAASE,WAAT,EAHnC,EAIE,6DAJF;AAMA,aAAOR,EAAEI,aAAF,CAAgBE,KAAhB,CAAP;AACF,SAAK,kBAAL;AACE,+BAAUL,KAAKQ,QAAL,KAAkB,KAA5B,EAAmC,iDAAnC;AACA,aAAOT,EAAEU,mBAAF,CACLb,iCAAiCI,KAAKU,MAAtC,EAA8C,KAA9C,CADK,EAEHd,iCAAiCI,KAAKW,QAAtC,EAAgD,KAAhD,CAFG,CAAP;AAIF;AACE,+BAAU,KAAV,EAAiB,kBAAjB;AA7BJ;AA+BD,C,CAzDD;;;;;;;;;AA2DO,SAASd,gCAAT,CACLG,IADK,EAE4C;AACjD,UAAQA,KAAKE,IAAb;AACE,SAAK,eAAL;AACE,aAAOH,EAAEa,UAAF,CAAaZ,KAAKI,IAAlB,CAAP;AACF,SAAK,qBAAL;AACE,aAAOL,EAAEc,gBAAF,CACLhB,iCAAiCG,KAAKU,MAAtC,CADK,EAEJb,iCAAiCG,KAAKW,QAAtC,CAFI,CAAP;AAIF;AACE,+BAAU,KAAV,EAAiB,kBAAjB;AATJ;AAWD;;AAEM,SAASb,6BAAT,CAAuCgB,GAAvC,EAAoDd,IAApD,EAA+E;AACpF,SAAOD,EAAEgB,YAAF,CAAehB,EAAEI,aAAF,CAAgBW,GAAhB,CAAf,EAAqCd,KAAKE,IAAL,KAAc,eAAd,GAAgCF,IAAhC,GAAuCD,EAAEiB,sBAAF,CAAyBhB,IAAzB,CAA5E,CAAP;AACD","file":"jsx.js","sourcesContent":["/**\n * Copyright (c) 2017-present, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\n/* @flow */\n\nimport * as t from \"babel-types\";\nimport type {\n BabelNodeExpression,\n BabelNodeJSXMemberExpression,\n BabelNodeJSXIdentifier,\n BabelNodeIdentifier,\n BabelNodeMemberExpression,\n} from \"babel-types\";\nimport invariant from \"../invariant.js\";\nimport { isReactComponent } from \"./utils\";\n\nexport function convertExpressionToJSXIdentifier(\n expr: BabelNodeExpression,\n isRoot: boolean\n): BabelNodeJSXMemberExpression | BabelNodeJSXIdentifier {\n switch (expr.type) {\n case \"ThisExpression\":\n invariant(isRoot === false, `invalid conversion of root expression to JSXIdentifier for ThisExpression`);\n return t.jSXIdentifier(\"this\");\n case \"Identifier\":\n let name = expr.name;\n invariant(\n // ensure the 1st character of the string is uppercase\n // for a component unless it is not the root\n isRoot === false || isReactComponent(name),\n \"invalid JSXIdentifer from Identifier, Identifier name must be uppercase\"\n );\n return t.jSXIdentifier(name);\n case \"StringLiteral\":\n let value = expr.value;\n invariant(\n // ensure the 1st character of the string is lowercase\n // otherwise it will appear as a component\n value.length > 0 && value[0] === value[0].toLowerCase(),\n \"invalid JSXIdentifer from string, strings must be lowercase\"\n );\n return t.jSXIdentifier(value);\n case \"MemberExpression\":\n invariant(expr.computed === false, \"Cannot inline computed expressions in JSX type.\");\n return t.jSXMemberExpression(\n convertExpressionToJSXIdentifier(expr.object, false),\n ((convertExpressionToJSXIdentifier(expr.property, false): any): BabelNodeJSXIdentifier)\n );\n default:\n invariant(false, \"Invalid JSX type\");\n }\n}\n\nexport function convertJSXExpressionToIdentifier(\n expr: BabelNodeExpression\n): BabelNodeMemberExpression | BabelNodeIdentifier {\n switch (expr.type) {\n case \"JSXIdentifier\":\n return t.identifier(expr.name);\n case \"JSXMemberExpression\":\n return t.memberExpression(\n convertJSXExpressionToIdentifier(expr.object),\n (convertJSXExpressionToIdentifier(expr.property): any)\n );\n default:\n invariant(false, \"Invalid JSX type\");\n }\n}\n\nexport function convertKeyValueToJSXAttribute(key: string, expr: BabelNodeExpression) {\n return t.jSXAttribute(t.jSXIdentifier(key), expr.type === \"StringLiteral\" ? expr : t.jSXExpressionContainer(expr));\n}\n"]}

301
build/node_modules/prepack/lib/react/reconcilation.js generated vendored Normal file
View File

@@ -0,0 +1,301 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Reconciler = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
var _realm = require("../realm.js");
var _modules = require("../serializer/modules.js");
var _index = require("../values/index.js");
var _types = require("../serializer/types.js");
var _utils = require("./utils");
var _index2 = require("../methods/index.js");
var _invariant = require("../invariant.js");
var _invariant2 = _interopRequireDefault(_invariant);
var _errors = require("../errors.js");
var _branching = require("./branching.js");
var _components = require("./components.js");
var _errors2 = require("./errors.js");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Reconciler = exports.Reconciler = function () {
function Reconciler(realm, moduleTracer, statistics, reactSerializerState, simpleClassComponents) {
_classCallCheck(this, Reconciler);
this.realm = realm;
this.moduleTracer = moduleTracer;
this.statistics = statistics;
this.reactSerializerState = reactSerializerState;
this.simpleClassComponents = simpleClassComponents;
}
_createClass(Reconciler, [{
key: "render",
value: function render(componentType) {
var _this = this;
return this.realm.wrapInGlobalEnv(function () {
return (
// TODO: (sebmarkbage): You could use the return value of this to detect if there are any mutations on objects other
// than newly created ones. Then log those to the error logger. That'll help us track violations in
// components. :)
_this.realm.evaluateForEffects(function () {
// initialProps and initialContext are created from Flow types from:
// - if a functional component, the 1st and 2nd paramater of function
// - if a class component, use this.props and this.context
// if there are no Flow types for props or context, we will throw a
// FatalError, unless it's a functional component that has no paramater
// i.e let MyComponent = () => <div>Hello world</div>
try {
var initialProps = (0, _components.getInitialProps)(_this.realm, componentType);
var initialContext = (0, _components.getInitialContext)(_this.realm, componentType);
var _renderComponent2 = _this._renderComponent(componentType, initialProps, initialContext, "ROOT", null),
result = _renderComponent2.result;
_this.statistics.optimizedTrees++;
return result;
} catch (error) {
// if there was a bail-out on the root component in this reconcilation process, then this
// should be an invariant as the user has explicitly asked for this component to get folded
if (error instanceof _errors2.ExpectedBailOut) {
var diagnostic = new _errors.CompilerDiagnostic("__registerReactComponentRoot() failed due to - " + error.message, _this.realm.currentLocation, "PP0020", "FatalError");
_this.realm.handleError(diagnostic);
throw new _errors.FatalError();
}
throw error;
}
},
/*state*/null, "react component: " + componentType.getName())
);
});
}
}, {
key: "_renderComplexClassComponent",
value: function _renderComplexClassComponent(componentType, props, context, branchStatus, branchState) {
if (branchStatus !== "ROOT") {
throw new _errors2.ExpectedBailOut("only complex class components at the root of __registerReactComponentRoot() are supported");
}
// create a new instance of this React class component
var instance = (0, _components.createClassInstance)(this.realm, componentType, props, context);
// get the "render" method off the instance
var renderMethod = (0, _index2.Get)(this.realm, instance, "render");
(0, _invariant2.default)(renderMethod instanceof _index.ECMAScriptSourceFunctionValue && renderMethod.$Call, "Expected render method to be a FunctionValue with $Call method");
// the render method doesn't have any arguments, so we just assign the context of "this" to be the instance
return renderMethod.$Call(instance, []);
}
}, {
key: "_renderSimpleClassComponent",
value: function _renderSimpleClassComponent(componentType, props, context, branchStatus, branchState) {
// create a new simple instance of this React class component
var instance = (0, _components.createSimpleClassInstance)(this.realm, componentType, props, context);
// get the "render" method off the instance
var renderMethod = (0, _index2.Get)(this.realm, instance, "render");
(0, _invariant2.default)(renderMethod instanceof _index.ECMAScriptSourceFunctionValue && renderMethod.$Call, "Expected render method to be a FunctionValue with $Call method");
// the render method doesn't have any arguments, so we just assign the context of "this" to be the instance
return renderMethod.$Call(instance, []);
}
}, {
key: "_renderFunctionalComponent",
value: function _renderFunctionalComponent(componentType, props, context) {
(0, _invariant2.default)(componentType.$Call, "Expected componentType to be a FunctionValue with $Call method");
return componentType.$Call(this.realm.intrinsics.undefined, [props, context]);
}
}, {
key: "_renderComponent",
value: function _renderComponent(componentType, props, context, branchStatus, branchState) {
var value = void 0;
var childContext = context;
// first we check if it's a legacy class component
if ((0, _utils.valueIsLegacyCreateClassComponent)(this.realm, componentType)) {
throw new _errors2.ExpectedBailOut("components created with create-react-class are not supported");
} else if ((0, _utils.valueIsClassComponent)(this.realm, componentType)) {
// We first need to know what type of class component we're dealing with.
// A "simple" class component is defined as:
//
// - having only a "render" method or many method, i.e. render(), _renderHeader(), _renderFooter()
// - having no lifecycle events
// - having no state
// - having no instance variables
//
// the only things a class component should be able to access on "this" are:
// - this.props
// - this.context
// - this._someRenderMethodX() etc
//
// Otherwise, the class component is a "complex" one.
// To begin with, we don't know what type of component it is, so we try and render it as if it were
// a simple component using the above heuristics. If an error occurs during this process, we assume
// that the class wasn't simple, then try again with the "complex" heuristics.
try {
value = this._renderSimpleClassComponent(componentType, props, context, branchStatus, branchState);
this.simpleClassComponents.add(value);
} catch (error) {
// if we get back a SimpleClassBailOut error, we know that this class component
// wasn't a simple one and is likely to be a complex class component instead
if (error instanceof _errors2.SimpleClassBailOut) {
// the component was not simple, so we continue with complex case
} else {
// else we rethrow the error
throw error;
}
}
// handle the complex class component if there is not value
if (value === undefined) {
value = this._renderComplexClassComponent(componentType, props, context, branchStatus, branchState);
}
} else {
value = this._renderFunctionalComponent(componentType, props, context);
}
(0, _invariant2.default)(value !== undefined);
return {
result: this._resolveDeeply(value, context, branchStatus === "ROOT" ? "NO_BRANCH" : branchStatus, branchState),
childContext: childContext
};
}
}, {
key: "_resolveDeeply",
value: function _resolveDeeply(value, context, branchStatus, branchState) {
if (value instanceof _index.StringValue || value instanceof _index.NumberValue || value instanceof _index.BooleanValue || value instanceof _index.NullValue || value instanceof _index.UndefinedValue) {
// terminal values
return value;
} else if (value instanceof _index.AbstractValue) {
var length = value.args.length;
if (length > 0) {
var newBranchState = new _branching.BranchState();
// TODO investigate what other kinds than "conditional" might be safe to deeply resolve
for (var i = 0; i < length; i++) {
value.args[i] = this._resolveDeeply(value.args[i], context, "NEW_BRANCH", newBranchState);
}
newBranchState.applyBranchedLogic(this.realm, this.reactSerializerState);
}
return value;
}
// TODO investigate what about other iterables type objects
if (value instanceof _index.ArrayValue) {
this._resolveFragment(value, context, branchStatus, branchState);
return value;
}
if (value instanceof _index.ObjectValue && (0, _utils.isReactElement)(value)) {
// we call value reactElement, to make it clearer what we're dealing with in this block
var reactElement = value;
var typeValue = (0, _index2.Get)(this.realm, reactElement, "type");
var propsValue = (0, _index2.Get)(this.realm, reactElement, "props");
var refValue = (0, _index2.Get)(this.realm, reactElement, "ref");
if (typeValue instanceof _index.StringValue) {
// terminal host component. Start evaluating its children.
if (propsValue instanceof _index.ObjectValue) {
var childrenProperty = propsValue.properties.get("children");
if (childrenProperty) {
var childrenPropertyDescriptor = childrenProperty.descriptor;
// if the descriptor is undefined, the property is likely deleted, if it exists
// proceed to resolve the children
if (childrenPropertyDescriptor !== undefined) {
var childrenPropertyValue = childrenPropertyDescriptor.value;
(0, _invariant2.default)(childrenPropertyValue instanceof _index.Value, "Bad \"children\" prop passed in JSXElement");
var resolvedChildren = this._resolveDeeply(childrenPropertyValue, context, branchStatus, branchState);
childrenPropertyDescriptor.value = resolvedChildren;
}
}
}
return reactElement;
}
// we do not support "ref" on <Component /> ReactElements
if (!(refValue instanceof _index.NullValue)) {
this._assignBailOutMessage(reactElement, "Bail-out: refs are not supported on <Components />");
return reactElement;
}
if (!(propsValue instanceof _index.ObjectValue || propsValue instanceof _index.AbstractObjectValue)) {
this._assignBailOutMessage(reactElement, "Bail-out: props on <Component /> was not not an ObjectValue or an AbstractValue");
return reactElement;
}
if (!(typeValue instanceof _index.ECMAScriptSourceFunctionValue)) {
this._assignBailOutMessage(reactElement, "Bail-out: type on <Component /> was not a ECMAScriptSourceFunctionValue");
return reactElement;
}
try {
var _renderComponent3 = this._renderComponent(typeValue, propsValue, context, branchStatus === "NEW_BRANCH" ? "BRANCH" : branchStatus, null),
result = _renderComponent3.result;
if (result instanceof _index.UndefinedValue) {
this._assignBailOutMessage(reactElement, "Bail-out: undefined was returned from render");
if (branchStatus === "NEW_BRANCH" && branchState) {
return branchState.captureBranchedValue(typeValue, reactElement);
}
return reactElement;
}
this.statistics.inlinedComponents++;
if (branchStatus === "NEW_BRANCH" && branchState) {
return branchState.captureBranchedValue(typeValue, result);
}
return result;
} catch (error) {
// assign a bail out message
if (error instanceof _errors2.ExpectedBailOut) {
this._assignBailOutMessage(reactElement, "Bail-out: " + error.message);
} else if (error instanceof _errors.FatalError) {
this._assignBailOutMessage(reactElement, "Evaluation bail-out");
} else {
throw error;
}
// a child component bailed out during component folding, so return the function value and continue
if (branchStatus === "NEW_BRANCH" && branchState) {
return branchState.captureBranchedValue(typeValue, reactElement);
}
return reactElement;
}
} else {
throw new _errors2.ExpectedBailOut("unsupported value type during reconcilation");
}
}
}, {
key: "_assignBailOutMessage",
value: function _assignBailOutMessage(reactElement, message) {
// $BailOutReason is a field on ObjectValue that allows us to specify a message
// that gets serialized as a comment node during the ReactElement serialization stage
if (reactElement.$BailOutReason !== undefined) {
// merge bail out messages if one already exists
reactElement.$BailOutReason += ", " + message;
} else {
reactElement.$BailOutReason = message;
}
}
}, {
key: "_resolveFragment",
value: function _resolveFragment(arrayValue, context, branchStatus, branchState) {
var _this2 = this;
(0, _utils.mapOverArrayValue)(this.realm, arrayValue, function (elementValue, elementPropertyDescriptor) {
elementPropertyDescriptor.value = _this2._resolveDeeply(elementValue, context, branchStatus, branchState);
});
}
}]);
return Reconciler;
}();
//# sourceMappingURL=reconcilation.js.map

File diff suppressed because one or more lines are too long

255
build/node_modules/prepack/lib/react/utils.js generated vendored Normal file
View File

@@ -0,0 +1,255 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isReactElement = isReactElement;
exports.getReactSymbol = getReactSymbol;
exports.isTagName = isTagName;
exports.isReactComponent = isReactComponent;
exports.valueIsClassComponent = valueIsClassComponent;
exports.valueIsReactLibraryObject = valueIsReactLibraryObject;
exports.valueIsLegacyCreateClassComponent = valueIsLegacyCreateClassComponent;
exports.addKeyToReactElement = addKeyToReactElement;
exports.getUniqueReactElementKey = getUniqueReactElementKey;
exports.mapOverArrayValue = mapOverArrayValue;
exports.convertSimpleClassComponentToFunctionalComponent = convertSimpleClassComponentToFunctionalComponent;
var _realm = require("../realm.js");
var _index = require("../values/index.js");
var _index2 = require("../methods/index.js");
var _BinaryExpression = require("../evaluators/BinaryExpression.js");
require("../serializer/types.js");
var _invariant = require("../invariant.js");
var _invariant2 = _interopRequireDefault(_invariant);
var _singletons = require("../singletons.js");
var _babelTraverse = require("babel-traverse");
var _babelTraverse2 = _interopRequireDefault(_babelTraverse);
var _babelTypes = require("babel-types");
var t = _interopRequireWildcard(_babelTypes);
var _errors = require("../errors.js");
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
function isReactElement(val) {
if (val instanceof _index.ObjectValue && val.properties.has("$$typeof")) {
var realm = val.$Realm;
var $$typeof = (0, _index2.Get)(realm, val, "$$typeof");
var globalObject = realm.$GlobalObject;
var globalSymbolValue = (0, _index2.Get)(realm, globalObject, "Symbol");
if (globalSymbolValue === realm.intrinsics.undefined) {
if ($$typeof instanceof _index.NumberValue) {
return $$typeof.value === 0xeac7;
}
} else if ($$typeof instanceof _index.SymbolValue) {
var symbolFromRegistry = realm.globalSymbolRegistry.find(function (e) {
return e.$Symbol === $$typeof;
});
return symbolFromRegistry !== undefined && symbolFromRegistry.$Key === "react.element";
}
}
return false;
}
function getReactSymbol(symbolKey, realm) {
var reactSymbol = realm.react.symbols.get(symbolKey);
if (reactSymbol !== undefined) {
return reactSymbol;
}
var SymbolFor = realm.intrinsics.Symbol.properties.get("for");
if (SymbolFor !== undefined) {
var SymbolForDescriptor = SymbolFor.descriptor;
if (SymbolForDescriptor !== undefined) {
var SymbolForValue = SymbolForDescriptor.value;
if (SymbolForValue !== undefined && typeof SymbolForValue.$Call === "function") {
reactSymbol = SymbolForValue.$Call(realm.intrinsics.Symbol, [new _index.StringValue(realm, symbolKey)]);
realm.react.symbols.set(symbolKey, reactSymbol);
}
}
}
(0, _invariant2.default)(reactSymbol instanceof _index.SymbolValue, "Symbol(\"" + symbolKey + "\") could not be found in realm");
return reactSymbol;
}
function isTagName(ast) {
return ast.type === "JSXIdentifier" && /^[a-z]|\-/.test(ast.name);
}
function isReactComponent(name) {
return name.length > 0 && name[0] === name[0].toUpperCase();
}
function valueIsClassComponent(realm, value) {
if (!(value instanceof _index.FunctionValue)) {
return false;
}
if (value.$Prototype instanceof _index.ObjectValue) {
var prototype = (0, _index2.Get)(realm, value.$Prototype, "prototype");
if (prototype instanceof _index.ObjectValue) {
return prototype.properties.has("isReactComponent");
}
}
return false;
}
// logger isn't typed otherwise it will increase flow cycle length :()
function valueIsReactLibraryObject(realm, value, logger) {
if (realm.react.reactLibraryObject === value) {
return true;
}
// we check that the object is the React or React-like library by checking for
// core properties that should exist on it
var reactVersion = logger.tryQuery(function () {
return (0, _index2.Get)(realm, value, "version");
}, undefined, false);
if (!(reactVersion instanceof _index.StringValue)) {
return false;
}
var reactCreateElement = logger.tryQuery(function () {
return (0, _index2.Get)(realm, value, "createElement");
}, undefined, false);
if (!(reactCreateElement instanceof _index.FunctionValue)) {
return false;
}
var reactCloneElement = logger.tryQuery(function () {
return (0, _index2.Get)(realm, value, "cloneElement");
}, undefined, false);
if (!(reactCloneElement instanceof _index.FunctionValue)) {
return false;
}
var reactIsValidElement = logger.tryQuery(function () {
return (0, _index2.Get)(realm, value, "isValidElement");
}, undefined, false);
if (!(reactIsValidElement instanceof _index.FunctionValue)) {
return false;
}
var reactComponent = logger.tryQuery(function () {
return (0, _index2.Get)(realm, value, "Component");
}, undefined, false);
if (!(reactComponent instanceof _index.FunctionValue)) {
return false;
}
var reactChildren = logger.tryQuery(function () {
return (0, _index2.Get)(realm, value, "Children");
}, undefined, false);
if (!(reactChildren instanceof _index.ObjectValue)) {
return false;
}
return false;
}
function valueIsLegacyCreateClassComponent(realm, value) {
if (!(value instanceof _index.FunctionValue)) {
return false;
}
var prototype = (0, _index2.Get)(realm, value, "prototype");
if (prototype instanceof _index.ObjectValue) {
return prototype.properties.has("__reactAutoBindPairs");
}
return false;
}
function addKeyToReactElement(realm, reactSerializerState, reactElement) {
// we need to apply a key when we're branched
var currentKeyValue = (0, _index2.Get)(realm, reactElement, "key") || realm.intrinsics.null;
var uniqueKey = getUniqueReactElementKey("", reactSerializerState.usedReactElementKeys);
var newKeyValue = new _index.StringValue(realm, uniqueKey);
if (currentKeyValue !== realm.intrinsics.null) {
newKeyValue = (0, _BinaryExpression.computeBinary)(realm, "+", currentKeyValue, newKeyValue);
}
// TODO: This might not be safe in DEV because these objects are frozen (Object.freeze).
// We should probably go behind the scenes in this case to by-pass that.
reactElement.$Set("key", newKeyValue, reactElement);
}
// we create a unique key for each JSXElement to prevent collisions
// otherwise React will detect a missing/conflicting key at runtime and
// this can break the reconcilation of JSXElements in arrays
function getUniqueReactElementKey(index, usedReactElementKeys) {
var key = void 0;
do {
key = Math.random().toString(36).replace(/[^a-z]+/g, "").substring(0, 2);
} while (usedReactElementKeys.has(key));
usedReactElementKeys.add(key);
if (index !== undefined) {
return "" + key + index;
}
return key;
}
// a helper function to map over ArrayValues
function mapOverArrayValue(realm, array, mapFunc) {
var lengthValue = (0, _index2.Get)(realm, array, "length");
(0, _invariant2.default)(lengthValue instanceof _index.NumberValue, "Invalid length on ArrayValue during reconcilation");
var length = lengthValue.value;
for (var i = 0; i < length; i++) {
var elementProperty = array.properties.get("" + i);
var elementPropertyDescriptor = elementProperty && elementProperty.descriptor;
(0, _invariant2.default)(elementPropertyDescriptor, "Invalid ArrayValue[" + i + "] descriptor");
var elementValue = elementPropertyDescriptor.value;
if (elementValue instanceof _index.Value) {
mapFunc(elementValue, elementPropertyDescriptor);
}
}
}
function convertSimpleClassComponentToFunctionalComponent(realm, componentType, additionalFunctionEffects) {
var prototype = componentType.properties.get("prototype");
(0, _invariant2.default)(prototype);
(0, _invariant2.default)(prototype.descriptor);
prototype.descriptor.configurable = true;
_singletons.Properties.DeletePropertyOrThrow(realm, componentType, "prototype");
// set the prototype back to an object
componentType.$Prototype = realm.intrinsics.FunctionPrototype;
// give the function the functional components params
componentType.$FormalParameters = [t.identifier("props"), t.identifier("context")];
// add a transform to occur after the additional function has serialized the body of the class
additionalFunctionEffects.transforms.push(function (body) {
// as this was a class before and is now a functional component, we need to replace
// this.props and this.context to props and context, via the function arugments
var funcNode = t.functionExpression(null, [], t.blockStatement(body));
(0, _babelTraverse2.default)(t.file(t.program([t.expressionStatement(funcNode)])), {
"Identifier|ThisExpression": function IdentifierThisExpression(path) {
var node = path.node;
if (t.isIdentifier(node) && node.name === "this" || t.isThisExpression(node)) {
var parentPath = path.parentPath;
var parentNode = parentPath.node;
if (t.isMemberExpression(parentNode)) {
// remove the "this" from the member
parentPath.replaceWith(parentNode.property);
} else {
throw new _errors.FatalError("conversion of a simple class component to functional component failed due to \"this\" not being replaced");
}
}
}
}, undefined, undefined, undefined);
});
}
//# sourceMappingURL=utils.js.map

1
build/node_modules/prepack/lib/react/utils.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long