本文整理汇总了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;未经允许,请勿转载。 |
请发表评论