当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript esprima.parse函数代码示例

本文整理汇总了TypeScript中esprima.parse函数的典型用法代码示例。如果您正苦于以下问题:TypeScript parse函数的具体用法?TypeScript parse怎么用?TypeScript parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了parse函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: it

    it('should discover dependencies from a syntax tree', () => {
      const validIds = ['RESULT', 'GROSS', 'NET', 'STEP_1'];
      const expression = `RESULT = (STEP_1 + GROSS - NET) / NET * STEP_1`;

      const deps = discoverDependencies(esprima.parse(expression), validIds);

      expect(deps.sort()).to.be.deep.equal(['RESULT', 'STEP_1', 'GROSS', 'NET'].sort());
    });
开发者ID:pretur,项目名称:pipeline,代码行数:8,代码来源:utils.spec.ts

示例2: purecheck

function purecheck(code: string,
	{ globals = OPT_GLOBALS } = {}): FPErrorReport {
	let tree = esprima.parse(code, {
		loc: true,
		comment: true,
		sourceType: 'module',
	});
	return checkTree(tree, globals);
}
开发者ID:lcrespom,项目名称:purecheck,代码行数:9,代码来源:purecheck.ts

示例3: parse

export function parse(code: string): any {
  if (code === undefined) {
    throw new Error('Code parameter cannot be undefined');
  }
  if (code === '') {
    return {};
  }

  var abstractSyntaxTree = esprima.parse(code, esprimaOptions);

  return abstractSyntaxTree;
};
开发者ID:devlucas,项目名称:stryker,代码行数:12,代码来源:parserUtils.ts

示例4: discoverDependencies

export function discoverDependencies(expression: string | ESTree.Program, validIdentifiers: string[]): string[] {
  const ast = typeof expression === 'string' ? esprima.parse(expression) : expression;

  const identifiers = [];

  walk(ast, node => {
    if (node &&
      node.type === 'Identifier' &&
      validIdentifiers.indexOf(node.name) !== -1 &&
      identifiers.indexOf(node.name) === -1) {
      identifiers.push(node.name);
    }
  });

  return identifiers;
}
开发者ID:pretur,项目名称:pipeline,代码行数:16,代码来源:utils.ts

示例5: requires

function requires(code: string): string[] {
    let ast = esprima.parse(code);
    let requires: string[] = [];
    estraverse.traverse(ast, {
        enter: node => {
            if (node.type == "CallExpression" && node.callee.name == "require") {
                if (node.arguments > 1) {
                    throw "require 的參數大於 1";
                }
                if (node.arguments[0].type != "Literal") {
                    throw "require 的參數解析失敗";
                }
                requires.push(node.arguments[0].value);
            }
        }
    });
    return requires;
}
开发者ID:leon740727,项目名称:wcp,代码行数:18,代码来源:type-js.ts

示例6: getNodeStructure

 /**
  *  JSCrush version of following code
  *
  *  (function () {
  *      var _console = []["filter"]["constructor"]("return this")().console;
  *      var _function = function () {};
  *
  *      _console.log = _function;
  *      _console.info = _function;
  *      _console.warn = _function;
  *      _console.error = _function;
  *  _console
  *  })();
  *
  * @returns {INode}
  */
 protected getNodeStructure (): INode {
     return NodeUtils.getBlockStatementNodeByIndex(
         esprima.parse(`
             (function () {
                 var _ = '(\u0004\u0006\u0003\u0005[]' + '["filter"]["\u0007tructor"]' + '("return this")()' + '.' + '\u0003;\u0006\u0002\u0005\u0004};' + '_\u0003.log\u0001.in' + 'fo\u0001.' + 'war' + 'n\u0001.er' + 'r' + 'or\u0001})();' + '\u0001\u0005_\u0002;' + '_\u0003\u0002function' + '\u0003\u0007ole\u0004\u0002 ()' + '{\u0005 = \u0006var ' + '_\u0007cons', 
                     Y, 
                     $;
                 
                 for (Y in $ = "\u0007\u0006\u0005\u0004\u0003\u0002\u0001") {
                   var arr = _.split($[Y]);
                   _ = arr.join(arr.pop());
                 }
                 
                 []["filter"]["constructor"](_)();
             })()
         `)
     );
 }
开发者ID:duczone,项目名称:javascript-obfuscator,代码行数:34,代码来源:ConsoleOutputDisableExpressionNode.ts

示例7: esprimaParse

function esprimaParse(source: string, options: ParserOptions = {}) {
  try {
    return esprima.parse(
      source,
      Object.assign(
        {
          range: true,
          comment: true,
          attachComment: true,
          loc: true,
          source: true
        },
        options
      )
    );
  } catch (e) {
    throw new ParseError(e);
  }
}
开发者ID:metaes,项目名称:metaes,代码行数:19,代码来源:parse.ts

示例8: function

    paths.forEach((p:string) => {
      var src = fs.readFileSync(p).toString()
      var ast = esprima.parse(src, {comment: true, attachComment: true})

      var matcher = jsstana.createMatcher("(call (lookup AWS.util.update) ? ?)")

      estraverse.traverse(ast, {
        enter: function (n:any) {
          if (matcher(n)) {
            var classname = escodegen.generate(n.arguments[0]).replace(/AWS\.(\w+)\.prototype/, "$1")

            var methodList = n.arguments[1].properties.map((x:any) => {
              var context = {
                classname: classname,
                name: x.key.name,
                commentStr: (x.leadingComments && x.leadingComments.map((x: any) => { return x.value }).join('\n')) || ""
              } as ExtraClientMethod

              context.commentStr = context.commentStr.replace(/\n\s+\*/g, "\n     *");

              var m = /@api\s+private/.exec(context.commentStr)

              if (m) {
                return null
              }

              if (0 == context.commentStr.length) {
                context.commentStr = null;
              }

              return context
            }).filter((x: ExtraClientMethod) => {
              return null != x
            })

            console.log("Adding class: ", classname, " and methods: ", methodList)

            methodsToAdd[classname] = methodList
          }
        }
      })
    })
开发者ID:AitorGuerrero,项目名称:aws-sdk-typescript,代码行数:42,代码来源:app.ts

示例9: function

    paths.forEach(function(p: string) {
      var src = fs.readFileSync(p).toString()
      var ast = esprima.parse(src)

      var matcher = jsstana.createMatcher("(call (lookup AWS.util.update) ? ?)")

      estraverse.traverse(ast, {
        enter: function(n: any) {
          if (matcher(n)) {
            var classname = escodegen.generate(n.arguments[0]).replace(/AWS\.(\w+)\.prototype/, "$1")

            var methodList = n.arguments[1].properties.map(function(x: any) { return x.key.name })

            console.log("Adding class: ", classname, " and methods: ", methodList)

            methodsToAdd[classname] = methodList
          }
        }
      })
    })
开发者ID:Bnaya,项目名称:aws-sdk-typescript,代码行数:20,代码来源:app.ts

示例10: function

    fs.readFile(fullPath, "utf8", function(err, code) {
      if (err) {
        throw err;
      }

      n.Program.assert(esprimaParse(code), true);
      n.Program.assert(esprimaParse(code, {
        loc: true
      }), true);

      done();
    });
开发者ID:benjamn,项目名称:ast-types,代码行数:12,代码来源:shared.ts


注:本文中的esprima.parse函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。