js-slang
Version:
Javascript-based implementations of Source, written in Typescript
32 lines • 1.01 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.NoVarError = void 0;
const astring_1 = require("astring");
const errors_1 = require("../../errors");
const helpers_1 = require("../../../utils/ast/helpers");
class NoVarError extends errors_1.RuleError {
explain() {
return 'Variable declaration using "var" is not allowed.';
}
elaborate() {
const { id: { name }, init } = (0, helpers_1.getSourceVariableDeclaration)(this.node);
const value = (0, astring_1.generate)(init);
return `Use keyword "let" instead, to declare a variable:\n\n\tlet ${name} = ${value};`;
}
}
exports.NoVarError = NoVarError;
const noVar = {
name: 'no-var',
checkers: {
VariableDeclaration(node) {
if (node.kind === 'var') {
return [new NoVarError(node)];
}
else {
return [];
}
}
}
};
exports.default = noVar;
//# sourceMappingURL=noVar.js.map
;