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


TypeScript babel-core.transformFile函數代碼示例

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


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

示例1: Promise

 return new Promise((resolve, reject) => {
   transformFile(filename, defaultOptions, (err, result) => {
     if (err) {
       reject(err);
     } else {
       resolve(result);
     }
   });
 });
開發者ID:Mercateo,項目名稱:typedocs,代碼行數:9,代碼來源:babel.ts

示例2: function



// Example from https://github.com/babel/babel/tree/master/packages/babel-core
const code = `class Example {}`;
const result = babel.transform(code, { /* options */ });
result.code; // Generated code
result.map; // Sourcemap
result.ast; // AST


// Examples from http://babeljs.io/docs/usage/api/
let options: babel.TransformOptions = {
    plugins: [
        "es2015-arrow-functions",
        "es2015-block-scoped-functions",
        "es2015-block-scoping",
        "es2015-classes",
    ],
    only: /.*\.js/,
    ast: false,
    sourceMaps: true
};

babel.transformFile("filename.js", options, function (err, result) {
    result.code;
    result.map;
    result.ast;
});

babel.transformFileSync("filename.js", options).code;
開發者ID:1drop,項目名稱:DefinitelyTyped,代碼行數:28,代碼來源:babel-core-tests.ts

示例3: function

const options: babel.TransformOptions = {
    plugins: [
        "es2015-arrow-functions",
        "es2015-block-scoped-functions",
        "es2015-block-scoping",
        "es2015-classes",
    ],
    only: /.*\.js/,
    ast: false,
    sourceMaps: true
};

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

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

// Slightly modified example from https://github.com/thejameskyle/babel-handbook/blob/master/translations/en/plugin-handbook.md#-pre-and-post-in-plugins
export default function(): babel.PluginObj<{ cache: Map<string, number>}> {
    return {
        pre(state) {
            this.cache = new Map();
        },
        visitor: {
            StringLiteral(path) {
            this.cache.set(path.node.value, 1);
開發者ID:AlexGalays,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:babel-core-tests.ts


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