coffee-compiler.js 753 B

12345678910111213141516171819202122232425262728
  1. var ensureRequire = require('../ensure-require.js')
  2. const throwError = require('../throw-error')
  3. const loadBabelConfig = require('../load-babel-config.js')
  4. module.exports = function (raw, vueJestConfig, filePath) {
  5. ensureRequire('coffee', ['coffeescript'])
  6. var coffee = require('coffeescript')
  7. var compiled
  8. var babelConfig = loadBabelConfig(vueJestConfig, filePath)
  9. // babel throws error if filename is undefined, "unknown" is default
  10. if (!babelConfig.filename) babelConfig.filename = 'unknown'
  11. try {
  12. compiled = coffee.compile(raw, {
  13. bare: true,
  14. sourceMap: true,
  15. transpile: babelConfig
  16. })
  17. return {
  18. code: compiled.js,
  19. map: compiled.v3SourceMap
  20. }
  21. } catch (err) {
  22. throwError(err)
  23. }
  24. }