How to use the uglify-js.AST_SymbolRef function in uglify-js

To help you get started, we’ve selected a few uglify-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ctripcorp / moles-packer / lib / transform.js View on Github external
// 转换成绝对路径。

                if (!requireRealpath) {
                    inform.exit(`Required "${requireName}" not found in "${info.realpath}"`);
                }

                _pushQueue(requireRealpath);
                transformedRequireName = _getModuleName(requireRealpath);
            }

            // 加入到当前模块的依赖列表中。
            modules.push(transformedRequireName);

            if (OPTIONS.execOnRequired) {
                return new UglifyJS.AST_Call({
                    expression: new UglifyJS.AST_SymbolRef({ name: OPTIONS.symbol.execRequire }),
                    args: [ new UglifyJS.AST_String({ value: transformedRequireName }) ]
                });
            }
            else {
                var varname = MODULE_VARNAME_PREFIX + (modules.length - 1);

                // 用“变量引用”节点替代 require() “函数调用”节点。
                return new UglifyJS.AST_SymbolRef({ name: varname });
            }
        }

        /**
         * AppRegistry.registerComponent('registerComponent', () => componentInstanceVarName);
         */
        else if (node instanceof UglifyJS.AST_Statement
            && node.body
github dntzhang / kmdjs / kud / kud.js View on Github external
for (var i = nodes.length; --i >= 0;) {
        var item = nodes[i],
            node=item.node;
        //   name=item.name;
        //var fullName=getFullName(deps,name);
        var replacement;
        if (node instanceof  U2.AST_New) {
            replacement = new U2.AST_New({
                expression: new U2.AST_SymbolRef({
                    name:node.fullName
                }),
                args: node.args
            });
        } else if (node instanceof  U2.AST_Dot) {
            replacement = new U2.AST_Dot({
                expression: new U2.AST_SymbolRef({
                    name: node.fullName
                }),
                property: node.property
            });
        }else if(node instanceof U2.AST_SymbolRef){
            replacement = new U2.AST_SymbolRef({
                name: node.fullName
            });
        }
        var start_pos = node.start.pos;
        var end_pos = node.end.endpos;
        for (var k = 0; k < nodes.length; k++) {
            var item2 = nodes[k];
            var otherNode = item2.node;
            if (otherNode.start.pos < start_pos && otherNode.end.endpos > end_pos) {
                var fna2 = otherNode.fullName;
github ctripcorp / moles-packer / lib / transform.js View on Github external
varnames.push(MODULE_VARNAME_PREFIX + index);
            });
            varnames.forEach(function(varname) {
                // 创建函数参数符号节点,添加到数组中。
                funargs.push(new UglifyJS.AST_SymbolFunarg({ name: varname }));
            });

            // 创建“函数”节点。
            var nodeFunction = new UglifyJS.AST_Function({
                argnames: funargs,
                body: node.body
            });

            // 创建“返回”节点。
            var nodeReturn = new UglifyJS.AST_Return({
                value: new UglifyJS.AST_SymbolRef({ name: 'module.exports' })
            });
            let nodeSemicolon = new UglifyJS.AST_Symbol({ name: ';' });
            nodeFunction.body.push(nodeSemicolon);
            nodeFunction.body.push(nodeReturn);

            // 创建“函数调用”节点。
            var nodeDefine = new UglifyJS.AST_Call({
                expression: new UglifyJS.AST_SymbolRef({ name: CONFIG.symbol.define }),
                args: [ nodeString, nodeArray, nodeFunction ]
            });

            return nodeDefine;
        }

        // 捕捉所有的 require() 调用。
        else if (node instanceof UglifyJS.AST_Call && node.expression.name == 'require') {
github mishoo / livenode / livenode.js View on Github external
var body = u2.AST_Seq.from_array(node.definitions.map(function(def){
                return new u2.AST_Assign({
                    operator: "=",
                    left: new u2.AST_Dot({
                        expression: new u2.AST_SymbolRef({ name: "$__CONTEXT" }),
                        property: def.name.name
                    }),
                    right: def.value || new u2.AST_Undefined()
                });
            }));
            if (!(p instanceof u2.AST_For && p.init === node))
github dbankier / TiShadow / cli / support / uglify.js View on Github external
'__app.' + node.expression.end.value,
          [
            new UglifyJS.AST_String({
              value: node.expression.expression.property
            })
          ].concat(node.args)
        );
      }
      //control localisation -- API
      if (node.expression.expression.property === 'API') {
        if (typeof node.expression.property === 'string') {
          return functionCall('__log.' + node.expression.end.value, node.args);
        } else {
          return functionCallByNode(
            new UglifyJS.AST_Sub({
              expression: new UglifyJS.AST_SymbolRef({ name: '__log' }),
              property: node.expression.property
            }),
            node.args
          );
        }
      }

      //control database source - Database
      if (
        node.expression.end.value === 'install' &&
        node.expression.expression.property === 'Database'
      ) {
        node.args[0] = functionCall('__p.file', [node.args[0]]);
        return node;
      }
    }
github dntzhang / kmdjs / kud / kud.js View on Github external
if (node instanceof  U2.AST_New) {
            replacement = new U2.AST_New({
                expression: new U2.AST_SymbolRef({
                    name:node.fullName
                }),
                args: node.args
            });
        } else if (node instanceof  U2.AST_Dot) {
            replacement = new U2.AST_Dot({
                expression: new U2.AST_SymbolRef({
                    name: node.fullName
                }),
                property: node.property
            });
        }else if(node instanceof U2.AST_SymbolRef){
            replacement = new U2.AST_SymbolRef({
                name: node.fullName
            });
        }
        var start_pos = node.start.pos;
        var end_pos = node.end.endpos;
        for (var k = 0; k < nodes.length; k++) {
            var item2 = nodes[k];
            var otherNode = item2.node;
            if (otherNode.start.pos < start_pos && otherNode.end.endpos > end_pos) {
                var fna2 = otherNode.fullName;
                var step = fna2.length - item2.name.length;
                otherNode.replaceArea.push({
                    step: step,
                    begin: start_pos,
                    end: end_pos,
                    replaceM: replacement,
github appcelerator / tio2 / lib / suite.js View on Github external
fn.node.body = [
				new UglifyJS.AST_Try({
					body: fn.node.body,
					bcatch: new UglifyJS.AST_Catch({
						argname: new UglifyJS.AST_SymbolCatch({
							name: '$ex'
						}),
						body: [
							new UglifyJS.AST_SimpleStatement({
								body: new UglifyJS.AST_Call({
									args: [
										new UglifyJS.AST_SymbolRef({
											name: '$ex'
										})
									],
									expression: new UglifyJS.AST_SymbolRef({
										name: fn.callback
									})
								})
							})
						]
					})
				})
			];
		}
	});
github Bobris / bobril-build / dist / bundler.js View on Github external
let symbVar = new uglify.AST_SymbolVar({
                                name: newName,
                                start: node.start,
                                end: node.end
                            });
                            varDecls.push(new uglify.AST_VarDef({
                                name: symbVar,
                                value: null
                            }));
                            let symb = ast.def_variable(symbVar);
                            symb.undeclared = false;
                            symb.bbAlwaysClone = true;
                            selfExpNames[key] = true;
                            cached.selfexports.push({
                                name: key,
                                node: new uglify.AST_SymbolRef({
                                    name: newName,
                                    thedef: symb
                                })
                            });
                            return false;
                        }
                    }
                }
            }
            let req = constParamOfCallRequire(node);
            if (req != null) {
                let reqr = resolveRequire(req, name);
                if (reqr == null) {
                    throw new Error('require("' + req + '") not found from ' + name);
                }
                let parent = walker.parent();
github pugjs / react-jade / lib / utils / compiler.js View on Github external
if (fixAttributeNames && key === 'maxlength') key = 'maxLength';
    if (key.substr(0, 2) === 'on') {
      var ast = uglify.parse('jade_interp = (' + attr.val + ')');
      var val = ast.body[0].body.right;
      if (val.TYPE === 'Call') {
        if (val.expression.TYPE !== 'Dot' && val.expression.TYPE !== 'Sub') {
          val.expression = new uglify.AST_Dot({
            expression: val.expression,
            property: 'bind'
          });
          val.args.unshift(new uglify.AST_Null({}));
          attr.val = val.print_to_string();
        } else if ((val.expression.TYPE === 'Dot' && val.expression.property !== 'bind') ||
                   val.expression.TYPE == 'Sub')  {
          var obj = val.expression.expression;
          val.expression.expression = new uglify.AST_SymbolRef({name: 'jade_interp'});
          val.expression = new uglify.AST_Dot({
            expression: val.expression,
            property: 'bind'
          });
          val.args.unshift(new uglify.AST_SymbolRef({name: 'jade_interp'}));
          val = new uglify.AST_Seq({
            car: new uglify.AST_Assign({
              operator: '=',
              left: new uglify.AST_SymbolRef({name: 'jade_interp'}),
              right: obj
            }),
            cdr: val
          });
          attr.val = '(' + val.print_to_string() + ')';
        }
      }
github spocke / amdlc / lib / AmdCompiler.js View on Github external
function exposeModules(body, publicModules) {
	var moduleIdArray = [];

	publicModules.forEach(function(module) {
		moduleIdArray.push(new UglifyJS.AST_SymbolVar({name: idToVarName(module.id)}));
	});

	body.push(new UglifyJS.AST_SimpleStatement({
		body: new UglifyJS.AST_Call({
			expression: new UglifyJS.AST_SymbolRef({name: "expose"}),
			args: [new UglifyJS.AST_Array({elements: moduleIdArray})]
		})
	}));
}