本文整理汇总了TypeScript中fable-utils.client.send方法的典型用法代码示例。如果您正苦于以下问题:TypeScript client.send方法的具体用法?TypeScript client.send怎么用?TypeScript client.send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fable-utils.client
的用法示例。
在下文中一共展示了client.send方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getBabelAst
async function getBabelAst(path: string, options: FableSplitterOptions, info: CompilationInfo) {
let ast: Babel.types.Node | null = null;
if (FSHARP_EXT.test(path)) {
// return Babel AST from F# file
const fableMsg = JSON.stringify(Object.assign({}, options.fable, { path, rootDir: process.cwd() }));
const response = await fableUtils.client.send(options.port as number, fableMsg);
const babelAst = JSON.parse(response);
if (babelAst.error) {
throw new Error(babelAst.error);
} else if (path.endsWith(".fsproj")) {
info.projectFiles = babelAst.sourceFiles;
}
addLogs(babelAst.logs, info);
ast = babelAst;
} else {
// return Babel AST from JS file
path = JAVASCRIPT_EXT.test(path) ? path : path + ".js";
if (await fs.pathExists(path)) {
ast = await getBabelAstFromJsFile(path, info);
} else {
console.log(`fable: Skip missing JS file: ${path}`);
}
}
return ast;
}