123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- 'use strict';
- const {
- VMError
- } = require('./bridge');
- let cacheCoffeeScriptCompiler;
- function getCoffeeScriptCompiler() {
- if (!cacheCoffeeScriptCompiler) {
- try {
-
-
-
- const coffeeScript = require('coffee-script');
- cacheCoffeeScriptCompiler = (code, filename) => {
- return coffeeScript.compile(code, {header: false, bare: true});
- };
- } catch (e) {
- throw new VMError('Coffee-Script compiler is not installed.');
- }
- }
- return cacheCoffeeScriptCompiler;
- }
- function removeShebang(code) {
- if (!code.startsWith('#!')) return code;
- return '//' + code.substring(2);
- }
- function jsCompiler(code, filename) {
- return removeShebang(code);
- }
- function lookupCompiler(compiler) {
- if ('function' === typeof compiler) return compiler;
- switch (compiler) {
- case 'coffeescript':
- case 'coffee-script':
- case 'cs':
- case 'text/coffeescript':
- return getCoffeeScriptCompiler();
- case 'javascript':
- case 'java-script':
- case 'js':
- case 'text/javascript':
- return jsCompiler;
- default:
- throw new VMError(`Unsupported compiler '${compiler}'.`);
- }
- }
- exports.removeShebang = removeShebang;
- exports.lookupCompiler = lookupCompiler;
|