react / react-0.13.3 / examples / basic-commonjs / node_modules / browserify / node_modules / umd / node_modules / uglify-js / lib / transform.js
80743 views/***********************************************************************12A JavaScript tokenizer / parser / beautifier / compressor.3https://github.com/mishoo/UglifyJS245-------------------------------- (C) ---------------------------------67Author: Mihai Bazon8<[email protected]>9http://mihai.bazon.net/blog1011Distributed under the BSD license:1213Copyright 2012 (c) Mihai Bazon <[email protected]>1415Redistribution and use in source and binary forms, with or without16modification, are permitted provided that the following conditions17are met:1819* Redistributions of source code must retain the above20copyright notice, this list of conditions and the following21disclaimer.2223* Redistributions in binary form must reproduce the above24copyright notice, this list of conditions and the following25disclaimer in the documentation and/or other materials26provided with the distribution.2728THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY29EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE30IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR31PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE32LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,33OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,34PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR35PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY36THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR37TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF38THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF39SUCH DAMAGE.4041***********************************************************************/4243"use strict";4445// Tree transformer helpers.4647function TreeTransformer(before, after) {48TreeWalker.call(this);49this.before = before;50this.after = after;51}52TreeTransformer.prototype = new TreeWalker;5354(function(undefined){5556function _(node, descend) {57node.DEFMETHOD("transform", function(tw, in_list){58var x, y;59tw.push(this);60if (tw.before) x = tw.before(this, descend, in_list);61if (x === undefined) {62if (!tw.after) {63x = this;64descend(x, tw);65} else {66tw.stack[tw.stack.length - 1] = x = this.clone();67descend(x, tw);68y = tw.after(x, in_list);69if (y !== undefined) x = y;70}71}72tw.pop();73return x;74});75};7677function do_list(list, tw) {78return MAP(list, function(node){79return node.transform(tw, true);80});81};8283_(AST_Node, noop);8485_(AST_LabeledStatement, function(self, tw){86self.label = self.label.transform(tw);87self.body = self.body.transform(tw);88});8990_(AST_SimpleStatement, function(self, tw){91self.body = self.body.transform(tw);92});9394_(AST_Block, function(self, tw){95self.body = do_list(self.body, tw);96});9798_(AST_DWLoop, function(self, tw){99self.condition = self.condition.transform(tw);100self.body = self.body.transform(tw);101});102103_(AST_For, function(self, tw){104if (self.init) self.init = self.init.transform(tw);105if (self.condition) self.condition = self.condition.transform(tw);106if (self.step) self.step = self.step.transform(tw);107self.body = self.body.transform(tw);108});109110_(AST_ForIn, function(self, tw){111self.init = self.init.transform(tw);112self.object = self.object.transform(tw);113self.body = self.body.transform(tw);114});115116_(AST_With, function(self, tw){117self.expression = self.expression.transform(tw);118self.body = self.body.transform(tw);119});120121_(AST_Exit, function(self, tw){122if (self.value) self.value = self.value.transform(tw);123});124125_(AST_LoopControl, function(self, tw){126if (self.label) self.label = self.label.transform(tw);127});128129_(AST_If, function(self, tw){130self.condition = self.condition.transform(tw);131self.body = self.body.transform(tw);132if (self.alternative) self.alternative = self.alternative.transform(tw);133});134135_(AST_Switch, function(self, tw){136self.expression = self.expression.transform(tw);137self.body = do_list(self.body, tw);138});139140_(AST_Case, function(self, tw){141self.expression = self.expression.transform(tw);142self.body = do_list(self.body, tw);143});144145_(AST_Try, function(self, tw){146self.body = do_list(self.body, tw);147if (self.bcatch) self.bcatch = self.bcatch.transform(tw);148if (self.bfinally) self.bfinally = self.bfinally.transform(tw);149});150151_(AST_Catch, function(self, tw){152self.argname = self.argname.transform(tw);153self.body = do_list(self.body, tw);154});155156_(AST_Definitions, function(self, tw){157self.definitions = do_list(self.definitions, tw);158});159160_(AST_VarDef, function(self, tw){161self.name = self.name.transform(tw);162if (self.value) self.value = self.value.transform(tw);163});164165_(AST_Lambda, function(self, tw){166if (self.name) self.name = self.name.transform(tw);167self.argnames = do_list(self.argnames, tw);168self.body = do_list(self.body, tw);169});170171_(AST_Call, function(self, tw){172self.expression = self.expression.transform(tw);173self.args = do_list(self.args, tw);174});175176_(AST_Seq, function(self, tw){177self.car = self.car.transform(tw);178self.cdr = self.cdr.transform(tw);179});180181_(AST_Dot, function(self, tw){182self.expression = self.expression.transform(tw);183});184185_(AST_Sub, function(self, tw){186self.expression = self.expression.transform(tw);187self.property = self.property.transform(tw);188});189190_(AST_Unary, function(self, tw){191self.expression = self.expression.transform(tw);192});193194_(AST_Binary, function(self, tw){195self.left = self.left.transform(tw);196self.right = self.right.transform(tw);197});198199_(AST_Conditional, function(self, tw){200self.condition = self.condition.transform(tw);201self.consequent = self.consequent.transform(tw);202self.alternative = self.alternative.transform(tw);203});204205_(AST_Array, function(self, tw){206self.elements = do_list(self.elements, tw);207});208209_(AST_Object, function(self, tw){210self.properties = do_list(self.properties, tw);211});212213_(AST_ObjectProperty, function(self, tw){214self.value = self.value.transform(tw);215});216217})();218219220