source: imaps-frontend/node_modules/@babel/template/lib/formatters.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.5 KB
RevLine 
[d565449]1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.statements = exports.statement = exports.smart = exports.program = exports.expression = void 0;
7var _t = require("@babel/types");
8const {
9 assertExpressionStatement
10} = _t;
11function makeStatementFormatter(fn) {
12 return {
13 code: str => `/* @babel/template */;\n${str}`,
14 validate: () => {},
15 unwrap: ast => {
16 return fn(ast.program.body.slice(1));
17 }
18 };
19}
20const smart = exports.smart = makeStatementFormatter(body => {
21 if (body.length > 1) {
22 return body;
23 } else {
24 return body[0];
25 }
26});
27const statements = exports.statements = makeStatementFormatter(body => body);
28const statement = exports.statement = makeStatementFormatter(body => {
29 if (body.length === 0) {
30 throw new Error("Found nothing to return.");
31 }
32 if (body.length > 1) {
33 throw new Error("Found multiple statements but wanted one");
34 }
35 return body[0];
36});
37const expression = exports.expression = {
38 code: str => `(\n${str}\n)`,
39 validate: ast => {
40 if (ast.program.body.length > 1) {
41 throw new Error("Found multiple statements but wanted one");
42 }
43 if (expression.unwrap(ast).start === 0) {
44 throw new Error("Parse result included parens.");
45 }
46 },
47 unwrap: ({
48 program
49 }) => {
50 const [stmt] = program.body;
51 assertExpressionStatement(stmt);
52 return stmt.expression;
53 }
54};
55const program = exports.program = {
56 code: str => str,
57 validate: () => {},
58 unwrap: ast => ast.program
59};
60
61//# sourceMappingURL=formatters.js.map
Note: See TracBrowser for help on using the repository browser.