jest-pegjs-transform.js 489 B

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