js-slang
Version:
Javascript-based implementations of Source, written in Typescript
34 lines • 1.13 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.NoUnspecifiedLiteral = void 0;
const errors_1 = require("../../errors");
const specifiedLiterals = ['boolean', 'string', 'number'];
class NoUnspecifiedLiteral extends errors_1.RuleError {
explain() {
/**
* A check is used for RegExp to ensure that only RegExp are caught.
* Any other unspecified literal value should not be caught.
*/
const literal = this.node.value instanceof RegExp ? 'RegExp' : '';
return `'${literal}' literals are not allowed.`;
}
elaborate() {
return '';
}
}
exports.NoUnspecifiedLiteral = NoUnspecifiedLiteral;
const noUnspecifiedLiteral = {
name: 'no-unspecified-literal',
checkers: {
Literal(node) {
if (node.value !== null && !specifiedLiterals.includes(typeof node.value)) {
return [new NoUnspecifiedLiteral(node)];
}
else {
return [];
}
}
}
};
exports.default = noUnspecifiedLiteral;
//# sourceMappingURL=noUnspecifiedLiteral.js.map
;