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