當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。