Пример #1
0
 infer.withContext(ctx, function() {
   var ast = infer.parse(text);
   infer.analyze(ast, "steal");
   infer.findRefs(ast, ctx.topScope, "steal", ctx.topScope, function(ref) {
     stealFound = stealFound || !!ref;
   });
 });
 infer.withContext(context, function () {
   file.ast = infer.parse(file.text, {
     directSourceFile: file,
     allowReturnOutsideFunction: true,
     allowImportExportEverywhere: true,
     ecmaVersion: 6
   });
   file.scope = context.topScope;
   if (wrap) {
     file.scope = buildWrappingScope(file.scope, file.name, file.ast);
   }
   infer.analyze(file.ast, file.text, file.scope);
 });
Пример #3
0
  infer.withContext(cx, function() {
    //console.log(JSON.stringify(filename));
    var ast = infer.parse(fileContents, {}, {});
    infer.analyze(ast, "file:"+filename /* just an id */);
    // find all calls
    require("acorn/dist/walk").simple(ast, { "CallExpression" : function(n) {
     var expr = infer.findExpressionAt(n.callee);
     var type = infer.expressionType(expr);

     // Try and handle 'require(...).foo) - this doesn't work for 
     // var fs = require("fs") though.
     if (n.callee.type=="MemberExpression" && 
         n.callee.object.type=="CallExpression" &&
         n.callee.object.callee.type=="Identifier" &&
         n.callee.object.callee.name=="require" &&
         n.callee.object.arguments.length==1 &&
         n.callee.object.arguments[0].type=="Literal") {
       var lib = n.callee.object.arguments[0].value;
       var name = n.callee.property.name;       
       if (defs[0][lib] && defs[0][lib][name] && defs[0][lib][name]["!url"]) { 
//         console.log(">>>>>>>>>>>>>>>"+lib+":"+name);       
//         console.log(defs[0][lib][name], defs[0][lib][name]["!url"]);
         addLink(defs[0][lib][name]["!url"], n);
       }
     }

     // search prototype chain of type to try and find our call
     if (type.forward && type.types) {
       var name = type.forward[0].propName;
       type.types.forEach(function(t) {
         var def = undefined;
         while (t && !def) {
           if (t.props && name in t.props)
             def = t.props[name];
           t = t.proto;
         }
         if (def) type = def;
       });
     }
     if (type && type.types && type.types.length>0) {
       var url = type.types[0].url;
       if (url) addLink(url, n);
     }
    }});
  });