@mistlog/typetype
Version:
A programming language designed for typescript type generation
50 lines (49 loc) • 2.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExtendsClause = exports.TypeIfStatement = void 0;
const react_peg_1 = require("react-peg");
const common_1 = require("../common");
const expression_1 = require("../expression");
const statement_1 = require("./statement");
function TypeIfStatement() {
const action = ({ condition, consequent, alternate }) => {
return {
kind: "TypeIfStatement",
condition,
consequent,
alternate
};
};
return (react_peg_1.ReactPeg.createChunk("pattern", { action: action },
common_1.Text("if"),
common_1.Text("("),
react_peg_1.ReactPeg.createChunk(ExtendsClause, { label: "condition" }),
common_1.Text(")"),
common_1.Text("{"),
react_peg_1.ReactPeg.createChunk(statement_1.TypeReturnStatement, { label: "consequent" }),
common_1.Text("}"),
common_1.Text("else"),
react_peg_1.ReactPeg.createChunk("or", { label: "alternate" },
react_peg_1.ReactPeg.createChunk(TypeIfStatement, null),
react_peg_1.ReactPeg.createChunk("pattern", { action: ({ statement }) => statement },
common_1.Text("{"),
react_peg_1.ReactPeg.createChunk(statement_1.TypeReturnStatement, { label: "statement" }),
common_1.Text("}")))));
}
exports.TypeIfStatement = TypeIfStatement;
function ExtendsClause() {
const action = ({ checkType, extendsType }) => {
return {
kind: "ExtendsClause",
checkType,
extendsType
};
};
return (react_peg_1.ReactPeg.createChunk("pattern", { action: action },
react_peg_1.ReactPeg.createChunk(common_1._, null),
react_peg_1.ReactPeg.createChunk(expression_1.TypeExpression, { label: "checkType" }),
common_1.Text("extends"),
react_peg_1.ReactPeg.createChunk(expression_1.TypeExpression, { label: "extendsType" }),
react_peg_1.ReactPeg.createChunk(common_1._, null)));
}
exports.ExtendsClause = ExtendsClause;