本文整理汇总了TypeScript中coffeescript.compile函数的典型用法代码示例。如果您正苦于以下问题:TypeScript compile函数的具体用法?TypeScript compile怎么用?TypeScript compile使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了compile函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: switch
const compile_and_resolve_deps = (input: {code: string, lang: string, file: string}) => {
let code: string
switch (input.lang) {
case "coffeescript":
try {
code = coffee.compile(input.code, {bare: true, shiftLine: true})
} catch (error) {
return reply({error: mkCoffeescriptError(error, input.file)})
}
break;
case "javascript":
case "typescript":
code = input.code
break;
case "less":
const options = {
paths: [path.dirname(input.file)],
compress: true,
ieCompat: false,
}
less.render(input.code, options, (error: any, output: any) => {
if (error != null)
reply({error: mkLessError(error, input.file)})
else
reply({code: output.css})
})
return
default:
throw new Error(`unsupported input type: ${input.lang}`)
}
const result = ts.transpileModule(code, {
fileName: input.file,
reportDiagnostics: true,
compilerOptions: {
noEmitOnError: false,
noImplicitAny: false,
target: ts.ScriptTarget.ES5,
module: ts.ModuleKind.CommonJS,
},
})
if (result.diagnostics != null && result.diagnostics.length > 0) {
const diagnostic = result.diagnostics[0]
return reply({error: mkTypeScriptError(diagnostic)})
}
const source = result.outputText
try {
const deps = detective(source)
return reply({ code: source, deps: deps })
} catch(error) {
return reply({error: error})
}
}
示例2: task
task("test:compile", async () => {
const success = compileTypeScript("./test/tsconfig.json", {log})
if (argv.emitError && !success)
process.exit(1)
for (const file of scan("./test", [".coffee"])) {
const js = coffee.compile(read(file)!, {bare: true})
write(join("./build", rename(file, {ext: ".js"})), js)
}
})
示例3: require
return uncompiled => {
const comp = require('coffeescript');
const compiled = comp.compile('0 || (' + uncompiled + ')');
// Strip out coffeescript scoping wrapper to get translated condition
const re = /\(function\(\) {\s*0 \|\| \((.*)\);\n\n\}\)\.call\(this\);/;
const match = re.exec(compiled);
if (match && match.length > 1) {
return match[1].trim();
} else {
throw new Error('Compilation Error for: ' + uncompiled);
}
};