source: trip-planner-front/node_modules/@babel/template/lib/formatters.js@ 188ee53

Last change on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

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