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


TypeScript decaffeinate-parser.parse函数代码示例

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


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

示例1: statement

function statement(code: string): Node {
  let body = parse(code).body;
  if (!body) {
    throw new Error('Expected non-null body.');
  }
  return body.statements[0];
}
开发者ID:alangpierce,项目名称:decaffeinate,代码行数:7,代码来源:Scope_test.ts

示例2: it

 it('does simple counting within a program', () => {
   let ast = parse(`
     x = 1
     for x in y
       console.log x
   `);
   strictEqual(countVariableUsages(ast, 'x'), 3);
   strictEqual(countVariableUsages(ast, 'y'), 1);
   strictEqual(countVariableUsages(ast, 'z'), 0);
 });
开发者ID:alangpierce,项目名称:decaffeinate,代码行数:10,代码来源:countVariableUsages_test.ts

示例3: it

 it('formats an AST for normal CoffeeScript code', () => {
   let source = stripSharedIndent(`
     loop
       x = a()
       break
   `);
   let formattedTokens = formatDecaffeinateParserAst(parse(source), new CodeContext(source));
   strictEqual(
     formattedTokens,
     stripSharedIndent(`
     Program [1:1(0)-3:8(22)] {
       body: Block [1:1(0)-3:8(22)] {
         inline: false
         statements: [
           Loop [1:1(0)-3:8(22)] {
             body: Block [2:3(7)-3:8(22)] {
               inline: false
               statements: [
                 AssignOp [2:3(7)-2:10(14)] {
                   assignee: Identifier [2:3(7)-2:4(8)] {
                     data: "x"
                   }
                   expression: FunctionApplication [2:7(11)-2:10(14)] {
                     function: Identifier [2:7(11)-2:8(12)] {
                       data: "a"
                     }
                     arguments: []
                   }
                 }
                 Break [3:3(17)-3:8(22)] {
                 }
               ]
             }
           }
         ]
       }
     }
   `) + '\n'
   );
 });
开发者ID:alangpierce,项目名称:decaffeinate,代码行数:40,代码来源:formatDecaffeinateParserAst_test.ts

示例4: convertCustomStage

function convertCustomStage(source: string, stageName: string, useCS2: boolean): ConversionResult {
  let context = new CodeContext(source);
  if (stageName === 'coffeescript-lexer') {
    let tokens = useCS2 ? getCoffee2Tokens(source) : getCoffee1Tokens(source);
    return {
      code: formatCoffeeScriptLexerTokens(tokens, context)
    };
  } else if (stageName === 'coffeescript-parser') {
    let nodes = useCS2 ? getCoffee2Nodes(source) : getCoffee1Nodes(source);
    return {
      code: formatCoffeeScriptAst(nodes, context)
    };
  } else if (stageName === 'coffee-lex') {
    return {
      code: formatCoffeeLexTokens(lex(source, { useCS2 }), context)
    };
  } else if (stageName === 'decaffeinate-parser') {
    return {
      code: formatDecaffeinateParserAst(decaffeinateParse(source, { useCS2 }), context)
    };
  } else {
    throw new Error(`Unrecognized stage name: ${stageName}`);
  }
}
开发者ID:alangpierce,项目名称:decaffeinate,代码行数:24,代码来源:index.ts

示例5: create

 static create(source: string, useCS2: boolean): DecaffeinateContext {
   let program = decaffeinateParse(source, { useCS2 });
   return new DecaffeinateContext(
     program,
     source,
     program.context.sourceTokens,
     program.context.ast,
     program.context.linesAndColumns,
     computeParentMap(program),
     computeScopeMap(program)
   );
 }
开发者ID:alangpierce,项目名称:decaffeinate,代码行数:12,代码来源:DecaffeinateContext.ts


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