How to use the uglify-js.AST_String 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 dbankier / TiShadow / cli / support / uglify.js View on Github external
if (
      !is_titaniumified &&
      ((!config.isTicommonjs && node.expression.name === 'require') ||
        (config.isTicommonjs &&
          (node.expression.name === 'tirequire' ||
            node.expression.name === '_require')))
    ) {
      node.expression.name = '__p.require';
      node.args[0].value = toFullPath(node.args[0].value);
      return node;
    }
    if (node.expression.start.value === 'console') {
      if (typeof node.expression.property === 'string') {
        // console.log(...) => __log.log('info', ...)
        if (node.expression.property === 'log') {
          node.args.unshift(new UglifyJS.AST_String({ value: 'info' }));
        }
        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
        );
      }
    }
    if (node.expression.start.value === 'L') {
      node.expression.name = '__L';
      node.name = '__L';
      return node;
github spmjs / spm / lib / utils / ast.js View on Github external
var replace = new UglifyJS.TreeTransformer(null, function(node, descend) {
    if (isCmdDefine(node)) {
      find = true;
      var args = node.args;  

      // 添加 id 和 依赖 节点.
      var idNode = new UglifyJS.AST_String({
        value: id 
      });

      var elements = [];
      deps.forEach(function(dep) {
        elements.push(new UglifyJS.AST_String({value: dep}));
      });
      var depsNode = new UglifyJS.AST_Array({
        elements: elements 
      });

      args.unshift(depsNode);
      args.unshift(idNode);
    }
    return node;
  });
github erzu / porter / lib / cmd-util / ast.js View on Github external
var trans = new UglifyJS.TreeTransformer(function(node, descend) {
    // modify define
    if ((idfn || depfn) && node instanceof UglifyJS.AST_Call && node.expression.name === 'define' && node.args.length) {
      var args = []
      var meta = getDefine(node)
      if (idfn && isFunction(idfn)) {
        meta.id = idfn(meta.id)
      } else if (idfn && isString(idfn)) {
        meta.id = idfn
      }
      if (meta.id) {
        args.push(new UglifyJS.AST_String({
          value: meta.id
        }))
      }
      // modify dependencies
      if (meta.dependencyNode && !depfn) {
        args.push(meta.dependencyNode)
      } else if (depfn) {
        var elements = []
        if (meta.dependencies.length && isFunction(depfn)) {
          meta.dependencies.forEach(function(d) {
            var value = depfn(d)
            if (value) {
              elements.push(
                new UglifyJS.AST_String({value: value})
              )
            }
github ctripcorp / moles-packer / lib / transform.js View on Github external
modules.forEach(function(name) {
                // 创建字符串节点,添加到数组中。
                names.push(new UglifyJS.AST_String({ value: name }));
            });
github mishoo / livenode / livenode.js View on Github external
// this is the ugliest.
            // we convert exports.foo = bar into:
            //
            // exports.__defineGetter__("foo", function(){ return bar }),
            // exports.__defineSetter__("foo", function(v){
            //   exports.__defineGetter__("foo", function(){ return v });
            // })
            //
            // this way we emulate the functionality of exports.bar
            // while allowing it to refer to "global" (module)
            // variables that might be changed later, i.e. bar would
            // turn to $__CONTEXT.bar.

            var prop = node.left.property instanceof u2.AST_Node
                ? node.left.property
                : new u2.AST_String({ value: node.left.property });

            var exp = new u2.AST_Seq({
                car: new u2.AST_Call({
                    expression: new u2.AST_Dot({
                        expression: node.left.expression,
                        property: "__defineGetter__"
                    }),
                    args: [
                        prop,
                        new u2.AST_Lambda({
                            argnames: [],
                            body: [
                                new u2.AST_Return({ value: node.right })
                            ]
                        })
                    ]
github ctripcorp / moles-packer / lib / transform.js View on Github external
var transformer = new UglifyJS.TreeTransformer(function(node, descend) {
        if (node instanceof UglifyJS.AST_Toplevel) {
            descend(node, this);

            // 构建语法树:。
            // Function(String, [ String, ... ], Function(SymbolFunarg, ...) { body })。

            // 创建“字符串”节点。
            var nodeString = new UglifyJS.AST_String({ value: info.name });

            // 创建“字符串”节点数组。
            var names = [ new UglifyJS.AST_String({ value: 'module' }) ];
            modules.forEach(function(name) {
                // 创建字符串节点,添加到数组中。
                names.push(new UglifyJS.AST_String({ value: name }));
            });

            // 创建“数组”节点。
            var nodeArray = new UglifyJS.AST_Array({
                elements: names
            });

            // 创建“函数参数”节点数组。
            var funargs = [], varnames = [ 'module' ];
            modules.forEach(function(name, index) {
github qooxdoo / qooxdoo / tool / grunt / task / package / compression / lib / compression.js View on Github external
function replaceAstStrings(classId, code, privates, globalPrivatesMap) {
  var l = privates.length;
  while (l--) {
    var node = privates[l];
    var startPos = node.start.pos;
    var endPos = node.end.endpos;
    var value = node.value;

    var classIdAndValue = classId+"#"+value;

    globalPrivatesMap[classIdAndValue] = shortenPrivate(classId, value, globalPrivatesMap);
    var replacement = new U2.AST_String({
      value: globalPrivatesMap[classIdAndValue]
    }).print_to_string({ beautify: false });
    code = replaceSourceCode(code, startPos, endPos, replacement);
  }
  return code;
}
github stephenmathieson / node-obfuscator / lib / utils.js View on Github external
function mangleString(node) {
  if (!(node instanceof uglifyjs.AST_String)) {
    return;
  }

  var str = node.getValue();
  var hex = exports.hex(str);
  var obj = merge({}, node);
  obj.value = hex;
  return new uglifyjs.AST_String(obj);
}
github spmjs / cmd-util / lib / ast.js View on Github external
meta.dependencies.forEach(function(d) {
            var value = depfn(d);
            if (value) {
              elements.push(
                new UglifyJS.AST_String({value: value})
              );
            }
          });
        } else if (isString(depfn)) {