prepack
Version:
Execute a JS bundle, serialize global state and side effects to a snapshot that can be quickly restored.
59 lines (42 loc) • 2.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = function (ast, strictCode, env, realm) {
// 1. Let oldEnv be the running execution context's LexicalEnvironment.
let oldEnv = realm.getRunningContext().lexicalEnvironment;
// 2. Let blockEnv be NewDeclarativeEnvironment(oldEnv).
let blockEnv = _singletons.Environment.NewDeclarativeEnvironment(realm, oldEnv);
// 3. Perform BlockDeclarationInstantiation(StatementList, blockEnv).
_singletons.Environment.BlockDeclarationInstantiation(realm, strictCode, ast.body, blockEnv);
// 4. Set the running execution context's LexicalEnvironment to blockEnv.
realm.getRunningContext().lexicalEnvironment = blockEnv;
try {
// 5. Let blockValue be the result of evaluating StatementList.
let blockValue;
if (ast.directives) {
for (let directive of ast.directives) {
blockValue = new _index.StringValue(realm, directive.value.value);
}
}
let [res, bAst] = _singletons.Functions.PartiallyEvaluateStatements(ast.body, blockValue, strictCode, blockEnv, realm);
(0, _invariant2.default)(bAst.length > 0 || res instanceof _index.EmptyValue);
if (bAst.length === 0) return [res, t.emptyStatement(), []];
let rAst = t.blockStatement(bAst, ast.directives);
return [res, rAst, []];
} finally {
// 6. Set the running execution context's LexicalEnvironment to oldEnv.
realm.getRunningContext().lexicalEnvironment = oldEnv;
realm.onDestroyScope(blockEnv);
}
};
var _completions = require("../completions.js");
var _index = require("../values/index.js");
var _singletons = require("../singletons.js");
var _invariant = require("../invariant.js");
var _invariant2 = _interopRequireDefault(_invariant);
var _babelTypes = require("babel-types");
var t = _interopRequireWildcard(_babelTypes);
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 }; }
//# sourceMappingURL=BlockStatement.js.map