prepack
Version:
Execute a JS bundle, serialize global state and side effects to a snapshot that can be quickly restored.
69 lines (50 loc) • 2.45 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _index = require("./index.js");
var t = _interopRequireWildcard(require("@babel/types"));
var _invariant = _interopRequireDefault(require("../invariant.js"));
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)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
/**
* 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.
*/
/* Non built-in ECMAScript function objects with source code */
class ECMAScriptSourceFunctionValue extends _index.ECMAScriptFunctionValue {
constructor(realm, intrinsicName) {
super(realm, intrinsicName);
}
initialize(params, body) {
let node = body;
this.getHash(); // Record the sequence number, reflecting when this function was initialized for the first time
if (node.uniqueOrderedTag === undefined) node.uniqueOrderedTag = this.$Realm.functionBodyUniqueTagSeed++;
this.$ECMAScriptCode = body;
this.$FormalParameters = params;
} // Override.
getName() {
const uniqueTag = this.$ECMAScriptCode.uniqueOrderedTag; // Should only be called after the function is initialized.
(0, _invariant.default)(uniqueTag);
return this.__originalName ? this.__originalName : `function#${uniqueTag}`;
}
hasDefaultLength() {
let params = this.$FormalParameters;
let expected = params.length;
for (let i = 0; i < params.length; i++) {
let param = params[i];
if (t.isAssignmentPattern(param) || t.isRestElement(param)) {
expected = i;
break;
}
}
return expected === this.getLength();
}
}
exports.default = ECMAScriptSourceFunctionValue;
//# sourceMappingURL=ECMAScriptSourceFunctionValue.js.map