source: imaps-frontend/node_modules/terser/lib/transform.js

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

F4 Finalna Verzija

  • Property mode set to 100644
File size: 9.6 KB
Line 
1/***********************************************************************
2
3 A JavaScript tokenizer / parser / beautifier / compressor.
4 https://github.com/mishoo/UglifyJS2
5
6 -------------------------------- (C) ---------------------------------
7
8 Author: Mihai Bazon
9 <mihai.bazon@gmail.com>
10 http://mihai.bazon.net/blog
11
12 Distributed under the BSD license:
13
14 Copyright 2012 (c) Mihai Bazon <mihai.bazon@gmail.com>
15
16 Redistribution and use in source and binary forms, with or without
17 modification, are permitted provided that the following conditions
18 are met:
19
20 * Redistributions of source code must retain the above
21 copyright notice, this list of conditions and the following
22 disclaimer.
23
24 * Redistributions in binary form must reproduce the above
25 copyright notice, this list of conditions and the following
26 disclaimer in the documentation and/or other materials
27 provided with the distribution.
28
29 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
30 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
32 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
33 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
34 OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
35 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
36 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
38 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
39 THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 SUCH DAMAGE.
41
42 ***********************************************************************/
43
44"use strict";
45
46import {
47 AST_Array,
48 AST_Await,
49 AST_Binary,
50 AST_PrivateIn,
51 AST_Block,
52 AST_Call,
53 AST_Case,
54 AST_Catch,
55 AST_Chain,
56 AST_Class,
57 AST_ClassStaticBlock,
58 AST_Conditional,
59 AST_Definitions,
60 AST_Destructuring,
61 AST_Do,
62 AST_Exit,
63 AST_Expansion,
64 AST_Export,
65 AST_For,
66 AST_ForIn,
67 AST_If,
68 AST_Import,
69 AST_LabeledStatement,
70 AST_Lambda,
71 AST_LoopControl,
72 AST_NameMapping,
73 AST_Node,
74 AST_Number,
75 AST_Object,
76 AST_ObjectProperty,
77 AST_PrefixedTemplateString,
78 AST_PropAccess,
79 AST_Sequence,
80 AST_SimpleStatement,
81 AST_Sub,
82 AST_Switch,
83 AST_TemplateString,
84 AST_Try,
85 AST_Unary,
86 AST_VarDef,
87 AST_While,
88 AST_With,
89 AST_Yield,
90} from "./ast.js";
91import {
92 MAP as do_list,
93 noop,
94} from "./utils/index.js";
95
96function def_transform(node, descend) {
97 node.DEFMETHOD("transform", function(tw, in_list) {
98 let transformed = undefined;
99 tw.push(this);
100 if (tw.before) transformed = tw.before(this, descend, in_list);
101 if (transformed === undefined) {
102 transformed = this;
103 descend(transformed, tw);
104 if (tw.after) {
105 const after_ret = tw.after(transformed, in_list);
106 if (after_ret !== undefined) transformed = after_ret;
107 }
108 }
109 tw.pop();
110 return transformed;
111 });
112}
113
114def_transform(AST_Node, noop);
115
116def_transform(AST_LabeledStatement, function(self, tw) {
117 self.label = self.label.transform(tw);
118 self.body = self.body.transform(tw);
119});
120
121def_transform(AST_SimpleStatement, function(self, tw) {
122 self.body = self.body.transform(tw);
123});
124
125def_transform(AST_Block, function(self, tw) {
126 self.body = do_list(self.body, tw);
127});
128
129def_transform(AST_Do, function(self, tw) {
130 self.body = self.body.transform(tw);
131 self.condition = self.condition.transform(tw);
132});
133
134def_transform(AST_While, function(self, tw) {
135 self.condition = self.condition.transform(tw);
136 self.body = self.body.transform(tw);
137});
138
139def_transform(AST_For, function(self, tw) {
140 if (self.init) self.init = self.init.transform(tw);
141 if (self.condition) self.condition = self.condition.transform(tw);
142 if (self.step) self.step = self.step.transform(tw);
143 self.body = self.body.transform(tw);
144});
145
146def_transform(AST_ForIn, function(self, tw) {
147 self.init = self.init.transform(tw);
148 self.object = self.object.transform(tw);
149 self.body = self.body.transform(tw);
150});
151
152def_transform(AST_With, function(self, tw) {
153 self.expression = self.expression.transform(tw);
154 self.body = self.body.transform(tw);
155});
156
157def_transform(AST_Exit, function(self, tw) {
158 if (self.value) self.value = self.value.transform(tw);
159});
160
161def_transform(AST_LoopControl, function(self, tw) {
162 if (self.label) self.label = self.label.transform(tw);
163});
164
165def_transform(AST_If, function(self, tw) {
166 self.condition = self.condition.transform(tw);
167 self.body = self.body.transform(tw);
168 if (self.alternative) self.alternative = self.alternative.transform(tw);
169});
170
171def_transform(AST_Switch, function(self, tw) {
172 self.expression = self.expression.transform(tw);
173 self.body = do_list(self.body, tw);
174});
175
176def_transform(AST_Case, function(self, tw) {
177 self.expression = self.expression.transform(tw);
178 self.body = do_list(self.body, tw);
179});
180
181def_transform(AST_Try, function(self, tw) {
182 self.body = self.body.transform(tw);
183 if (self.bcatch) self.bcatch = self.bcatch.transform(tw);
184 if (self.bfinally) self.bfinally = self.bfinally.transform(tw);
185});
186
187def_transform(AST_Catch, function(self, tw) {
188 if (self.argname) self.argname = self.argname.transform(tw);
189 self.body = do_list(self.body, tw);
190});
191
192def_transform(AST_Definitions, function(self, tw) {
193 self.definitions = do_list(self.definitions, tw);
194});
195
196def_transform(AST_VarDef, function(self, tw) {
197 self.name = self.name.transform(tw);
198 if (self.value) self.value = self.value.transform(tw);
199});
200
201def_transform(AST_Destructuring, function(self, tw) {
202 self.names = do_list(self.names, tw);
203});
204
205def_transform(AST_Lambda, function(self, tw) {
206 if (self.name) self.name = self.name.transform(tw);
207 self.argnames = do_list(self.argnames, tw, /* allow_splicing */ false);
208 if (self.body instanceof AST_Node) {
209 self.body = self.body.transform(tw);
210 } else {
211 self.body = do_list(self.body, tw);
212 }
213});
214
215def_transform(AST_Call, function(self, tw) {
216 self.expression = self.expression.transform(tw);
217 self.args = do_list(self.args, tw, /* allow_splicing */ false);
218});
219
220def_transform(AST_Sequence, function(self, tw) {
221 const result = do_list(self.expressions, tw);
222 self.expressions = result.length
223 ? result
224 : [new AST_Number({ value: 0 })];
225});
226
227def_transform(AST_PropAccess, function(self, tw) {
228 self.expression = self.expression.transform(tw);
229});
230
231def_transform(AST_Sub, function(self, tw) {
232 self.expression = self.expression.transform(tw);
233 self.property = self.property.transform(tw);
234});
235
236def_transform(AST_Chain, function(self, tw) {
237 self.expression = self.expression.transform(tw);
238});
239
240def_transform(AST_Yield, function(self, tw) {
241 if (self.expression) self.expression = self.expression.transform(tw);
242});
243
244def_transform(AST_Await, function(self, tw) {
245 self.expression = self.expression.transform(tw);
246});
247
248def_transform(AST_Unary, function(self, tw) {
249 self.expression = self.expression.transform(tw);
250});
251
252def_transform(AST_Binary, function(self, tw) {
253 self.left = self.left.transform(tw);
254 self.right = self.right.transform(tw);
255});
256
257def_transform(AST_PrivateIn, function(self, tw) {
258 self.key = self.key.transform(tw);
259 self.value = self.value.transform(tw);
260});
261
262def_transform(AST_Conditional, function(self, tw) {
263 self.condition = self.condition.transform(tw);
264 self.consequent = self.consequent.transform(tw);
265 self.alternative = self.alternative.transform(tw);
266});
267
268def_transform(AST_Array, function(self, tw) {
269 self.elements = do_list(self.elements, tw);
270});
271
272def_transform(AST_Object, function(self, tw) {
273 self.properties = do_list(self.properties, tw);
274});
275
276def_transform(AST_ObjectProperty, function(self, tw) {
277 if (self.key instanceof AST_Node) {
278 self.key = self.key.transform(tw);
279 }
280 if (self.value) self.value = self.value.transform(tw);
281});
282
283def_transform(AST_Class, function(self, tw) {
284 if (self.name) self.name = self.name.transform(tw);
285 if (self.extends) self.extends = self.extends.transform(tw);
286 self.properties = do_list(self.properties, tw);
287});
288
289def_transform(AST_ClassStaticBlock, function(self, tw) {
290 self.body = do_list(self.body, tw);
291});
292
293def_transform(AST_Expansion, function(self, tw) {
294 self.expression = self.expression.transform(tw);
295});
296
297def_transform(AST_NameMapping, function(self, tw) {
298 self.foreign_name = self.foreign_name.transform(tw);
299 self.name = self.name.transform(tw);
300});
301
302def_transform(AST_Import, function(self, tw) {
303 if (self.imported_name) self.imported_name = self.imported_name.transform(tw);
304 if (self.imported_names) do_list(self.imported_names, tw);
305 self.module_name = self.module_name.transform(tw);
306});
307
308def_transform(AST_Export, function(self, tw) {
309 if (self.exported_definition) self.exported_definition = self.exported_definition.transform(tw);
310 if (self.exported_value) self.exported_value = self.exported_value.transform(tw);
311 if (self.exported_names) do_list(self.exported_names, tw);
312 if (self.module_name) self.module_name = self.module_name.transform(tw);
313});
314
315def_transform(AST_TemplateString, function(self, tw) {
316 self.segments = do_list(self.segments, tw);
317});
318
319def_transform(AST_PrefixedTemplateString, function(self, tw) {
320 self.prefix = self.prefix.transform(tw);
321 self.template_string = self.template_string.transform(tw);
322});
323
Note: See TracBrowser for help on using the repository browser.