Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
}
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
}
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];
},
});
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':
_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;
}
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('>>') + ' ';
exports.transformCoffee = function (input) {
return coffee.compile(input);
};
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);
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());
});