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


TypeScript astring.generate函数代码示例

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


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

示例1: elaborate

  elaborate() {
    return stripIndent`
      This "if" block requires corresponding "else" block which will be
      evaluated when ${generate(this.node.test)} expression evaluates to false.

      Later in the course we will lift this restriction and allow "if" without
      else.
    `
  }
开发者ID:evansb,项目名称:source-toolchain,代码行数:9,代码来源:noIfWithoutElse.ts

示例2: elaborate

  elaborate() {
    let ifOrElse
    let header
    let body
    if (this.type === 'consequent') {
      ifOrElse = 'if'
      header = `if (${generate(this.node.test)})`
      body = this.node.consequent
    } else {
      ifOrElse = header = 'else'
      body = this.node.alternate
    }

    return stripIndent`
      ${ifOrElse} block need to be enclosed with a pair of curly braces.

      ${header} {
        ${generate(body)}
      }

      An exception is when you have an "if" followed by "else if", in this case
      "else if" block does not need to be surrounded by curly braces.

      if (someCondition) {
        // ...
      } else /* notice missing { here */ if (someCondition) {
        // ...
      } else {
        // ...
      }

      Rationale: Readability in dense packed code.

      In the snippet below, for instance, with poor indentation it is easy to
      mistaken hello() and world() to belong to the same branch of logic.

      if (someCondition) {
        2;
      } else
        hello();
      world();

    `
  }
开发者ID:evansb,项目名称:source-toolchain,代码行数:44,代码来源:bracesAroundIfElse.ts

示例3: astToHDWalletProvider

  function astToHDWalletProvider(node: ESTree.NewExpression): IProvider {
    const provider: IProvider = {
      raw: generate(node),
    };

    const mnemonicNode = node.arguments[0];
    if (mnemonicNode && mnemonicNode.type === 'Literal') {
      provider.mnemonic = '' + mnemonicNode.value;
    }

    const urlNode = node.arguments[1];
    if (urlNode && urlNode.type === 'Literal') {
      provider.url = '' + urlNode.value;
    }

    if (urlNode && urlNode.type !== 'Literal') {
      provider.url = generate(urlNode);
    }

    return provider;
  }
开发者ID:chrisseg,项目名称:vscode-azure-blockchain-ethereum,代码行数:21,代码来源:truffleConfig.ts

示例4: while

  tests.forEach(t => {
    const generator = evaluators[t.statement.type](t.statement, state)
    let isDone = false

    while (!isDone) {
      const g = generator.next()
      isDone = g.done
      state = g.value
    }

    if (state.value !== t.expectedValue) {
      // tslint:disable-next-line
      console.log(`L${t.statement.loc!.start.line}: ${generate(t.statement)}`)
    }

    expect(state.value).toBe(t.expectedValue)
  })
开发者ID:evansb,项目名称:source-toolchain,代码行数:17,代码来源:conformation.ts

示例5: createInterpreter

export const testVisualizer = (program: string, expectedOutput: string[]) => {
  let state = createInterpreter()
  let visualizer = create()

  const node = parse(program, 3).parser.program!
  const evaluator = evalProgram(node, state)
  const prints = []

  let gen = evaluator.next()
  while (gen) {
    state = gen.value
    if (!state) {
      break
    }
    const prev = visualizer
    visualizer = next(visualizer, state)
    if (visualizer.root && visualizer.id !== prev.id) {
      prints.push(generate(visualizer.root))
    }
    gen = evaluator.next()
  }
  expect(prints).toEqual(expectedOutput)
}
开发者ID:evansb,项目名称:source-toolchain,代码行数:23,代码来源:visualizer.ts

示例6: generate

 const fixs = this.fixs.map(n => '\t' + generate(n)).join('\n')
开发者ID:evansb,项目名称:source-toolchain,代码行数:1,代码来源:singleVariableDeclaration.ts

示例7: writeAST

 public async writeAST(): Promise<void> {
   return fs.writeFile(this.filePath, generate(this.ast as ESTree.Node, {comments: true}));
 }
开发者ID:chrisseg,项目名称:vscode-azure-blockchain-ethereum,代码行数:3,代码来源:truffleConfig.ts

示例8: generate

import { baseGenerator, generate } from "astring";
import { FunctionExpression, MemberExpression, Program } from "estree";
import { Stream } from "stream";

const ast: Program = null;
const functionE: FunctionExpression = null;
const memberE: MemberExpression = null;

// should accept different nodes
generate(ast);
generate(functionE);
generate(memberE);

// options without output option should generate string
const string: string = generate(ast, {
    comments: true,
    generator: baseGenerator,
    indent: "\t",
    lineEnd: "\n",
    startingIndentLevel: 42,
    sourceMap: null
});

// options with output option should return Stream
const stream: Stream = generate(ast, {
    output: new Stream()
});

// Generator should map node types to functions whose first parameter is same node type
baseGenerator.Program(ast, { write(s: string) { return; } });
baseGenerator.FunctionExpression(functionE, { write(s: string) { return; } });
开发者ID:AlexGalays,项目名称:DefinitelyTyped,代码行数:31,代码来源:astring.test.ts


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