1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.program = exports.expression = exports.statement = exports.statements = exports.smart = void 0;
|
7 |
|
8 | function makeStatementFormatter(fn) {
|
9 | return {
|
10 | code: str => `/* @babel/template */;\n${str}`,
|
11 | validate: () => {},
|
12 | unwrap: ast => {
|
13 | return fn(ast.program.body.slice(1));
|
14 | }
|
15 | };
|
16 | }
|
17 |
|
18 | const smart = makeStatementFormatter(body => {
|
19 | if (body.length > 1) {
|
20 | return body;
|
21 | } else {
|
22 | return body[0];
|
23 | }
|
24 | });
|
25 | exports.smart = smart;
|
26 | const statements = makeStatementFormatter(body => body);
|
27 | exports.statements = statements;
|
28 | const statement = makeStatementFormatter(body => {
|
29 | if (body.length === 0) {
|
30 | throw new Error("Found nothing to return.");
|
31 | }
|
32 |
|
33 | if (body.length > 1) {
|
34 | throw new Error("Found multiple statements but wanted one");
|
35 | }
|
36 |
|
37 | return body[0];
|
38 | });
|
39 | exports.statement = statement;
|
40 | const expression = {
|
41 | code: str => `(\n${str}\n)`,
|
42 | validate: ({
|
43 | program
|
44 | }) => {
|
45 | if (program.body.length > 1) {
|
46 | throw new Error("Found multiple statements but wanted one");
|
47 | }
|
48 |
|
49 | const expression = program.body[0].expression;
|
50 |
|
51 | if (expression.start === 0) {
|
52 | throw new Error("Parse result included parens.");
|
53 | }
|
54 | },
|
55 | unwrap: ast => ast.program.body[0].expression
|
56 | };
|
57 | exports.expression = expression;
|
58 | const program = {
|
59 | code: str => str,
|
60 | validate: () => {},
|
61 | unwrap: ast => ast.program
|
62 | };
|
63 | exports.program = program; |
\ | No newline at end of file |