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


TypeScript core.transformFile函数代码示例

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


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

示例1: addLogs

 return new Promise<Babel.types.Node | null>((resolve) => {
     Babel.transformFile(path, { code: false, ast: true }, (error, res) => {
         if (error != null) {
             const log = `${path}(1,1): error BABEL: ${error.message}`;
             addLogs({ error: [log] }, info);
             resolve(null);
         } else {
             resolve(res != null ? res.ast : null);
         }
     });
 });
开发者ID:TheAngryByrd,项目名称:Fable,代码行数:11,代码来源:index.ts

示例2: addLogs

 return new Promise<Babel.types.Program | null>((resolve) => {
     Babel.transformFile(path, { code: false, ast: true }, (error, res) => {
         if (error != null) {
             const log = `${path}(1,1): error BABEL: ${error.message}`;
             addLogs({ error: [log] }, info);
             resolve(null);
         } else {
             let program: Babel.types.Program | null = null;
             if (res != null && res.ast != null) {
                 program = (res.ast as Babel.types.File).program;
             }
             resolve(program);
         }
     });
 });
开发者ID:rfrerebe,项目名称:Fable,代码行数:15,代码来源:index.ts

示例3: addLogs

 return new Promise<Babel.types.Program | null>((resolve) => {
     const babelOpts = {
         code: false,
         ast: true,
         // Prevent Babel from searching for config files, see #1751
         configFile: false,
         babelrc: false
     };
     Babel.transformFile(path, babelOpts, (error, res) => {
         if (error != null) {
             const log = `${path}(1,1): error BABEL: ${error.message}`;
             addLogs({ error: [log] }, info);
             resolve(null);
         } else {
             let program: Babel.types.Program | null = null;
             if (res != null && res.ast != null) {
                 program = (res.ast as Babel.types.File).program;
             }
             resolve(program);
         }
     });
 });
开发者ID:ncave,项目名称:Fable,代码行数:22,代码来源:index.ts

示例4:

const options: babel.TransformOptions = {
    ast: true,
    sourceMaps: true
};

babel.transform("code();", options, (err, result) => {
    const { code, map, ast } = result!;
});

const transformSyncResult = babel.transformSync("code();", options);
if (transformSyncResult) {
    const { code, map, ast } = transformSyncResult;
}

babel.transformFile("filename.js", options, (err, result) => {
    const { code, map, ast } = result!;
});

babel.transformFileSync("filename.js", options)!.code;

const sourceCode = "if (true) return;";
const parsedAst = babel.parse(sourceCode, options);

babel.transformFromAst(parsedAst!, sourceCode, options, (err, result) => {
    const { code, map, ast } = result!;
});

const transformFromAstSyncResult = babel.transformFromAstSync(parsedAst!, sourceCode, options);
const { code, map, ast } = transformFromAstSyncResult!;
开发者ID:AlexGalays,项目名称:DefinitelyTyped,代码行数:29,代码来源:babel__core-tests.ts

示例5:

    sourceMaps: true
};

babel.transform("code();", options, (err, result) => {
    const { code, map, ast } = result!;
    const { body } = ast!.program;
});

const transformSyncResult = babel.transformSync("code();", options);
if (transformSyncResult) {
    const { code, map, ast } = transformSyncResult;
    const { body } = ast!.program;
}

babel.transformFile("filename.js", options, (err, result) => {
    const { code, map, ast } = result!;
    const { body } = ast!.program;
});

babel.transformFileSync("filename.js", options)!.code;

const sourceCode = "if (true) return;";
const parsedAst = babel.parse(sourceCode, options);

babel.transformFromAst(parsedAst!, sourceCode, options, (err, result) => {
    const { code, map, ast } = result!;
    const { body } = ast!.program;
});

const transformFromAstSyncResult = babel.transformFromAstSync(parsedAst!, sourceCode, options);
const { code, map, ast } = transformFromAstSyncResult!;
const { body } = ast!.program;
开发者ID:CNBoland,项目名称:DefinitelyTyped,代码行数:32,代码来源:babel__core-tests.ts


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