Files
actual/packages/loot-core/peg-transform.mjs
Davis Silverman b0c5a9389c Use Peggy instead of deprecated Peg.js (#934)
Hi there, `Peg.js` is unmaintained, so I figure you all would appreciate
if I replaced it with the drop-in replacement of Peggy. This is work I
am breaking out of #918.

Peggy adds new features like source map support that we could use,
although I do not include that in this change-set. It may be useful for
debugging changes to the .pegjs file we have.e
2023-04-22 20:16:07 -04:00

25 lines
584 B
JavaScript

// A peggy version of the pegjs-jest-transformer
// Transforms .pegjs compliant files to JS code.
import * as crypto from 'crypto';
import peg from 'peggy';
const transform = {
process(sourceText, sourcePath, _options) {
return `module.exports = ${peg.generate(sourceText, {
output: 'source-with-inline-map',
grammarSource: sourcePath,
})}`;
},
getCacheKey(sourceText, _sourcePath, options) {
return crypto
.createHash('md5')
.update(sourceText)
.update(options.configString)
.digest('hex');
},
};
export default transform;