source: trip-planner-front/node_modules/@babel/generator/lib/generators/methods.js@ 6a3a178

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

initial commit

  • Property mode set to 100644
File size: 3.1 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports._params = _params;
7exports._parameters = _parameters;
8exports._param = _param;
9exports._methodHead = _methodHead;
10exports._predicate = _predicate;
11exports._functionHead = _functionHead;
12exports.FunctionDeclaration = exports.FunctionExpression = FunctionExpression;
13exports.ArrowFunctionExpression = ArrowFunctionExpression;
14
15var t = require("@babel/types");
16
17function _params(node) {
18 this.print(node.typeParameters, node);
19 this.token("(");
20
21 this._parameters(node.params, node);
22
23 this.token(")");
24 this.print(node.returnType, node);
25}
26
27function _parameters(parameters, parent) {
28 for (let i = 0; i < parameters.length; i++) {
29 this._param(parameters[i], parent);
30
31 if (i < parameters.length - 1) {
32 this.token(",");
33 this.space();
34 }
35 }
36}
37
38function _param(parameter, parent) {
39 this.printJoin(parameter.decorators, parameter);
40 this.print(parameter, parent);
41 if (parameter.optional) this.token("?");
42 this.print(parameter.typeAnnotation, parameter);
43}
44
45function _methodHead(node) {
46 const kind = node.kind;
47 const key = node.key;
48
49 if (kind === "get" || kind === "set") {
50 this.word(kind);
51 this.space();
52 }
53
54 if (node.async) {
55 this._catchUp("start", key.loc);
56
57 this.word("async");
58 this.space();
59 }
60
61 if (kind === "method" || kind === "init") {
62 if (node.generator) {
63 this.token("*");
64 }
65 }
66
67 if (node.computed) {
68 this.token("[");
69 this.print(key, node);
70 this.token("]");
71 } else {
72 this.print(key, node);
73 }
74
75 if (node.optional) {
76 this.token("?");
77 }
78
79 this._params(node);
80}
81
82function _predicate(node) {
83 if (node.predicate) {
84 if (!node.returnType) {
85 this.token(":");
86 }
87
88 this.space();
89 this.print(node.predicate, node);
90 }
91}
92
93function _functionHead(node) {
94 if (node.async) {
95 this.word("async");
96 this.space();
97 }
98
99 this.word("function");
100 if (node.generator) this.token("*");
101 this.space();
102
103 if (node.id) {
104 this.print(node.id, node);
105 }
106
107 this._params(node);
108
109 this._predicate(node);
110}
111
112function FunctionExpression(node) {
113 this._functionHead(node);
114
115 this.space();
116 this.print(node.body, node);
117}
118
119function ArrowFunctionExpression(node) {
120 if (node.async) {
121 this.word("async");
122 this.space();
123 }
124
125 const firstParam = node.params[0];
126
127 if (!this.format.retainLines && !this.format.auxiliaryCommentBefore && !this.format.auxiliaryCommentAfter && node.params.length === 1 && t.isIdentifier(firstParam) && !hasTypesOrComments(node, firstParam)) {
128 this.print(firstParam, node);
129 } else {
130 this._params(node);
131 }
132
133 this._predicate(node);
134
135 this.space();
136 this.token("=>");
137 this.space();
138 this.print(node.body, node);
139}
140
141function hasTypesOrComments(node, param) {
142 var _param$leadingComment, _param$trailingCommen;
143
144 return !!(node.typeParameters || node.returnType || node.predicate || param.typeAnnotation || param.optional || (_param$leadingComment = param.leadingComments) != null && _param$leadingComment.length || (_param$trailingCommen = param.trailingComments) != null && _param$trailingCommen.length);
145}
Note: See TracBrowser for help on using the repository browser.