freeCodeCamp/curriculum/test/utils/extract-js-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

18 lines
426 B
JavaScript

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