Files
asciidisco.com/build/node_modules/prepack/lib/evaluators/LabeledStatement.js
2023-08-01 13:49:46 +02:00

81 lines
2.7 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = function (ast, strictCode, env, realm) {
//1. Let newLabelSet be a new empty List.
var newLabelSet = [];
//2. Return LabelledEvaluation of this LabelledStatement with argument newLabelSet.
return LabelledEvaluation(newLabelSet, ast, strictCode, env, realm);
};
var _index = require("../values/index.js");
var _completions = require("../completions.js");
var _invariant = require("../invariant.js");
var _invariant2 = _interopRequireDefault(_invariant);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// ECMA262 13.13.14
function LabelledEvaluation(labelSet, ast, strictCode, env, realm) {
// LabelledStatement:LabelIdentifier:LabelledItem
switch (ast.type) {
case "LabeledStatement":
var labeledAst = ast;
// 1. Let label be the StringValue of LabelIdentifier.
var label = labeledAst.label.name;
// 2. Append label as an element of labelSet.
labelSet.push(label);
// 3. Let stmtResult be LabelledEvaluation of LabelledItem with argument labelSet.
var normalCompletionStmtResult = void 0;
try {
normalCompletionStmtResult = LabelledEvaluation(labelSet, labeledAst.body, strictCode, env, realm);
} catch (stmtResult) {
// 4. If stmtResult.[[Type]] is break and SameValue(stmtResult.[[Target]], label) is true, then
if (stmtResult instanceof _completions.BreakCompletion && stmtResult.target === label) {
// a. Let stmtResult be NormalCompletion(stmtResult.[[Value]]).
normalCompletionStmtResult = stmtResult.value;
} else {
// 5. Return Completion(stmtResult).
throw stmtResult;
}
}
// 5. Return Completion(stmtResult).
return normalCompletionStmtResult;
case "VariableDeclaration":
if (ast.kind === "var") {
var _r = env.evaluate(ast, strictCode);
(0, _invariant2.default)(_r instanceof _index.Value);
return _r;
}
// fall through to throw
case "FunctionDeclaration":
case "ClassDeclaration":
throw realm.createErrorThrowCompletion(realm.intrinsics.SyntaxError, ast.type + " may not have a label");
default:
var r = env.evaluate(ast, strictCode, labelSet);
(0, _invariant2.default)(r instanceof _index.Value);
return r;
}
}
// ECMA262 13.13.15
/**
* 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.
*/
//# sourceMappingURL=LabeledStatement.js.map