UNPKG

js-slang

Version:

Javascript-based implementations of Source, written in Typescript

39 lines 1.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MultipleDeclarationsError = void 0; const astring_1 = require("astring"); const errors_1 = require("../../errors"); class MultipleDeclarationsError extends errors_1.RuleError { constructor(node) { super(node); this.fixs = node.declarations.map(declaration => ({ type: 'VariableDeclaration', kind: node.kind, loc: declaration.loc, declarations: [declaration] })); } explain() { return 'Multiple declarations in a single statement.'; } elaborate() { const fixs = this.fixs.map(n => ' ' + (0, astring_1.generate)(n)).join('\n'); return 'Split the variable declaration into multiple lines as follows\n\n' + fixs + '\n'; } } exports.MultipleDeclarationsError = MultipleDeclarationsError; const singleVariableDeclaration = { name: 'single-variable-declaration', checkers: { VariableDeclaration(node) { if (node.declarations.length > 1) { return [new MultipleDeclarationsError(node)]; } else { return []; } } } }; exports.default = singleVariableDeclaration; //# sourceMappingURL=singleVariableDeclaration.js.map