How to use the acorn/dist/walk.simple function in acorn

To help you get started, we’ve selected a few acorn 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 zhang14725804 / notebook / react-vue / vue-src / packages / weex-template-compiler / build.js View on Github external
function generateBinding (exp) {
  if (exp && typeof exp === 'string') {
    var ast = null;
    try {
      ast = acorn.parse(("(" + exp + ")"));
    } catch (e) {
      // warn(`Failed to parse the expression: "${exp}"`)
      return ''
    }

    var output = '';
    walk.simple(ast, {
      Expression: function Expression (node) {
        output = nodeToBinding(node);
      }
    });
    return output
  }
}
github pugjs / pug-lexer / test / check-lexer-functions.js View on Github external
module.exports = function () {
  var str = fs.readFileSync(__dirname + '/../index.js', 'utf8');
  var ast = acorn.parse(str, {locations: true});
  walk.simple(ast, {
    CallExpression: function (node) {
      checkDirectCalls(node);
      checkMissingLexerFunction(node);
    }
  });
  if (hadErrors) process.exit(1);
};
github thx / magix-combine / plugins / tmpl-attr-object.js View on Github external
if (stringReg.test(node.raw)) {
                let q = node.raw.charAt(0);
                let value = node.raw.slice(1, -1);
                if (q == '"') {
                    q = '\'';
                    value = value.replace(/'/g, '\\\'');
                }
                value = escapeQ(value);
                modifiers.push({
                    start: node.start,
                    end: node.end,
                    value: q + value + q
                });
            }
        };
        walker.simple(ast, {
            Property(node) {
                let key = node.key;
                let value = node.value;
                if (key.type == 'Literal') {
                    processString(key);
                }
                if (value.type == 'Identifier' || value.type == 'MemberExpression') {
                    let oValue = str.slice(value.start, value.end);
                    if (node.shorthand) {
                        modifiers.push({
                            start: node.end,
                            end: node.end,
                            value: ':' + endChar + '",' + oValue + ',"' + startChar
                        });
                    } else if (node.computed) {
                        modifiers.push({
github aredotna / ervell / node_modules / browserify / node_modules / module-deps / node_modules / detective / index.js View on Github external
var isRequire = opts.isRequire || function (node) {
        return node.callee.type === 'Identifier'
            && node.callee.name === word
        ;
    };
    
    var modules = { strings : [], expressions : [] };
    if (opts.nodes) modules.nodes = [];
    
    var wordRe = word === 'require' ? requireRe : RegExp('\\b' + word + '\\b');
    if (!wordRe.test(src)) return modules;
    
    var ast = parse(src, opts.parse);
    
    walk.simple(ast, {
        CallExpression: function (node) {
            if (!isRequire(node)) return;
            if (node.arguments.length) {
                if (node.arguments[0].type === 'Literal') {
                    modules.strings.push(node.arguments[0].value);
                }
                else {
                    modules.expressions.push(escodegen.generate(node.arguments[0]));
                }
            }
            if (opts.nodes) modules.nodes.push(node);
        }
    });
    
    return modules;
};
github dortaldt / notyet / node_modules / constantinople / index.js View on Github external
lastSRC = src;
  lastConstants = constants;
  if (!isExpression(src)) return lastRes = false;
  var ast;
  try {
    ast = acorn.parse(src, {
      ecmaVersion: 6,
      allowReturnOutsideFunction: true,
      allowImportExportEverywhere: true,
      allowHashBang: true
    });
  } catch (ex) {
    return lastRes = false;
  }
  var isConstant = true;
  walk.simple(ast, {
    Statement: function (node) {
      if (isConstant) {
        if (STATEMENT_WHITE_LIST[node.type] !== true) {
          isConstant = false;
        }
      }
    },
    Expression: function (node) {
      if (isConstant) {
        if (EXPRESSION_WHITE_LIST[node.type] !== true) {
          isConstant = false;
        }
      }
    },
    MemberExpression: function (node) {
      if (isConstant) {
github NCBI-Hackathons / deSRA / web / app / node_modules / constantinople / index.js View on Github external
lastSRC = src;
  lastConstants = constants;
  if (!isExpression(src)) return lastRes = false;
  var ast;
  try {
    ast = acorn.parse(src, {
      ecmaVersion: 6,
      allowReturnOutsideFunction: true,
      allowImportExportEverywhere: true,
      allowHashBang: true
    });
  } catch (ex) {
    return lastRes = false;
  }
  var isConstant = true;
  walk.simple(ast, {
    Statement: function (node) {
      if (isConstant) {
        if (STATEMENT_WHITE_LIST[node.type] !== true) {
          isConstant = false;
        }
      }
    },
    Expression: function (node) {
      if (isConstant) {
        if (EXPRESSION_WHITE_LIST[node.type] !== true) {
          isConstant = false;
        }
      }
    },
    MemberExpression: function (node) {
      if (isConstant) {
github buxlabs / amd-to-es6 / src / lib / getModuleCode.js View on Github external
module.exports = function (ast) {
  var body = []
  walk.simple(ast, {
    CallExpression: function (node) {
      if (isDefineWithDependencies(node) || isNamedDefine(node)) {
        let define = getDefineCallbackArguments(node)
        if (define.body.type === 'BlockStatement') {
          body = define.body.body
        } else {
          body = [{ type: 'ReturnStatement', argument: define.body }]
        }
      }
    }
  })
  return body
}
github aredotna / ervell / node_modules / jade / node_modules / constantinople / index.js View on Github external
lastSRC = src;
  lastConstants = constants;
  if (!isExpression(src)) return lastRes = false;
  var ast;
  try {
    ast = acorn.parse(src, {
      ecmaVersion: 6,
      allowReturnOutsideFunction: true,
      allowImportExportEverywhere: true,
      allowHashBang: true
    });
  } catch (ex) {
    return lastRes = false;
  }
  var isConstant = true;
  walk.simple(ast, {
    Statement: function (node) {
      if (isConstant) {
        if (STATEMENT_WHITE_LIST[node.type] !== true) {
          isConstant = false;
        }
      }
    },
    Expression: function (node) {
      if (isConstant) {
        if (EXPRESSION_WHITE_LIST[node.type] !== true) {
          isConstant = false;
        }
      }
    },
    MemberExpression: function (node) {
      if (isConstant) {
github UltimateSoftware / ng6-cli / lib / reflect.js View on Github external
CallExpression: function(callExpression) {

        if( callExpression.callee && callExpression.callee.object && callExpression.callee.property ) {

          if (callExpression.callee.object.name === 'angular' && callExpression.callee.property.name === 'module') {
            walk.simple(callExpression, {
              ArrayExpression: function (arrayExpression) {

                //todo: check whether the identifier already exists

                if (arrayExpression.elements.length > 0) {
                  lastAngularDependency = arrayExpression.elements[arrayExpression.elements.length - 1].end;
                } else {
                  arrayExpressionStart = arrayExpression.start + 1;
                }
              }
            });
          }
        }
      }
    });
github UltimateSoftware / ng6-cli / lib / reflect.js View on Github external
findLastAngularDependency: function(moduleFilePath) {

    var source = fs.readFileSync(moduleFilePath);
    var ast = acorn.parse(source, {sourceType: 'module', ranges: true});

    var lastAngularDependency = false;
    var arrayExpressionStart = false;

    walk.simple(ast, {
      CallExpression: function(callExpression) {

        if( callExpression.callee && callExpression.callee.object && callExpression.callee.property ) {

          if (callExpression.callee.object.name === 'angular' && callExpression.callee.property.name === 'module') {
            walk.simple(callExpression, {
              ArrayExpression: function (arrayExpression) {

                //todo: check whether the identifier already exists

                if (arrayExpression.elements.length > 0) {
                  lastAngularDependency = arrayExpression.elements[arrayExpression.elements.length - 1].end;
                } else {
                  arrayExpressionStart = arrayExpression.start + 1;
                }
              }