89 lines
2.4 KiB
JavaScript
89 lines
2.4 KiB
JavaScript
"use strict";
|
|
|
|
var _realm = require("./realm.js");
|
|
|
|
var _errors = require("./errors.js");
|
|
|
|
var _index = require("./methods/index.js");
|
|
|
|
var _completions = require("./completions.js");
|
|
|
|
var _index2 = require("./values/index.js");
|
|
|
|
var _singletons = require("./singletons.js");
|
|
|
|
var _construct_realm = require("./construct_realm.js");
|
|
|
|
var _construct_realm2 = _interopRequireDefault(_construct_realm);
|
|
|
|
var _globals = require("./globals.js");
|
|
|
|
var _globals2 = _interopRequireDefault(_globals);
|
|
|
|
var _repl = require("repl");
|
|
|
|
var _repl2 = _interopRequireDefault(_repl);
|
|
|
|
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 serialize(realm, res) {
|
|
if (res && res instanceof _index2.Value) {
|
|
return res.serialize();
|
|
}
|
|
|
|
if (res && res instanceof _completions.ThrowCompletion) {
|
|
var context = new _realm.ExecutionContext();
|
|
realm.pushContext(context);
|
|
var err = void 0;
|
|
try {
|
|
var value = res.value;
|
|
if (value instanceof _index2.ObjectValue && (0, _index.InstanceofOperator)(realm, value, realm.intrinsics.Error)) {
|
|
err = new _errors.FatalError(_singletons.To.ToStringPartial(realm, (0, _index.Get)(realm, value, "message")));
|
|
err.stack = _singletons.To.ToStringPartial(realm, (0, _index.Get)(realm, value, "stack"));
|
|
} else {
|
|
err = new _errors.FatalError(_singletons.To.ToStringPartial(realm, value));
|
|
}
|
|
} finally {
|
|
realm.popContext(context);
|
|
}
|
|
return err;
|
|
}
|
|
|
|
return res;
|
|
}
|
|
|
|
var realm = (0, _construct_realm2.default)({
|
|
reactEnabled: true,
|
|
reactOutput: "jsx"
|
|
});
|
|
(0, _globals2.default)(realm);
|
|
|
|
_repl2.default.start({
|
|
prompt: "> ",
|
|
input: process.stdin,
|
|
output: process.stdout,
|
|
eval: function _eval(code, context, filename, callback) {
|
|
try {
|
|
var res = realm.$GlobalEnv.execute(code, "repl");
|
|
res = serialize(realm, res);
|
|
if (res instanceof Error) {
|
|
callback(res);
|
|
} else {
|
|
callback(null, res);
|
|
}
|
|
} catch (err) {
|
|
console.error(err);
|
|
callback(err);
|
|
}
|
|
}
|
|
});
|
|
//# sourceMappingURL=repl-cli.js.map
|