"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.prepackVersion = undefined; exports.InitializationError = InitializationError; exports.prepackSources = prepackSources; exports.prepackString = prepackString; exports.prepack = prepack; exports.prepackFromAst = prepackFromAst; var _index = require("./serializer/index.js"); var _index2 = _interopRequireDefault(_index); var _construct_realm = require("./construct_realm.js"); var _construct_realm2 = _interopRequireDefault(_construct_realm); var _globals = require("./globals.js"); var _globals2 = _interopRequireDefault(_globals); var _babelTypes = require("babel-types"); var t = _interopRequireWildcard(_babelTypes); var _prepackOptions = require("./prepack-options"); var _errors = require("./errors.js"); var _completions = require("./completions.js"); var _options = require("./options"); var _invariant = require("./invariant.js"); var _invariant2 = _interopRequireDefault(_invariant); var _package = require("../package.json"); 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 }; } // IMPORTANT: This function is now deprecated and will go away in a future release. // Please use FatalError instead. /** * 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. */ /* APIs for running Prepack for code where a model of the environment is supplied as part of the code. */ function InitializationError() { var self = new Error("An error occurred while prepacking. See the error logs."); Object.setPrototypeOf(self, InitializationError.prototype); return self; } Object.setPrototypeOf(InitializationError, Error); Object.setPrototypeOf(InitializationError.prototype, Error.prototype); Object.setPrototypeOf(_errors.FatalError.prototype, InitializationError.prototype); function prepackSources(sources) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _options.defaultOptions; var debugChannel = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined; var realmOptions = (0, _prepackOptions.getRealmOptions)(options); realmOptions.errorHandler = options.errorHandler; var realm = (0, _construct_realm2.default)(realmOptions, debugChannel); (0, _globals2.default)(realm); if (typeof options.additionalGlobals === "function") { options.additionalGlobals(realm); } if (options.serialize || !options.residual) { var serializer = new _index2.default(realm, (0, _prepackOptions.getSerializerOptions)(options)); var serialized = serializer.init(sources, options.sourceMaps); //Turn off the debugger if there is one if (realm.debuggerInstance) { realm.debuggerInstance.shutdown(); } if (!serialized) { throw new _errors.FatalError("serializer failed"); } if (!options.residual) return serialized; var residualSources = [{ filePath: options.outputFilename || "unknown", fileContents: serialized.code, sourceMapContents: JSON.stringify(serialized.map) }]; var result = realm.$GlobalEnv.executePartialEvaluator(residualSources, options); if (result instanceof _completions.AbruptCompletion) throw result; // $FlowFixMe This looks like a Flow bug return result; } else { (0, _invariant2.default)(options.residual); var _result = realm.$GlobalEnv.executePartialEvaluator(sources, options); if (_result instanceof _completions.AbruptCompletion) throw _result; // $FlowFixMe This looks like a Flow bug return _result; } } /* deprecated: please use prepackSources instead. */ function prepackString(filename, code, sourceMap) { var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _options.defaultOptions; return prepackSources([{ filePath: filename, fileContents: code, sourceMapContents: sourceMap }], options); } /* deprecated: please use prepackSources instead. */ function prepack(code) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _options.defaultOptions; var filename = options.filename || "unknown"; var sources = [{ filePath: filename, fileContents: code }]; var realmOptions = (0, _prepackOptions.getRealmOptions)(options); realmOptions.errorHandler = options.errorHandler; var realm = (0, _construct_realm2.default)(realmOptions); (0, _globals2.default)(realm); var serializer = new _index2.default(realm, (0, _prepackOptions.getSerializerOptions)(options)); var serialized = serializer.init(sources, options.sourceMaps); if (!serialized) { throw new _errors.FatalError("serializer failed"); } return serialized; } /* deprecated: please use prepackSources instead. */ function prepackFromAst(ast, code) { var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _options.defaultOptions; if (ast && ast.type === "Program") { ast = t.file(ast, [], []); } (0, _invariant2.default)(ast && ast.type === "File"); var filename = options.filename || ast.loc && ast.loc.source || "unknown"; var sources = [{ filePath: filename, fileContents: code }]; var realm = (0, _construct_realm2.default)((0, _prepackOptions.getRealmOptions)(options)); (0, _globals2.default)(realm); var serializer = new _index2.default(realm, (0, _prepackOptions.getSerializerOptions)(options)); var serialized = serializer.init(sources, options.sourceMaps); if (!serialized) { throw new _errors.FatalError("serializer failed"); } return serialized; } var prepackVersion = exports.prepackVersion = _package.version; //# sourceMappingURL=prepack-standalone.js.map