jstransform 回调函数

当 ast 树为 define factory 中的 return 语句时进入。

@param  {Function} traverse  可用来继续处理子节点。
@param  {Object} node 当前节点。
@param  {Array} path 路径数组，包含进入该节点前的父级节点。
@param  {Object} state state 对象，用来保存对 node 修改状态。
@return {boolean} false
545558
function visitReturnInFactory(traverse, node, path, state) {
        utils.catchup(node.range[0], state);
        utils.move(node.argument.range[0], state);
        utils.append('module.exports = ', state);
        utils.catchup(node.range[1] - 1, state);
        return false;
    }
253552
function (id, traversePath) {
      var datatype = this.ds.find(function (dt) {
        return dt.id == id;
      });
      if (datatype.format != 0 && datatype.format != 2 || datatype.id === 10000) {
        // 非哈希、非数组、可变类型时不会有循环依赖产生
        return;
      }
      var foundLoop = traversePath.find(function (item) {
        // todo: 这里不使用严格相等判断, 因为后端返回的数据类型有时是字符有时是数字
        return item.id == id;
      });
      if (foundLoop) {
        // 如果存在环, 就返回数据类型的名称
        // console.log(traversePath)
        // console.log(foundLoop.name)
        return '<' + foundLoop.name + '>';
      } else {
        traversePath.push({
          id: id,
          name: datatype.name
        });
      }
    }
865478
function getProp (obj, path, isArray) {
  var next;
  path = _.isString(path) ? path.split('.') : path;

  // We have more traversing to do
  if (path.length > 1) {
    next = path.shift();
    if (_.isArray(obj[next])) {
      isArray = true;
      var arr = _.compact(_.flatten(obj[next].map(function (el, i) {
        return getProp(el, _.clone(path), isArray);
      })));
      return arr.length ? arr : undefined;
    } else {
      if (!obj[next]) { return; }
      return getProp(obj[next], path, isArray);
    }

  // No more traversing. We can now target the final node with path[0]
  } else {
    next = path[0];
    // if we are at the end of the path and `obj` is an array
    if (_.isArray(obj)) {
      return _.pluck(obj, next);
    } else {
      if (!obj[next]) { return; }
      return isArray ? [obj[next]] : obj[next];
    }
  }
}
12907
function _walk(node){
			var i, l, child, s, state, allSelected,someSelected,
				children = node.children;

			if( children && children.length ){
				// check all children recursively
				allSelected = true;
				someSelected = false;

				for( i=0, l=children.length; i<l; i++ ){
					child = children[i];
					// the selection state of a node is not relevant; we need the end-nodes
					s = _walk(child);
					if( s !== false ) {
						someSelected = true;
					}
					if( s !== true ) {
						allSelected = false;
					}
				}
				state = allSelected ? true : (someSelected ? undefined : false);
			}else{
				// This is an end-node: simply report the status
//				state = ( node.unselectable ) ? undefined : !!node.selected;
				state = !!node.selected;
			}
			node._changeSelectStatusAttrs(state);
			return state;
		}
143967
function baseStatePredicate(state, full) {
    if (full) {
        return this.extract(state);
    }

    // Cache a state predicate function
    const fn = getPredicateFunction(state);

    return this.flatten(node => {
        // Never include removed nodes unless specifically requested
        if (state !== 'removed' && node.removed()) {
            return false;
        }

        return fn(node);
    });
}
155807
function isDefine(node, path) {
        if (node.type === Syntax.CallExpression
            && node.callee.type === Syntax.Identifier
            && node.callee.name === 'define') {

            // 查找当前作用域和父级作用域，如果存在 define 的定义，则不转换。
            // 此类情况一般都是内部 amd 实现。
            if (!util.existsFunction(path, node.callee)) {
                return true;
            }
        }

        return false;
    }
766766
function traverse(tokens, options) {
    const traverser = new Traverser()
    const nodes = Array.isArray(tokens) ? tokens : [tokens]
    for (const node of nodes) {
        traverser.traverse(node, options)
        if (traverser.isBroken()) {
            return
        }
    }
}
1067193
function (path) {
      var paths = this._paths;
      paths[path] = (paths[path] || 0) + 1;

      var key = firstKey(path);
      var tail = path.slice(key.length + 1);

      this.chain(key, tail);
    }
615777
function ancestor(node, visitors, base, state) {
  if (!base) base = exports.base;
  if (!state) state = [];(function c(node, st, override) {
    var type = override || node.type,
        found = visitors[type];
    if (node != st[st.length - 1]) {
      st = st.slice();
      st.push(node);
    }
    base[type](node, st, c);
    if (found) found(node, st);
  })(node, state);
}
605423
function  (node) {
		  	var parent = node.parentNode,
			  	path = [],
			  	index = this.getChildIndex(node);

		  if(parent && (path = this.getNodePath(parent))){
			   if(index > -1){
				   path.push(index);
			   }
		  }
		  return path;
		}
348392
function(state) {
      var url = state.url, config = { params: state.params || {} };

      if (isString(url)) {
        if (url.charAt(0) == '^') return $urlMatcherFactory.compile(url.substring(1), config);
        return (state.parent.navigable || root).url.concat(url, config);
      }

      if (!url || $urlMatcherFactory.isMatcher(url)) return url;
      throw new Error("Invalid url '" + url + "' in state '" + state + "'");
    }
260144
function traverseTree(
  url: ParsedURL,
  tree: TreeDirectory,
  debuggeeHost: ?string,
  source: Source
): TreeNode {
  const parts = url.path.split("/").filter(p => p !== "");
  parts.unshift(url.group);

  let path = "";
  return parts.reduce((subTree, part, index) => {
    path = path ? `${path}/${part}` : part;
    const debuggeeHostIfRoot = index === 0 ? debuggeeHost : null;
    return findOrCreateNode(
      parts,
      subTree,
      path,
      part,
      index,
      url,
      debuggeeHostIfRoot,
      source
    );
  }, tree);
}
43561
function(path, state) {
  var defaultReexportSpecifier = path.get('specifiers')[0];
  var local = defaultReexportSpecifier.get('local').get('name').node;
  var exported = defaultReexportSpecifier.get('exported').get('name').node;

  if (local !== 'default') {
    throw path.buildCodeFrameError('Only named exports allowed are reexports in index.js');
  }

  // used by Program's exit visitor
  state.set('reexports', true);

  path.replaceWith(
    buildExportsAssignment(
      t.callExpression(
        t.identifier('require'),
        [t.stringLiteral(path.node.source.value)]
      ),
      exported
    )
  );
}
151173
function renderDesructuration(pattern, expr, traverse, path, state) {
  utils.catchupNewlines(pattern.range[1], state);

  var id;

  if (pattern.type === Syntax.ObjectPattern && pattern.properties.length === 1) {
    id = expr;
  } else if (pattern.type === Syntax.ArrayPattern && pattern.elements.length === 1) {
    id = expr;
  } else {
    id = renderExpressionMemoized(expr, traverse, path, state);
  }

  if (pattern.type === Syntax.ObjectPattern) {

    pattern.properties.forEach(function(prop, idx) {
      var comma = (idx !== pattern.properties.length - 1) ? ', ' : '';

      if (isPattern(prop.value)) {
        renderDesructuration(prop.value, [id, '.', prop.key.name], traverse, path, state);
      } else {
        utils.append(prop.value.name + ' = ', state);
        render([id, '.' + prop.key.name], traverse, path, state);
        utils.append(comma, state);
      }
    });

  } else {

    pattern.elements.forEach(function(elem, idx) {
      // null means skip
      if (elem === null) {
        return;
      }

      var comma = (idx !== pattern.elements.length - 1) ? ', ' : '';

      if (isPattern(elem)) {
        renderDesructuration(elem, [id, '[' + idx + ']'], traverse, path, state);
      } else if (elem.type === Syntax.SpreadElement) {
        utils.append(elem.argument.name + ' = ', state);
        render([id, '.slice(' + idx + ')'], traverse, path, state);
        utils.append(comma, state);
      } else {
        utils.append(elem.name + ' = ', state);
        render([id, '[' + idx + ']'], traverse, path, state);
        utils.append(comma, state);
      }
    });
  }
}
302667
function(arg) {

            var segments = this.segments;
            var numSegments = segments.length;
            // works even if path has no segments

            var currentSegment;

            var previousSegment = ((numSegments !== 0) ? segments[numSegments - 1] : null); // if we are appending to an empty path, previousSegment is null
            var nextSegment = null;

            if (!Array.isArray(arg)) { // arg is a segment
                if (!arg || !arg.isSegment) throw new Error('Segment required.');

                currentSegment = this.prepareSegment(arg, previousSegment, nextSegment);
                segments.push(currentSegment);

            } else { // arg is an array of segments
                if (!arg[0].isSegment) throw new Error('Segments required.');

                var n = arg.length;
                for (var i = 0; i < n; i++) {

                    var currentArg = arg[i];
                    currentSegment = this.prepareSegment(currentArg, previousSegment, nextSegment);
                    segments.push(currentSegment);
                    previousSegment = currentSegment;
                }
            }
        }
65473
function render(expr, traverse, path, state) {
  if (isString(expr)) {
    utils.append(expr, state);
  } else if (Array.isArray(expr)) {
    expr.forEach(function(w) {
      render(w, traverse, path, state);
    });
  } else {
    utils.move(expr.range[0], state);
    traverse(expr, path, state);
    utils.catchup(expr.range[1], state);
  }
}
634242
function(path) {
            const { node } = path;
            if (isVoid0(node.consequent) && isVoid0(node.alternate)) {
              path.replaceWith(t.sequenceExpression([path.node.test, VOID_0]));
            }
          }