source: imaps-frontend/node_modules/@babel/generator/lib/generators/statements.js

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 5 months ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 6.7 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.BreakStatement = BreakStatement;
7exports.CatchClause = CatchClause;
8exports.ContinueStatement = ContinueStatement;
9exports.DebuggerStatement = DebuggerStatement;
10exports.DoWhileStatement = DoWhileStatement;
11exports.ForOfStatement = exports.ForInStatement = void 0;
12exports.ForStatement = ForStatement;
13exports.IfStatement = IfStatement;
14exports.LabeledStatement = LabeledStatement;
15exports.ReturnStatement = ReturnStatement;
16exports.SwitchCase = SwitchCase;
17exports.SwitchStatement = SwitchStatement;
18exports.ThrowStatement = ThrowStatement;
19exports.TryStatement = TryStatement;
20exports.VariableDeclaration = VariableDeclaration;
21exports.VariableDeclarator = VariableDeclarator;
22exports.WhileStatement = WhileStatement;
23exports.WithStatement = WithStatement;
24var _t = require("@babel/types");
25var _index = require("../node/index.js");
26const {
27 isFor,
28 isForStatement,
29 isIfStatement,
30 isStatement
31} = _t;
32function WithStatement(node) {
33 this.word("with");
34 this.space();
35 this.tokenChar(40);
36 this.print(node.object);
37 this.tokenChar(41);
38 this.printBlock(node);
39}
40function IfStatement(node) {
41 this.word("if");
42 this.space();
43 this.tokenChar(40);
44 this.print(node.test);
45 this.tokenChar(41);
46 this.space();
47 const needsBlock = node.alternate && isIfStatement(getLastStatement(node.consequent));
48 if (needsBlock) {
49 this.tokenChar(123);
50 this.newline();
51 this.indent();
52 }
53 this.printAndIndentOnComments(node.consequent);
54 if (needsBlock) {
55 this.dedent();
56 this.newline();
57 this.tokenChar(125);
58 }
59 if (node.alternate) {
60 if (this.endsWith(125)) this.space();
61 this.word("else");
62 this.space();
63 this.printAndIndentOnComments(node.alternate);
64 }
65}
66function getLastStatement(statement) {
67 const {
68 body
69 } = statement;
70 if (isStatement(body) === false) {
71 return statement;
72 }
73 return getLastStatement(body);
74}
75function ForStatement(node) {
76 this.word("for");
77 this.space();
78 this.tokenChar(40);
79 {
80 const exit = this.enterForStatementInit();
81 this.tokenContext |= _index.TokenContext.forHead;
82 this.print(node.init);
83 exit();
84 }
85 this.tokenChar(59);
86 if (node.test) {
87 this.space();
88 this.print(node.test);
89 }
90 this.token(";", false, 1);
91 if (node.update) {
92 this.space();
93 this.print(node.update);
94 }
95 this.tokenChar(41);
96 this.printBlock(node);
97}
98function WhileStatement(node) {
99 this.word("while");
100 this.space();
101 this.tokenChar(40);
102 this.print(node.test);
103 this.tokenChar(41);
104 this.printBlock(node);
105}
106function ForXStatement(node) {
107 this.word("for");
108 this.space();
109 const isForOf = node.type === "ForOfStatement";
110 if (isForOf && node.await) {
111 this.word("await");
112 this.space();
113 }
114 this.noIndentInnerCommentsHere();
115 this.tokenChar(40);
116 {
117 const exit = isForOf ? null : this.enterForStatementInit();
118 this.tokenContext |= isForOf ? _index.TokenContext.forOfHead : _index.TokenContext.forInHead;
119 this.print(node.left);
120 exit == null || exit();
121 }
122 this.space();
123 this.word(isForOf ? "of" : "in");
124 this.space();
125 this.print(node.right);
126 this.tokenChar(41);
127 this.printBlock(node);
128}
129const ForInStatement = exports.ForInStatement = ForXStatement;
130const ForOfStatement = exports.ForOfStatement = ForXStatement;
131function DoWhileStatement(node) {
132 this.word("do");
133 this.space();
134 this.print(node.body);
135 this.space();
136 this.word("while");
137 this.space();
138 this.tokenChar(40);
139 this.print(node.test);
140 this.tokenChar(41);
141 this.semicolon();
142}
143function printStatementAfterKeyword(printer, node) {
144 if (node) {
145 printer.space();
146 printer.printTerminatorless(node);
147 }
148 printer.semicolon();
149}
150function BreakStatement(node) {
151 this.word("break");
152 printStatementAfterKeyword(this, node.label);
153}
154function ContinueStatement(node) {
155 this.word("continue");
156 printStatementAfterKeyword(this, node.label);
157}
158function ReturnStatement(node) {
159 this.word("return");
160 printStatementAfterKeyword(this, node.argument);
161}
162function ThrowStatement(node) {
163 this.word("throw");
164 printStatementAfterKeyword(this, node.argument);
165}
166function LabeledStatement(node) {
167 this.print(node.label);
168 this.tokenChar(58);
169 this.space();
170 this.print(node.body);
171}
172function TryStatement(node) {
173 this.word("try");
174 this.space();
175 this.print(node.block);
176 this.space();
177 if (node.handlers) {
178 this.print(node.handlers[0]);
179 } else {
180 this.print(node.handler);
181 }
182 if (node.finalizer) {
183 this.space();
184 this.word("finally");
185 this.space();
186 this.print(node.finalizer);
187 }
188}
189function CatchClause(node) {
190 this.word("catch");
191 this.space();
192 if (node.param) {
193 this.tokenChar(40);
194 this.print(node.param);
195 this.print(node.param.typeAnnotation);
196 this.tokenChar(41);
197 this.space();
198 }
199 this.print(node.body);
200}
201function SwitchStatement(node) {
202 this.word("switch");
203 this.space();
204 this.tokenChar(40);
205 this.print(node.discriminant);
206 this.tokenChar(41);
207 this.space();
208 this.tokenChar(123);
209 this.printSequence(node.cases, true, undefined, function addNewlines(leading, cas) {
210 if (!leading && node.cases[node.cases.length - 1] === cas) return -1;
211 });
212 this.rightBrace(node);
213}
214function SwitchCase(node) {
215 if (node.test) {
216 this.word("case");
217 this.space();
218 this.print(node.test);
219 this.tokenChar(58);
220 } else {
221 this.word("default");
222 this.tokenChar(58);
223 }
224 if (node.consequent.length) {
225 this.newline();
226 this.printSequence(node.consequent, true);
227 }
228}
229function DebuggerStatement() {
230 this.word("debugger");
231 this.semicolon();
232}
233function VariableDeclaration(node, parent) {
234 if (node.declare) {
235 this.word("declare");
236 this.space();
237 }
238 const {
239 kind
240 } = node;
241 if (kind === "await using") {
242 this.word("await");
243 this.space();
244 this.word("using", true);
245 } else {
246 this.word(kind, kind === "using");
247 }
248 this.space();
249 let hasInits = false;
250 if (!isFor(parent)) {
251 for (const declar of node.declarations) {
252 if (declar.init) {
253 hasInits = true;
254 }
255 }
256 }
257 this.printList(node.declarations, undefined, undefined, node.declarations.length > 1, hasInits ? function (occurrenceCount) {
258 this.token(",", false, occurrenceCount);
259 this.newline();
260 } : undefined);
261 if (isFor(parent)) {
262 if (isForStatement(parent)) {
263 if (parent.init === node) return;
264 } else {
265 if (parent.left === node) return;
266 }
267 }
268 this.semicolon();
269}
270function VariableDeclarator(node) {
271 this.print(node.id);
272 if (node.definite) this.tokenChar(33);
273 this.print(node.id.typeAnnotation);
274 if (node.init) {
275 this.space();
276 this.tokenChar(61);
277 this.space();
278 this.print(node.init);
279 }
280}
281
282//# sourceMappingURL=statements.js.map
Note: See TracBrowser for help on using the repository browser.