js-slang
Version:
Javascript-based implementations of Source, written in Typescript
56 lines • 2.05 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StepperReturnStatement = void 0;
const generator_1 = require("../../generator");
const __1 = require("../..");
class StepperReturnStatement {
constructor(argument, leadingComments, trailingComments, loc, range) {
this.type = 'ReturnStatement';
this.argument = argument;
this.leadingComments = leadingComments;
this.trailingComments = trailingComments;
this.loc = loc;
this.range = range;
}
static create(node) {
return new StepperReturnStatement(node.argument ? (0, generator_1.convert)(node.argument) : null, node.leadingComments, node.trailingComments, node.loc, node.range);
}
isContractible() {
return true;
}
isOneStepPossible() {
return true;
}
contract() {
if (!this.argument) {
throw new Error('Cannot contract return statement without argument');
}
__1.redex.preRedex = [this];
__1.redex.postRedex = [this.argument];
return this.argument;
}
contractEmpty() {
__1.redex.preRedex = [this];
__1.redex.postRedex = [];
}
oneStep() {
if (!this.argument) {
throw new Error('Cannot step return statement without argument');
}
return this.contract();
}
substitute(id, value) {
return new StepperReturnStatement(this.argument ? this.argument.substitute(id, value) : null, this.leadingComments, this.trailingComments, this.loc, this.range);
}
freeNames() {
return this.argument ? this.argument.freeNames() : [];
}
allNames() {
return this.argument ? this.argument.allNames() : [];
}
rename(before, after) {
return new StepperReturnStatement(this.argument ? this.argument.rename(before, after) : null, this.leadingComments, this.trailingComments, this.loc, this.range);
}
}
exports.StepperReturnStatement = StepperReturnStatement;
//# sourceMappingURL=ReturnStatement.js.map