Lines Matching refs:tw

415     function is_modified(compressor, tw, node, value, level, immutable, recursive) {  argument
416 var parent = tw.parent(level);
423 … if (parent instanceof AST_Array) return is_modified(compressor, tw, parent, parent, level + 1);
426 return is_modified(compressor, tw, parent, value, level + 1, immutable, recursive);
430 return is_modified(compressor, tw, parent, parent, level + 1);
436 return is_modified(compressor, tw, parent, parent, level + 1);
446 return is_modified(compressor, tw, parent, parent, level + 1);
451 var obj = tw.parent(level + 1);
452 return is_modified(compressor, tw, obj, obj, level + 2);
457 … return (!immutable || recursive) && is_modified(compressor, tw, parent, prop, level + 1);
461 return is_modified(compressor, tw, parent, value, level + 1, immutable, recursive);
525 function reset_def(tw, compressor, def) { argument
543 function reset_block_variables(tw, compressor, scope) { argument
545 reset_def(tw, compressor, def);
549 function reset_variables(tw, compressor, scope) { argument
552 reset_def(tw, compressor, def);
559 def.safe_ids = tw.safe_ids;
560 mark(tw, def);
562 tw.loop_ids[def.id] = tw.in_loop;
563 mark(tw, def);
578 function safe_to_visit(tw, fn) { argument
580 return marker === undefined || marker === tw.safe_ids;
583 function walk_fn_def(tw, fn) { argument
584 var was_scanning = tw.fn_scanning;
585 tw.fn_scanning = fn;
586 fn.walk(tw);
587 tw.fn_scanning = was_scanning;
590 function revisit_fn_def(tw, fn) { argument
593 if (safe_to_read(tw, d)) return;
602 function mark_fn_def(tw, def, fn) { argument
607 if (member(fn, tw.fn_visited)) revisit_fn_def(tw, fn);
609 var visited = member(fn, tw.fn_visited);
610 if (marker === tw.safe_ids) {
611 if (!visited) walk_fn_def(tw, fn);
613 revisit_fn_def(tw, fn);
617 } else if (tw.fn_scanning && tw.fn_scanning !== def.scope.resolve()) {
620 fn.safe_ids = tw.safe_ids;
621 walk_fn_def(tw, fn);
625 function pop_scope(tw, scope) { argument
629 fn.safe_ids = tw.safe_ids;
630 walk_fn_def(tw, fn);
633 pop(tw);
635 fn.safe_ids = tw.safe_ids;
636 walk_fn_def(tw, fn);
645 function push(tw, sequential) { argument
646 var safe_ids = Object.create(tw.safe_ids);
648 tw.safe_ids = safe_ids;
651 function pop(tw) { argument
652 tw.safe_ids = Object.getPrototypeOf(tw.safe_ids);
655 function mark(tw, def) { argument
656 tw.safe_ids[def.id] = {};
664 function safe_to_read(tw, def) { argument
666 var safe = tw.safe_ids[def.id];
668 var in_order = HOP(tw.safe_ids, def.id);
670 var seq = tw.safe_ids.seq;
680 tw.loop_ids[def.id] = null;
685 return !safe.assign || safe.assign === tw.safe_ids;
690 function safe_to_assign(tw, def, declare) { argument
692 … if (is_funarg(def) && def.scope.uses_arguments && !tw.has_directive("use strict")) return false;
701 var safe = tw.safe_ids[def.id];
705 return def.fixed === null || HOP(tw.safe_ids, def.id) && !safe.read;
707 if (!HOP(tw.safe_ids, def.id)) {
709 if (safe.read || tw.in_loop) {
710 var scope = tw.find_parent(AST_BlockScope);
714 safe.assign = safe.assign && safe.assign !== tw.safe_ids ? true : tw.safe_ids;
717 if (safe.read !== tw.safe_ids.seq) return false;
718 if (tw.loop_ids[def.id] !== tw.in_loop) return false;
720 return safe_to_read(tw, def) && all(def.orig, function(sym) {
751 function mark_escaped(tw, d, scope, node, value, level, depth) { argument
752 var parent = tw.parent(level);
762 mark_escaped(tw, d, scope, parent, parent, level + 1, depth);
764 var obj = tw.parent(level + 1);
765 mark_escaped(tw, d, scope, obj, obj, level + 2, depth);
768 mark_escaped(tw, d, scope, parent, value, level + 1, depth + 1);
823 function scan_declaration(tw, compressor, lhs, fixed, visit) { argument
827 push(tw, true);
828 node.value.walk(tw);
829 pop(tw);
871 push(tw);
872 node.key.walk(tw);
873 pop(tw);
900 var save_len = tw.stack.length;
902 tw.stack.push(scanner.stack[i]);
904 node.walk(tw);
905 tw.stack.length = save_len;
912 function reduce_iife(tw, descend, compressor) { argument
915 var iife = tw.parent();
924 if (aborts) push(tw, sequential);
925 reset_variables(tw, compressor, fn);
929 var safe = !fn.uses_arguments || tw.has_directive("use strict");
932 scan_declaration(tw, compressor, argname, function() {
940 … if (rest) scan_declaration(tw, compressor, rest, compressor.option("rests") && function() {
946 walk_lambda(fn, tw);
947 var safe_ids = tw.safe_ids;
948 pop_scope(tw, fn);
949 if (!aborts) tw.safe_ids = safe_ids;
955 mark(tw, d);
956 tw.loop_ids[d.id] = tw.in_loop;
965 def(AST_Assign, function(tw, descend, compressor) { argument
974 right.walk(tw);
983 if (!ld.fixed || !node.write_only) mark_fn_def(tw, ld, right);
987 right.walk(tw);
1004 if (is_modified(compressor, tw, node, node, 0)) {
1008 var safe = safe_to_read(tw, ld);
1009 if (lazy) push(tw, true);
1010 right.walk(tw);
1011 if (lazy) pop(tw);
1012 if (safe && !left.in_arg && safe_to_assign(tw, ld)) {
1014 mark(tw, ld);
1029 left.walk(tw);
1041 lhs.property.walk(tw);
1054 lhs.walk(tw);
1059 var recursive = ld && recursive_ref(tw, ld);
1060 … var modified = is_modified(compressor, tw, node, right, 0, is_immutable(right), recursive);
1061 scan_declaration(tw, compressor, left, function() {
1071 if (!fixed || sym.in_arg || !safe_to_assign(tw, d)) {
1076 mark(tw, d);
1081 tw.loop_ids[d.id] = tw.in_loop;
1085 mark_escaped(tw, d, sym.scope, node, right, 0, 1);
1092 left.walk(tw);
1093 push(tw, true);
1094 right.walk(tw);
1095 pop(tw);
1099 def(AST_Binary, function(tw) { argument
1101 this.left.walk(tw);
1102 push(tw, true);
1103 this.right.walk(tw);
1104 pop(tw);
1107 def(AST_BlockScope, function(tw, descend, compressor) { argument
1108 reset_block_variables(tw, compressor, this);
1110 def(AST_Call, function(tw, descend) { argument
1116 arg.walk(tw);
1120 exp.walk(tw);
1124 if (node.TYPE == "Call") switch (tw.in_boolean_context()) {
1130 exp.walk(tw);
1132 if (optional) push(tw, true);
1134 arg.walk(tw);
1136 if (optional) pop(tw);
1139 mark_fn_def(tw, exp.definition(), fixed);
1141 tw.find_parent(AST_Scope).may_call_this();
1164 def(AST_Class, function(tw, descend, compressor) { argument
1166 reset_block_variables(tw, compressor, node);
1167 if (node.extends) node.extends.walk(tw);
1171 tw.push(prop);
1172 prop.key.walk(tw);
1173 tw.pop();
1179 var parent = tw.parent();
1181 if (safe_to_assign(tw, d, true)) {
1182 mark(tw, d);
1183 tw.loop_ids[d.id] = tw.in_loop;
1194 tw.push(prop);
1196 push(tw);
1197 prop.value.walk(tw);
1198 pop(tw);
1200 prop.value.walk(tw);
1202 tw.pop();
1206 def(AST_ClassInitBlock, function(tw, descend, compressor) { argument
1208 push(tw, true);
1209 reset_variables(tw, compressor, node);
1211 pop_scope(tw, node);
1214 def(AST_Conditional, function(tw) { argument
1215 this.condition.walk(tw);
1216 push(tw, true);
1217 this.consequent.walk(tw);
1218 pop(tw);
1219 push(tw, true);
1220 this.alternative.walk(tw);
1221 pop(tw);
1224 def(AST_DefaultValue, function(tw) { argument
1225 push(tw, true);
1226 this.value.walk(tw);
1227 pop(tw);
1228 this.name.walk(tw);
1231 def(AST_Do, function(tw) { argument
1232 var save_loop = tw.in_loop;
1233 tw.in_loop = this;
1234 push(tw);
1235 this.body.walk(tw);
1236 if (has_loop_control(this, tw.parent())) {
1237 pop(tw);
1238 push(tw);
1240 this.condition.walk(tw);
1241 pop(tw);
1242 tw.in_loop = save_loop;
1245 def(AST_For, function(tw, descend, compressor) { argument
1247 reset_block_variables(tw, compressor, node);
1248 if (node.init) node.init.walk(tw);
1249 var save_loop = tw.in_loop;
1250 tw.in_loop = node;
1251 push(tw);
1252 if (node.condition) node.condition.walk(tw);
1253 node.body.walk(tw);
1255 if (has_loop_control(node, tw.parent())) {
1256 pop(tw);
1257 push(tw);
1259 node.step.walk(tw);
1261 pop(tw);
1262 tw.in_loop = save_loop;
1265 def(AST_ForEnumeration, function(tw, descend, compressor) { argument
1267 reset_block_variables(tw, compressor, node);
1268 node.object.walk(tw);
1269 var save_loop = tw.in_loop;
1270 tw.in_loop = node;
1271 push(tw);
1280 }, tw);
1289 }, tw);
1291 init.walk(tw);
1293 node.body.walk(tw);
1294 pop(tw);
1295 tw.in_loop = save_loop;
1298 def(AST_If, function(tw) { argument
1299 this.condition.walk(tw);
1300 push(tw, true);
1301 this.body.walk(tw);
1302 pop(tw);
1304 push(tw, true);
1305 this.alternative.walk(tw);
1306 pop(tw);
1310 def(AST_LabeledStatement, function(tw) { argument
1311 push(tw, true);
1312 this.body.walk(tw);
1313 pop(tw);
1316 def(AST_Lambda, function(tw, descend, compressor) { argument
1318 if (!safe_to_visit(tw, fn)) return true;
1319 if (!push_uniq(tw.fn_visited, fn)) return true;
1321 push(tw);
1322 reset_variables(tw, compressor, fn);
1324 pop_scope(tw, fn);
1325 if (fn.name) mark_escaped(tw, fn.name.definition(), fn, fn.name, fn, 0, 1);
1328 def(AST_LambdaDefinition, function(tw, descend, compressor) { argument
1331 var parent = tw.parent();
1333 if (!safe_to_visit(tw, fn)) return true;
1334 if (!push_uniq(tw.fn_visited, fn)) return true;
1336 push(tw);
1337 reset_variables(tw, compressor, fn);
1339 pop_scope(tw, fn);
1342 def(AST_Sub, function(tw) { argument
1344 this.expression.walk(tw);
1345 push(tw, true);
1346 this.property.walk(tw);
1347 pop(tw);
1350 def(AST_Switch, function(tw, descend, compressor) { argument
1352 reset_block_variables(tw, compressor, node);
1353 node.expression.walk(tw);
1357 branch.expression.walk(tw);
1360 push(tw, true);
1363 if (!first) pop(tw);
1364 walk_body(node, tw);
1367 def(AST_SwitchBranch, function(tw) { argument
1368 push(tw, true);
1369 walk_body(this, tw);
1370 pop(tw);
1379 def(AST_SymbolRef, function(tw, descend, compressor) { argument
1385 tw.loop_ids[d.id] = tw.in_loop;
1387 var recursive = recursive_ref(tw, d);
1394 var safe = tw.safe_ids[def.id];
1404 if (!safe_to_read(tw, d)) d.fixed = false;
1413 if (!safe_to_read(tw, d)) {
1422 d.in_loop = tw.loop_ids[d.id] !== tw.in_loop;
1425 && (!d.in_loop || tw.parent() instanceof AST_Call)
1432 if (is_modified(compressor, tw, ref, value, 0, is_immutable(value), recursive)) {
1439 if (d.fixed && tw.loop_ids[d.id] !== tw.in_loop) d.cross_loop = true;
1440 mark_escaped(tw, d, ref.scope, ref, value, 0, 1);
1446 && !((parent = tw.parent()) instanceof AST_Call && parent.expression === ref)) {
1447 mark_fn_def(tw, d, value);
1450 def(AST_Template, function(tw, descend) { argument
1456 exp.walk(tw);
1458 tag.walk(tw);
1461 tag.walk(tw);
1463 exp.walk(tw);
1467 mark_fn_def(tw, tag.definition(), fixed);
1469 tw.find_parent(AST_Scope).may_call_this();
1473 def(AST_Toplevel, function(tw, descend, compressor) { argument
1476 reset_def(tw, compressor, def);
1478 push(tw, true);
1479 reset_variables(tw, compressor, node);
1481 pop_scope(tw, node);
1484 def(AST_Try, function(tw, descend, compressor) { argument
1486 reset_block_variables(tw, compressor, node);
1487 push(tw, true);
1488 walk_body(node, tw);
1489 pop(tw);
1491 push(tw, true);
1492 node.bcatch.walk(tw);
1493 pop(tw);
1495 if (node.bfinally) node.bfinally.walk(tw);
1498 def(AST_Unary, function(tw, descend) { argument
1509 if (safe_to_read(tw, d) && !exp.in_arg && safe_to_assign(tw, d)) {
1511 mark(tw, d);
1540 exp.walk(tw);
1545 def(AST_VarDef, function(tw, descend, compressor) { argument
1553 if (!ld.fixed) mark_fn_def(tw, ld, value);
1555 value.walk(tw);
1557 } else if (tw.parent() instanceof AST_Let) {
1563 scan_declaration(tw, compressor, node.name, function() {
1567 if (fixed && safe_to_assign(tw, d, true)) {
1568 mark(tw, d);
1569 tw.loop_ids[d.id] = tw.in_loop;
1582 def(AST_While, function(tw, descend) { argument
1583 var save_loop = tw.in_loop;
1584 tw.in_loop = this;
1585 push(tw);
1587 pop(tw);
1588 tw.in_loop = save_loop;
1603 var tw = new TreeWalker(compressor.option("reduce_vars") ? function(node, descend) {
1605 return node.reduce_vars(tw, descend, compressor);
1608 tw.fn_scanning = null;
1609 tw.fn_visited = [];
1611 tw.in_loop = null;
1612 tw.loop_ids = Object.create(null);
1617 tw.safe_ids = Object.create(null);
1618 tw.safe_ids.seq = {};
1619 this.walk(tw);
1680 function mark_destructured(process, tw) { argument
1683 node.value.walk(tw);
1688 if (node.key instanceof AST_Node) node.key.walk(tw);
1709 var tw = new TreeWalker(function(node) {
1713 node.name.walk(tw);
1718 node.value.walk(tw);
1723 this.walk(tw);
2731 return node instanceof AST_Await && !tw.find_parent(AST_Scope);
2736 var tw = new TreeWalker(function(node, descend) {
2792 arg.walk(tw);
3238 return function(node, tw) { argument
3239 if (tw.in_boolean_context()) {
3285 var tw = new TreeWalker(function(node) {
3295 … && (has_escaped(def, node.scope, node, tw.parent()) || !same_scope(def))) {
3303 lvalues.add(node.name, is_modified(compressor, tw, node, value, 0));
3305 … for (var level = 0, parent, child = node; parent = tw.parent(level++); child = parent) {
3355 expr.walk(tw);
6362 var tw = new TreeWalker(function(node, descend) {
6367 rhs.walk(tw);
6372 lhs.walk(tw);
6374 rhs.walk(tw);
6381 rhs.walk(tw);
6393 var target = tw.loopcontrol_target(node);
6401 arg.walk(tw);
6403 exp.walk(tw);
6411 if (node.name) node.name.walk(tw);
6412 if (node.extends) node.extends.walk(tw);
6414 if (prop.key instanceof AST_Node) prop.key.walk(tw);
6418 prop.value.walk(tw);
6422 prop.value.walk(tw);
6433 var target = tw.loopcontrol_target(node);
6442 node.body.walk(tw);
6444 node.condition.walk(tw);
6449 if (node.init) node.init.walk(tw);
6453 if (node.condition) node.condition.walk(tw);
6454 node.body.walk(tw);
6455 if (node.step) node.step.walk(tw);
6460 node.object.walk(tw);
6464 node.init.walk(tw);
6465 node.body.walk(tw);
6477 node.body.walk(tw);
6488 … var marker = node.uses_arguments && !tw.has_directive("use strict") ? function(node) {
6500 walk_lambda(node, tw);
6507 exp.walk(tw);
6509 node.property.walk(tw);
6518 node.expression.walk(tw);
6522 branch.expression.walk(tw);
6530 walk_body(branch, tw);
6547 walk_body(node, tw);
6555 }, tw);
6557 walk_body(node.bcatch, tw);
6560 walk_body(node.bcatch, tw);
6565 if (node.bfinally) node.bfinally.walk(tw);
6578 assigned.walk(tw);
6580 … assigned = segment.block instanceof AST_ForEnumeration && segment.block.init === tw.parent();
6586 node.walk(tw);
6598 node.walk(tw);
6615 if (sym instanceof AST_SymbolRef) sym.walk(tw);
6630 condition.walk(tw);
6635 condition.walk(tw);
6640 consequent.walk(tw);
6646 alternative.walk(tw);
6653 tw.directives = Object.create(compressor.directives);
6654 self.walk(tw);
6718 node.value.walk(tw);
6727 node.key.walk(tw);
6731 node.key.walk(tw);
6737 node.walk(tw);
6800 var scope = find_scope(tw);
6949 var tw = new TreeWalker(function(node, descend) {
6950 … if (node instanceof AST_Lambda && node.uses_arguments && !tw.has_directive("use strict")) {
6968 var used = tw.parent() instanceof AST_ExportDefault;
6974 if (node.extends) node.extends.walk(tw);
6977 if (prop.key instanceof AST_Node) prop.key.walk(tw);
7000 if (tw.parent() instanceof AST_ExportDefault) {
7037 }, tw);
7038 if (side_effects) value.walk(tw);
7062 value.walk(tw);
7066 tw.directives = Object.create(compressor.directives);
7067 self.walk(tw);
7085 node.walk(tw);
7095 tw = new TreeWalker(scan_ref_scoped);
7099 init.walk(tw);
7835 assign.walk(tw);
7838 prop.walk(tw);
7845 right.walk(tw);
7869 node.left.walk(tw);
7888 node.object.walk(tw);
8708 var tw = new TreeWalker(function(node) {
8710 if (tw.parent() === exp && node.may_throw(compressor)) return abort = true;
8719 exp.walk(tw);
9153 var tw = new TreeWalker(function(node) {
9155 if (node instanceof type && tw.loopcontrol_target(node) === loop) {
9159 if (parent instanceof AST_LabeledStatement) tw.push(parent);
9160 tw.push(loop);
9161 loop.body.walk(tw);
9403 var tw = new TreeWalker(function(node, descend) {
9408 node.right.walk(tw);
9427 fn.walk(tw);
9439 if (node.init) node.init.walk(tw);
9441 if (node.condition) node.condition.walk(tw);
9442 node.body.walk(tw);
9443 if (node.step) node.step.walk(tw);
9448 node.object.walk(tw);
9450 node.init.walk(tw);
9451 node.body.walk(tw);
9464 body.walk(tw);
10032 function is_break(node, tw) { argument
10033 return node instanceof AST_Break && tw.loopcontrol_target(node) === self;
10038 var tw = new TreeWalker(function(node) {
10042 if (is_break(node, tw)) found = true;
10044 tw.push(self);
10045 node.walk(tw);
10342 var tw = new TreeWalker(function(node) {
10347 … for (var i = 0; safe && i < node.argnames.length; i++) node.argnames[i].walk(tw);
10355 fn.walk(tw);
10936 var tw = new TreeWalker(function(node, descend) {
10952 if (is_lhs(node, tw.parent())) return abort = true;
10965 node.left.expression.walk(tw);
10966 if (node.left instanceof AST_Sub) node.left.property.walk(tw);
10967 node.right.walk(tw);
10977 value.walk(tw);