UNPKG

js-slang

Version:

Javascript-based implementations of Source, written in Typescript

38 lines (37 loc) 1.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NoIfWithoutElseError = void 0; const astring_1 = require("astring"); const formatters_1 = require("../../../utils/formatters"); const errors_1 = require("../../errors"); const types_1 = require("../../../types"); class NoIfWithoutElseError extends errors_1.RuleError { explain() { return 'Missing "else" in "if-else" statement.'; } elaborate() { return (0, formatters_1.stripIndent) ` This "if" block requires corresponding "else" block which will be evaluated when ${(0, astring_1.generate)(this.node.test)} expression evaluates to false. Later in the course we will lift this restriction and allow "if" without else. `; } } exports.NoIfWithoutElseError = NoIfWithoutElseError; const noIfWithoutElse = { name: 'no-if-without-else', disableFromChapter: types_1.Chapter.SOURCE_3, checkers: { IfStatement(node) { if (!node.alternate) { return [new NoIfWithoutElseError(node)]; } else { return []; } } } }; exports.default = noIfWithoutElse; //# sourceMappingURL=noIfWithoutElse.js.map