react-imported-component
Version:
I will import your component, and help to handle it
19 lines (18 loc) • 499 B
JavaScript
import vm from 'vm';
import { CLIENT_SIDE_ONLY } from '../configuration/constants';
const parseMagicComments = (str) => {
if (str.trim() === CLIENT_SIDE_ONLY) {
return {};
}
try {
const values = vm.runInNewContext(`(function(){return {${str}};})()`);
return values;
}
catch (e) {
return {};
}
};
export const commentsToConfiguration = (comments) => comments.reduce((acc, comment) => ({
...acc,
...parseMagicComments(comment),
}), {});