freeCodeCamp/curriculum/test/utils/extract-jsx-comments.js
Oliver Eyton-Williams 793fa8fb52 test: check replaced iff translatable comment
All translatable comments should be replaced, but nothing else.
2020-10-22 03:18:13 +05:30

19 lines
476 B
JavaScript

const acorn = require('acorn');
const jsx = require('acorn-jsx');
const { commentToData } = require('./comment-to-data');
const parser = acorn.Parser.extend(jsx());
function extractComments(jsx) {
let comments = [];
const file = { data: {} };
parser.parse(jsx, { onComment: comments, ecmaVersion: 2020 });
comments
.map(({ value }) => value.trim())
.forEach(comment => commentToData(file, comment));
return file.data;
}
module.exports = extractComments;