本文整理匯總了TypeScript中babel-core.transformFileSync函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript transformFileSync函數的具體用法?TypeScript transformFileSync怎麽用?TypeScript transformFileSync使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了transformFileSync函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: getFileAstAsync
async function getFileAstAsync(path: string, options: FableCompilerOptions, info: CompilationInfo) {
let ast: Babel.BabelFileResult | undefined;
if (FSHARP_EXT.test(path)) {
// return Babel AST from F# file
const fableMsg = JSON.stringify(Object.assign({}, options.fable, { path }));
const response = await fableUtils.client.send(options.port as number, fableMsg);
const babelAst = JSON.parse(response);
if (babelAst.error) {
throw new Error(babelAst.error);
}
addLogs(babelAst.logs, info);
ast = Babel.transformFromAst(babelAst, undefined, { code: false });
} else {
// return Babel AST from JS file
path = JAVASCRIPT_EXT.test(path) ? path : path + ".js";
if (fs.existsSync(path)) {
try {
ast = Babel.transformFileSync(path, { code: false });
} catch (err) {
const log = `${path}(1,1): error BABEL: ${err.message}`;
addLogs({ error: [log] }, info);
}
} else {
console.log(`fable: Skipping missing JS file: ${path}`);
}
}
return ast;
}
示例2: pathJoin
babelAst.jsIncludes.forEach(js => {
parsed = babel.transformFileSync(js.sourcePath, babelOpts);
res.push({
isEntry: false,
fileName: pathJoin(outDir, "js_includes/" + js.name) + ".js",
code: parsed.code,
map: parsed.map
});
});
示例3: getFileAstAsync
async function getFileAstAsync(path: string, options: FableCompilerOptions) {
let result: Babel.BabelFileResult | undefined;
if (FSHARP_EXT.test(path)) {
// return Babel AST from F# file
const fableMsg = JSON.stringify(Object.assign({}, options.fable, { path }));
const babelAst = JSON.parse(await client.send(options.port, fableMsg));
if (babelAst.error) { throw new Error(babelAst.error); }
Object.keys(babelAst.logs || {}).forEach((key) => {
ensureArray(babelAst.logs[key]).forEach(
(log: string) => output(key)(`${key} ==> ${log}`));
});
result = Babel.transformFromAst(babelAst, undefined, { code: false });
} else {
// return Babel AST from JS file
path = JAVASCRIPT_EXT.test(path) ? path : path + ".js";
if (fs.existsSync(path)) {
result = Babel.transformFileSync(path, { code: false });
}
}
return result;
}
示例4: 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;