當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript escodegen.generate函數代碼示例

本文整理匯總了TypeScript中escodegen.generate函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript generate函數的具體用法?TypeScript generate怎麽用?TypeScript generate使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了generate函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: function

        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,代碼行數:33,代碼來源:app.ts

示例2: function

        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,代碼行數:11,代碼來源:app.ts

示例3: getLscAst

    return qFs.read(inputLambdaScriptFile).then(function(lambdaScriptCode: string) {
        const lscAst = getLscAst(lambdaScriptCode),
            jsAst = astToJsAst(lscAst);
        logger.debug({jsAst: jsAst}, 'Converted LambdaScript AST to JS AST');

        const js = escodegen.generate(jsAst);
        logger.debug({js: js}, 'Generated raw js');

        const jsWithPrelude = withPrelude(js);
        logger.debug({jsWithPrelude: jsWithPrelude}, 'Added prelude to raw js');

        return qFs.write(outputJsFile, jsWithPrelude);
    });
開發者ID:NickHeiner,項目名稱:lambdascript,代碼行數:13,代碼來源:index.ts

示例4: bundle

export function bundle(options: IBundleOptions, host: IHost = new DefaultHost()): string {
  const context: IPaeckchenContext = {
    config: createConfig(options, host),
    host
  };
  if (!context.config.input.entryPoint) {
    throw new Error('Missing entry-point');
  }

  const detectedGlobals: IDetectedGlobals = {
    global: false,
    process: false,
    buffer: false
  };
  const paeckchenAst = parse(paeckchenSource);
  const modules = getModules(paeckchenAst).elements;
  const absoluteEntryPath = join(host.cwd(), context.config.input.entryPoint);
  // start bundling...
  enqueueModule(getModulePath('.', absoluteEntryPath, context));
  while (bundleNextModule(modules, context, detectedGlobals)) {
    process.stderr.write('.');
  }
  // ... when ready inject globals...
  injectGlobals(detectedGlobals, paeckchenAst, context);
  // ... and bundle global dependencies
  while (bundleNextModule(modules, context, detectedGlobals)) {
    process.stderr.write('.');
  }
  process.stderr.write('\n');

  const bundleResult = generate(paeckchenAst, {
    comment: true
  });
  if (context.config.output.file) {
    host.writeFile(
      host.joinPath(context.config.output.folder, context.config.output.file),
        bundleResult);
    return undefined;
  }
  return bundleResult;
}
開發者ID:ZauberNerd,項目名稱:paeckchen,代碼行數:41,代碼來源:bundle.ts

示例5: function

    files.forEach((file: {src: string[]; dest: string}) => {
      var jsFileContent = fs.readFileSync(file.src[0]).toString(),
        ast = esprima.parse(jsFileContent, {loc: true, range: true});
      // Ensure destination folder exists
      if (!fs.existsSync(path.dirname(file.dest))) {
        grunt.file.mkdir(path.dirname(file.dest));
      }
      var processedAst = estraverse.replace(ast, {
        enter: function(node: any) {
            if (node.type === 'ExpressionStatement' &&
                node.expression.type === 'CallExpression' &&
                remove.indexOf(node.expression.callee.name) > -1) {
                return {type:'EmptyStatement'};
            }
        }
      }), output = escodegen.generate(processedAst, {sourceMap: path.relative(path.dirname(file.dest), file.src[0]), sourceMapWithCode: true});

      var mapDest = file.dest + '.map';
      fs.writeFileSync(mapDest, output.map);
      fs.writeFileSync(file.dest, `${output.code}\n//# sourceMappingURL=${path.basename(file.dest)}.map`);
    });
開發者ID:Warlander,項目名稱:doppio,代碼行數:21,代碼來源:ice-cream.ts

示例6: addShadowDomTests

async function addShadowDomTests(element: ElementRepo): Promise<void> {
  const testDir = path.join(element.dir, 'test');
  if (!existsSync(testDir) || !fs.statSync(testDir).isDirectory()) {
    return;  // nothing to do
  }
  const testIndexFile = path.join(testDir, 'index.html');
  if (!existsSync(testIndexFile)) {
    return;  // nothing to do
  }

  const contents = fs.readFileSync(testIndexFile, 'utf8');
  const domTree = dom5.parse(contents);
  const scripts = dom5.queryAll(domTree, (n) => n.tagName === 'script');
  let updateNeeded = false;
  for (const script of scripts) {
    const data = script.childNodes[0];
    if (!data || data.nodeName !== '#text') {
      continue;
    }
    const program = espree.parse(data.value, {attachComment: true});
    estree_walker.walk(program, {
      enter(n) {
        if (!(n.type === 'CallExpression' &&
              n.callee.type === 'MemberExpression')) {
          return;
        }
        if (!(n.callee.object && n.callee.property)) {
          return;
        }
        if (!(n.callee.object.name === 'WCT' &&
              n.callee.property.name === 'loadSuites')) {
          return;
        }
        if (!(n.arguments && n.arguments.length === 1 &&
              n.arguments[0].type === 'ArrayExpression')) {
          return;
        }
        const testFilenameExpressions = n.arguments[0];
        const shadyFilenames = new Set<string>();
        const shadowFilenames = new Set<string>();
        for (const filenameExpression of testFilenameExpressions.elements) {
          if (/dom=shadow/.test(filenameExpression.value)) {
            shadowFilenames.add(filenameExpression.value);
          } else {
            shadyFilenames.add(filenameExpression.value);
          }
        }
        for (const shadyFilename of shadyFilenames) {
          if (!shadowFilenames.has(shadyFilename + '?dom=shadow')) {
            updateNeeded = true;
          }
        }
        testFilenameExpressions.elements = [];
        for (const shadyFilename of shadyFilenames) {
          testFilenameExpressions.elements.push(
              {type: 'Literal', value: shadyFilename});
        }
        for (const shadyFilename of shadyFilenames) {
          testFilenameExpressions.elements.push(
              {type: 'Literal', value: shadyFilename + '?dom=shadow'});
        }
      }
    });
    // Try to infer indentation
    let indentation = '  ';
    const parent = script.parentNode;
    const scriptIndex = parent.childNodes.indexOf(script);
    if (scriptIndex >= 0 &&
        parent.childNodes[scriptIndex - 1].nodeName === '#text') {
      const textJustBefore = parent.childNodes[scriptIndex - 1].value;
      indentation = textJustBefore.match(/( +)$/)[1];
    }
    data.value = '\n' + escodegen.generate(program, {
      comment: true,
      format: {
        indent: {
          style: '  ',
          base: (indentation.length / 2) + 1,
          adjustMultilineComment: true
        }
      }
    }) + '\n' + indentation;
  }

  if (updateNeeded) {
    fs.writeFileSync(testIndexFile, dom5.serialize(domTree) + '\n', 'utf8');
    element.needsReview = true;
    await makeCommit(
        element, ['test/index.html'],
        'Add shadow dom test configurations.');
  }
}
開發者ID:BruceZu,項目名稱:tedium,代碼行數:92,代碼來源:tests.ts

示例7:

    safeConcatenation: true,
    preserveBlankLines: true
};

let emptyMozillaOptions: escodegen.MozillaOptions = {};
let mozillaOptions: escodegen.MozillaOptions = {
    starlessGenerator: true,
    parenthesizedComprehensionBlock: true,
    comprehensionExpressionStartsWithAssignment: true
}

let emptyGenerateOptions: escodegen.GenerateOptions = {};
let generateOptions: escodegen.GenerateOptions = {
    format: formatOptions,
    moz: mozillaOptions,
    parse: () => {},
    comment: true,
    sourceMap: " ",
    sourceMapWithCode: true,
    sourceContent: " ",
    sourceCode: " ",
    sourceMapRoot: " ",
    directive: true,
    file: " ",
    verbatim: " "
};

let precedence: escodegen.Precedence = escodegen.Precedence.Primary;
let myCode: string = escodegen.generate({}, generateOptions);
let ast: any = escodegen.attachComments({}, {}, {});
開發者ID:AbraaoAlves,項目名稱:DefinitelyTyped,代碼行數:30,代碼來源:escodegen-tests.ts

示例8: generate

export function generate(node: ESTree.Node): string {
  return escodegen.generate(node);
};
開發者ID:devlucas,項目名稱:stryker,代碼行數:3,代碼來源:parserUtils.ts

示例9: function

export default function (tree: ESTree.Program, options?: TransformOptions): string {
    return escodegen.generate(transform(tree, options));
}
開發者ID:KallynGowdy,項目名稱:RxUI-View,代碼行數:3,代碼來源:emit.ts


注:本文中的escodegen.generate函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。