jest-pegjs-transform.js 435 B

12345678910111213141516171819
  1. /* eslint-env node */
  2. const crypto = require('crypto');
  3. const peg = require('pegjs');
  4. function getCacheKey(fileData, _filePath, config, _options) {
  5. return crypto
  6. .createHash('md5')
  7. .update(fileData)
  8. .update(config.configString)
  9. .digest('hex');
  10. }
  11. function process(sourceText) {
  12. return {
  13. code: `module.exports = ${peg.generate(sourceText, {output: 'source'})}`,
  14. };
  15. }
  16. module.exports = {getCacheKey, process};