How to use the coffeescript.compile function in coffeescript

To help you get started, we’ve selected a few coffeescript examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gatsbyjs / gatsby / packages / gatsby-plugin-coffeescript / src / gatsby-node.js View on Github external
export function preprocessSource({ filename, contents }, pluginOptions) {
  // Don't need to account for ES6, Babylon can parse it.
  if (CJSX.test(filename)) {
    return compile(transform(contents), pluginOptions)
  } else if (COFFEE.test(filename)) {
    return compile(contents, pluginOptions)
  } else return null
}
github gatsbyjs / gatsby / packages / gatsby-plugin-coffeescript / src / gatsby-node.js View on Github external
export function preprocessSource({ filename, contents }, pluginOptions) {
  // Don't need to account for ES6, Babylon can parse it.
  if (CJSX.test(filename)) {
    return compile(transform(contents), pluginOptions)
  } else if (COFFEE.test(filename)) {
    return compile(contents, pluginOptions)
  } else return null
}
github parcel-bundler / parcel / packages / transformers / coffeescript / src / CoffeeScriptTransformer.js View on Github external
async transform({asset, options}) {
    let sourceFileName: string = relativeUrl(
      options.projectRoot,
      asset.filePath,
    );

    asset.type = 'js';
    let output = coffee.compile(await asset.getCode(), {
      filename: sourceFileName,
      sourceMap: options.sourceMaps,
    });

    // return from compile is based on sourceMaps option
    if (options.sourceMaps) {
      asset.setCode(output.js);
      asset.setMap(await SourceMap.fromRawSourceMap(output.v3SourceMap));
    } else {
      asset.setCode(output);
    }

    return [asset];
  },
});
github googleapis / cloud-debug-nodejs / src / agent / util / utils.ts View on Github external
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);
        }
      };
    case 'es6':
github DevExpress / testcafe / src / compiler / test-file / formats / coffeescript / compiler.js View on Github external
_compileCode (code, filename) {
        if (this.cache[filename])
            return this.cache[filename];

        const transpiled = CoffeeScript.compile(code, {
            filename,
            bare:      true,
            sourceMap: true,
            inlineMap: true,
            header:    false
        });

        const { babel }    = loadBabelLibs();
        const babelOptions = ESNextTestFileCompiler.getBabelOptions(filename, code);
        const compiled     = babel.transform(transpiled.js, babelOptions);

        this.cache[filename] = compiled.code;

        return compiled.code;
    }
github gruntjs / grunt-contrib-coffee / tasks / coffee.js View on Github external
var compileCoffee = function(code, options, filepath) {
    var coffeeOptions = _.clone(options);
    if (filepath) {
      coffeeOptions.filename = filepath;
      coffeeOptions.literate = isLiterate(path.extname(filepath));
    } else {
      coffeeOptions.literate = isLiterate(path.extname(options.joinExt));
    }

    try {
      return require('coffeescript').compile(code, coffeeOptions);
    } catch (e) {
      if (e.location == null ||
          e.location.first_column == null ||
          e.location.first_line == null) {
        grunt.log.error('Got an unexpected exception ' +
                        'from the coffee-script compiler. ' +
                        'The original exception was: ' +
                        e);
        grunt.log.error('(The coffee-script compiler should not raise *unexpected* exceptions. ' +
                        'You can file this error as an issue of the coffee-script compiler: ' +
                        'https://github.com/jashkenas/coffee-script/issues)');
      } else {
        var firstColumn = e.location.first_column;
        var firstLine = e.location.first_line;
        var codeLine = code.split('\n')[firstLine];
        var errorArrows = chalk.red('>>') + ' ';
github JacksonTian / loader-builder / lib / transform.js View on Github external
exports.transformCoffee = function (input) {
  return coffee.compile(input);
};
github RallyApps / rally-app-builder / lib / build / get-script.js View on Github external
let wrapper = function(error, fileContents){
      if (error) {
        error = new Error(`${file} could not be loaded. Is the path correct?`);
      }
      if (file.match(/.coffee$/)) {
        fileContents = coffeeScript.compile(fileContents);
      }
      return callback(error, fileContents);
    };
    return fs.readFile(file, "utf-8", wrapper);
github mhevery / jasmine-node / lib / jasmine-node / requirejs-runner.js View on Github external
specCollection.getSpecs().forEach(function(s){
    var script = fs.readFileSync(s.path(), 'utf8');

    if (s.filename().substr(-6).toLowerCase() == 'coffee') {
      script = coffeescript.compile(script);
    }

    var newContext = buildNewContext(s);
    newContext.setTimeout = jasmine.getGlobal().setTimeout;
    newContext.setInterval = jasmine.getGlobal().setInterval;

    var vmContext = vm.createContext(newContext);
    vm.runInContext(template, vmContext);
    vm.runInContext(script, vmContext, s.path());
  });