How to use the decaffeinate.convert function in decaffeinate

To help you get started, we’ve selected a few decaffeinate 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 hypothesis / client / scripts / decaf / decaf.js View on Github external
function convertFile(inFile, outFile) {
  console.log('Converting', inFile);

  let js;

  try {
    js = decaffeinate.convert(fs.readFileSync(inFile).toString('utf8'));
  } catch (err) {
    return Promise.reject(err);
  }

  return reformat(js).then(result => {
    fs.writeFileSync(outFile, result);
  });
}
github nikaspran / coffee-to-ts / src / index.js View on Github external
fs.readFile(fileName, (err, file) => {
			if (err) {
				console.log(`Could not read ${fileName}: ${err}`);
				return stats.report('failureRead', fileName);
			}

			const coffeeScript = file.toString();
			let es6;
			try {
				es6 = decaffeinate.convert(coffeeScript).code;
			} catch (err) {
				console.log(`Could not decaffeinate ${fileName}: ${err}`);
				return stats.report('failureDecaffeinate', fileName);
			}

			let typescript;
			try {
				typescript = jsToTs(es6);
			} catch (err) {
				console.log(`Could not convert ${fileName}:`);
				console.error(err.stack);
				return stats.report('failureSelf', fileName);
			}

			const outputFileName = fileName.replace(/\.coffee$/, '.ts');
			fs.writeFile(outputFileName, typescript, function (err) {
github nikaspran / coffee-to-ts / lib / index.js View on Github external
fs.readFile(fileName, function (err, file) {
			if (err) {
				console.log('Could not read ' + fileName + ': ' + err);
				return stats.report('failureRead', fileName);
			}

			var coffeeScript = file.toString();
			var es6 = void 0;
			try {
				es6 = decaffeinate.convert(coffeeScript).code;
			} catch (err) {
				console.log('Could not decaffeinate ' + fileName + ': ' + err);
				return stats.report('failureDecaffeinate', fileName);
			}

			var typescript = void 0;
			try {
				typescript = jsToTs(es6);
			} catch (err) {
				console.log('Could not convert ' + fileName + ':');
				console.error(err.stack);
				return stats.report('failureSelf', fileName);
			}

			var outputFileName = fileName.replace(/\.coffee$/, '.ts');
			fs.writeFile(outputFileName, typescript, function (err) {

decaffeinate

Move your CoffeeScript source to modern JavaScript.

MIT
Latest version published 2 years ago

Package Health Score

62 / 100
Full package analysis

Popular decaffeinate functions