@sudoo/marked
Version:
JavaScript & TypeScript code runner in JavaScript, safe with marked territory, asynchronous
45 lines (44 loc) • 2.17 kB
JavaScript
;
/**
* @author WMXPY
* @namespace Evaluate
* @description Import Declaration
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.importDeclarationEvaluator = exports.mountImportDeclaration = void 0;
const error_code_1 = require("../declare/error-code");
const error_1 = require("../util/error/error");
const import_1 = require("../util/import");
const flag_1 = require("../variable/flag");
const mountImportDeclaration = (sandbox) => {
sandbox.mount("ImportDeclaration", exports.importDeclarationEvaluator);
};
exports.mountImportDeclaration = mountImportDeclaration;
const importDeclarationEvaluator = function (node, scope, trace) {
return __awaiter(this, void 0, void 0, function* () {
if (!scope.isExecuteScope()) {
throw (0, error_1.error)(error_code_1.ERROR_CODE.IMPORT_ONLY_AVAILABLE_IN_ROOT_SCOPE, void 0, node, trace);
}
const nextTrace = trace.stack(node);
const source = yield this.execute(node.source, scope, nextTrace);
const bindResolveImport = import_1.resolveImport.bind(this);
const result = yield bindResolveImport(source, node, scope, trace, nextTrace);
if (result instanceof flag_1.Flag) {
return result;
}
if (!result) {
throw (0, error_1.error)(error_code_1.ERROR_CODE.MODULE_IS_NOT_PROVIDED, source, node, trace);
}
return;
});
};
exports.importDeclarationEvaluator = importDeclarationEvaluator;