@taquito/michelson-encoder
Version:
converts michelson data and types into convenient JS/TS objects
69 lines (68 loc) • 2.12 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.NeverToken = exports.NeverTokenError = void 0;
const token_1 = require("./token");
/**
* @category Error
* @description Error that indicates a failure happening when parsing encoding/executing a Never Token
*/
class NeverTokenError extends token_1.TokenValidationError {
constructor(value, token, message) {
super(value, token, message);
this.value = value;
this.token = token;
this.name = 'NeverTokenError';
}
}
exports.NeverTokenError = NeverTokenError;
class NeverToken extends token_1.Token {
constructor(val, idx, fac) {
super(val, idx, fac);
this.val = val;
this.idx = idx;
this.fac = fac;
}
/**
* @throws {@link NeverTokenError}
*/
Encode(args) {
const val = args.pop();
throw new NeverTokenError(val, this, `Assigning a value to the type never is forbidden. Trying to assign ${JSON.stringify(val)}.`);
}
/**
* @throws {@link NeverTokenError}
*/
EncodeObject(val, semantic) {
if (semantic && semantic[NeverToken.prim]) {
return semantic[NeverToken.prim](val);
}
throw new NeverTokenError(val, this, `Assigning a value to the type never is forbidden. Trying to assign ${JSON.stringify(val)}.`);
}
/**
* @throws {@link NeverTokenError}
*/
Execute(val) {
throw new NeverTokenError(val, this, `There is no literal value for the type never. Trying to execute ${JSON.stringify(val)}.`);
}
/**
* @deprecated ExtractSchema has been deprecated in favor of generateSchema
*
*/
ExtractSchema() {
return NeverToken.prim;
}
generateSchema() {
return {
__michelsonType: NeverToken.prim,
schema: NeverToken.prim,
};
}
findAndReturnTokens(tokenToFind, tokens) {
if (NeverToken.prim === tokenToFind) {
tokens.push(this);
}
return tokens;
}
}
exports.NeverToken = NeverToken;
NeverToken.prim = 'never';
;