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