• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript babel-core.transform函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: it

it('should move static apis under "Taro"', function () {
  const code = `
    import { noop } from '@tarojs/taro-h5';
    noop;
    noop();
  `

  const result = babel.transform(code, { plugins: [pluginOptions] })
  expect(result.code).toMatchSnapshot();

  const ast = result.ast as t.File
  const body = ast.program.body as [t.ImportDeclaration, t.ExpressionStatement]
  expect(t.isImportDeclaration(body[0])).toBeTruthy()
  expect(t.isExpressionStatement(body[1])).toBeTruthy()
  const defaultImport = body[0].specifiers.find(v => t.isImportDefaultSpecifier(v))
  expect(defaultImport).toBeTruthy()

  const taroName = defaultImport!.local.name
  let memberExpression = body[1].expression
  if (t.isCallExpression(body[1])) {
    memberExpression = (body[1].expression as t.CallExpression).callee
  }
  expect(memberExpression).toMatchObject(t.memberExpression(
    t.identifier(taroName),
    t.identifier('noop')
  ))
})
开发者ID:YangShaoQun,项目名称:taro,代码行数:27,代码来源:index-test.ts


示例2: default

export default () => ({
  visitor: {
    CallExpression(nodePath: NodePath<CallExpression>, { opts, file }: { opts: { configFile: string }, file: any }) {
      if (isRequireCallExpression(nodePath)) {
        const arg = (nodePath.get("arguments") as any)[0];
        const filename = file.opts.filename;
        const targetFilename = arg.node.value;
        const webpackConfig = opts.configFile ? resolveWebpackConfig(opts.configFile) : opts;

        const loaders = webpackConfig.module
          ? ((webpackConfig.module as NewModule).rules || (webpackConfig.module as OldModule).loaders)
          : [];

        if (arg && arg.isStringLiteral() && isFileNeedToProcess(targetFilename, loaders)) {
          const finalTargetFileName = path.resolve(path.dirname(filename), targetFilename);

          const webpackResult = runWebpackSync(finalTargetFileName, webpackConfig);

          if (webpackResult.length === 0) {
            return;
          }
          const webpackResultAst = transform(webpackResult).ast;
          const pickedWebpackExpr = pickTheReturnOfWebpackResult(webpackResultAst);

          if (pickedWebpackExpr !== null) {
            nodePath.replaceWith(pickedWebpackExpr);
          }
        }
      }
    },
  },
});
开发者ID:morlay,项目名称:babel-plugin-webpack-loaders-inline-exports,代码行数:32,代码来源:index.ts


示例3: transform

 .then((code) => {
     const result = transform(code, {
         presets: ['es2015'],
         plugins: [
             'transform-decorators-legacy',
             'transform-class-properties',
             'transform-decorators',
             'transform-object-rest-spread'
         ]
     }).code;
     return result;
 })
开发者ID:beregovoy68,项目名称:WavesGUI,代码行数:12,代码来源:utils.ts


示例4: runValidation

function runValidation(source: string, expectedOutput: {}, options: Options, skipNodeCheck: boolean): void {
  let compile = options.useCS2 ? cs2Compile : cs1Compile;
  let coffeeES5 = compile(source, { bare: true }) as string;
  let decaffeinateES6 = convert(source, options).code;
  let decaffeinateES5 =
    babel.transform(decaffeinateES6, {
      presets: ['es2015'],
      plugins: ['transform-optional-chaining']
    }).code || '';

  let coffeeOutput = runCodeAndExtract(coffeeES5);
  let decaffeinateOutput = runCodeAndExtract(decaffeinateES5);
  try {
    assertDeepEqual(decaffeinateOutput, coffeeOutput, 'decaffeinate and coffee output were different.');
  } catch (err) {
    // add some additional context for debugging
    err.message = `Additional Debug:
SOURCE
${source}
********************
INPUT -> COFFEE-SCRIPT -> ES5
${coffeeES5}
********************
INPUT -> DECAFFEINATE -> ES6
${decaffeinateES6}
********************
INPUT -> DECAFFEINATE -> ES6 -> BABEL -> ES5
${decaffeinateES5}
********************
COFFEE-SCRIPT ES5 compared to DECAFFEINATE/BABEL ES5
${err.message}`;
    throw err;
  }

  // Make sure babel and V8 behave the same if we're on node >= 6.
  if (!skipNodeCheck) {
    let nodeOutput = runCodeAndExtract(decaffeinateES6);
    assertDeepEqual(decaffeinateOutput, nodeOutput, 'babel and node output were different.');
  }

  if (expectedOutput !== undefined) {
    assertDeepEqual(decaffeinateOutput, expectedOutput, 'decaffeinate and expected output were different.');
  }
}
开发者ID:alangpierce,项目名称:decaffeinate,代码行数:44,代码来源:validate.ts


示例5: test

test("should transform code with absolute configFile", (t) => {
  const babelOptions = {
    plugins: [
      [
        webpackInlineLoaders,
        {
          configFile: path.join(process.cwd(), "./fixtures/webpack.config.js"),
        },
      ],
    ],
    filename: __filename,
  };

  const codeString = transform(source, babelOptions).code;

  const exports = getExportsFromCodeString(codeString);

  t.true(_.isObject(exports));
});
开发者ID:morlay,项目名称:babel-plugin-webpack-loaders-inline-exports,代码行数:19,代码来源:index.spec.ts


示例6: parseCode

export function parseCode (code: string) {
  return (transform(code, {
    parserOpts: {
      sourceType: 'module',
      plugins: [
        'classProperties',
        'jsx',
        'flow',
        'flowComment',
        'trailingFunctionCommas',
        'asyncFunctions',
        'exponentiationOperator',
        'asyncGenerators',
        'objectRestSpread',
        'decorators',
        'dynamicImport'
      ]
    }
  }) as { ast: t.File }).ast
}
开发者ID:YangShaoQun,项目名称:taro,代码行数:20,代码来源:utils.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript babel-core.transformFile函数代码示例发布时间:2022-05-25
下一篇:
TypeScript b-o-a.O类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap